* [PATCH 2/6] env: erase/protect in envfs_save
2014-04-28 9:49 [PATCH 1/6] environment: drop envfs_register_partition Sascha Hauer
@ 2014-04-28 9:49 ` Sascha Hauer
2014-04-28 9:49 ` [PATCH 3/6] mtd: nand: bb: use mtd api directly Sascha Hauer
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2014-04-28 9:49 UTC (permalink / raw)
To: barebox
So that the envfs_save is more useful outside of the saveenv command
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/saveenv.c | 46 +---------------------------------------------
common/environment.c | 38 ++++++++++++++++++++++++++++++++++++--
2 files changed, 37 insertions(+), 47 deletions(-)
diff --git a/commands/saveenv.c b/commands/saveenv.c
index 8ead98d..cb2b01d 100644
--- a/commands/saveenv.c
+++ b/commands/saveenv.c
@@ -29,7 +29,7 @@
static int do_saveenv(int argc, char *argv[])
{
- int ret, fd;
+ int ret;
char *filename, *dirname;
printf("saving environment\n");
@@ -42,52 +42,8 @@ static int do_saveenv(int argc, char *argv[])
else
filename = argv[1];
- fd = open(filename, O_WRONLY | O_CREAT);
- if (fd < 0) {
- printf("could not open %s: %s\n", filename, errno_str());
- return 1;
- }
-
- ret = protect(fd, ~0, 0, 0);
-
- /* ENOSYS is no error here, many devices do not need it */
- if (ret && errno != ENOSYS) {
- printf("could not unprotect %s: %s\n", filename, errno_str());
- close(fd);
- return 1;
- }
-
- ret = erase(fd, ~0, 0);
-
- /* ENOSYS is no error here, many devices do not need it */
- if (ret && errno != ENOSYS) {
- printf("could not erase %s: %s\n", filename, errno_str());
- close(fd);
- return 1;
- }
-
- close(fd);
-
ret = envfs_save(filename, dirname);
- if (ret) {
- printf("saveenv failed\n");
- goto out;
- }
-
- fd = open(filename, O_WRONLY | O_CREAT);
-
- ret = protect(fd, ~0, 0, 1);
-
- /* ENOSYS is no error here, many devices do not need it */
- if (ret && errno != ENOSYS) {
- printf("could not protect %s: %s\n", filename, errno_str());
- close(fd);
- return 1;
- }
- ret = 0;
-out:
- close(fd);
return ret;
}
diff --git a/common/environment.c b/common/environment.c
index e55df40..2d1edf8 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -60,6 +60,16 @@ char *default_environment_path_get(void)
{
return default_environment_path;
}
+#else
+static inline int protect(int fd, size_t count, unsigned long offset, int prot)
+{
+ return 0;
+}
+
+static inline int erase(int fd, size_t count, unsigned long offset)
+{
+ return 0;
+}
#endif
static int file_size_action(const char *filename, struct stat *statbuf,
@@ -196,11 +206,27 @@ int envfs_save(const char *filename, const char *dirname)
envfd = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
if (envfd < 0) {
- printf("Open %s %s\n", filename, errno_str());
- ret = envfd;
+ printf("could not open %s: %s\n", filename, errno_str());
+ ret = -errno;
goto out1;
}
+ ret = protect(envfd, ~0, 0, 0);
+
+ /* ENOSYS is no error here, many devices do not need it */
+ if (ret && errno != ENOSYS) {
+ printf("could not unprotect %s: %s\n", filename, errno_str());
+ goto out;
+ }
+
+ ret = erase(envfd, ~0, 0);
+
+ /* ENOSYS is no error here, many devices do not need it */
+ if (ret && errno != ENOSYS) {
+ printf("could not erase %s: %s\n", filename, errno_str());
+ goto out;
+ }
+
size += sizeof(struct envfs_super);
wbuf = buf;
@@ -216,6 +242,14 @@ int envfs_save(const char *filename, const char *dirname)
size -= now;
}
+ ret = protect(envfd, ~0, 0, 1);
+
+ /* ENOSYS is no error here, many devices do not need it */
+ if (ret && errno != ENOSYS) {
+ printf("could not protect %s: %s\n", filename, errno_str());
+ goto out;
+ }
+
ret = 0;
out:
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/6] mtd: nand: bb: use mtd api directly
2014-04-28 9:49 [PATCH 1/6] environment: drop envfs_register_partition Sascha Hauer
2014-04-28 9:49 ` [PATCH 2/6] env: erase/protect in envfs_save Sascha Hauer
@ 2014-04-28 9:49 ` Sascha Hauer
2014-04-28 13:05 ` Alexander Aring
2014-04-28 9:49 ` [PATCH 4/6] mtd: refactor bb device creation Sascha Hauer
` (2 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Sascha Hauer @ 2014-04-28 9:49 UTC (permalink / raw)
To: barebox
The devfs layer just adds an addition indirection between mtd
and the bb devices with no purpose. Drop it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/nand/nand-bb.c | 122 +++++++++++++++++++--------------------------
1 file changed, 50 insertions(+), 72 deletions(-)
diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
index f387ef6..06b5824 100644
--- a/drivers/mtd/nand/nand-bb.c
+++ b/drivers/mtd/nand/nand-bb.c
@@ -25,22 +25,18 @@
#include <init.h>
#include <ioctl.h>
#include <nand.h>
-#include <linux/mtd/mtd-abi.h>
+#include <linux/mtd/mtd.h>
#include <fcntl.h>
#include <libgen.h>
#include <linux/list.h>
struct nand_bb {
- char cdevname[MAX_DRIVER_NAME];
- struct cdev *cdev_parent;
char *name;
int open;
int needs_write;
- struct mtd_info_user info;
+ struct mtd_info *mtd;
- loff_t raw_size;
- loff_t size;
loff_t offset;
unsigned long flags;
void *writebuf;
@@ -54,31 +50,28 @@ static ssize_t nand_bb_read(struct cdev *cdev, void *buf, size_t count,
loff_t offset, ulong flags)
{
struct nand_bb *bb = cdev->priv;
- struct cdev *parent = bb->cdev_parent;
+ size_t retlen;
int ret, bytes = 0, now;
debug("%s 0x%08llx %d\n", __func__, offset, count);
- while(count) {
- ret = cdev_ioctl(parent, MEMGETBADBLOCK, &bb->offset);
- if (ret < 0)
- return ret;
-
- if (ret) {
+ while (count) {
+ if (mtd_block_isbad(bb->mtd, offset)) {
printf("skipping bad block at 0x%08llx\n", bb->offset);
- bb->offset += bb->info.erasesize;
+ bb->offset += bb->mtd->erasesize;
continue;
}
- now = min(count, (size_t)(bb->info.erasesize -
- ((size_t)bb->offset % bb->info.erasesize)));
- ret = cdev_read(parent, buf, now, bb->offset, 0);
+ now = min(count, (size_t)(bb->mtd->erasesize -
+ ((size_t)bb->offset % bb->mtd->erasesize)));
+
+ ret = mtd_read(bb->mtd, bb->offset, now, &retlen, buf);
if (ret < 0)
return ret;
- buf += now;
- count -= now;
- bb->offset += now;
- bytes += now;
+ buf += retlen;
+ count -= retlen;
+ bb->offset += retlen;
+ bytes += retlen;
};
return bytes;
@@ -91,29 +84,25 @@ static ssize_t nand_bb_read(struct cdev *cdev, void *buf, size_t count,
static int nand_bb_write_buf(struct nand_bb *bb, size_t count)
{
int ret, now;
- struct cdev *parent = bb->cdev_parent;
+ size_t retlen;
void *buf = bb->writebuf;
loff_t cur_ofs = bb->offset & ~(BB_WRITEBUF_SIZE - 1);
while (count) {
- ret = cdev_ioctl(parent, MEMGETBADBLOCK, &cur_ofs);
- if (ret < 0)
- return ret;
-
- if (ret) {
+ if (mtd_block_isbad(bb->mtd, cur_ofs)) {
debug("skipping bad block at 0x%08llx\n", cur_ofs);
- bb->offset += bb->info.erasesize;
- cur_ofs += bb->info.erasesize;
+ bb->offset += bb->mtd->erasesize;
+ cur_ofs += bb->mtd->erasesize;
continue;
}
- now = min(count, (size_t)(bb->info.erasesize));
- ret = cdev_write(parent, buf, now, cur_ofs, 0);
+ now = min(count, (size_t)(bb->mtd->erasesize));
+ ret = mtd_write(bb->mtd, cur_ofs, now, &retlen, buf);
if (ret < 0)
return ret;
- buf += now;
- count -= now;
- cur_ofs += now;
+ buf += retlen;
+ count -= retlen;
+ cur_ofs += retlen;
};
return 0;
@@ -152,13 +141,17 @@ static ssize_t nand_bb_write(struct cdev *cdev, const void *buf, size_t count,
static int nand_bb_erase(struct cdev *cdev, size_t count, loff_t offset)
{
struct nand_bb *bb = cdev->priv;
+ struct erase_info erase = {};
if (offset != 0) {
printf("can only erase from beginning of device\n");
return -EINVAL;
}
- return cdev_erase(bb->cdev_parent, bb->raw_size, 0);
+ erase.addr = 0;
+ erase.len = bb->mtd->size;
+
+ return mtd_erase(bb->mtd, &erase);
}
#endif
@@ -195,16 +188,12 @@ static int nand_bb_close(struct cdev *cdev)
static int nand_bb_calc_size(struct nand_bb *bb)
{
loff_t pos = 0;
- int ret;
- while (pos < bb->raw_size) {
- ret = cdev_ioctl(bb->cdev_parent, MEMGETBADBLOCK, &pos);
- if (ret < 0)
- return ret;
- if (!ret)
- bb->cdev.size += bb->info.erasesize;
+ while (pos < bb->mtd->size) {
+ if (!mtd_block_isbad(bb->mtd, pos))
+ bb->cdev.size += bb->mtd->erasesize;
- pos += bb->info.erasesize;
+ pos += bb->mtd->erasesize;
}
return 0;
@@ -215,22 +204,18 @@ static loff_t nand_bb_lseek(struct cdev *cdev, loff_t __offset)
struct nand_bb *bb = cdev->priv;
loff_t raw_pos = 0;
uint32_t offset = __offset;
- int ret;
/* lseek only in readonly mode */
if (bb->flags & O_ACCMODE)
return -ENOSYS;
- while (raw_pos < bb->raw_size) {
- off_t now = min(offset, bb->info.erasesize);
+ while (raw_pos < bb->mtd->size) {
+ off_t now = min(offset, bb->mtd->erasesize);
- ret = cdev_ioctl(bb->cdev_parent, MEMGETBADBLOCK, &raw_pos);
- if (ret < 0)
- return ret;
- if (!ret) {
+ if (mtd_block_isbad(bb->mtd, raw_pos)) {
+ raw_pos += bb->mtd->erasesize;
+ } else {
offset -= now;
raw_pos += now;
- } else {
- raw_pos += bb->info.erasesize;
}
if (!offset) {
@@ -264,28 +249,23 @@ static LIST_HEAD(bb_list);
int dev_add_bb_dev(const char *path, const char *name)
{
struct nand_bb *bb;
+ struct cdev *parent;
int ret = -ENOMEM;
- bb = xzalloc(sizeof(*bb));
-
- bb->cdev_parent = cdev_open(path, O_RDWR);
- if (!bb->cdev_parent)
- goto out1;
-
- if (name) {
- strcpy(bb->cdevname, name);
- } else {
- strcpy(bb->cdevname, path);
- strcat(bb->cdevname, ".bb");
- }
+ parent = cdev_by_name(path);
+ if (!parent)
+ return -ENODEV;
- bb->cdev.name = bb->cdevname;
+ if (!parent->mtd)
+ return -EINVAL;
- bb->raw_size = bb->cdev_parent->size;
+ bb = xzalloc(sizeof(*bb));
+ bb->mtd = parent->mtd;
- ret = cdev_ioctl(bb->cdev_parent, MEMGETINFO, &bb->info);
- if (ret)
- goto out4;
+ if (name)
+ bb->cdev.name = xstrdup(name);
+ else
+ bb->cdev.name = asprintf("%s.bb", path);;
nand_bb_calc_size(bb);
bb->cdev.ops = &nand_bb_ops;
@@ -300,8 +280,6 @@ int dev_add_bb_dev(const char *path, const char *name)
return 0;
out4:
- cdev_close(bb->cdev_parent);
-out1:
free(bb);
return ret;
}
@@ -313,8 +291,8 @@ int dev_remove_bb_dev(const char *name)
list_for_each_entry(bb, &bb_list, list) {
if (!strcmp(bb->cdev.name, name)) {
devfs_remove(&bb->cdev);
- cdev_close(bb->cdev_parent);
list_del_init(&bb->list);
+ free(bb->name);
free(bb);
return 0;
}
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/6] mtd: nand: bb: use mtd api directly
2014-04-28 9:49 ` [PATCH 3/6] mtd: nand: bb: use mtd api directly Sascha Hauer
@ 2014-04-28 13:05 ` Alexander Aring
2014-04-28 18:48 ` Sascha Hauer
0 siblings, 1 reply; 8+ messages in thread
From: Alexander Aring @ 2014-04-28 13:05 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
Hi Sascha,
On Mon, Apr 28, 2014 at 11:49:36AM +0200, Sascha Hauer wrote:
> The devfs layer just adds an addition indirection between mtd
> and the bb devices with no purpose. Drop it.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> drivers/mtd/nand/nand-bb.c | 122 +++++++++++++++++++--------------------------
> 1 file changed, 50 insertions(+), 72 deletions(-)
>
> diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
> index f387ef6..06b5824 100644
> --- a/drivers/mtd/nand/nand-bb.c
> +++ b/drivers/mtd/nand/nand-bb.c
> @@ -25,22 +25,18 @@
> #include <init.h>
> #include <ioctl.h>
> #include <nand.h>
> -#include <linux/mtd/mtd-abi.h>
> +#include <linux/mtd/mtd.h>
> #include <fcntl.h>
> #include <libgen.h>
...
> @@ -313,8 +291,8 @@ int dev_remove_bb_dev(const char *name)
> list_for_each_entry(bb, &bb_list, list) {
> if (!strcmp(bb->cdev.name, name)) {
> devfs_remove(&bb->cdev);
> - cdev_close(bb->cdev_parent);
> list_del_init(&bb->list);
> + free(bb->name);
> free(bb);
> return 0;
> }
I know you doesn't change this line but I think we need a
list_for_each_entry_safe here instead of list_for_each_entry.
- Alex
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/6] mtd: nand: bb: use mtd api directly
2014-04-28 13:05 ` Alexander Aring
@ 2014-04-28 18:48 ` Sascha Hauer
0 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2014-04-28 18:48 UTC (permalink / raw)
To: Alexander Aring; +Cc: barebox
On Mon, Apr 28, 2014 at 03:05:26PM +0200, Alexander Aring wrote:
> Hi Sascha,
>
> On Mon, Apr 28, 2014 at 11:49:36AM +0200, Sascha Hauer wrote:
> > The devfs layer just adds an addition indirection between mtd
> > and the bb devices with no purpose. Drop it.
> >
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> > drivers/mtd/nand/nand-bb.c | 122 +++++++++++++++++++--------------------------
> > 1 file changed, 50 insertions(+), 72 deletions(-)
> >
> > diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
> > index f387ef6..06b5824 100644
> > --- a/drivers/mtd/nand/nand-bb.c
> > +++ b/drivers/mtd/nand/nand-bb.c
> > @@ -25,22 +25,18 @@
> > #include <init.h>
> > #include <ioctl.h>
> > #include <nand.h>
> > -#include <linux/mtd/mtd-abi.h>
> > +#include <linux/mtd/mtd.h>
> > #include <fcntl.h>
> > #include <libgen.h>
> ...
>
> > @@ -313,8 +291,8 @@ int dev_remove_bb_dev(const char *name)
> > list_for_each_entry(bb, &bb_list, list) {
> > if (!strcmp(bb->cdev.name, name)) {
> > devfs_remove(&bb->cdev);
> > - cdev_close(bb->cdev_parent);
> > list_del_init(&bb->list);
> > + free(bb->name);
> > free(bb);
> > return 0;
> > }
>
> I know you doesn't change this line but I think we need a
> list_for_each_entry_safe here instead of list_for_each_entry.
Ouch, you are right. I'll prepare a patch for this.
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] 8+ messages in thread
* [PATCH 4/6] mtd: refactor bb device creation
2014-04-28 9:49 [PATCH 1/6] environment: drop envfs_register_partition Sascha Hauer
2014-04-28 9:49 ` [PATCH 2/6] env: erase/protect in envfs_save Sascha Hauer
2014-04-28 9:49 ` [PATCH 3/6] mtd: nand: bb: use mtd api directly Sascha Hauer
@ 2014-04-28 9:49 ` Sascha Hauer
2014-04-28 9:49 ` [PATCH 5/6] mtd: nand: create bb devices automatically Sascha Hauer
2014-04-28 9:49 ` [PATCH 6/6] OF: barebox-env: Use bb device on NAND Sascha Hauer
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2014-04-28 9:49 UTC (permalink / raw)
To: barebox
This refactors the code so that we get a mtd_add_bb which can
be used to create a bb dev on a mtd_info.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/nand/nand-bb.c | 53 +++++++++++++++++++++++++++-------------------
include/nand.h | 6 ++++++
2 files changed, 37 insertions(+), 22 deletions(-)
diff --git a/drivers/mtd/nand/nand-bb.c b/drivers/mtd/nand/nand-bb.c
index 06b5824..0d3de41 100644
--- a/drivers/mtd/nand/nand-bb.c
+++ b/drivers/mtd/nand/nand-bb.c
@@ -29,6 +29,7 @@
#include <fcntl.h>
#include <libgen.h>
#include <linux/list.h>
+#include <linux/err.h>
struct nand_bb {
char *name;
@@ -240,32 +241,18 @@ static struct file_operations nand_bb_ops = {
static LIST_HEAD(bb_list);
-/**
- * Add a bad block aware device ontop of another (NAND) device
- * @param[in] dev The device to add a partition on
- * @param[in] name Partition name (can be obtained with devinfo command)
- * @return The device representing the new partition.
- */
-int dev_add_bb_dev(const char *path, const char *name)
+struct cdev *mtd_add_bb(struct mtd_info *mtd, const char *name)
{
struct nand_bb *bb;
- struct cdev *parent;
- int ret = -ENOMEM;
-
- parent = cdev_by_name(path);
- if (!parent)
- return -ENODEV;
-
- if (!parent->mtd)
- return -EINVAL;
+ int ret;
bb = xzalloc(sizeof(*bb));
- bb->mtd = parent->mtd;
+ bb->mtd = mtd;
if (name)
bb->cdev.name = xstrdup(name);
else
- bb->cdev.name = asprintf("%s.bb", path);;
+ bb->cdev.name = asprintf("%s.bb", mtd->cdev.name);
nand_bb_calc_size(bb);
bb->cdev.ops = &nand_bb_ops;
@@ -273,15 +260,37 @@ int dev_add_bb_dev(const char *path, const char *name)
ret = devfs_create(&bb->cdev);
if (ret)
- goto out4;
+ goto err;
list_add_tail(&bb->list, &bb_list);
- return 0;
+ return &bb->cdev;
-out4:
+err:
free(bb);
- return ret;
+ return ERR_PTR(ret);
+}
+
+/**
+ * Add a bad block aware device ontop of another (NAND) device
+ * @param[in] dev The device to add a partition on
+ * @param[in] name Partition name (can be obtained with devinfo command)
+ * @return The device representing the new partition.
+ */
+int dev_add_bb_dev(const char *path, const char *name)
+{
+ struct cdev *parent, *cdev;
+
+ parent = cdev_by_name(path);
+ if (!parent)
+ return -ENODEV;
+
+ if (!parent->mtd)
+ return -EINVAL;
+
+ cdev = mtd_add_bb(parent->mtd, name);
+
+ return PTR_ERR(cdev);
}
int dev_remove_bb_dev(const char *name)
diff --git a/include/nand.h b/include/nand.h
index a0e77cc..1da35d0 100644
--- a/include/nand.h
+++ b/include/nand.h
@@ -7,6 +7,7 @@ struct nand_bb;
#ifdef CONFIG_NAND
int dev_add_bb_dev(const char *filename, const char *name);
int dev_remove_bb_dev(const char *name);
+struct cdev *mtd_add_bb(struct mtd_info *mtd, const char *name);
#else
static inline int dev_add_bb_dev(const char *filename, const char *name) {
return 0;
@@ -15,6 +16,11 @@ static inline int dev_remove_bb_dev(const char *name)
{
return 0;
}
+
+static inline struct cdev *mtd_add_bb(struct mtd_info *mtd, const char *name)
+{
+ return NULL;
+}
#endif
#endif /* __NAND_H__ */
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 5/6] mtd: nand: create bb devices automatically
2014-04-28 9:49 [PATCH 1/6] environment: drop envfs_register_partition Sascha Hauer
` (2 preceding siblings ...)
2014-04-28 9:49 ` [PATCH 4/6] mtd: refactor bb device creation Sascha Hauer
@ 2014-04-28 9:49 ` Sascha Hauer
2014-04-28 9:49 ` [PATCH 6/6] OF: barebox-env: Use bb device on NAND Sascha Hauer
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2014-04-28 9:49 UTC (permalink / raw)
To: barebox
When a mtd device can have bad blocks we want to create a
bb device, so do this automatically. This allows us to
drop bb device creation from the environment.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/boards/a9m2410/env/bin/hush_hack | 1 -
arch/arm/boards/a9m2410/env/bin/init | 4 ----
arch/arm/boards/a9m2440/env/bin/hush_hack | 1 -
arch/arm/boards/a9m2440/env/bin/init | 4 ----
arch/arm/boards/eukrea_cpuimx27/env/bin/hush_hack | 1 -
arch/arm/boards/eukrea_cpuimx27/env/bin/init | 4 ----
arch/arm/boards/freescale-mx25-3ds/env/bin/hush_hack | 1 -
arch/arm/boards/freescale-mx25-3ds/env/bin/init | 4 ----
arch/arm/boards/mmccpu/env/bin/hush_hack | 1 -
arch/arm/boards/mmccpu/env/bin/init | 4 ----
arch/arm/boards/pm9263/env/bin/hush_hack | 1 -
arch/arm/boards/pm9263/env/bin/init | 4 ----
defaultenv/defaultenv-1/bin/init | 1 -
defaultenv/defaultenv-2-base/bin/mtdparts-add | 4 ----
drivers/mtd/core.c | 3 +++
drivers/of/partition.c | 3 ---
include/linux/mtd/mtd.h | 2 ++
17 files changed, 5 insertions(+), 38 deletions(-)
delete mode 100644 arch/arm/boards/a9m2410/env/bin/hush_hack
delete mode 100644 arch/arm/boards/a9m2440/env/bin/hush_hack
delete mode 100644 arch/arm/boards/eukrea_cpuimx27/env/bin/hush_hack
delete mode 100644 arch/arm/boards/freescale-mx25-3ds/env/bin/hush_hack
delete mode 100644 arch/arm/boards/mmccpu/env/bin/hush_hack
delete mode 100644 arch/arm/boards/pm9263/env/bin/hush_hack
diff --git a/arch/arm/boards/a9m2410/env/bin/hush_hack b/arch/arm/boards/a9m2410/env/bin/hush_hack
deleted file mode 100644
index 5fffa92..0000000
--- a/arch/arm/boards/a9m2410/env/bin/hush_hack
+++ /dev/null
@@ -1 +0,0 @@
-nand -a /dev/nand0.*
diff --git a/arch/arm/boards/a9m2410/env/bin/init b/arch/arm/boards/a9m2410/env/bin/init
index 5ae44dd..dd94ef6 100644
--- a/arch/arm/boards/a9m2410/env/bin/init
+++ b/arch/arm/boards/a9m2410/env/bin/init
@@ -7,10 +7,6 @@ export PATH
if [ -e /dev/nand0 ]; then
addpart /dev/nand0 $nand_parts
-
- # Uh, oh, hush first expands wildcards and then starts executing
- # commands. What a bug!
- source /env/bin/hush_hack
fi
if [ -z $eth0.ethaddr ]; then
diff --git a/arch/arm/boards/a9m2440/env/bin/hush_hack b/arch/arm/boards/a9m2440/env/bin/hush_hack
deleted file mode 100644
index 5fffa92..0000000
--- a/arch/arm/boards/a9m2440/env/bin/hush_hack
+++ /dev/null
@@ -1 +0,0 @@
-nand -a /dev/nand0.*
diff --git a/arch/arm/boards/a9m2440/env/bin/init b/arch/arm/boards/a9m2440/env/bin/init
index 5ae44dd..dd94ef6 100644
--- a/arch/arm/boards/a9m2440/env/bin/init
+++ b/arch/arm/boards/a9m2440/env/bin/init
@@ -7,10 +7,6 @@ export PATH
if [ -e /dev/nand0 ]; then
addpart /dev/nand0 $nand_parts
-
- # Uh, oh, hush first expands wildcards and then starts executing
- # commands. What a bug!
- source /env/bin/hush_hack
fi
if [ -z $eth0.ethaddr ]; then
diff --git a/arch/arm/boards/eukrea_cpuimx27/env/bin/hush_hack b/arch/arm/boards/eukrea_cpuimx27/env/bin/hush_hack
deleted file mode 100644
index 5fffa92..0000000
--- a/arch/arm/boards/eukrea_cpuimx27/env/bin/hush_hack
+++ /dev/null
@@ -1 +0,0 @@
-nand -a /dev/nand0.*
diff --git a/arch/arm/boards/eukrea_cpuimx27/env/bin/init b/arch/arm/boards/eukrea_cpuimx27/env/bin/init
index cd74974..e3c1091 100644
--- a/arch/arm/boards/eukrea_cpuimx27/env/bin/init
+++ b/arch/arm/boards/eukrea_cpuimx27/env/bin/init
@@ -10,10 +10,6 @@ fi
if [ -e /dev/nand0 ]; then
addpart /dev/nand0 $nand_parts
-
- # Uh, oh, hush first expands wildcards and then starts executing
- # commands. What a bug!
- source /env/bin/hush_hack
fi
if [ -f /env/logo.bmp ]; then
diff --git a/arch/arm/boards/freescale-mx25-3ds/env/bin/hush_hack b/arch/arm/boards/freescale-mx25-3ds/env/bin/hush_hack
deleted file mode 100644
index 5fffa92..0000000
--- a/arch/arm/boards/freescale-mx25-3ds/env/bin/hush_hack
+++ /dev/null
@@ -1 +0,0 @@
-nand -a /dev/nand0.*
diff --git a/arch/arm/boards/freescale-mx25-3ds/env/bin/init b/arch/arm/boards/freescale-mx25-3ds/env/bin/init
index 0600b9e..8eafa34 100644
--- a/arch/arm/boards/freescale-mx25-3ds/env/bin/init
+++ b/arch/arm/boards/freescale-mx25-3ds/env/bin/init
@@ -10,10 +10,6 @@ fi
if [ -e /dev/nand0 ]; then
addpart /dev/nand0 $nand_parts
-
- # Uh, oh, hush first expands wildcards and then starts executing
- # commands. What a bug!
- source /env/bin/hush_hack
fi
echo
diff --git a/arch/arm/boards/mmccpu/env/bin/hush_hack b/arch/arm/boards/mmccpu/env/bin/hush_hack
deleted file mode 100644
index 5fffa92..0000000
--- a/arch/arm/boards/mmccpu/env/bin/hush_hack
+++ /dev/null
@@ -1 +0,0 @@
-nand -a /dev/nand0.*
diff --git a/arch/arm/boards/mmccpu/env/bin/init b/arch/arm/boards/mmccpu/env/bin/init
index ac84bd5..ad9b65a 100644
--- a/arch/arm/boards/mmccpu/env/bin/init
+++ b/arch/arm/boards/mmccpu/env/bin/init
@@ -10,10 +10,6 @@ fi
if [ -e /dev/nand0 ]; then
addpart /dev/nand0 $nand_parts
-
- # Uh, oh, hush first expands wildcards and then starts executing
- # commands. What a bug!
- source /env/bin/hush_hack
fi
if [ -z $eth0.ethaddr ]; then
diff --git a/arch/arm/boards/pm9263/env/bin/hush_hack b/arch/arm/boards/pm9263/env/bin/hush_hack
deleted file mode 100644
index 5fffa92..0000000
--- a/arch/arm/boards/pm9263/env/bin/hush_hack
+++ /dev/null
@@ -1 +0,0 @@
-nand -a /dev/nand0.*
diff --git a/arch/arm/boards/pm9263/env/bin/init b/arch/arm/boards/pm9263/env/bin/init
index 02f5cd4..ad9b65a 100644
--- a/arch/arm/boards/pm9263/env/bin/init
+++ b/arch/arm/boards/pm9263/env/bin/init
@@ -10,10 +10,6 @@ fi
if [ -e /dev/nand0 ]; then
addpart /dev/nand0 $nand_parts
-
- # Uh, oh, hush first expands wildcards and then starts executing
- # commands. What a bug!
- source /env/bin/hush_hack
fi
if [ -z $eth0.ethaddr ]; then
diff --git a/defaultenv/defaultenv-1/bin/init b/defaultenv/defaultenv-1/bin/init
index adb3c43..4781b5a 100644
--- a/defaultenv/defaultenv-1/bin/init
+++ b/defaultenv/defaultenv-1/bin/init
@@ -16,7 +16,6 @@ fi
if [ -e /dev/nand0 -a -n "$nand_parts" ]; then
addpart /dev/nand0 $nand_parts
- nand -a /dev/nand0.*
fi
if [ -f /env/bin/init_board ]; then
diff --git a/defaultenv/defaultenv-2-base/bin/mtdparts-add b/defaultenv/defaultenv-2-base/bin/mtdparts-add
index 58c9fa7..05ab638 100644
--- a/defaultenv/defaultenv-2-base/bin/mtdparts-add
+++ b/defaultenv/defaultenv-2-base/bin/mtdparts-add
@@ -39,10 +39,6 @@ fi
addpart -n /dev/${device} "$parts" || exit
mkdir -p /tmp/mtdparts/${device}
-if [ -n "${bbdev}" ]; then
- nand -a /dev/${device}.*
-fi
-
if [ -n ${kernelname} ]; then
global linux.mtdparts.${device}
global.linux.mtdparts.${device}="${kernelname}:${parts}"
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index c97c8c1..d954f72 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -409,6 +409,9 @@ int add_mtd_device(struct mtd_info *mtd, char *devname, int device_id)
devfs_create(&mtd->cdev);
+ if (mtd_can_have_bb(mtd))
+ mtd->cdev_bb = mtd_add_bb(mtd, NULL);
+
if (mtd->parent && !mtd->master)
of_parse_partitions(&mtd->cdev, mtd->parent->device_node);
diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index 5ed44a8..074be09 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -61,9 +61,6 @@ struct cdev *of_parse_partition(struct cdev *cdev, struct device_node *node)
new = devfs_add_partition(cdev->name, offset, size, flags, filename);
- if (cdev->mtd && cdev->mtd->type == MTD_NANDFLASH)
- dev_add_bb_dev(filename, NULL);
-
free(filename);
return new;
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index c63b514..5f02aee 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -211,6 +211,8 @@ struct mtd_info {
struct device_d *parent;
struct cdev cdev;
+ struct cdev *cdev_bb;
+
struct param_d param_size;
char *size_str;
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 6/6] OF: barebox-env: Use bb device on NAND
2014-04-28 9:49 [PATCH 1/6] environment: drop envfs_register_partition Sascha Hauer
` (3 preceding siblings ...)
2014-04-28 9:49 ` [PATCH 5/6] mtd: nand: create bb devices automatically Sascha Hauer
@ 2014-04-28 9:49 ` Sascha Hauer
4 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2014-04-28 9:49 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/barebox.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/drivers/of/barebox.c b/drivers/of/barebox.c
index 44ec820..8c05924 100644
--- a/drivers/of/barebox.c
+++ b/drivers/of/barebox.c
@@ -24,6 +24,7 @@
#include <malloc.h>
#include <partition.h>
#include <envfs.h>
+#include <linux/mtd/mtd.h>
struct of_partition {
struct list_head list;
@@ -57,6 +58,24 @@ static int environment_probe(struct device_d *dev)
if (ret)
return ret;
+ /*
+ * The environment support is not bad block aware, hence we
+ * have to use the .bb device. Test if we have a nand device
+ * and if yes, append .bb to the filename.
+ */
+ if (!strncmp(path, "/dev/", 5)) {
+ struct cdev *cdev;
+ char *cdevname;
+
+ cdevname = path + 5;
+ cdev = cdev_by_name(cdevname);
+ if (cdev && cdev->mtd && mtd_can_have_bb(cdev->mtd)) {
+ char *bbpath = asprintf("%s.bb", path);
+ free(path);
+ path = bbpath;
+ }
+ }
+
dev_info(dev, "setting default environment path to %s\n", path);
default_environment_path_set(path);
--
1.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread