From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 12/12] Add UBI commands: ubiattach, ubidetach, ubimkvol, ubirmvol
Date: Mon, 5 Jul 2010 15:16:35 +0200 [thread overview]
Message-ID: <1278335795-16289-13-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1278335795-16289-1-git-send-email-s.hauer@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/Kconfig | 6 +++
commands/Makefile | 1 +
commands/ubi.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 136 insertions(+), 0 deletions(-)
create mode 100644 commands/ubi.c
diff --git a/commands/Kconfig b/commands/Kconfig
index 0ea32d9..1ffc826 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -180,6 +180,12 @@ menu "flash "
config CMD_FLASH
tristate
prompt "protect/erase"
+
+config CMD_UBI
+ tristate
+ default y if UBI
+ prompt "ubimkvol, ubirmvol, ubiattach"
+
endmenu
diff --git a/commands/Makefile b/commands/Makefile
index 3eef5de..b99f042 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -49,3 +49,4 @@ obj-$(CONFIG_USB_GADGET_DFU) += dfu.o
obj-$(CONFIG_CMD_GPIO) += gpio.o
obj-$(CONFIG_CMD_UNLZO) += unlzo.o
obj-$(CONFIG_CMD_I2C) += i2c.o
+obj-$(CONFIG_CMD_UBI) += ubi.o
diff --git a/commands/ubi.c b/commands/ubi.c
new file mode 100644
index 0000000..3da0835
--- /dev/null
+++ b/commands/ubi.c
@@ -0,0 +1,129 @@
+#include <common.h>
+#include <command.h>
+#include <fs.h>
+#include <fcntl.h>
+#include <ioctl.h>
+#include <errno.h>
+#include <getopt.h>
+#include <linux/mtd/mtd.h>
+#include <linux/kernel.h>
+#include <linux/mtd/mtd-abi.h>
+#include <mtd/ubi-user.h>
+#include <ubi-media.h>
+
+static int do_ubimkvol(struct command *cmdtp, int argc, char *argv[])
+{
+ struct ubi_mkvol_req req;
+ int fd, ret;
+ size_t size;
+
+ if (argc != 4)
+ return COMMAND_ERROR_USAGE;
+
+ size = strtoul_suffix(argv[3], NULL, 0);
+ req.name_len = min_t(int, strlen(argv[2]), UBI_VOL_NAME_MAX);
+ strncpy(req.name, argv[2], req.name_len);
+ req.name[req.name_len] = 0;
+
+ req.vol_type = UBI_DYNAMIC_VOLUME;
+ req.bytes = size;
+ req.vol_id = UBI_VOL_NUM_AUTO;
+ req.alignment = 1;
+
+ fd = open(argv[1], O_WRONLY);
+ if (fd < 0) {
+ perror("open");
+ return 1;
+ }
+
+ ret = ioctl(fd, UBI_IOCMKVOL, &req);
+ if (ret)
+ printf("failed to create: %s\n", strerror(-ret));
+ close(fd);
+
+ return ret ? 1 : 0;
+}
+
+static const __maybe_unused char cmd_ubimkvol_help[] =
+"Usage: ubimkvol <ubidev> <name> <size>\n"
+"Create an ubi volume on <ubidev> with name <name> and size <size>\n"
+"If size os zero all available space is used for the volume\n";
+
+BAREBOX_CMD_START(ubimkvol)
+ .cmd = do_ubimkvol,
+ .usage = "create an ubi volume",
+ BAREBOX_CMD_HELP(cmd_ubimkvol_help)
+BAREBOX_CMD_END
+
+
+static int do_ubiattach(struct command *cmdtp, int argc, char *argv[])
+{
+ struct mtd_info_user user;
+ int fd, ret;
+
+ if (argc != 2)
+ return COMMAND_ERROR_USAGE;
+
+ fd = open(argv[1], O_RDWR);
+ if (fd < 0) {
+ perror("open");
+ return 1;
+ }
+
+ ret = ioctl(fd, MEMGETINFO, &user);
+ if (!ret)
+ ret = ubi_attach_mtd_dev(user.mtd, UBI_DEV_NUM_AUTO, 0);
+
+ if (ret)
+ printf("failed to attach: %s\n", strerror(-ret));
+
+ close(fd);
+
+ return ret ? 1 : 0;
+}
+
+static const __maybe_unused char cmd_ubiattach_help[] =
+"Usage: ubiattach <mtddev>\n"
+"Attach <mtddev> to ubi\n";
+
+BAREBOX_CMD_START(ubiattach)
+ .cmd = do_ubiattach,
+ .usage = "attach a mtd dev to ubi",
+ BAREBOX_CMD_HELP(cmd_ubiattach_help)
+BAREBOX_CMD_END
+
+static int do_ubirmvol(struct command *cmdtp, int argc, char *argv[])
+{
+ struct ubi_mkvol_req req;
+ int fd, ret;
+
+ if (argc != 3)
+ return COMMAND_ERROR_USAGE;
+
+ strncpy(req.name, argv[2], UBI_VOL_NAME_MAX);
+ req.name[UBI_VOL_NAME_MAX] = 0;
+
+ fd = open(argv[1], O_WRONLY);
+ if (fd < 0) {
+ perror("open");
+ return 1;
+ }
+
+ ret = ioctl(fd, UBI_IOCRMVOL, &req);
+ if (ret)
+ printf("failed to delete: %s\n", strerror(-ret));
+ close(fd);
+
+ return ret ? 1 : 0;
+}
+
+static const __maybe_unused char cmd_ubirmvol_help[] =
+"Usage: ubirmvol <ubidev> <name>\n"
+"Delete ubi volume <name> from <ubidev>\n";
+
+BAREBOX_CMD_START(ubirmvol)
+ .cmd = do_ubirmvol,
+ .usage = "delete an ubi volume",
+ BAREBOX_CMD_HELP(cmd_ubirmvol_help)
+BAREBOX_CMD_END
+
--
1.7.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2010-07-05 13:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-05 13:16 UBI support Sascha Hauer
2010-07-05 13:16 ` [PATCH 01/12] crc32: activate crc32_no_comp (needed for jffs2 and UBI) Sascha Hauer
2010-07-05 13:16 ` [PATCH 02/12] move drivers/nand to drivers/mtd/nand Sascha Hauer
2010-07-05 13:16 ` [PATCH 03/12] add rbtree support (needed for ubi) Sascha Hauer
2010-07-05 13:16 ` [PATCH 04/12] add partition mtd support Sascha Hauer
2010-07-05 13:16 ` [PATCH 05/12] cfi_flash: Do not typedef struct flash_info Sascha Hauer
2010-07-05 13:16 ` [PATCH 06/12] cfi_flash: Do not print debug info while erasing Sascha Hauer
2010-07-05 13:16 ` [PATCH 07/12] cfi_flash: Add mtd partition support for UBI Sascha Hauer
2010-07-05 13:16 ` [PATCH 08/12] devfs: only check for ioctl function when needed Sascha Hauer
2010-07-05 13:16 ` [PATCH 09/12] include stuff missing for ubi Sascha Hauer
2010-07-05 13:16 ` [PATCH 10/12] add ubi support from u-boot. Just enough to compile and scan Sascha Hauer
2010-07-05 13:16 ` [PATCH 11/12] barebox ubi changes Sascha Hauer
2010-07-05 13:16 ` Sascha Hauer [this message]
2010-07-05 15:22 ` [PATCH 02/12] move drivers/nand to drivers/mtd/nand Alessandro Rubini
2010-07-06 6:31 ` Sascha Hauer
2010-07-08 9:19 ` UBI support Baruch Siach
2010-07-16 7:27 ` Sascha Hauer
2010-07-16 8:57 ` Eric Bénard
2010-07-16 12:13 ` Esben Haabendal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1278335795-16289-13-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox