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 --- misc-utils/flashcp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'misc-utils/flashcp.c') diff --git a/misc-utils/flashcp.c b/misc-utils/flashcp.c index 50f8c04..e1be292 100644 --- a/misc-utils/flashcp.c +++ b/misc-utils/flashcp.c @@ -110,7 +110,7 @@ static NORETURN void showusage(bool error) " -A | --erase-all Erases the whole device regardless of the image size\n" " -V | --version Show version information and exit\n" " File which you want to copy to flash\n" - " Flash device to write to (e.g. /dev/mtd0, /dev/mtd1, etc.)\n" + " Flash device node or 'mtd:' to write to (e.g. /dev/mtd0, /dev/mtd1, mtd:data, etc.)\n" "\n", PROGRAM_NAME); @@ -275,7 +275,10 @@ int main (int argc,char *argv[]) DEBUG("Got filename: %s\n",filename); flags |= FLAG_DEVICE; - device = argv[optind+1]; + device = mtd_find_dev_node(argv[optind+1]); + if (!device) + log_failure("Failed to find device %s\n", argv[optind+1]); + DEBUG("Got device: %s\n",device); } -- cgit v1.2.3