summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/ubi.c30
-rw-r--r--commands/ubiformat.c24
-rw-r--r--commands/umount.c2
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