summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2016-03-14 12:44:39 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2016-04-08 13:34:45 +0200
commitabb8c2703a3171fa33ea429e127c63a87975f6ab (patch)
tree9fb2b80f82c329195fab74ae784bb736dd17e6c3
parent05be9036220af61ee8d93f0197a05251e840c852 (diff)
downloadbarebox-abb8c2703a3171fa33ea429e127c63a87975f6ab.tar.gz
barebox-abb8c2703a3171fa33ea429e127c63a87975f6ab.tar.xz
commands: ubidetach: Allow mtd devices as argument
Instead of only allow ubi numbers make it possible to detach a mtd device. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--commands/ubi.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/commands/ubi.c b/commands/ubi.c
index 8e35787fa2..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(ubi_num);
+ 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