Skip to contentSkip to conversation

UBI: Enable re-initializing of the "ubi part" command

PATCH New Stefan Roese 1 participant 1 message Dec 2, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 UBI: Enable re-initializing of the "ubi part" command

With this patch now, the user can call "ubi part" multiple times to re-connect the UBI device to another MTD partition.

---
v2:
- Call del_mtd_partitions() after calling ubi_exit() to really clean up the previously configured mtd subsystem.

 common/cmd_ubi.c        |   11 +++++++++++
 drivers/mtd/ubi/build.c |    1 +
 include/ubi_uboot.h     |    1 +
 3 files changed, 13 insertions(+), 0 deletions(-)
common/cmd_ubi.c +11 -0
index 8446765..495d71e 100644
@@ -31,6 +31,7 @@
 /* Private own data */
 static struct ubi_device *ubi;
 static char buffer[80];
+static int ubi_initialized;
 
 struct selected_dev {
 	char dev_name[32];	/* NAND/OneNAND etc */
@@ -428,6 +429,8 @@ static int ubi_dev_scan(struct mtd_info *info, char *ubidev)
 		return err;
 	}
 
+	ubi_initialized = 1;
+
 	return 0;
 }
 
@@ -464,6 +467,14 @@ static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 		ubi_dev.nr = 0;
 
 		/*
+		 * Call ubi_exit() before re-initializing the UBI subsystem
+		 */
+		if (ubi_initialized) {
+			ubi_exit();
+			del_mtd_partitions(ubi_dev.mtd_info);
+		}
+
+		/*
 		 * Check for nand|onenand selection
 		 */
 #if defined(CONFIG_CMD_NAND)
drivers/mtd/ubi/build.c +1 -0
index 17cabb2..bdf75c9 100644
@@ -1059,6 +1059,7 @@ void __exit ubi_exit(void)
 	misc_deregister(&ubi_ctrl_cdev);
 	class_remove_file(ubi_class, &ubi_version);
 	class_destroy(ubi_class);
+	mtd_devs = 0;
 }
 module_exit(ubi_exit);
 
include/ubi_uboot.h +1 -0
index 295f2c0..095dfc1 100644
@@ -211,6 +211,7 @@ static inline long IS_ERR(const void *ptr)
 /* functions */
 extern int ubi_mtd_param_parse(const char *val, struct kernel_param *kp);
 extern int ubi_init(void);
+extern void ubi_exit(void);
 
 extern struct ubi_device *ubi_devices[];
 
Signature · 1 line
1.6.0.4