[U-Boot] [PATCH] ubi: reset relevant globals in ubi_exit()
Andrew Ruder
andrew.ruder at elecsyscorp.com
Thu Nov 13 18:05:28 CET 2014
Before calling ubi_init() the U-Boot wrapper calls ubi_mtd_param_parse()
to have the UBI driver add it to its mtd_dev_param[] array and increment
mtd_devs. The first time ubi_init() is called, mtd_devs would be 1.
Before ubi_init() is called again (another partition is attached),
ubi_mtd_param_parse() is called again, incrementing mtd_devs again (now
2). This results in ubi_init() now trying to attach the first partition
and the second partition.
Fix this by adding a section at the end of ubi_exit() where we reset any
globals that would need to be reset (in this case, just mtd_devs).
Test case:
$ ubi part <mtdname> ; ubi part <mtdname>
Before patch:
$ ubi part data
UBI: attaching mtd1 to ubi0
UBI: scanning is finished
UBI: attached mtd1 (name "mtd=4", size 4 MiB) to ubi0
[...]
UBI: available PEBs: 0, total reserved PEBs: 32, [...]
$ ubi part data
UBI: detaching mtd1 from ubi0
UBI: mtd1 is detached from ubi0
UBI: attaching mtd1 to ubi0
[...]
UBI: available PEBs: 0, total reserved PEBs: 32, [...]
** Note that this is where it tries to attach mtd1 again, fails, and
** then detaches everything as it errors out of ubi_init()
UBI: detaching mtd1 from ubi0
UBI: mtd1 is detached from ubi0
UBI init error 17
$
After patch:
$ ubi part data
UBI: attaching mtd1 to ubi0
UBI: scanning is finished
UBI: attached mtd1 (name "mtd=4", size 4 MiB) to ubi0
[...]
UBI: available PEBs: 0, total reserved PEBs: 32, [...]
$ ubi part data
UBI: detaching mtd1 from ubi0
UBI: mtd1 is detached from ubi0
UBI: attaching mtd1 to ubi0
UBI: scanning is finished
UBI: attached mtd1 (name "mtd=4", size 4 MiB) to ubi0
[...]
UBI: available PEBs: 0, total reserved PEBs: 32, [...]
$
Signed-off-by: Andrew Ruder <andrew.ruder at elecsyscorp.com>
Cc: Heiko Schocher <hs at denx.de>
Cc: Kyungmin Park <kmpark at infradead.org>
---
drivers/mtd/ubi/build.c | 4 ++++
1 file changed, 4 insertions(+)
Not sure this is the best place to make the change, but it is one of the least
obtrusive, IMO. Please Cc: me on any responses as it will go directly to my inbox!
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 584cf5f..fc5cbce 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -1384,6 +1384,10 @@ void ubi_exit(void)
misc_deregister(&ubi_ctrl_cdev);
class_remove_file(ubi_class, &ubi_version);
class_destroy(ubi_class);
+#ifdef __UBOOT__
+ /* Reset any globals that the driver depends on being zeroed */
+ mtd_devs = 0;
+#endif
}
module_exit(ubi_exit);
--
2.1.1
More information about the U-Boot
mailing list