[PATCH 6/6] OF: barebox-env: Use bb device on NAND

Sascha Hauer s.hauer at pengutronix.de
Mon Apr 28 02:49:39 PDT 2014


Signed-off-by: Sascha Hauer <s.hauer at 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




More information about the barebox mailing list