* [PATCH 01/16] fs: remove unused field 'type' from struct fs_driver_d
2011-04-08 14:36 various cleanup patches Sascha Hauer
@ 2011-04-08 14:36 ` Sascha Hauer
2011-04-08 14:36 ` [PATCH 02/16] mci: make it compile without info support Sascha Hauer
` (14 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/cramfs/cramfs.c | 1 -
fs/devfs.c | 1 -
fs/ramfs.c | 1 -
include/fs.h | 5 -----
4 files changed, 0 insertions(+), 8 deletions(-)
diff --git a/fs/cramfs/cramfs.c b/fs/cramfs/cramfs.c
index 73a3759..b9ab50f 100644
--- a/fs/cramfs/cramfs.c
+++ b/fs/cramfs/cramfs.c
@@ -456,7 +456,6 @@ static void cramfs_remove(struct device_d *dev)
}
static struct fs_driver_d cramfs_driver = {
- .type = FS_TYPE_CRAMFS,
.open = cramfs_open,
.close = cramfs_close,
.read = cramfs_read,
diff --git a/fs/devfs.c b/fs/devfs.c
index 7019c8d..d40bf90 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -282,7 +282,6 @@ static void devfs_delete(struct device_d *dev)
}
static struct fs_driver_d devfs_driver = {
- .type = FS_TYPE_DEVFS,
.read = devfs_read,
.write = devfs_write,
.lseek = devfs_lseek,
diff --git a/fs/ramfs.c b/fs/ramfs.c
index 91001f1..db417e1 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -543,7 +543,6 @@ static void ramfs_remove(struct device_d *dev)
}
static struct fs_driver_d ramfs_driver = {
- .type = FS_TYPE_RAMFS,
.create = ramfs_create,
.unlink = ramfs_unlink,
.open = ramfs_open,
diff --git a/include/fs.h b/include/fs.h
index 4c03978..3834fe4 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -3,10 +3,6 @@
#include <driver.h>
-#define FS_TYPE_CRAMFS 1
-#define FS_TYPE_RAMFS 2
-#define FS_TYPE_DEVFS 3
-
#define PATH_MAX 1024 /* include/linux/limits.h */
struct partition;
@@ -41,7 +37,6 @@ typedef struct filep {
#define FS_DRIVER_NO_DEV 1
struct fs_driver_d {
- ulong type;
char *name;
int (*probe) (struct device_d *dev);
int (*mkdir)(struct device_d *dev, const char *pathname);
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 02/16] mci: make it compile without info support
2011-04-08 14:36 various cleanup patches Sascha Hauer
2011-04-08 14:36 ` [PATCH 01/16] fs: remove unused field 'type' from struct fs_driver_d Sascha Hauer
@ 2011-04-08 14:36 ` Sascha Hauer
2011-04-08 14:36 ` [PATCH 03/16] ubi: do not use filep Sascha Hauer
` (13 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mci/mci-core.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index f3d975d..8fd948c 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1338,7 +1338,9 @@ on_error:
static struct driver_d mci_driver = {
.name = "mci",
.probe = mci_probe,
+#ifdef CONFIG_MCI_INFO
.info = mci_info,
+#endif
};
static int mci_init(void)
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 03/16] ubi: do not use filep
2011-04-08 14:36 various cleanup patches Sascha Hauer
2011-04-08 14:36 ` [PATCH 01/16] fs: remove unused field 'type' from struct fs_driver_d Sascha Hauer
2011-04-08 14:36 ` [PATCH 02/16] mci: make it compile without info support Sascha Hauer
@ 2011-04-08 14:36 ` Sascha Hauer
2011-04-08 14:36 ` [PATCH 04/16] devfs: remove unused struct filep* argument from open/close Sascha Hauer
` (12 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/ubi/cdev.c | 8 +-------
1 files changed, 1 insertions(+), 7 deletions(-)
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 5520132..46e1cb5 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -9,7 +9,6 @@ struct ubi_volume_cdev_priv {
struct ubi_device *ubi;
struct ubi_volume *vol;
int updating;
- unsigned long mode;
};
static ssize_t ubi_volume_cdev_read(struct cdev *cdev, void *buf, size_t size,
@@ -86,12 +85,7 @@ static int ubi_volume_cdev_open(struct cdev *cdev, struct filep *f)
{
struct ubi_volume_cdev_priv *priv = cdev->priv;
- /* only allow read or write, but not both */
- if ((f->flags & O_ACCMODE) == O_RDWR)
- return -EINVAL;
-
priv->updating = 0;
- priv->mode = f->flags & O_ACCMODE;
return 0;
}
@@ -132,7 +126,7 @@ static off_t ubi_volume_cdev_lseek(struct cdev *cdev, off_t ofs)
struct ubi_volume_cdev_priv *priv = cdev->priv;
/* We can only update ubi volumes sequentially */
- if (priv->mode == O_WRONLY)
+ if (priv->updating)
return -EINVAL;
return ofs;
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 04/16] devfs: remove unused struct filep* argument from open/close
2011-04-08 14:36 various cleanup patches Sascha Hauer
` (2 preceding siblings ...)
2011-04-08 14:36 ` [PATCH 03/16] ubi: do not use filep Sascha Hauer
@ 2011-04-08 14:36 ` Sascha Hauer
2011-04-08 14:36 ` [PATCH 05/16] fs: implement flush function Sascha Hauer
` (11 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:36 UTC (permalink / raw)
To: barebox
the cdev layer is under the file layer, so it should not use
struct filep*.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/nand.c | 4 ++--
drivers/mtd/ubi/cdev.c | 4 ++--
fs/devfs.c | 4 ++--
include/driver.h | 4 ++--
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/commands/nand.c b/commands/nand.c
index 70e83aa..dc8fd9b 100644
--- a/commands/nand.c
+++ b/commands/nand.c
@@ -163,7 +163,7 @@ static int nand_bb_erase(struct cdev *cdev, size_t count, unsigned long offset)
}
#endif
-static int nand_bb_open(struct cdev *cdev, struct filep *f)
+static int nand_bb_open(struct cdev *cdev)
{
struct nand_bb *bb = cdev->priv;
@@ -178,7 +178,7 @@ static int nand_bb_open(struct cdev *cdev, struct filep *f)
return 0;
}
-static int nand_bb_close(struct cdev *cdev, struct filep *f)
+static int nand_bb_close(struct cdev *cdev)
{
struct nand_bb *bb = cdev->priv;
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 46e1cb5..96ae16e 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -81,7 +81,7 @@ static ssize_t ubi_volume_cdev_write(struct cdev* cdev, const void *buf,
return err;
}
-static int ubi_volume_cdev_open(struct cdev *cdev, struct filep *f)
+static int ubi_volume_cdev_open(struct cdev *cdev)
{
struct ubi_volume_cdev_priv *priv = cdev->priv;
@@ -90,7 +90,7 @@ static int ubi_volume_cdev_open(struct cdev *cdev, struct filep *f)
return 0;
}
-static int ubi_volume_cdev_close(struct cdev *cdev, struct filep *f)
+static int ubi_volume_cdev_close(struct cdev *cdev)
{
struct ubi_volume_cdev_priv *priv = cdev->priv;
struct ubi_volume *vol = priv->vol;
diff --git a/fs/devfs.c b/fs/devfs.c
index d40bf90..ddb3447 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -143,7 +143,7 @@ static int devfs_open(struct device_d *_dev, FILE *f, const char *filename)
f->inode = cdev;
if (cdev->ops->open) {
- ret = cdev->ops->open(cdev, f);
+ ret = cdev->ops->open(cdev);
if (ret)
return ret;
}
@@ -159,7 +159,7 @@ static int devfs_close(struct device_d *_dev, FILE *f)
int ret;
if (cdev->ops->close) {
- ret = cdev->ops->close(cdev, f);
+ ret = cdev->ops->close(cdev);
if (ret)
return ret;
}
diff --git a/include/driver.h b/include/driver.h
index b9edca0..bd00069 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -290,8 +290,8 @@ struct file_operations {
int (*ioctl)(struct cdev*, int, void *);
off_t (*lseek)(struct cdev*, off_t);
- int (*open)(struct cdev*, struct filep*);
- int (*close)(struct cdev*, struct filep*);
+ int (*open)(struct cdev*);
+ int (*close)(struct cdev*);
int (*erase)(struct cdev*, size_t count, unsigned long offset);
int (*protect)(struct cdev*, size_t count, unsigned long offset, int prot);
int (*memmap)(struct cdev*, void **map, int flags);
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 05/16] fs: implement flush function
2011-04-08 14:36 various cleanup patches Sascha Hauer
` (3 preceding siblings ...)
2011-04-08 14:36 ` [PATCH 04/16] devfs: remove unused struct filep* argument from open/close Sascha Hauer
@ 2011-04-08 14:36 ` Sascha Hauer
2011-04-08 14:36 ` [PATCH 06/16] devfs: factor out core devfs functionality Sascha Hauer
` (10 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:36 UTC (permalink / raw)
To: barebox
Once we have caching in file functions we need a way to sync
the the underlying devices.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/devfs.c | 11 +++++++++++
fs/fs.c | 20 ++++++++++++++++++++
include/driver.h | 1 +
include/fs.h | 2 ++
4 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/fs/devfs.c b/fs/devfs.c
index ddb3447..f82fddd 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -169,6 +169,16 @@ static int devfs_close(struct device_d *_dev, FILE *f)
return 0;
}
+static int devfs_flush(struct device_d *_dev, FILE *f)
+{
+ struct cdev *cdev = f->inode;
+
+ if (cdev->ops->flush)
+ return cdev->ops->flush(cdev);
+
+ return 0;
+}
+
static int partition_ioctl(struct cdev *cdev, int request, void *buf)
{
size_t offset;
@@ -287,6 +297,7 @@ static struct fs_driver_d devfs_driver = {
.lseek = devfs_lseek,
.open = devfs_open,
.close = devfs_close,
+ .flush = devfs_flush,
.ioctl = devfs_ioctl,
.opendir = devfs_opendir,
.readdir = devfs_readdir,
diff --git a/fs/fs.c b/fs/fs.c
index f684d45..059f67a 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -536,6 +536,26 @@ ssize_t write(int fd, const void *buf, size_t count)
}
EXPORT_SYMBOL(write);
+int flush(int fd)
+{
+ struct device_d *dev;
+ struct fs_driver_d *fsdrv;
+ FILE *f = &files[fd];
+
+ if (check_fd(fd))
+ return errno;
+
+ dev = f->dev;
+
+ fsdrv = (struct fs_driver_d *)dev->driver->type_data;
+ if (fsdrv->flush)
+ errno = fsdrv->flush(dev, f);
+ else
+ errno = 0;
+
+ return errno;
+}
+
off_t lseek(int fildes, off_t offset, int whence)
{
struct device_d *dev;
diff --git a/include/driver.h b/include/driver.h
index bd00069..14ccc6d 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -292,6 +292,7 @@ struct file_operations {
off_t (*lseek)(struct cdev*, off_t);
int (*open)(struct cdev*);
int (*close)(struct cdev*);
+ int (*flush)(struct cdev*);
int (*erase)(struct cdev*, size_t count, unsigned long offset);
int (*protect)(struct cdev*, size_t count, unsigned long offset, int prot);
int (*memmap)(struct cdev*, void **map, int flags);
diff --git a/include/fs.h b/include/fs.h
index 3834fe4..97d5995 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -53,6 +53,7 @@ struct fs_driver_d {
int (*close)(struct device_d *dev, FILE *f);
int (*read)(struct device_d *dev, FILE *f, void *buf, size_t size);
int (*write)(struct device_d *dev, FILE *f, const void *buf, size_t size);
+ int (*flush)(struct device_d *dev, FILE *f);
off_t (*lseek)(struct device_d *dev, FILE *f, off_t pos);
struct dir* (*opendir)(struct device_d *dev, const char *pathname);
@@ -98,6 +99,7 @@ int open(const char *pathname, int flags, ...);
int creat(const char *pathname, mode_t mode);
int unlink(const char *pathname);
int close(int fd);
+int flush(int fd);
int stat(const char *filename, struct stat *s);
int read(int fd, void *buf, size_t count);
int ioctl(int fd, int request, void *buf);
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 06/16] devfs: factor out core devfs functionality
2011-04-08 14:36 various cleanup patches Sascha Hauer
` (4 preceding siblings ...)
2011-04-08 14:36 ` [PATCH 05/16] fs: implement flush function Sascha Hauer
@ 2011-04-08 14:36 ` Sascha Hauer
2011-04-08 14:36 ` [PATCH 07/16] nand: remove unused header file Sascha Hauer
` (9 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:36 UTC (permalink / raw)
To: barebox
This makes it possible to compile without devfs. devfs_create/devfs_remove
is used by drivers and thus must still be present even without devfs support.
Also, this patch adds cdev_open/cdev_close/cdev_flush/cdev_ioctl calls to
work with devices without using the file api.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/Makefile | 1 +
fs/devfs-core.c | 236 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
fs/devfs.c | 167 +-------------------------------------
include/driver.h | 5 +
4 files changed, 244 insertions(+), 165 deletions(-)
create mode 100644 fs/devfs-core.c
diff --git a/fs/Makefile b/fs/Makefile
index 228af6e..4aa92ef 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -1,4 +1,5 @@
obj-$(CONFIG_FS_CRAMFS) += cramfs/
obj-$(CONFIG_FS_RAMFS) += ramfs.o
+obj-y += devfs-core.o
obj-$(CONFIG_FS_DEVFS) += devfs.o
obj-y += fs.o
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
new file mode 100644
index 0000000..519e18e
--- /dev/null
+++ b/fs/devfs-core.c
@@ -0,0 +1,236 @@
+/*
+ * devfs.c - a device file system for barebox
+ *
+ * Copyright (c) 2011 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <common.h>
+#include <driver.h>
+#include <errno.h>
+#include <malloc.h>
+#include <ioctl.h>
+#include <linux/err.h>
+#include <linux/mtd/mtd.h>
+
+LIST_HEAD(cdev_list);
+
+struct cdev *cdev_by_name(const char *filename)
+{
+ struct cdev *cdev;
+
+ list_for_each_entry(cdev, &cdev_list, list) {
+ if (!strcmp(cdev->name, filename))
+ return cdev;
+ }
+ return NULL;
+}
+
+struct cdev *cdev_open(const char *name, unsigned long flags)
+{
+ struct cdev *cdev = cdev_by_name(name);
+ int ret;
+
+ if (!cdev)
+ return NULL;
+
+ if (cdev->ops->open) {
+ ret = cdev->ops->open(cdev);
+ if (ret)
+ return NULL;
+ }
+
+ return cdev;
+}
+
+void cdev_close(struct cdev *cdev)
+{
+ if (cdev->ops->close)
+ cdev->ops->close(cdev);
+}
+
+ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, ulong offset, ulong flags)
+{
+ if (!cdev->ops->read)
+ return -ENOSYS;
+
+ return cdev->ops->read(cdev, buf, count, cdev->offset +offset, flags);
+}
+
+ssize_t cdev_write(struct cdev *cdev, const void *buf, size_t count, ulong offset, ulong flags)
+{
+ if (!cdev->ops->write)
+ return -ENOSYS;
+
+ return cdev->ops->write(cdev, buf, count, cdev->offset + offset, flags);
+}
+
+int cdev_flush(struct cdev *cdev)
+{
+ if (!cdev->ops->flush)
+ return 0;
+
+ return cdev->ops->flush(cdev);
+}
+
+static int partition_ioctl(struct cdev *cdev, int request, void *buf)
+{
+ size_t offset;
+ struct mtd_info_user *user = buf;
+
+ switch (request) {
+ case MEMSETBADBLOCK:
+ case MEMGETBADBLOCK:
+ offset = (off_t)buf;
+ offset += cdev->offset;
+ return cdev->ops->ioctl(cdev, request, (void *)offset);
+ case MEMGETINFO:
+ if (cdev->mtd) {
+ user->type = cdev->mtd->type;
+ user->flags = cdev->mtd->flags;
+ user->size = cdev->mtd->size;
+ user->erasesize = cdev->mtd->erasesize;
+ user->oobsize = cdev->mtd->oobsize;
+ user->mtd = cdev->mtd;
+ /* The below fields are obsolete */
+ user->ecctype = -1;
+ user->eccsize = 0;
+ return 0;
+ }
+ if (!cdev->ops->ioctl)
+ return -EINVAL;
+ return cdev->ops->ioctl(cdev, request, buf);
+ default:
+ return -EINVAL;
+ }
+}
+
+int cdev_ioctl(struct cdev *cdev, int request, void *buf)
+{
+ if (cdev->flags & DEVFS_IS_PARTITION)
+ return partition_ioctl(cdev, request, buf);
+
+ if (!cdev->ops->ioctl)
+ return -EINVAL;
+
+ return cdev->ops->ioctl(cdev, request, buf);
+}
+
+int cdev_erase(struct cdev *cdev, size_t count, unsigned long offset)
+{
+ if (!cdev->ops->erase)
+ return -ENOSYS;
+
+ return cdev->ops->erase(cdev, count, cdev->offset + offset);
+}
+
+int devfs_create(struct cdev *new)
+{
+ struct cdev *cdev;
+
+ cdev = cdev_by_name(new->name);
+ if (cdev)
+ return -EEXIST;
+
+ list_add_tail(&new->list, &cdev_list);
+ if (new->dev)
+ list_add_tail(&new->devices_list, &new->dev->cdevs);
+
+ return 0;
+}
+
+int devfs_remove(struct cdev *cdev)
+{
+ if (cdev->open)
+ return -EBUSY;
+
+ list_del(&cdev->list);
+ if (cdev->dev)
+ list_del(&cdev->devices_list);
+
+ return 0;
+}
+
+int devfs_add_partition(const char *devname, unsigned long offset, size_t size,
+ int flags, const char *name)
+{
+ struct cdev *cdev, *new;
+
+ cdev = cdev_by_name(name);
+ if (cdev)
+ return -EEXIST;
+
+ cdev = cdev_by_name(devname);
+ if (!cdev)
+ return -ENOENT;
+
+ if (offset + size > cdev->size)
+ return -EINVAL;
+
+ new = xzalloc(sizeof (*new));
+ new->name = strdup(name);
+ new->ops = cdev->ops;
+ new->priv = cdev->priv;
+ new->size = size;
+ new->offset = offset + cdev->offset;
+ new->dev = cdev->dev;
+ new->flags = flags | DEVFS_IS_PARTITION;
+
+#ifdef CONFIG_PARTITION_NEED_MTD
+ if (cdev->mtd) {
+ new->mtd = mtd_add_partition(cdev->mtd, offset, size, flags, name);
+ if (IS_ERR(new->mtd)) {
+ int ret = PTR_ERR(new->mtd);
+ free(new);
+ return ret;
+ }
+ }
+#endif
+
+ devfs_create(new);
+
+ return 0;
+}
+
+int devfs_del_partition(const char *name)
+{
+ struct cdev *cdev;
+ int ret;
+
+ cdev = cdev_by_name(name);
+ if (!cdev)
+ return -ENOENT;
+
+ if (!(cdev->flags & DEVFS_IS_PARTITION))
+ return -EINVAL;
+ if (cdev->flags & DEVFS_PARTITION_FIXED)
+ return -EPERM;
+
+#ifdef CONFIG_PARTITION_NEED_MTD
+ if (cdev->mtd)
+ mtd_del_partition(cdev->mtd);
+#endif
+
+ ret = devfs_remove(cdev);
+ if (ret)
+ return ret;
+
+ free(cdev->name);
+ free(cdev);
+
+ return 0;
+}
diff --git a/fs/devfs.c b/fs/devfs.c
index f82fddd..07ca16c 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -36,34 +36,7 @@
#include <linux/mtd/mtd-abi.h>
#include <partition.h>
-static LIST_HEAD(cdev_list);
-
-struct cdev *cdev_by_name(const char *filename)
-{
- struct cdev *cdev;
-
- list_for_each_entry(cdev, &cdev_list, list) {
- if (!strcmp(cdev->name, filename))
- return cdev;
- }
- return NULL;
-}
-
-ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, ulong offset, ulong flags)
-{
- if (!cdev->ops->read)
- return -ENOSYS;
-
- return cdev->ops->read(cdev, buf, count, cdev->offset +offset, flags);
-}
-
-ssize_t cdev_write(struct cdev *cdev, const void *buf, size_t count, ulong offset, ulong flags)
-{
- if (!cdev->ops->write)
- return -ENOSYS;
-
- return cdev->ops->write(cdev, buf, count, cdev->offset + offset, flags);
-}
+extern struct list_head cdev_list;
static int devfs_read(struct device_d *_dev, FILE *f, void *buf, size_t size)
{
@@ -179,49 +152,11 @@ static int devfs_flush(struct device_d *_dev, FILE *f)
return 0;
}
-static int partition_ioctl(struct cdev *cdev, int request, void *buf)
-{
- size_t offset;
- struct mtd_info_user *user = buf;
-
- switch (request) {
- case MEMSETBADBLOCK:
- case MEMGETBADBLOCK:
- offset = (off_t)buf;
- offset += cdev->offset;
- return cdev->ops->ioctl(cdev, request, (void *)offset);
- case MEMGETINFO:
- if (cdev->mtd) {
- user->type = cdev->mtd->type;
- user->flags = cdev->mtd->flags;
- user->size = cdev->mtd->size;
- user->erasesize = cdev->mtd->erasesize;
- user->oobsize = cdev->mtd->oobsize;
- user->mtd = cdev->mtd;
- /* The below fields are obsolete */
- user->ecctype = -1;
- user->eccsize = 0;
- return 0;
- }
- if (!cdev->ops->ioctl)
- return -EINVAL;
- return cdev->ops->ioctl(cdev, request, buf);
- default:
- return -EINVAL;
- }
-}
-
static int devfs_ioctl(struct device_d *_dev, FILE *f, int request, void *buf)
{
struct cdev *cdev = f->inode;
- if (cdev->flags & DEVFS_IS_PARTITION)
- return partition_ioctl(cdev, request, buf);
-
- if (!cdev->ops->ioctl)
- return -EINVAL;
-
- return cdev->ops->ioctl(cdev, request, buf);
+ return cdev_ioctl(cdev, request, buf);
}
static int devfs_truncate(struct device_d *dev, FILE *f, ulong size)
@@ -322,101 +257,3 @@ static int devfs_init(void)
}
coredevice_initcall(devfs_init);
-
-int devfs_create(struct cdev *new)
-{
- struct cdev *cdev;
-
- cdev = cdev_by_name(new->name);
- if (cdev)
- return -EEXIST;
-
- list_add_tail(&new->list, &cdev_list);
- if (new->dev)
- list_add_tail(&new->devices_list, &new->dev->cdevs);
-
- return 0;
-}
-
-int devfs_remove(struct cdev *cdev)
-{
- if (cdev->open)
- return -EBUSY;
-
- list_del(&cdev->list);
- if (cdev->dev)
- list_del(&cdev->devices_list);
-
- return 0;
-}
-
-int devfs_add_partition(const char *devname, unsigned long offset, size_t size,
- int flags, const char *name)
-{
- struct cdev *cdev, *new;
-
- cdev = cdev_by_name(name);
- if (cdev)
- return -EEXIST;
-
- cdev = cdev_by_name(devname);
- if (!cdev)
- return -ENOENT;
-
- if (offset + size > cdev->size)
- return -EINVAL;
-
- new = xzalloc(sizeof (*new));
- new->name = strdup(name);
- new->ops = cdev->ops;
- new->priv = cdev->priv;
- new->size = size;
- new->offset = offset + cdev->offset;
- new->dev = cdev->dev;
- new->flags = flags | DEVFS_IS_PARTITION;
-
-#ifdef CONFIG_PARTITION_NEED_MTD
- if (cdev->mtd) {
- new->mtd = mtd_add_partition(cdev->mtd, offset, size, flags, name);
- if (IS_ERR(new->mtd)) {
- int ret = PTR_ERR(new->mtd);
- free(new);
- return ret;
- }
- }
-#endif
-
- devfs_create(new);
-
- return 0;
-}
-
-int devfs_del_partition(const char *name)
-{
- struct cdev *cdev;
- int ret;
-
- cdev = cdev_by_name(name);
- if (!cdev)
- return -ENOENT;
-
- if (!(cdev->flags & DEVFS_IS_PARTITION))
- return -EINVAL;
- if (cdev->flags & DEVFS_PARTITION_FIXED)
- return -EPERM;
-
-#ifdef CONFIG_PARTITION_NEED_MTD
- if (cdev->mtd)
- mtd_del_partition(cdev->mtd);
-#endif
-
- ret = devfs_remove(cdev);
- if (ret)
- return ret;
-
- free(cdev->name);
- free(cdev);
-
- return 0;
-}
-
diff --git a/include/driver.h b/include/driver.h
index 14ccc6d..6a4d45e 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -315,8 +315,13 @@ struct cdev {
int devfs_create(struct cdev *);
int devfs_remove(struct cdev *);
struct cdev *cdev_by_name(const char *filename);
+struct cdev *cdev_open(const char *name, unsigned long flags);
+void cdev_close(struct cdev *cdev);
+int cdev_flush(struct cdev *cdev);
ssize_t cdev_read(struct cdev *cdev, void *buf, size_t count, ulong offset, ulong flags);
ssize_t cdev_write(struct cdev *cdev, const void *buf, size_t count, ulong offset, ulong flags);
+int cdev_ioctl(struct cdev *cdev, int cmd, void *buf);
+int cdev_erase(struct cdev *cdev, size_t count, unsigned long offset);
#define DEVFS_PARTITION_FIXED (1 << 0)
#define DEVFS_PARTITION_READONLY (1 << 1)
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 07/16] nand: remove unused header file
2011-04-08 14:36 various cleanup patches Sascha Hauer
` (5 preceding siblings ...)
2011-04-08 14:36 ` [PATCH 06/16] devfs: factor out core devfs functionality Sascha Hauer
@ 2011-04-08 14:36 ` Sascha Hauer
2011-04-08 14:36 ` [PATCH 08/16] startup: we can only mount root and devfs when compiled in Sascha Hauer
` (8 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/linux/mtd/compat.h | 46 --------------------------------------------
1 files changed, 0 insertions(+), 46 deletions(-)
delete mode 100644 include/linux/mtd/compat.h
diff --git a/include/linux/mtd/compat.h b/include/linux/mtd/compat.h
deleted file mode 100644
index a99d86e..0000000
--- a/include/linux/mtd/compat.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#ifndef _LINUX_COMPAT_H_
-#define _LINUX_COMPAT_H_
-
-#define __user
-#define __iomem
-
-#define ndelay(x) udelay(1)
-
-#define printk printf
-
-#define KERN_EMERG
-#define KERN_ALERT
-#define KERN_CRIT
-#define KERN_ERR
-#define KERN_WARNING
-#define KERN_NOTICE
-#define KERN_INFO
-#define KERN_DEBUG
-
-#define kmalloc(size, flags) malloc(size)
-#define kfree(ptr) free(ptr)
-
-/*
- * ..and if you can't take the strict
- * types, you can specify one yourself.
- *
- * Or not use min/max at all, of course.
- */
-#define min_t(type,x,y) \
- ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
-#define max_t(type,x,y) \
- ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
-
-#ifndef BUG
-#define BUG() do { \
- printf("barebox BUG at %s:%d!\n", __FILE__, __LINE__); \
-} while (0)
-
-#define BUG_ON(condition) do { if (condition) BUG(); } while(0)
-#endif /* BUG */
-
-#define likely(x) __builtin_expect(!!(x), 1)
-#define unlikely(x) __builtin_expect(!!(x), 0)
-
-#define PAGE_SIZE 4096
-#endif
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 08/16] startup: we can only mount root and devfs when compiled in
2011-04-08 14:36 various cleanup patches Sascha Hauer
` (6 preceding siblings ...)
2011-04-08 14:36 ` [PATCH 07/16] nand: remove unused header file Sascha Hauer
@ 2011-04-08 14:36 ` Sascha Hauer
2011-04-08 14:36 ` [PATCH 09/16] nand: remove unused nand_util file Sascha Hauer
` (7 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/startup.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/common/startup.c b/common/startup.c
index aa76cb7..b487c5b 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -103,6 +103,7 @@ static int register_default_env(void)
device_initcall(register_default_env);
#endif
+#if defined CONFIG_FS_RAMFS && defined CONFIG_FS_DEVFS
static int mount_root(void)
{
mount("none", "ramfs", "/");
@@ -111,6 +112,7 @@ static int mount_root(void)
return 0;
}
fs_initcall(mount_root);
+#endif
void start_barebox (void)
{
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 09/16] nand: remove unused nand_util file
2011-04-08 14:36 various cleanup patches Sascha Hauer
` (7 preceding siblings ...)
2011-04-08 14:36 ` [PATCH 08/16] startup: we can only mount root and devfs when compiled in Sascha Hauer
@ 2011-04-08 14:36 ` Sascha Hauer
2011-04-08 14:36 ` [PATCH 10/16] move version_string to seperate file Sascha Hauer
` (6 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/nand/Makefile | 1 -
drivers/mtd/nand/nand_util.c | 858 ------------------------------------------
2 files changed, 0 insertions(+), 859 deletions(-)
delete mode 100644 drivers/mtd/nand/nand_util.c
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index fb92f89..3a31bc1 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -15,4 +15,3 @@ obj-$(CONFIG_NAND_IMX) += nand_imx.o
obj-$(CONFIG_NAND_OMAP_GPMC) += nand_omap_gpmc.o nand_omap_bch_decoder.o
obj-$(CONFIG_NAND_ATMEL) += atmel_nand.o
obj-$(CONFIG_NAND_S3C24X0) += nand_s3c2410.o
-#obj-$(CONFIG_NAND) += nand_util.o
diff --git a/drivers/mtd/nand/nand_util.c b/drivers/mtd/nand/nand_util.c
deleted file mode 100644
index d57294e..0000000
--- a/drivers/mtd/nand/nand_util.c
+++ /dev/null
@@ -1,858 +0,0 @@
-/*
- * drivers/nand/nand_util.c
- *
- * Copyright (C) 2006 by Weiss-Electronic GmbH.
- * All rights reserved.
- *
- * @author: Guido Classen <clagix@gmail.com>
- * @descr: NAND Flash support
- * @references: borrowed heavily from Linux mtd-utils code:
- * flash_eraseall.c by Arcom Control System Ltd
- * nandwrite.c by Steven J. Hill (sjhill@realitydiluted.com)
- * and Thomas Gleixner (tglx@linutronix.de)
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version
- * 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- *
- */
-
-#include <common.h>
-#include <command.h>
-#include <watchdog.h>
-#include <malloc.h>
-
-#include <nand.h>
-//#include <jffs2/jffs2.h>
-
-typedef struct erase_info erase_info_t;
-typedef struct mtd_info mtd_info_t;
-
-/* support only for native endian JFFS2 */
-#define cpu_to_je16(x) (x)
-#define cpu_to_je32(x) (x)
-
-/*****************************************************************************/
-static int nand_block_bad_scrub(struct mtd_info *mtd, loff_t ofs, int getchip)
-{
- return 0;
-}
-
-/**
- * nand_erase_opts: - erase NAND flash with support for various options
- * (jffs2 formating)
- *
- * @param meminfo NAND device to erase
- * @param opts options, @see struct nand_erase_options
- * @return 0 in case of success
- *
- * This code is ported from flash_eraseall.c from Linux mtd utils by
- * Arcom Control System Ltd.
- */
-int nand_erase_opts(nand_info_t *meminfo, const nand_erase_options_t *opts)
-{
- struct jffs2_unknown_node cleanmarker;
- int clmpos = 0;
- int clmlen = 8;
- erase_info_t erase;
- ulong erase_length;
- int isNAND;
- int bbtest = 1;
- int result;
- int percent_complete = -1;
- int (*nand_block_bad_old)(struct mtd_info *, loff_t, int) = NULL;
- const char *mtd_device = meminfo->name;
-
- memset(&erase, 0, sizeof(erase));
-
- erase.mtd = meminfo;
- erase.len = meminfo->erasesize;
- erase.addr = opts->offset;
- erase_length = opts->length;
-
- isNAND = meminfo->type == MTD_NANDFLASH ? 1 : 0;
-
- if (opts->jffs2) {
- cleanmarker.magic = cpu_to_je16 (JFFS2_MAGIC_BITMASK);
- cleanmarker.nodetype = cpu_to_je16 (JFFS2_NODETYPE_CLEANMARKER);
- if (isNAND) {
- struct nand_oobinfo *oobinfo = &meminfo->oobinfo;
-
- /* check for autoplacement */
- if (oobinfo->useecc == MTD_NANDECC_AUTOPLACE) {
- /* get the position of the free bytes */
- if (!oobinfo->oobfree[0][1]) {
- printf(" Eeep. Autoplacement selected "
- "and no empty space in oob\n");
- return -1;
- }
- clmpos = oobinfo->oobfree[0][0];
- clmlen = oobinfo->oobfree[0][1];
- if (clmlen > 8)
- clmlen = 8;
- } else {
- /* legacy mode */
- switch (meminfo->oobsize) {
- case 8:
- clmpos = 6;
- clmlen = 2;
- break;
- case 16:
- clmpos = 8;
- clmlen = 8;
- break;
- case 64:
- clmpos = 16;
- clmlen = 8;
- break;
- }
- }
-
- cleanmarker.totlen = cpu_to_je32(8);
- } else {
- cleanmarker.totlen =
- cpu_to_je32(sizeof(struct jffs2_unknown_node));
- }
- cleanmarker.hdr_crc = cpu_to_je32(
- crc32_no_comp(0, (unsigned char *) &cleanmarker,
- sizeof(struct jffs2_unknown_node) - 4));
- }
-
- /* scrub option allows to erase badblock. To prevent internal
- * check from erase() method, set block check method to dummy
- * and disable bad block table while erasing.
- */
- if (opts->scrub) {
- struct nand_chip *priv_nand = meminfo->priv;
-
- nand_block_bad_old = priv_nand->block_bad;
- priv_nand->block_bad = nand_block_bad_scrub;
- /* we don't need the bad block table anymore...
- * after scrub, there are no bad blocks left!
- */
- if (priv_nand->bbt) {
- kfree(priv_nand->bbt);
- }
- priv_nand->bbt = NULL;
- }
-
- for (;
- erase.addr < opts->offset + erase_length;
- erase.addr += meminfo->erasesize) {
-
- WATCHDOG_RESET ();
-
- if (!opts->scrub && bbtest) {
- int ret = meminfo->block_isbad(meminfo, erase.addr);
- if (ret > 0) {
- if (!opts->quiet)
- printf("\rSkipping bad block at "
- "0x%08x "
- " \n",
- erase.addr);
- continue;
-
- } else if (ret < 0) {
- printf("\n%s: MTD get bad block failed: %d\n",
- mtd_device,
- ret);
- return -1;
- }
- }
-
- result = meminfo->erase(meminfo, &erase);
- if (result != 0) {
- printf("\n%s: MTD Erase failure: %d\n",
- mtd_device, result);
- continue;
- }
-
- /* format for JFFS2 ? */
- if (opts->jffs2) {
-
- /* write cleanmarker */
- if (isNAND) {
- size_t written;
- result = meminfo->write_oob(meminfo,
- erase.addr + clmpos,
- clmlen,
- &written,
- (unsigned char *)
- &cleanmarker);
- if (result != 0) {
- printf("\n%s: MTD writeoob failure: %d\n",
- mtd_device, result);
- continue;
- }
- } else {
- printf("\n%s: this erase routine only supports"
- " NAND devices!\n",
- mtd_device);
- }
- }
-
- if (!opts->quiet) {
- int percent = (int)
- ((unsigned long long)
- (erase.addr+meminfo->erasesize-opts->offset)
- * 100 / erase_length);
-
- /* output progress message only at whole percent
- * steps to reduce the number of messages printed
- * on (slow) serial consoles
- */
- if (percent != percent_complete) {
- percent_complete = percent;
-
- printf("\rErasing at 0x%x -- %3d%% complete.",
- erase.addr, percent);
-
- if (opts->jffs2 && result == 0)
- printf(" Cleanmarker written at 0x%x.",
- erase.addr);
- }
- }
- }
- if (!opts->quiet)
- printf("\n");
-
- if (nand_block_bad_old) {
- struct nand_chip *priv_nand = meminfo->priv;
-
- priv_nand->block_bad = nand_block_bad_old;
- priv_nand->scan_bbt(meminfo);
- }
-
- return 0;
-}
-
-#define MAX_PAGE_SIZE 2048
-#define MAX_OOB_SIZE 64
-
-/*
- * buffer array used for writing data
- */
-static unsigned char data_buf[MAX_PAGE_SIZE];
-static unsigned char oob_buf[MAX_OOB_SIZE];
-
-/* OOB layouts to pass into the kernel as default */
-static struct nand_oobinfo none_oobinfo = {
- .useecc = MTD_NANDECC_OFF,
-};
-
-static struct nand_oobinfo jffs2_oobinfo = {
- .useecc = MTD_NANDECC_PLACE,
- .eccbytes = 6,
- .eccpos = { 0, 1, 2, 3, 6, 7 }
-};
-
-static struct nand_oobinfo yaffs_oobinfo = {
- .useecc = MTD_NANDECC_PLACE,
- .eccbytes = 6,
- .eccpos = { 8, 9, 10, 13, 14, 15}
-};
-
-static struct nand_oobinfo autoplace_oobinfo = {
- .useecc = MTD_NANDECC_AUTOPLACE
-};
-
-/**
- * nand_write_opts: - write image to NAND flash with support for various options
- *
- * @param meminfo NAND device to erase
- * @param opts write options (@see nand_write_options)
- * @return 0 in case of success
- *
- * This code is ported from nandwrite.c from Linux mtd utils by
- * Steven J. Hill and Thomas Gleixner.
- */
-int nand_write_opts(nand_info_t *meminfo, const nand_write_options_t *opts)
-{
- int imglen = 0;
- int pagelen;
- int baderaseblock;
- int blockstart = -1;
- loff_t offs;
- int readlen;
- int oobinfochanged = 0;
- int percent_complete = -1;
- struct nand_oobinfo old_oobinfo;
- ulong mtdoffset = opts->offset;
- ulong erasesize_blockalign;
- u_char *buffer = opts->buffer;
- size_t written;
- int result;
-
- if (opts->pad && opts->writeoob) {
- printf("Can't pad when oob data is present.\n");
- return -1;
- }
-
- /* set erasesize to specified number of blocks - to match
- * jffs2 (virtual) block size */
- if (opts->blockalign == 0) {
- erasesize_blockalign = meminfo->erasesize;
- } else {
- erasesize_blockalign = meminfo->erasesize * opts->blockalign;
- }
-
- /* make sure device page sizes are valid */
- if (!(meminfo->oobsize == 16 && meminfo->oobblock == 512)
- && !(meminfo->oobsize == 8 && meminfo->oobblock == 256)
- && !(meminfo->oobsize == 64 && meminfo->oobblock == 2048)) {
- printf("Unknown flash (not normal NAND)\n");
- return -1;
- }
-
- /* read the current oob info */
- memcpy(&old_oobinfo, &meminfo->oobinfo, sizeof(old_oobinfo));
-
- /* write without ecc? */
- if (opts->noecc) {
- memcpy(&meminfo->oobinfo, &none_oobinfo,
- sizeof(meminfo->oobinfo));
- oobinfochanged = 1;
- }
-
- /* autoplace ECC? */
- if (opts->autoplace && (old_oobinfo.useecc != MTD_NANDECC_AUTOPLACE)) {
-
- memcpy(&meminfo->oobinfo, &autoplace_oobinfo,
- sizeof(meminfo->oobinfo));
- oobinfochanged = 1;
- }
-
- /* force OOB layout for jffs2 or yaffs? */
- if (opts->forcejffs2 || opts->forceyaffs) {
- struct nand_oobinfo *oobsel =
- opts->forcejffs2 ? &jffs2_oobinfo : &yaffs_oobinfo;
-
- if (meminfo->oobsize == 8) {
- if (opts->forceyaffs) {
- printf("YAFSS cannot operate on "
- "256 Byte page size\n");
- goto restoreoob;
- }
- /* Adjust number of ecc bytes */
- jffs2_oobinfo.eccbytes = 3;
- }
-
- memcpy(&meminfo->oobinfo, oobsel, sizeof(meminfo->oobinfo));
- }
-
- /* get image length */
- imglen = opts->length;
- pagelen = meminfo->oobblock
- + ((opts->writeoob != 0) ? meminfo->oobsize : 0);
-
- /* check, if file is pagealigned */
- if ((!opts->pad) && ((imglen % pagelen) != 0)) {
- printf("Input block length is not page aligned\n");
- goto restoreoob;
- }
-
- /* check, if length fits into device */
- if (((imglen / pagelen) * meminfo->oobblock)
- > (meminfo->size - opts->offset)) {
- printf("Image %d bytes, NAND page %d bytes, "
- "OOB area %u bytes, device size %u bytes\n",
- imglen, pagelen, meminfo->oobblock, meminfo->size);
- printf("Input block does not fit into device\n");
- goto restoreoob;
- }
-
- if (!opts->quiet)
- printf("\n");
-
- /* get data from input and write to the device */
- while (imglen && (mtdoffset < meminfo->size)) {
-
- WATCHDOG_RESET ();
-
- /*
- * new eraseblock, check for bad block(s). Stay in the
- * loop to be sure if the offset changes because of
- * a bad block, that the next block that will be
- * written to is also checked. Thus avoiding errors if
- * the block(s) after the skipped block(s) is also bad
- * (number of blocks depending on the blockalign
- */
- while (blockstart != (mtdoffset & (~erasesize_blockalign+1))) {
- blockstart = mtdoffset & (~erasesize_blockalign+1);
- offs = blockstart;
- baderaseblock = 0;
-
- /* check all the blocks in an erase block for
- * bad blocks */
- do {
- int ret = meminfo->block_isbad(meminfo, offs);
-
- if (ret < 0) {
- printf("Bad block check failed\n");
- goto restoreoob;
- }
- if (ret == 1) {
- baderaseblock = 1;
- if (!opts->quiet)
- printf("\rBad block at 0x%lx "
- "in erase block from "
- "0x%x will be skipped\n",
- (long) offs,
- blockstart);
- }
-
- if (baderaseblock) {
- mtdoffset = blockstart
- + erasesize_blockalign;
- }
- offs += erasesize_blockalign
- / opts->blockalign;
- } while (offs < blockstart + erasesize_blockalign);
- }
-
- readlen = meminfo->oobblock;
- if (opts->pad && (imglen < readlen)) {
- readlen = imglen;
- memset(data_buf + readlen, 0xff,
- meminfo->oobblock - readlen);
- }
-
- /* read page data from input memory buffer */
- memcpy(data_buf, buffer, readlen);
- buffer += readlen;
-
- if (opts->writeoob) {
- /* read OOB data from input memory block, exit
- * on failure */
- memcpy(oob_buf, buffer, meminfo->oobsize);
- buffer += meminfo->oobsize;
-
- /* write OOB data first, as ecc will be placed
- * in there*/
- result = meminfo->write_oob(meminfo,
- mtdoffset,
- meminfo->oobsize,
- &written,
- (unsigned char *)
- &oob_buf);
-
- if (result != 0) {
- printf("\nMTD writeoob failure: %d\n",
- result);
- goto restoreoob;
- }
- imglen -= meminfo->oobsize;
- }
-
- /* write out the page data */
- result = meminfo->write(meminfo,
- mtdoffset,
- meminfo->oobblock,
- &written,
- (unsigned char *) &data_buf);
-
- if (result != 0) {
- printf("writing NAND page at offset 0x%lx failed\n",
- mtdoffset);
- goto restoreoob;
- }
- imglen -= readlen;
-
- if (!opts->quiet) {
- int percent = (int)
- ((unsigned long long)
- (opts->length-imglen) * 100
- / opts->length);
- /* output progress message only at whole percent
- * steps to reduce the number of messages printed
- * on (slow) serial consoles
- */
- if (percent != percent_complete) {
- printf("\rWriting data at 0x%x "
- "-- %3d%% complete.",
- mtdoffset, percent);
- percent_complete = percent;
- }
- }
-
- mtdoffset += meminfo->oobblock;
- }
-
- if (!opts->quiet)
- printf("\n");
-
-restoreoob:
- if (oobinfochanged) {
- memcpy(&meminfo->oobinfo, &old_oobinfo,
- sizeof(meminfo->oobinfo));
- }
-
- if (imglen > 0) {
- printf("Data did not fit into device, due to bad blocks\n");
- return -1;
- }
-
- /* return happy */
- return 0;
-}
-
-/**
- * nand_read_opts: - read image from NAND flash with support for various options
- *
- * @param meminfo NAND device to erase
- * @param opts read options (@see struct nand_read_options)
- * @return 0 in case of success
- *
- */
-int nand_read_opts(nand_info_t *meminfo, const nand_read_options_t *opts)
-{
- int imglen = opts->length;
- int pagelen;
- int baderaseblock;
- int blockstart = -1;
- int percent_complete = -1;
- loff_t offs;
- size_t readlen;
- ulong mtdoffset = opts->offset;
- u_char *buffer = opts->buffer;
- int result;
-
- /* make sure device page sizes are valid */
- if (!(meminfo->oobsize == 16 && meminfo->oobblock == 512)
- && !(meminfo->oobsize == 8 && meminfo->oobblock == 256)
- && !(meminfo->oobsize == 64 && meminfo->oobblock == 2048)) {
- printf("Unknown flash (not normal NAND)\n");
- return -1;
- }
-
- pagelen = meminfo->oobblock
- + ((opts->readoob != 0) ? meminfo->oobsize : 0);
-
- /* check, if length is not larger than device */
- if (((imglen / pagelen) * meminfo->oobblock)
- > (meminfo->size - opts->offset)) {
- printf("Image %d bytes, NAND page %d bytes, "
- "OOB area %u bytes, device size %u bytes\n",
- imglen, pagelen, meminfo->oobblock, meminfo->size);
- printf("Input block is larger than device\n");
- return -1;
- }
-
- if (!opts->quiet)
- printf("\n");
-
- /* get data from input and write to the device */
- while (imglen && (mtdoffset < meminfo->size)) {
-
- WATCHDOG_RESET ();
-
- /*
- * new eraseblock, check for bad block(s). Stay in the
- * loop to be sure if the offset changes because of
- * a bad block, that the next block that will be
- * written to is also checked. Thus avoiding errors if
- * the block(s) after the skipped block(s) is also bad
- * (number of blocks depending on the blockalign
- */
- while (blockstart != (mtdoffset & (~meminfo->erasesize+1))) {
- blockstart = mtdoffset & (~meminfo->erasesize+1);
- offs = blockstart;
- baderaseblock = 0;
-
- /* check all the blocks in an erase block for
- * bad blocks */
- do {
- int ret = meminfo->block_isbad(meminfo, offs);
-
- if (ret < 0) {
- printf("Bad block check failed\n");
- return -1;
- }
- if (ret == 1) {
- baderaseblock = 1;
- if (!opts->quiet)
- printf("\rBad block at 0x%lx "
- "in erase block from "
- "0x%x will be skipped\n",
- (long) offs,
- blockstart);
- }
-
- if (baderaseblock) {
- mtdoffset = blockstart
- + meminfo->erasesize;
- }
- offs += meminfo->erasesize;
-
- } while (offs < blockstart + meminfo->erasesize);
- }
-
-
- /* read page data to memory buffer */
- result = meminfo->read(meminfo,
- mtdoffset,
- meminfo->oobblock,
- &readlen,
- (unsigned char *) &data_buf);
-
- if (result != 0) {
- printf("reading NAND page at offset 0x%lx failed\n",
- mtdoffset);
- return -1;
- }
-
- if (imglen < readlen) {
- readlen = imglen;
- }
-
- memcpy(buffer, data_buf, readlen);
- buffer += readlen;
- imglen -= readlen;
-
- if (opts->readoob) {
- result = meminfo->read_oob(meminfo,
- mtdoffset,
- meminfo->oobsize,
- &readlen,
- (unsigned char *)
- &oob_buf);
-
- if (result != 0) {
- printf("\nMTD readoob failure: %d\n",
- result);
- return -1;
- }
-
-
- if (imglen < readlen) {
- readlen = imglen;
- }
-
- memcpy(buffer, oob_buf, readlen);
-
- buffer += readlen;
- imglen -= readlen;
- }
-
- if (!opts->quiet) {
- int percent = (int)
- ((unsigned long long)
- (opts->length-imglen) * 100
- / opts->length);
- /* output progress message only at whole percent
- * steps to reduce the number of messages printed
- * on (slow) serial consoles
- */
- if (percent != percent_complete) {
- if (!opts->quiet)
- printf("\rReading data from 0x%x "
- "-- %3d%% complete.",
- mtdoffset, percent);
- percent_complete = percent;
- }
- }
-
- mtdoffset += meminfo->oobblock;
- }
-
- if (!opts->quiet)
- printf("\n");
-
- if (imglen > 0) {
- printf("Could not read entire image due to bad blocks\n");
- return -1;
- }
-
- /* return happy */
- return 0;
-}
-
-/******************************************************************************
- * Support for locking / unlocking operations of some NAND devices
- *****************************************************************************/
-
-#define NAND_CMD_LOCK 0x2a
-#define NAND_CMD_LOCK_TIGHT 0x2c
-#define NAND_CMD_UNLOCK1 0x23
-#define NAND_CMD_UNLOCK2 0x24
-#define NAND_CMD_LOCK_STATUS 0x7a
-
-/**
- * nand_lock: Set all pages of NAND flash chip to the LOCK or LOCK-TIGHT
- * state
- *
- * @param meminfo nand mtd instance
- * @param tight bring device in lock tight mode
- *
- * @return 0 on success, -1 in case of error
- *
- * The lock / lock-tight command only applies to the whole chip. To get some
- * parts of the chip lock and others unlocked use the following sequence:
- *
- * - Lock all pages of the chip using nand_lock(mtd, 0) (or the lockpre pin)
- * - Call nand_unlock() once for each consecutive area to be unlocked
- * - If desired: Bring the chip to the lock-tight state using nand_lock(mtd, 1)
- *
- * If the device is in lock-tight state software can't change the
- * current active lock/unlock state of all pages. nand_lock() / nand_unlock()
- * calls will fail. It is only posible to leave lock-tight state by
- * an hardware signal (low pulse on _WP pin) or by power down.
- */
-int nand_lock(nand_info_t *meminfo, int tight)
-{
- int ret = 0;
- int status;
- struct nand_chip *this = meminfo->priv;
-
- /* select the NAND device */
- this->select_chip(meminfo, 0);
-
- this->cmdfunc(meminfo,
- (tight ? NAND_CMD_LOCK_TIGHT : NAND_CMD_LOCK),
- -1, -1);
-
- /* call wait ready function */
- status = this->waitfunc(meminfo, this, FL_WRITING);
-
- /* see if device thinks it succeeded */
- if (status & 0x01) {
- ret = -1;
- }
-
- /* de-select the NAND device */
- this->select_chip(meminfo, -1);
- return ret;
-}
-
-/**
- * nand_get_lock_status: - query current lock state from one page of NAND
- * flash
- *
- * @param meminfo nand mtd instance
- * @param offset page address to query (muss be page aligned!)
- *
- * @return -1 in case of error
- * >0 lock status:
- * bitfield with the following combinations:
- * NAND_LOCK_STATUS_TIGHT: page in tight state
- * NAND_LOCK_STATUS_LOCK: page locked
- * NAND_LOCK_STATUS_UNLOCK: page unlocked
- *
- */
-int nand_get_lock_status(nand_info_t *meminfo, ulong offset)
-{
- int ret = 0;
- int chipnr;
- int page;
- struct nand_chip *this = meminfo->priv;
-
- /* select the NAND device */
- chipnr = (int)(offset >> this->chip_shift);
- this->select_chip(meminfo, chipnr);
-
-
- if ((offset & (meminfo->oobblock - 1)) != 0) {
- printf ("nand_get_lock_status: "
- "Start address must be beginning of "
- "nand page!\n");
- ret = -1;
- goto out;
- }
-
- /* check the Lock Status */
- page = (int)(offset >> this->page_shift);
- this->cmdfunc(meminfo, NAND_CMD_LOCK_STATUS, -1, page & this->pagemask);
-
- ret = this->read_byte(meminfo) & (NAND_LOCK_STATUS_TIGHT
- | NAND_LOCK_STATUS_LOCK
- | NAND_LOCK_STATUS_UNLOCK);
-
- out:
- /* de-select the NAND device */
- this->select_chip(meminfo, -1);
- return ret;
-}
-
-/**
- * nand_unlock: - Unlock area of NAND pages
- * only one consecutive area can be unlocked at one time!
- *
- * @param meminfo nand mtd instance
- * @param start start byte address
- * @param length number of bytes to unlock (must be a multiple of
- * page size nand->oobblock)
- *
- * @return 0 on success, -1 in case of error
- */
-int nand_unlock(nand_info_t *meminfo, ulong start, ulong length)
-{
- int ret = 0;
- int chipnr;
- int status;
- int page;
- struct nand_chip *this = meminfo->priv;
- printf ("nand_unlock: start: %08x, length: %d!\n",
- (int)start, (int)length);
-
- /* select the NAND device */
- chipnr = (int)(start >> this->chip_shift);
- this->select_chip(meminfo, chipnr);
-
- /* check the WP bit */
- this->cmdfunc(meminfo, NAND_CMD_STATUS, -1, -1);
- if ((this->read_byte(meminfo) & 0x80) == 0) {
- printf ("nand_unlock: Device is write protected!\n");
- ret = -1;
- goto out;
- }
-
- if ((start & (meminfo->oobblock - 1)) != 0) {
- printf ("nand_unlock: Start address must be beginning of "
- "nand page!\n");
- ret = -1;
- goto out;
- }
-
- if (length == 0 || (length & (meminfo->oobblock - 1)) != 0) {
- printf ("nand_unlock: Length must be a multiple of nand page "
- "size!\n");
- ret = -1;
- goto out;
- }
-
- /* submit address of first page to unlock */
- page = (int)(start >> this->page_shift);
- this->cmdfunc(meminfo, NAND_CMD_UNLOCK1, -1, page & this->pagemask);
-
- /* submit ADDRESS of LAST page to unlock */
- page += (int)(length >> this->page_shift) - 1;
- this->cmdfunc(meminfo, NAND_CMD_UNLOCK2, -1, page & this->pagemask);
-
- /* call wait ready function */
- status = this->waitfunc(meminfo, this, FL_WRITING);
- /* see if device thinks it succeeded */
- if (status & 0x01) {
- /* there was an error */
- ret = -1;
- goto out;
- }
-
- out:
- /* de-select the NAND device */
- this->select_chip(meminfo, -1);
- return ret;
-}
-
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 10/16] move version_string to seperate file
2011-04-08 14:36 various cleanup patches Sascha Hauer
` (8 preceding siblings ...)
2011-04-08 14:36 ` [PATCH 09/16] nand: remove unused nand_util file Sascha Hauer
@ 2011-04-08 14:36 ` Sascha Hauer
2011-04-08 14:36 ` [PATCH 11/16] fs: use safe_strncpy instead of sprintf Sascha Hauer
` (5 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:36 UTC (permalink / raw)
To: barebox
In a noninteractive environment barebox will be compiled without
command support. So move version_string to a seperate file which
is compiled unconditionally.
Also, display the banner when the simple console support is used.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/Makefile | 1 +
common/command.c | 4 ----
common/console.c | 10 ++--------
common/console_simple.c | 2 ++
common/version.c | 13 +++++++++++++
include/common.h | 1 +
6 files changed, 19 insertions(+), 12 deletions(-)
create mode 100644 common/version.c
diff --git a/common/Makefile b/common/Makefile
index 6cc6143..d8c302f 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_POLLER) += poller.o
obj-y += dlmalloc.o
obj-y += clock.o
+obj-y += version.o
obj-y += command.o
obj-$(CONFIG_CONSOLE_FULL) += console.o
obj-$(CONFIG_CONSOLE_SIMPLE) += console_simple.o
diff --git a/common/command.c b/common/command.c
index f1aeeb9..ab02ed5 100644
--- a/common/command.c
+++ b/common/command.c
@@ -33,12 +33,8 @@
#include <linux/list.h>
#include <init.h>
#include <complete.h>
-#include <generated/utsrelease.h>
#include <getopt.h>
-const char version_string[] =
- "barebox " UTS_RELEASE " (" __DATE__ " - " __TIME__ ")";
-
LIST_HEAD(command_list);
EXPORT_SYMBOL(command_list);
diff --git a/common/console.c b/common/console.c
index 5548a40..d33a249 100644
--- a/common/console.c
+++ b/common/console.c
@@ -45,12 +45,6 @@ EXPORT_SYMBOL(console_list);
#define CONSOLE_INIT_EARLY 1
#define CONSOLE_INIT_FULL 2
-static void display_banner (void)
-{
- printf (RELOC("\n\n%s\n\n"), RELOC_VAR(version_string));
- printf(RELOC("Board: " CONFIG_BOARDINFO "\n"));
-}
-
static int __early_initdata initialized = 0;
static int console_std_set(struct device_d *dev, struct param_d *param,
@@ -169,7 +163,7 @@ int console_register(struct console_device *newcdev)
#ifndef CONFIG_HAS_EARLY_INIT
if (first)
- display_banner();
+ barebox_banner();
#endif
return 0;
@@ -420,7 +414,7 @@ void early_console_start(const char *name, int baudrate)
early_console_init(base, baudrate);
INITDATA(initialized) = CONSOLE_INIT_EARLY;
INITDATA(early_console_base) = base;
- display_banner();
+ barebox_banner();
}
}
diff --git a/common/console_simple.c b/common/console_simple.c
index 1b58dea..7304d8e 100644
--- a/common/console_simple.c
+++ b/common/console_simple.c
@@ -152,6 +152,8 @@ int console_register(struct console_device *newcdev)
console = newcdev;
console_list.prev = console_list.next = &newcdev->list;
newcdev->list.prev = newcdev->list.next = &console_list;
+
+ barebox_banner();
}
return 0;
}
diff --git a/common/version.c b/common/version.c
new file mode 100644
index 0000000..945475f
--- /dev/null
+++ b/common/version.c
@@ -0,0 +1,13 @@
+#include <common.h>
+#include <reloc.h>
+#include <generated/utsrelease.h>
+
+const char version_string[] =
+ "barebox " UTS_RELEASE " (" __DATE__ " - " __TIME__ ")";
+
+void barebox_banner (void)
+{
+ printf (RELOC("\n\n%s\n\n"), RELOC_VAR(version_string));
+ printf(RELOC("Board: " CONFIG_BOARDINFO "\n"));
+}
+
diff --git a/include/common.h b/include/common.h
index 35ad7b9..491bc98 100644
--- a/include/common.h
+++ b/include/common.h
@@ -219,6 +219,7 @@ int run_shell(void);
int memory_display(char *addr, ulong offs, ulong nbytes, int size);
extern const char version_string[];
+void barebox_banner(void);
#define IOMEM(addr) ((void __force __iomem *)(addr))
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 11/16] fs: use safe_strncpy instead of sprintf
2011-04-08 14:36 various cleanup patches Sascha Hauer
` (9 preceding siblings ...)
2011-04-08 14:36 ` [PATCH 10/16] move version_string to seperate file Sascha Hauer
@ 2011-04-08 14:36 ` Sascha Hauer
2011-04-08 14:36 ` [PATCH 12/16] script: update git ignore file Sascha Hauer
` (4 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:36 UTC (permalink / raw)
To: barebox
This is safe against string overflows.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/fs.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 059f67a..8f43481 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -30,6 +30,7 @@
#include <xfuncs.h>
#include <init.h>
#include <module.h>
+#include <libbb.h>
void *read_file(const char *filename, size_t *size)
{
@@ -783,7 +784,7 @@ int mount(const char *device, const char *fsname, const char *_path)
goto out;
}
}
- sprintf(fsdev->dev.name, "%s", fsname);
+ safe_strncpy(fsdev->dev.name, fsname, MAX_DRIVER_NAME);
fsdev->dev.type_data = fsdev;
fsdev->dev.id = get_free_deviceid(fsdev->dev.name);
@@ -807,7 +808,7 @@ int mount(const char *device, const char *fsname, const char *_path)
/* add mtab entry */
entry = &fsdev->mtab;
- sprintf(entry->path, "%s", path);
+ safe_strncpy(entry->path, path, PATH_MAX);
entry->dev = dev;
entry->parent_device = parent_device;
entry->next = NULL;
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 12/16] script: update git ignore file
2011-04-08 14:36 various cleanup patches Sascha Hauer
` (10 preceding siblings ...)
2011-04-08 14:36 ` [PATCH 11/16] fs: use safe_strncpy instead of sprintf Sascha Hauer
@ 2011-04-08 14:36 ` Sascha Hauer
2011-04-08 14:36 ` [PATCH 13/16] serial 16550: use xzalloc Sascha Hauer
` (3 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:36 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
scripts/.gitignore | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/scripts/.gitignore b/scripts/.gitignore
index 26317b2..11fd2df 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -2,4 +2,5 @@ bareboxenv
bin2c
mkimage
kallsyms
-
+gen_netx_image
+omap_signGP
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 13/16] serial 16550: use xzalloc
2011-04-08 14:36 various cleanup patches Sascha Hauer
` (11 preceding siblings ...)
2011-04-08 14:36 ` [PATCH 12/16] script: update git ignore file Sascha Hauer
@ 2011-04-08 14:36 ` Sascha Hauer
2011-04-08 14:37 ` [PATCH 14/16] ARM: compile in image size and magic into barebox image Sascha Hauer
` (2 subsequent siblings)
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:36 UTC (permalink / raw)
To: barebox
No need to check for the result and increases the chance that we
build a binary without the rarely used calloc function.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/serial/serial_ns16550.c | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index 290619f..ab172e7 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -211,9 +211,7 @@ static int ns16550_probe(struct device_d *dev)
if ((plat->reg_read == NULL) || (plat->reg_write == NULL))
return -EINVAL;
- cdev = calloc(1, sizeof(struct console_device));
- if (cdev == NULL)
- return -ENOMEM;
+ cdev = xzalloc(sizeof(*cdev));
dev->type_data = cdev;
cdev->dev = dev;
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 14/16] ARM: compile in image size and magic into barebox image
2011-04-08 14:36 various cleanup patches Sascha Hauer
` (12 preceding siblings ...)
2011-04-08 14:36 ` [PATCH 13/16] serial 16550: use xzalloc Sascha Hauer
@ 2011-04-08 14:37 ` Sascha Hauer
2011-04-10 4:33 ` Marc Reilly
2011-04-08 14:37 ` [PATCH 15/16] commands: seperate usb command from usb core Sascha Hauer
2011-04-08 14:37 ` [PATCH 16/16] fs mount: fix error handling Sascha Hauer
15 siblings, 1 reply; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:37 UTC (permalink / raw)
To: barebox
This is useful to detect a barebox image and to be able
to copy only the image size if barebox is stored on
raw partitions which are bigger than the image.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/cpu/start.c | 6 ++++++
arch/arm/lib/barebox.lds.S | 1 +
include/asm-generic/sections.h | 3 +++
3 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index e0fb712..ddb65e8 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -38,6 +38,12 @@ void __naked __section(.text_entry) exception_vectors(void)
"ldr pc, =not_used\n" /* (reserved) */
"ldr pc, =irq\n" /* irq (interrupt) */
"ldr pc, =fiq\n" /* fiq (fast interrupt) */
+ ".word 0x65726162\n" /* 'BARE' */
+ ".word 0x00786f62\n" /* 'BOX' */
+ ".word _text\n" /* text base. If copied there,
+ * barebox can skip relocation
+ */
+ ".word _barebox_image_size\n" /* image size to copy */
);
}
diff --git a/arch/arm/lib/barebox.lds.S b/arch/arm/lib/barebox.lds.S
index 7683f73..81a9123 100644
--- a/arch/arm/lib/barebox.lds.S
+++ b/arch/arm/lib/barebox.lds.S
@@ -93,4 +93,5 @@ SECTIONS
.bss : { *(.bss*) }
__bss_stop = .;
_end = .;
+ _barebox_image_size = __bss_start - _text;
}
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index c5d60a9..1f48fb8 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -4,5 +4,8 @@
extern char _text[], _stext[], _etext[];
extern char __bss_start[], __bss_stop[];
extern char _end[];
+extern void *_barebox_image_size;
+
+#define barebox_image_size (unsigned int)&_barebox_image_size
#endif /* _ASM_GENERIC_SECTIONS_H_ */
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 14/16] ARM: compile in image size and magic into barebox image
2011-04-08 14:37 ` [PATCH 14/16] ARM: compile in image size and magic into barebox image Sascha Hauer
@ 2011-04-10 4:33 ` Marc Reilly
2011-04-11 7:41 ` Sascha Hauer
0 siblings, 1 reply; 21+ messages in thread
From: Marc Reilly @ 2011-04-10 4:33 UTC (permalink / raw)
To: barebox
Hi,
> This is useful to detect a barebox image and to be able
> to copy only the image size if barebox is stored on
> raw partitions which are bigger than the image.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> arch/arm/cpu/start.c | 6 ++++++
> arch/arm/lib/barebox.lds.S | 1 +
> include/asm-generic/sections.h | 3 +++
> 3 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
> index e0fb712..ddb65e8 100644
> --- a/arch/arm/cpu/start.c
> +++ b/arch/arm/cpu/start.c
> @@ -38,6 +38,12 @@ void __naked __section(.text_entry)
> exception_vectors(void) "ldr pc, =not_used\n" /* (reserved) */
> "ldr pc, =irq\n" /* irq (interrupt) */
> "ldr pc, =fiq\n" /* fiq (fast interrupt) */
> + ".word 0x65726162\n" /* 'BARE' */
> + ".word 0x00786f62\n" /* 'BOX' */
> + ".word _text\n" /* text base. If copied there,
> + * barebox can skip relocation
> + */
> + ".word _barebox_image_size\n" /* image size to copy */
> );
> }
I like this, is there a way to include a version string/info also?
(The aim is to be able to derive the barebox version of an image from just
reading the file).
>
> diff --git a/arch/arm/lib/barebox.lds.S b/arch/arm/lib/barebox.lds.S
> index 7683f73..81a9123 100644
> --- a/arch/arm/lib/barebox.lds.S
> +++ b/arch/arm/lib/barebox.lds.S
> @@ -93,4 +93,5 @@ SECTIONS
> .bss : { *(.bss*) }
> __bss_stop = .;
> _end = .;
> + _barebox_image_size = __bss_start - _text;
> }
> diff --git a/include/asm-generic/sections.h
> b/include/asm-generic/sections.h index c5d60a9..1f48fb8 100644
> --- a/include/asm-generic/sections.h
> +++ b/include/asm-generic/sections.h
> @@ -4,5 +4,8 @@
> extern char _text[], _stext[], _etext[];
> extern char __bss_start[], __bss_stop[];
> extern char _end[];
> +extern void *_barebox_image_size;
> +
> +#define barebox_image_size (unsigned int)&_barebox_image_size
I don't understand this line. Did you mean something like:
#define barebox_image_size *((unsigned int *)_barebox_image_size)
Or am I missing something?
Cheers
Marc
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 14/16] ARM: compile in image size and magic into barebox image
2011-04-10 4:33 ` Marc Reilly
@ 2011-04-11 7:41 ` Sascha Hauer
2011-04-11 7:46 ` Robert Schwebel
2011-04-11 8:42 ` Marc Reilly
0 siblings, 2 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-11 7:41 UTC (permalink / raw)
To: Marc Reilly; +Cc: barebox
Hi Marc,
On Sun, Apr 10, 2011 at 02:33:44PM +1000, Marc Reilly wrote:
> Hi,
>
> > This is useful to detect a barebox image and to be able
> > to copy only the image size if barebox is stored on
> > raw partitions which are bigger than the image.
> >
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> > arch/arm/cpu/start.c | 6 ++++++
> > arch/arm/lib/barebox.lds.S | 1 +
> > include/asm-generic/sections.h | 3 +++
> > 3 files changed, 10 insertions(+), 0 deletions(-)
> >
> > diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
> > index e0fb712..ddb65e8 100644
> > --- a/arch/arm/cpu/start.c
> > +++ b/arch/arm/cpu/start.c
> > @@ -38,6 +38,12 @@ void __naked __section(.text_entry)
> > exception_vectors(void) "ldr pc, =not_used\n" /* (reserved) */
> > "ldr pc, =irq\n" /* irq (interrupt) */
> > "ldr pc, =fiq\n" /* fiq (fast interrupt) */
> > + ".word 0x65726162\n" /* 'BARE' */
> > + ".word 0x00786f62\n" /* 'BOX' */
I just see that the comment is wrong. It's actually in lower case
letters.
> > + ".word _text\n" /* text base. If copied there,
> > + * barebox can skip relocation
> > + */
> > + ".word _barebox_image_size\n" /* image size to copy */
> > );
> > }
>
> I like this, is there a way to include a version string/info also?
>
> (The aim is to be able to derive the barebox version of an image from just
> reading the file).
Should be possible. One problem might be that the length of the version
string is variable, so if we put it here, it must be the piece of
information here.
> > +extern void *_barebox_image_size;
> > +
> > +#define barebox_image_size (unsigned int)&_barebox_image_size
>
> I don't understand this line. Did you mean something like:
>
> #define barebox_image_size *((unsigned int *)_barebox_image_size)
>
> Or am I missing something?
_barebox_image_size is filled in by the linker. It can be seen as a
pointer which address corresponds to the image size. I know this looks
strange and I don't really like this. Maybe it can be done better?
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 14/16] ARM: compile in image size and magic into barebox image
2011-04-11 7:41 ` Sascha Hauer
@ 2011-04-11 7:46 ` Robert Schwebel
2011-04-11 8:42 ` Marc Reilly
1 sibling, 0 replies; 21+ messages in thread
From: Robert Schwebel @ 2011-04-11 7:46 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On Mon, Apr 11, 2011 at 09:41:09AM +0200, Sascha Hauer wrote:
> > I don't understand this line. Did you mean something like:
> >
> > #define barebox_image_size *((unsigned int *)_barebox_image_size)
> >
> > Or am I missing something?
>
> _barebox_image_size is filled in by the linker. It can be seen as a
> pointer which address corresponds to the image size. I know this looks
> strange and I don't really like this. Maybe it can be done better?
You could add a comment until there is a better solution.
rsc
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 14/16] ARM: compile in image size and magic into barebox image
2011-04-11 7:41 ` Sascha Hauer
2011-04-11 7:46 ` Robert Schwebel
@ 2011-04-11 8:42 ` Marc Reilly
1 sibling, 0 replies; 21+ messages in thread
From: Marc Reilly @ 2011-04-11 8:42 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
Hi,
> > > @@ -38,6 +38,12 @@ void __naked __section(.text_entry)
> > > exception_vectors(void) "ldr pc, =not_used\n" /* (reserved) */
> > >
> > > "ldr pc, =irq\n" /* irq (interrupt) */
> > > "ldr pc, =fiq\n" /* fiq (fast interrupt) */
> > >
> > > + ".word 0x65726162\n" /* 'BARE' */
> > > + ".word 0x00786f62\n" /* 'BOX' */
>
> I just see that the comment is wrong. It's actually in lower case
> letters.
>
True.
(This is why I'm always reluctant to ack patches - I'm not very thorough :)
> > > + ".word _text\n" /* text base. If copied there,
> > > + * barebox can skip relocation
> > > + */
> > > + ".word _barebox_image_size\n" /* image size to copy */
> > >
> > > );
> > >
> > > }
> >
> > I like this, is there a way to include a version string/info also?
> >
> > (The aim is to be able to derive the barebox version of an image from
> > just reading the file).
>
> Should be possible. One problem might be that the length of the version
> string is variable, so if we put it here, it must be the piece of
> information here.
"it must be the _last_ piece of information here"?
Could also dedicate a fixed maximum size, although that's the kind of thing
that becomes a pain later.
>
> > > +extern void *_barebox_image_size;
> > > +
> > > +#define barebox_image_size (unsigned int)&_barebox_image_size
> >
> > I don't understand this line. Did you mean something like:
> >
> > #define barebox_image_size *((unsigned int *)_barebox_image_size)
> >
> > Or am I missing something?
>
> _barebox_image_size is filled in by the linker. It can be seen as a
> pointer which address corresponds to the image size. I know this looks
> strange and I don't really like this.
Ah, _now_ I get it. It looks strange but makes sense with your explanation
above, and I reckon that's OK.
> Maybe it can be done better?
Roberts suggestion to give it a comment is probably the best and simplest. The
alternate way I come up with isn't any better.
Cheers
Marc
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 15/16] commands: seperate usb command from usb core
2011-04-08 14:36 various cleanup patches Sascha Hauer
` (13 preceding siblings ...)
2011-04-08 14:37 ` [PATCH 14/16] ARM: compile in image size and magic into barebox image Sascha Hauer
@ 2011-04-08 14:37 ` Sascha Hauer
2011-04-08 14:37 ` [PATCH 16/16] fs mount: fix error handling Sascha Hauer
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:37 UTC (permalink / raw)
To: barebox
This patch makes the USB command optional and makes usb_rescan a
global function. This way we can use USB in noninteractive
environments.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/Kconfig | 8 ++++++++
commands/Makefile | 1 +
commands/usb.c | 41 +++++++++++++++++++++++++++++++++++++++++
drivers/usb/core/usb.c | 21 +--------------------
include/usb/usb.h | 2 ++
5 files changed, 53 insertions(+), 20 deletions(-)
create mode 100644 commands/usb.c
diff --git a/commands/Kconfig b/commands/Kconfig
index 40213d2..9d0c72d 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -393,4 +393,12 @@ config CMD_LED_TRIGGER
The trigger command allows to control LED triggers from the command
line.
+config CMD_USB
+ bool
+ depends on USB
+ prompt "usb command"
+ default y
+ help
+ The usb command allows to rescan for USB devices.
+
endmenu
diff --git a/commands/Makefile b/commands/Makefile
index fb1b0ca..f7ef9a8 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -55,3 +55,4 @@ obj-$(CONFIG_CMD_PASSWD) += passwd.o
obj-$(CONFIG_CMD_LOGIN) += login.o
obj-$(CONFIG_CMD_LED) += led.o
obj-$(CONFIG_CMD_LED_TRIGGER) += trigger.o
+obj-$(CONFIG_CMD_USB) += usb.o
diff --git a/commands/usb.c b/commands/usb.c
new file mode 100644
index 0000000..0aac78e
--- /dev/null
+++ b/commands/usb.c
@@ -0,0 +1,41 @@
+/*
+ * usb.c - rescan for USB devices
+ *
+ * Copyright (c) 2011 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <common.h>
+#include <command.h>
+#include <usb/usb.h>
+
+static int do_usb(struct command *cmdtp, int argc, char *argv[])
+{
+ usb_rescan();
+
+ return 0;
+}
+
+static const __maybe_unused char cmd_usb_help[] =
+"Usage: usb\n"
+"(re-)detect USB devices\n";
+
+BAREBOX_CMD_START(usb)
+ .cmd = do_usb,
+ .usage = "(re-)detect USB devices",
+ BAREBOX_CMD_HELP(cmd_usb_help)
+BAREBOX_CMD_END
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 76e033e..df4e9e0 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -449,7 +449,7 @@ static struct usb_device *usb_alloc_new_device(void)
return usbdev;
}
-static int __usb_init(void)
+void usb_rescan(void)
{
struct usb_device *dev, *tmp;
struct usb_host *host;
@@ -477,27 +477,8 @@ static int __usb_init(void)
}
printf("%d USB Device(s) found\n", dev_index);
-
- return 0;
}
-static int do_usb(struct command *cmdtp, int argc, char *argv[])
-{
- __usb_init();
-
- return 0;
-}
-
-static const __maybe_unused char cmd_usb_help[] =
-"Usage: usb\n"
-"(re-)detect USB devices\n";
-
-BAREBOX_CMD_START(usb)
- .cmd = do_usb,
- .usage = "(re-)detect USB devices",
- BAREBOX_CMD_HELP(cmd_usb_help)
-BAREBOX_CMD_END
-
/*
* disables the asynch behaviour of the control message. This is used for data
* transfers that uses the exclusiv access to the control and bulk messages.
diff --git a/include/usb/usb.h b/include/usb/usb.h
index 1e4d750..6ef9977 100644
--- a/include/usb/usb.h
+++ b/include/usb/usb.h
@@ -252,6 +252,8 @@ int usb_clear_halt(struct usb_device *dev, int pipe);
int usb_string(struct usb_device *dev, int index, char *buf, size_t size);
int usb_set_interface(struct usb_device *dev, int interface, int alternate);
+void usb_rescan(void);
+
/* big endian -> little endian conversion */
/* some CPUs are already little endian e.g. the ARM920T */
#define __swap_16(x) \
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 16/16] fs mount: fix error handling
2011-04-08 14:36 various cleanup patches Sascha Hauer
` (14 preceding siblings ...)
2011-04-08 14:37 ` [PATCH 15/16] commands: seperate usb command from usb core Sascha Hauer
@ 2011-04-08 14:37 ` Sascha Hauer
15 siblings, 0 replies; 21+ messages in thread
From: Sascha Hauer @ 2011-04-08 14:37 UTC (permalink / raw)
To: barebox
If we register a device we have to unregister it later when
the driver did not accept the device. Also, do not forget to
free the backingstore string.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/fs.c | 19 +++++++++++++------
1 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/fs/fs.c b/fs/fs.c
index 8f43481..e71d5a2 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -780,8 +780,7 @@ int mount(const char *device, const char *fsname, const char *_path)
if (!device) {
printf("need a device for driver %s\n", fsname);
errno = -ENODEV;
- free(fsdev);
- goto out;
+ goto out1;
}
}
safe_strncpy(fsdev->dev.name, fsname, MAX_DRIVER_NAME);
@@ -789,16 +788,14 @@ int mount(const char *device, const char *fsname, const char *_path)
fsdev->dev.id = get_free_deviceid(fsdev->dev.name);
if ((ret = register_device(&fsdev->dev))) {
- free(fsdev);
errno = ret;
- goto out;
+ goto out1;
}
if (!fsdev->dev.driver) {
/* driver didn't accept the device. Bail out */
- free(fsdev);
errno = -EINVAL;
- goto out;
+ goto out2;
}
if (parent_device)
@@ -822,6 +819,16 @@ int mount(const char *device, const char *fsname, const char *_path)
e->next = entry;
}
errno = 0;
+
+ free(path);
+ return 0;
+
+out2:
+ unregister_device(&fsdev->dev);
+out1:
+ if (fsdev->backingstore)
+ free(fsdev->backingstore);
+ free(fsdev);
out:
free(path);
return errno;
--
1.7.2.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 21+ messages in thread