From 3781d93b06fddd9a5522e7ea7412e17693ece45c Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 9 Apr 2014 16:14:55 +0200 Subject: [PATCH] OF: barebox-env: Use bb device on NAND Signed-off-by: Sascha Hauer --- drivers/of/barebox.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/of/barebox.c b/drivers/of/barebox.c index 44ec820ec..8c05924be 100644 --- a/drivers/of/barebox.c +++ b/drivers/of/barebox.c @@ -24,6 +24,7 @@ #include #include #include +#include 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);