static struct selected_dev ubi_dev;
+#ifdef CONFIG_CMD_UBIFS
+int ubifs_is_mounted(void);
+void cmd_ubifs_umount(void);
+#endif
+
static void ubi_dump_vol_info(const struct ubi_volume *vol)
{
ubi_msg("volume information dump:");
{
int i, err, reserved_pebs;
int found = 0, vol_id = 0;
- struct ubi_volume *vol;
+ struct ubi_volume *vol = NULL;
for (i = 0; i < ubi->vtbl_slots; i++) {
vol = ubi->volumes[i];
return err ? err : count_save - size;
}
-static int ubi_dev_scan(struct mtd_info *info, char *ubidev)
+static int ubi_dev_scan(struct mtd_info *info, char *ubidev,
+ const char *vid_header_offset)
{
struct mtd_device *dev;
struct part_info *part;
struct mtd_partition mtd_part;
+ char ubi_mtd_param_buffer[80];
u8 pnum;
int err;
mtd_part.offset = part->offset;
add_mtd_partitions(info, &mtd_part, 1);
- err = ubi_mtd_param_parse(buffer, NULL);
+ strcpy(ubi_mtd_param_buffer, buffer);
+ if (vid_header_offset)
+ sprintf(ubi_mtd_param_buffer, "mtd=%d,%s", pnum,
+ vid_header_offset);
+ err = ubi_mtd_param_parse(ubi_mtd_param_buffer, NULL);
if (err) {
del_mtd_partitions(info);
return err;
return 0;
}
-static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+static int do_ubi(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
{
size_t size = 0;
ulong addr = 0;
int err = 0;
- if (argc < 2) {
- cmd_usage(cmdtp);
- return 1;
- }
+ if (argc < 2)
+ return cmd_usage(cmdtp);
if (mtdparts_init() != 0) {
printf("Error initializing mtdparts!\n");
char mtd_dev[16];
struct mtd_device *dev;
struct part_info *part;
+ const char *vid_header_offset = NULL;
u8 pnum;
/* Print current partition */
return 0;
}
- if (argc < 3) {
- cmd_usage(cmdtp);
- return 1;
- }
+ if (argc < 3)
+ return cmd_usage(cmdtp);
+
+#ifdef CONFIG_CMD_UBIFS
+ /*
+ * Automatically unmount UBIFS partition when user
+ * changes the UBI device. Otherwise the following
+ * UBIFS commands will crash.
+ */
+ if (ubifs_is_mounted())
+ cmd_ubifs_umount();
+#endif
/* todo: get dev number for NAND... */
ubi_dev.nr = 0;
ubi_dev.selected = 1;
+ if (argc > 3)
+ vid_header_offset = argv[3];
strcpy(ubi_dev.part_name, argv[2]);
- err = ubi_dev_scan(ubi_dev.mtd_info, ubi_dev.part_name);
+ err = ubi_dev_scan(ubi_dev.mtd_info, ubi_dev.part_name,
+ vid_header_offset);
if (err) {
printf("UBI init error %d\n", err);
ubi_dev.selected = 0;
return -1;
}
-U_BOOT_CMD(ubi, 6, 1, do_ubi,
+U_BOOT_CMD(
+ ubi, 6, 1, do_ubi,
"ubi commands",
- "part [part]"
- " - Show or set current partition\n"
+ "part [part] [offset]\n"
+ " - Show or set current partition (with optional VID"
+ " header offset)\n"
"ubi info [l[ayout]]"
" - Display volume and ubi layout information\n"
"ubi create[vol] volume [size] [type]"
"ubi remove[vol] volume"
" - Remove volume\n"
"[Legends]\n"
- " volume: charater name\n"
- " size: KiB, MiB, GiB, and bytes\n"
- " type: s[tatic] or d[ynamic] (default=dynamic)\n"
+ " volume: character name\n"
+ " size: specified in bytes\n"
+ " type: s[tatic] or d[ynamic] (default=dynamic)"
);