summaryrefslogtreecommitdiff
path: root/misc-utils/mtd_debug.c
diff options
context:
space:
mode:
authorBrandon Maier <brandon.maier@collins.com>2022-12-12 12:01:58 -0600
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-05-30 11:12:12 +0200
commit730148bc94411f13a0171204e872b0760fbde185 (patch)
tree8b07dd5ef274c0e4e36944f4ef6929399a77e56f /misc-utils/mtd_debug.c
parenta527b22f0a30d66d4674624d16f4bb0ffe2e94d0 (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 'misc-utils/mtd_debug.c')
-rw-r--r--misc-utils/mtd_debug.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/misc-utils/mtd_debug.c b/misc-utils/mtd_debug.c
index c0b7109..abee5e3 100644
--- a/misc-utils/mtd_debug.c
+++ b/misc-utils/mtd_debug.c
@@ -348,6 +348,7 @@ int main(int argc, char *argv[])
{
int err = 0, fd;
int open_flag;
+ char *dev;
enum {
OPT_INFO,
@@ -369,8 +370,12 @@ int main(int argc, char *argv[])
showusage();
/* open device */
+ dev = mtd_find_dev_node(argv[2]);
+ if (!dev)
+ errmsg_die("Failed to find MTD device %s", argv[2]);
+
open_flag = (option == OPT_INFO || option == OPT_READ) ? O_RDONLY : O_RDWR;
- if ((fd = open(argv[2], O_SYNC | open_flag)) < 0)
+ if ((fd = open(dev, O_SYNC | open_flag)) < 0)
errmsg_die("open()");
switch (option) {