From 730148bc94411f13a0171204e872b0760fbde185 Mon Sep 17 00:00:00 2001 From: Brandon Maier Date: Mon, 12 Dec 2022 12:01:58 -0600 Subject: 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 Signed-off-by: David Oberhollenzer --- tests/mtd-tests/flash_readtest.c | 10 +++++++--- tests/mtd-tests/flash_speed.c | 10 +++++++--- tests/mtd-tests/flash_stress.c | 10 +++++++--- tests/mtd-tests/flash_torture.c | 10 +++++++--- 4 files changed, 28 insertions(+), 12 deletions(-) (limited to 'tests/mtd-tests') diff --git a/tests/mtd-tests/flash_readtest.c b/tests/mtd-tests/flash_readtest.c index b4f4e10..519ff89 100644 --- a/tests/mtd-tests/flash_readtest.c +++ b/tests/mtd-tests/flash_readtest.c @@ -125,10 +125,14 @@ static void process_options(int argc, char **argv) } } - if (optind < argc) - mtddev = argv[optind++]; - else + if (optind < argc) { + mtddev = mtd_find_dev_node(argv[optind]); + if (!mtddev) + errmsg_die("Can't find MTD device %s", argv[optind]); + optind++; + } else { errmsg_die("No device specified!\n"); + } if (optind < argc) usage(EXIT_FAILURE); diff --git a/tests/mtd-tests/flash_speed.c b/tests/mtd-tests/flash_speed.c index 0f82047..5721dfb 100644 --- a/tests/mtd-tests/flash_speed.c +++ b/tests/mtd-tests/flash_speed.c @@ -141,10 +141,14 @@ static void process_options(int argc, char **argv) } } - if (optind < argc) - mtddev = argv[optind++]; - else + if (optind < argc) { + mtddev = mtd_find_dev_node(argv[optind]); + if (!mtddev) + errmsg_die("Can't find MTD device %s", argv[optind]); + optind++; + } else { errmsg_die("No device specified!\n"); + } if (optind < argc) usage(EXIT_FAILURE); diff --git a/tests/mtd-tests/flash_stress.c b/tests/mtd-tests/flash_stress.c index b7a0fec..da39e14 100644 --- a/tests/mtd-tests/flash_stress.c +++ b/tests/mtd-tests/flash_stress.c @@ -126,10 +126,14 @@ static void process_options(int argc, char **argv) } } - if (optind < argc) - mtddev = argv[optind++]; - else + if (optind < argc) { + mtddev = mtd_find_dev_node(argv[optind]); + if (!mtddev) + errmsg_die("Can't find MTD device %s", argv[optind]); + optind++; + } else { errmsg_die("No device specified!\n"); + } if (optind < argc) usage(EXIT_FAILURE); diff --git a/tests/mtd-tests/flash_torture.c b/tests/mtd-tests/flash_torture.c index 5aad8e0..6363f9e 100644 --- a/tests/mtd-tests/flash_torture.c +++ b/tests/mtd-tests/flash_torture.c @@ -144,10 +144,14 @@ static void process_options(int argc, char **argv) } } - if (optind < argc) - mtddev = argv[optind++]; - else + if (optind < argc) { + mtddev = mtd_find_dev_node(argv[optind]); + if (!mtddev) + errmsg_die("Can't find MTD device %s", argv[optind]); + optind++; + } else { errmsg_die("No device specified!\n"); + } if (optind < argc) usage(EXIT_FAILURE); -- cgit v1.2.3