Skip to contentSkip to conversation

ubinfo: document the new -N option

PATCH In review Artem Bityutskiy 2 participants 6 messages Apr 8, 2010 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 ubinfo: document the new -N option

From: Artem Bityutskiy <[email protected]>

---
 ubi-utils/src/ubinfo.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
ubi-utils/src/ubinfo.c +4 -2
index cd011c5..8f84382 100644
@@ -56,6 +56,7 @@ static const char *doc = PROGRAM_NAME " version " PROGRAM_VERSION
 static const char *optionsstr =
 "-d, --devn=<UBI device number>  UBI device number to get information about\n"
 "-n, --vol_id=<volume ID>        ID of UBI volume to print information about\n"
+"-N, --name=<volume name>        name of UBI volume to print information about\n"
 "-a, --all                       print information about all devices and volumes,\n"
 "                                or about all volumes if the UBI device was\n"
 "                                specified\n"
@@ -63,8 +64,8 @@ static const char *optionsstr =
 "-V, --version                   print program version";
 
 static const char *usage =
-"Usage 1: " PROGRAM_NAME " [-d <UBI device number>] [-n <volume ID>] [-a] [-h] [-V] [--vol_id=<volume ID>]\n"
-"\t\t[--devn <UBI device number>] [--all] [--help] [--version]\n"
+"Usage 1: " PROGRAM_NAME " [-d <UBI device number>] [-n <volume ID> | -N <volume name>] [-a] [-h] [-V]\n"
+"\t\t[--vol_id=<volume ID> | --name <volume name>] [--devn <UBI device number>] [--all] [--help] [--version]\n"
 "Usage 2: " PROGRAM_NAME " <UBI device node file name> [-a] [-h] [-V] [--all] [--help] [--version]\n"
 "Usage 3: " PROGRAM_NAME " <UBI volume node file name> [-h] [-V] [--help] [--version]\n\n"
 "Example 1: " PROGRAM_NAME " - (no arguments) print general UBI information\n"
