diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2016-04-08 13:37:28 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-04-08 13:37:28 +0200 |
commit | 5a4379527259d426c2ac8f5f06c358c175a33237 (patch) | |
tree | 2589a5cc2e223ae7706efb7035ebc729be2738fa /commands | |
parent | 11b2257f4b2c7440925f1c0772905f3c4eea2def (diff) | |
parent | d43c5b45ab24b9639a103b2ff9d829962c0e472b (diff) | |
download | barebox-5a4379527259d426c2ac8f5f06c358c175a33237.tar.gz barebox-5a4379527259d426c2ac8f5f06c358c175a33237.tar.xz |
Merge branch 'for-next/ubiformat'
Diffstat (limited to 'commands')
-rw-r--r-- | commands/ubi.c | 30 | ||||
-rw-r--r-- | commands/ubiformat.c | 24 | ||||
-rw-r--r-- | commands/umount.c | 2 |
3 files changed, 49 insertions, 7 deletions
diff --git a/commands/ubi.c b/commands/ubi.c index 9463127151..844d75dcb8 100644 --- a/commands/ubi.c +++ b/commands/ubi.c @@ -122,14 +122,36 @@ BAREBOX_CMD_END static int do_ubidetach(int argc, char *argv[]) { - int ubi_num, ret; + int fd, ret; + struct mtd_info_user user; if (argc != 2) return COMMAND_ERROR_USAGE; - ubi_num = simple_strtoul(argv[1], NULL, 0); - ret = ubi_detach_mtd_dev(ubi_num, 1); + fd = open(argv[optind], O_RDWR); + if (fd < 0) { + int ubi_num = simple_strtoul(argv[1], NULL, 0); + ret = ubi_detach(ubi_num); + goto out; + } + + ret = ioctl(fd, MEMGETINFO, &user); + if (!ret) { + int ubi_num = ubi_num_get_by_mtd(user.mtd); + if (ubi_num < 0) { + ret = ubi_num; + goto out; + } + + ret = ubi_detach(ubi_num); + if (!ret) + goto out_close; + } + +out_close: + close(fd); +out: if (ret) printf("failed to detach: %s\n", strerror(-ret)); @@ -139,7 +161,7 @@ static int do_ubidetach(int argc, char *argv[]) BAREBOX_CMD_START(ubidetach) .cmd = do_ubidetach, BAREBOX_CMD_DESC("detach an UBI device") - BAREBOX_CMD_OPTS("UBINUM") + BAREBOX_CMD_OPTS("mtd device/UBINUM") BAREBOX_CMD_GROUP(CMD_GRP_PART) BAREBOX_CMD_END diff --git a/commands/ubiformat.c b/commands/ubiformat.c index 0172654231..2ffdd0c1b5 100644 --- a/commands/ubiformat.c +++ b/commands/ubiformat.c @@ -42,6 +42,7 @@ #include <libbb.h> #include <libfile.h> #include <linux/mtd/mtd.h> +#include <linux/mtd/ubi.h> #include <linux/kernel.h> #include <linux/stat.h> #include <linux/log2.h> @@ -562,6 +563,7 @@ int do_ubiformat(int argc, char *argv[]) struct ubigen_info ui; struct ubi_scan_info *si; struct mtd_info_user mtd_user; + int ubi_num; err = parse_opt(argc, argv); if (err) @@ -622,8 +624,15 @@ int do_ubiformat(int argc, char *argv[]) goto out_close; } - /* Make sure this MTD device is not attached to UBI */ - /* FIXME! Find a proper way to do this in barebox! */ + ubi_num = ubi_num_get_by_mtd(mtd_user.mtd); + if (ubi_num >= 0) { + err = ubi_detach(ubi_num); + if (err) { + sys_errmsg("Cannot detach %d\n", err); + goto out_close; + } + } + eb_cnt = mtd_div_by_eb(mtd->size, mtd); @@ -759,6 +768,17 @@ int do_ubiformat(int argc, char *argv[]) } libscan_ubi_scan_free(si); + + /* Reattach the ubi device in case it was attached in the beginning */ + if (ubi_num >= 0) { + err = ubi_attach_mtd_dev(mtd_user.mtd, ubi_num, 0, 20); + if (err) { + pr_err("Failed to reattach ubi device to ubi number %d, %d\n", + ubi_num, err); + return err; + } + } + return 0; out_free: diff --git a/commands/umount.c b/commands/umount.c index 84c84e42c6..fdf4da95a0 100644 --- a/commands/umount.c +++ b/commands/umount.c @@ -37,7 +37,7 @@ BAREBOX_CMD_HELP_END BAREBOX_CMD_START(umount) .cmd = do_umount, BAREBOX_CMD_DESC("umount a filesystem") - BAREBOX_CMD_OPTS("MOUNTPOINT") + BAREBOX_CMD_OPTS("MOUNTPOINT/DEVICEPATH") BAREBOX_CMD_GROUP(CMD_GRP_PART) BAREBOX_CMD_HELP(cmd_umount_help) BAREBOX_CMD_END |