Skip to contentSkip to conversation

ubinfo: allow passing MTD device number

PATCH In review Rafał Miłecki 2 participants 3 messages Dec 13, 2014 – Dec 14, 2014 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ubinfo: allow passing MTD device number

This provides a nice way to find if and which UBI device is attached to the MTD.

---
 ubi-utils/ubinfo.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
ubi-utils/ubinfo.c +21 -1
index cb88f53..1499d0a 100644
@@ -36,6 +36,7 @@
 /* The variables below are set by command line arguments */
 struct args {
 	int devn;
+	int mtdn;
 	int vol_id;
 	int all;
 	const char *node;
@@ -45,6 +46,7 @@ struct args {
 static struct args args = {
 	.vol_id = -1,
 	.devn = -1,
+	.mtdn = -1,
 	.all = 0,
 	.node = NULL,
 	.vol_name = NULL,
@@ -55,6 +57,7 @@ static const char doc[] = PROGRAM_NAME " version " VERSION
 
 static const char optionsstr[] =
 "-d, --devn=<UBI device number>  UBI device number to get information about\n"
+"-m, --mtdn=<MTD device number>  or alternatively, MTD device number\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"
@@ -77,6 +80,7 @@ static const char usage[] =
 
 static const struct option long_options[] = {
 	{ .name = "devn",      .has_arg = 1, .flag = NULL, .val = 'd' },
+	{ .name = "mtdn",      .has_arg = 1, .flag = NULL, .val = 'm' },
 	{ .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' },
@@ -90,7 +94,7 @@ static int parse_opt(int argc, char * const argv[])
 	while (1) {
 		int key, error = 0;
 
-		key = getopt_long(argc, argv, "an:N:d:hV", long_options, NULL);
+		key = getopt_long(argc, argv, "an:N:d:m:hV", long_options, NULL);
 		if (key == -1)
 			break;
 
@@ -116,6 +120,13 @@ static int parse_opt(int argc, char * const argv[])
 
 			break;
 
+		case 'm':
+			args.mtdn = simple_strtoul(optarg, &error);
+			if (error || args.mtdn < 0)
+				return errmsg("bad MTD device number: \"%s\"", optarg);
+
+			break;
+
 		case 'h':
 			printf("%s\n\n", doc);
 			printf("%s\n\n", usage);
@@ -390,6 +401,15 @@ int main(int argc, char * const argv[])
 		return sys_errmsg("cannot open libubi");
 	}
 
+	if (args.mtdn >= 0) {
+		err = mtd_num2ubi_dev(libubi, args.mtdn, &args.devn);
+		if (err) {
+			sys_errmsg("cannot find UBI device attached to the MTD %d",
+				   args.mtdn);
+			goto out_libubi;
+		}
+	}
+
 	if (args.node) {
 		/*
 		 * A character device was specified, translate this into UBI
Signature · 1 line
1.8.4.5
#1 lore raw
Quoted 2 lines · Rafał Miłecki

This provides a nice way to find if and which UBI device is attached to the MTD.

Is it really worth adding this functionality to ubinfo? One can check /sys/class/ubi/ubiX/mtd_num.

The design behind UBI tools is to work only on UBI device nodes and not on MTD numbers.
i.e. to keep the layers separated.

Signature · 2 lines
Thanks,
//richard
#2 lore raw
Quoted 6 lines · Richard Weinberger
Quoted 2 lines · Rafał Miłecki

This provides a nice way to find if and which UBI device is attached to the MTD.

Is it really worth adding this functionality to ubinfo? One can check /sys/class/ubi/ubiX/mtd_num.

I didn't know about it when asking the questions, should be enough for me, thanks.

Signature · 1 line
Rafał