diff options
author | Brandon Maier <brandon.maier@collins.com> | 2022-12-12 12:01:58 -0600 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-05-30 11:12:12 +0200 |
commit | 730148bc94411f13a0171204e872b0760fbde185 (patch) | |
tree | 8b07dd5ef274c0e4e36944f4ef6929399a77e56f /ubi-utils/mtdinfo.c | |
parent | a527b22f0a30d66d4674624d16f4bb0ffe2e94d0 (diff) |
mtd-utils: Add new syntax to get devices by name
This introduces a new feature to the MTD command line utilities that
allows MTD devices to be referenced by name instead of device node. For
example this looks like:
> # Display info for the MTD device with name "data"
> mtdinfo mtd:data
> # Copy file to MTD device with name "data"
> flashcp /my/file mtd:data
This follows the syntax supported by the kernel which allows MTD
device's to be mounted by name[1].
Add the function mtd_find_dev_node() that accepts an MTD "identifier"
and returns the MTD's device node. The function accepts a string
starting with "mtd:" which it treats as the MTD's name. It then attempts
to search for the MTD, and if found maps it back to the /dev/mtdX device
node. If the string does not start with "mtd:", then assume it's the old
style and refers directly to a MTD device node.
The function is then hooked into existing tools like flashcp, mtdinfo,
flash_unlock, etc. To load in the new MTD parsing code in a consistent
way across programs.
[1] http://www.linux-mtd.infradead.org/faq/jffs2.html#L_mtdblock
Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'ubi-utils/mtdinfo.c')
-rw-r--r-- | ubi-utils/mtdinfo.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/ubi-utils/mtdinfo.c b/ubi-utils/mtdinfo.c index 8bd0fc8..154872d 100644 --- a/ubi-utils/mtdinfo.c +++ b/ubi-utils/mtdinfo.c @@ -54,7 +54,7 @@ static void display_help(void) printf( "%1$s version %2$s - a tool to print MTD information.\n" "\n" - "Usage: %1$s <MTD node file path> [--map | -M] [--ubi-info | -u]\n" + "Usage: %1$s <mtd device> [--map | -M] [--ubi-info | -u]\n" " %1$s --all [--ubi-info | -u]\n" " %1$s [--help | --version]\n" "\n" @@ -68,6 +68,8 @@ static void display_help(void) "-h, --help print help message\n" "-V, --version print program version\n" "\n" + "<mtd device> MTD device node or 'mtd:<name>'\n" + "\n" "Examples:\n" " %1$s /dev/mtd0 print information MTD device /dev/mtd0\n" " %1$s /dev/mtd0 -u print information MTD device /dev/mtd0\n" @@ -124,10 +126,13 @@ static int parse_opt(int argc, char * const argv[]) } } - if (optind == argc - 1) - args.node = argv[optind]; - else if (optind < argc) + if (optind == argc - 1) { + args.node = mtd_find_dev_node(argv[optind]); + if (!args.node) + return errmsg("Failed to find MTD device %s", argv[optind]); + } else if (optind < argc) { return errmsg("more then one MTD device specified (use -h for help)"); + } if (args.all && args.node) args.node = NULL; |