From 0551a3ab77e1a376b7ee981e934c68876a436d17 Mon Sep 17 00:00:00 2001 From: Mika Westerberg Date: Mon, 1 Feb 2010 10:03:48 +0100 Subject: ubiattach/ubidetach: add support to attach/detach by path Now there is a new option '-p' (or '--dev-path') that can be used to pass path to a MTD device node. Signed-off-by: Mika Westerberg Signed-off-by: Artem Bityutskiy --- ubi-utils/src/ubiattach.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'ubi-utils/src/ubiattach.c') diff --git a/ubi-utils/src/ubiattach.c b/ubi-utils/src/ubiattach.c index a935b42..67f8c85 100644 --- a/ubi-utils/src/ubiattach.c +++ b/ubi-utils/src/ubiattach.c @@ -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= 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 to attach\n" +"-p, --dev-path= path to MTD device node to attach\n" +"-m, --mtdn= 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 " [-m ] [-d ]\n" -"\t\t[--mtdn=] [--devn ]\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 " \n" +"\t[-m ] [-d ] [-p ]\n" +"\t[--mtdn=] [--devn=]\n" +"\t[--dev-path=]\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; } -- cgit v1.2.3