@@ -77,6 +78,7 @@ static const char *usage =
 static const struct option long_options[] = {
 	{ .name = "devn",      .has_arg = 1, .flag = NULL, .val = 'd' },
 	{ .name = "vol_id",    .has_arg = 1, .flag = NULL, .val = 'n' },
+	{ .name = "name",      .has_arg = 1, .flag = NULL, .val = 'N' },
 	{ .name = "all",       .has_arg = 0, .flag = NULL, .val = 'a' },
 	{ .name = "help",      .has_arg = 0, .flag = NULL, .val = 'h' },
 	{ .name = "version",   .has_arg = 0, .flag = NULL, .val = 'V' },
Signature · 1 line
1.6.6.1
#1 lore raw

PATCH 2/4 UBI: sync ubi-user.h with the lates kernel verion

From: Mika Westerberg <[email protected]>

---
 include/mtd/ubi-user.h |   28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 deletions(-)
include/mtd/ubi-user.h +21 -7
index 296efae..4b139a6 100644
@@ -25,11 +25,12 @@
  * UBI device creation (the same as MTD device attachment)
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  *
- * MTD devices may be attached using %UBI_IOCATT ioctl command of the UBI
- * control device. The caller has to properly fill and pass
- * &struct ubi_attach_req object - UBI will attach the MTD device specified in
- * the request and return the newly created UBI device number as the ioctl
- * return value.
+ * MTD and block devices may be attached using %UBI_IOCATT ioctl command of the
+ * UBI control device. The caller has to properly fill and pass
+ * &struct ubi_attach_req object. If the @bdev_major and @bdev_minor fields
+ * contain zeroes, UBI will attaches MTD device number @mtd_num. Otherwise it
+ * attaches block device with major/minor numbers @bdev_major and @bdev_minor.
+ * The ioctl returns the newly created UBI device number.
  *
  * UBI device deletion (the same as MTD device detachment)
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -235,14 +236,25 @@ enum {
  * @ubi_num: UBI device number to create
  * @mtd_num: MTD device number to attach
  * @vid_hdr_offset: VID header offset (use defaults if %0)
+ * @bdev_major: major number of the block device to attach
+ * @bdev_minor: minor number of the block device to attach
  * @padding: reserved for future, not used, has to be zeroed
  *
- * This data structure is used to specify MTD device UBI has to attach and the
+ * This data structure is used to specify the device UBI has to attach and the
  * parameters it has to use. The number which should be assigned to the new UBI
  * device is passed in @ubi_num. UBI may automatically assign the number if
  * @UBI_DEV_NUM_AUTO is passed. In this case, the device number is returned in
  * @ubi_num.
  *
+ * UBI can attach block and MTD devices. To attach a block device, @bdev_major
+ * and @bdev_minor have to contain block device major an minor numbers. And
+ * @mtd_num and @vid_hdr_offset have to contain zeroes. Note, the major number
+ * cannot be zero. To attach an MTD device, @bdev_major and @bdev_minor have to
+ * contain zeroes, while @mtd_num has to contain the MTD device number to
+ * attach.
+ *
+ * The rest of the documentation is specific to the MTD device case.
+ *
  * Most applications should pass %0 in @vid_hdr_offset to make UBI use default
  * offset of the VID header within physical eraseblocks. The default offset is
  * the next min. I/O unit after the EC header. For example, it will be offset
@@ -263,7 +275,9 @@ struct ubi_attach_req {
 	int32_t ubi_num;
 	int32_t mtd_num;
 	int32_t vid_hdr_offset;
-	int8_t padding[12];
+	int32_t bdev_major;
+	int32_t bdev_minor;
+	int8_t padding[4];
 };
 
 /**
Signature · 1 line
1.6.6.1
#2 lore raw

Re: [PATCH 2/4] UBI: sync ubi-user.h with the lates kernel verion

Quoted 6 lines

+ * UBI can attach block and MTD devices. To attach a block device, @bdev_major
+ * and @bdev_minor have to contain block device major an minor numbers. And
+ * @mtd_num and @vid_hdr_offset have to contain zeroes. Note, the major number
+ * cannot be zero. To attach an MTD device, @bdev_major and @bdev_minor have to
+ * contain zeroes, while @mtd_num has to contain the MTD device number to
+ * attach.

I can't find anything about UBI being able to attach block devices in
http://git.infradead.org/ubi-2.6.git,
did I miss something ?
Thanks

Signature · 2 lines
Corentin Chary
http://xf.iksaif.net
#3 lore raw

Re: [PATCH 2/4] UBI: sync ubi-user.h with the lates kernel verion

Quoted 10 lines · Corentin Chary
Quoted 6 lines

+ * UBI can attach block and MTD devices. To attach a block device, @bdev_major
+ * and @bdev_minor have to contain block device major an minor numbers. And
+ * @mtd_num and @vid_hdr_offset have to contain zeroes. Note, the major number
+ * cannot be zero. To attach an MTD device, @bdev_major and @bdev_minor have to
+ * contain zeroes, while @mtd_num has to contain the MTD device number to
+ * attach.

I can't find anything about UBI being able to attach block devices in
http://git.infradead.org/ubi-2.6.git,
did I miss something ?

Oh, right. This is wrong patch, sorry, it is not needed. The other are fine.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
#4 lore raw

PATCH 3/4 libubi: add support to attach/detach by MTD device path

In reply to Artem Bityutskiy

From: Mika Westerberg <[email protected]>

struct ubi_attach_request now has additional field 'dev' that can contain path to the MTD device node in the filesystem. Also there are two new functions that are able to handle path to the MTD device node:

ubi_attach() - attach MTD device by number or by path ubi_detach() - detach MTD device by path

ubi_attach() works like ubi_attach_mtd() when it is passed empty req->dev, otherwise it looks up correct MTD device number based on the given device node path.

---
 ubi-utils/include/libubi.h |   30 ++++++++++
 ubi-utils/src/libubi.c     |  127 +++++++++++++++++++++++++++++++++++++++-----
 ubi-utils/src/libubi_int.h |    1 +
 3 files changed, 145 insertions(+), 13 deletions(-)
ubi-utils/include/libubi.h +30 -0
index f52904d..64b5eed 100644
@@ -44,6 +44,7 @@ typedef void * libubi_t;
  *           (%UBI_DEV_NUM_AUTO should be used to automatically assign the
  *           number)
  * @mtd_num: MTD device number to attach
+ * @dev: path to device node to attach
  * @vid_hdr_offset: VID header offset (%0 means default offset and this is what
  *                  most of the users want)
  */
@@ -51,6 +52,7 @@ struct ubi_attach_request
 {
 	int dev_num;
 	int mtd_num;
+	const char *dev;
 	int vid_hdr_offset;
 };
 
@@ -219,6 +221,23 @@ int ubi_attach_mtd(libubi_t desc, const char *node,
 		   struct ubi_attach_request *req);
 
 /**
+ * ubi_attach - attach an MTD device by its node path.
+ * @desc: UBI library descriptor
+ * @node: name of the UBI control character device node
+ * @req: MTD attach request
+ *
+ * This function creates new UBI device by attaching an MTD device described by
+ * @req. If @req->dev is given it should contain path to the MTD device node.
+ * Otherwise functionality is similar than in function 'ubi_attach_mtd()' where
+ * @req->mtd_num is used.
+ *
+ * Returns %0 in case of success and %-1 in case of failure (errno is set). The
+ * newly created UBI device number is returned in @req->dev_num.
+ */
+int ubi_attach(libubi_t desc, const char *node,
+	       struct ubi_attach_request *req);
+
+/**
  * ubi_detach_mtd - detach an MTD device.
  * @desc: UBI library descriptor
  * @node: name of the UBI control character device node
@@ -231,6 +250,17 @@ int ubi_attach_mtd(libubi_t desc, const char *node,
 int ubi_detach_mtd(libubi_t desc, const char *node, int mtd_num);
 
 /**
+ * ubi_detach - detach an MTD device by its node path.
+ * @desc: UBI library descriptor
+ * @node: name of the UBI control character device node
+ * @dev: path to an MTD device node
+ *
+ * This function detaches an MTD device @dev from UBI. Returns zero in case of
+ * success and %-1 in case of failure.
+ */
+int ubi_detach(libubi_t desc, const char *node, const char *dev);
+
+/**
  * ubi_remove_dev - remove an UBI device.
  * @desc: UBI library descriptor
  * @node: name of the UBI control character device node
ubi-utils/src/libubi.c +114 -13

155 lines not on this page · raw message

ubi-utils/src/libubi_int.h +1 -0
index 6d17d57..c3aa37a 100644
@@ -83,6 +83,7 @@ extern "C" {
  *                handling
  * @dev_max_vols: maximum volumes number count sysfs path pattern
  * @dev_min_io_size: minimum I/O unit size sysfs path pattern
+ * @dev_mtd_num: MTD device number
  * @ubi_vol: UBI volume sysfs directory pattern
  * @vol_type: volume type sysfs path pattern
  * @vol_dev: volume major/minor numbers file pattern
Signature · 1 line
1.6.6.1
#5 lore raw

PATCH 4/4 ubiattach/ubidetach: add support to attach/detach by path

In reply to Artem Bityutskiy

From: Mika Westerberg <[email protected]>

Now there is a new option '-p' (or '--dev-path') that can be used to pass path to a MTD device node.

---
 ubi-utils/src/ubiattach.c |   35 +++++++++++++++++++--------
 ubi-utils/src/ubidetach.c |   57 ++++++++++++++++++++++++++++++--------------
 2 files changed, 64 insertions(+), 28 deletions(-)
ubi-utils/src/ubiattach.c +25 -10
index a935b42..67f8c85 100644
@@ -39,6 +39,7 @@ struct args {
 	int mtdn;
 	int vidoffs;
 	const char *node;
+	const char *dev;
 };
 
 static struct args args = {
@@ -46,6 +47,7 @@ static struct args args = {
 	.mtdn = -1,
 	.vidoffs = 0,
 	.node = NULL,
+	.dev = NULL,
 };
 
 static const char *doc = PROGRAM_NAME " version " PROGRAM_VERSION
@@ -55,7 +57,9 @@ static const char *optionsstr =
 "-d, --devn=<UBI device number>  the number to assign to the newly created UBI device\n"
 "                                (the number is assigned automatically if this is not\n"
 "                                specified\n"
-"-m, --mtdn=<MTD device number>  MTD device number to attach\n"
+"-p, --dev-path=<path to device> path to MTD device node to attach\n"
+"-m, --mtdn=<MTD device number>  MTD device number to attach (alternative method, e.g\n"
+"                                if the character device node does not exist)\n"
 "-O, --vid-hdr-offset            VID header offset (do not specify this unless you\n"
 "                                really know what you do and the optimal defaults will\n"
 "                                be used)\n"
@@ -63,14 +67,18 @@ static const char *optionsstr =
 "-V, --version                   print program version";
 
 static const char *usage =
-"Usage: " PROGRAM_NAME " <UBI control device node file name> [-m <MTD device number>] [-d <UBI device number>]\n"
-"\t\t[--mtdn=<MTD device number>] [--devn <UBI device number>]\n"
-"Example 1: " PROGRAM_NAME " /dev/ubi_ctrl -m 0 - attach MTD device 0 (mtd0) to UBI\n"
-"Example 2: " PROGRAM_NAME " /dev/ubi_ctrl -m 0 -d 3 - attach MTD device 0 (mtd0) to UBI and\n"
+"Usage: " PROGRAM_NAME " <UBI control device node file name>\n"
+"\t[-m <MTD device number>] [-d <UBI device number>] [-p <path to device>]\n"
+"\t[--mtdn=<MTD device number>] [--devn=<UBI device number>]\n"
+"\t[--dev-path=<path to device>]\n"
+"Example 1: " PROGRAM_NAME " /dev/ubi_ctrl -p /dev/mtd0 - attach /dev/mtd0 to UBI\n"
+"Example 2: " PROGRAM_NAME " /dev/ubi_ctrl -m 0 - attach MTD device 0 (mtd0) to UBI\n"
+"Example 3: " PROGRAM_NAME " /dev/ubi_ctrl -m 0 -d 3 - attach MTD device 0 (mtd0) to UBI and\n"
 "           and create UBI device number 3 (ubi3)";
 
 static const struct option long_options[] = {
 	{ .name = "devn",           .has_arg = 1, .flag = NULL, .val = 'd' },
+	{ .name = "dev-path",       .has_arg = 1, .flag = NULL, .val = 'p' },
 	{ .name = "mtdn",           .has_arg = 1, .flag = NULL, .val = 'm' },
 	{ .name = "vid-hdr-offset", .has_arg = 1, .flag = NULL, .val = 'O' },
 	{ .name = "help",           .has_arg = 0, .flag = NULL, .val = 'h' },
@@ -84,11 +92,14 @@ static int parse_opt(int argc, char * const argv[])
 		int key;
 		char *endp;
 
-		key = getopt_long(argc, argv, "m:d:O:hV", long_options, NULL);
+		key = getopt_long(argc, argv, "p:m:d:O:hV", long_options, NULL);
 		if (key == -1)
 			break;
 
 		switch (key) {
+		case 'p':
+			args.dev = optarg;
+			break;
 		case 'd':
 			args.devn = strtoul(optarg, &endp, 0);
 			if (*endp != '\0' || endp == optarg || args.devn < 0)
@@ -134,8 +145,8 @@ static int parse_opt(int argc, char * const argv[])
 	else if (optind != argc - 1)
 		return errmsg("more then one UBI control device specified (use -h for help)");
 
-	if (args.mtdn == -1)
-		return errmsg("MTD device number was not specified (use -h for help)");
+	if (args.mtdn == -1 && args.dev == NULL)
+		return errmsg("MTD device to attach was not specified (use -h for help)");
 
 	args.node = argv[optind];
 	return 0;
@@ -177,10 +188,14 @@ int main(int argc, char * const argv[])
 	req.dev_num = args.devn;
 	req.mtd_num = args.mtdn;
 	req.vid_hdr_offset = args.vidoffs;
+	req.dev = args.dev;
 
-	err = ubi_attach_mtd(libubi, args.node, &req);
+	err = ubi_attach(libubi, args.node, &req);
 	if (err) {
-		sys_errmsg("cannot attach mtd%d", args.mtdn);
+		if (args.dev)
+			sys_errmsg("cannot attach \"%s\"", args.dev);
+		else
+			sys_errmsg("cannot attach mtd%d", args.mtdn);
 		goto out_libubi;
 	}
 
ubi-utils/src/ubidetach.c +39 -18

105 lines not on this page · raw message

Signature · 1 line
1.6.6.1