From: Torstein Eide <torsteine@gmail.com>
To: linux-mmc@vger.kernel.org
Cc: Torstein Eide <torsteine+linux@gmail.com>
Subject: [PATCH v2 4/5] mmc-utils: lsmmc: Add mmc list command
Date: Fri, 15 May 2026 23:37:46 +0200 [thread overview]
Message-ID: <20260515213747.1452692-5-torsteine+linux@gmail.com> (raw)
In-Reply-To: <20260515213747.1452692-1-torsteine+linux@gmail.com>
Add a 'mmc list' command that scans /sys/bus/mmc/devices/, resolves
each card's sysfs path, and prints a one-line summary per device.
find_block_devname() maps a sysfs device path back to its mmcblkN
name by scanning /sys/class/block/mmcblkN/device symlinks.
print_list_entry() parses the CID register and formats a fixed-width
table row with device name, /dev path, bus type, manufacturer, product,
revision, serial number, and manufacturing date.
The header is printed once before the first result. Devices without a
readable cid file are skipped silently via access() so unrelated sysfs
entries do not produce spurious error messages.
Signed-off-by: Torstein Eide <torsteine+linux@gmail.com>
---
docs/HOWTO.rst | 12 ++++++++++++
lsmmc.c | 34 +++++++++++++++++++++++++++++++++-
mmc.c | 6 +++++-
mmc_cmds.h | 1 +
4 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/docs/HOWTO.rst b/docs/HOWTO.rst
index 76214a3..167a153 100644
--- a/docs/HOWTO.rst
+++ b/docs/HOWTO.rst
@@ -90,6 +90,18 @@ Running mmc-utils
sysfs: /sys/devices/platform/fe320000.mmc/mmc_host/mmc1/mmc1:aaaa
SCR Register: 0235800000000000
+ ``list``
+ List all MMC/SD devices present on the system. Output is a table with
+ columns: DEVICE (sysfs name), DEV (/dev path), TYPE (MMC or SD),
+ MANUFACTURER, PRODUCT, REV, SERIAL, and DATE.
+
+ Example::
+
+ $ mmc list
+ DEVICE DEV TYPE MANUFACTURER PRODUCT REV SERIAL DATE
+ mmc0:0001 /dev/mmcblk0 MMC Samsung MAG4FA 1.0 0x1a2b3c4d 2021-jan
+ mmc1:aaaa /dev/mmcblk1 SD SanDisk SP32G 8.0 0x5e6f7a8b 2020-mar
+
``ffu <image name> <device> [chunk-bytes]``
Default mode. Run Field Firmware Update with `<image name>` on `<device>`. `[chunk-bytes]` is optional and defaults to its max - 512k. Should be in decimal bytes and sector aligned.
diff --git a/lsmmc.c b/lsmmc.c
index 58d4609..0458d1b 100644
--- a/lsmmc.c
+++ b/lsmmc.c
@@ -225,6 +225,39 @@ static char *get_manufacturer(struct config *config, unsigned int manid)
return NULL;
}
+static char *find_block_devname(const char *sysfs_devpath)
+{
+ DIR *d;
+ struct dirent *ent;
+
+ d = opendir("/sys/class/block");
+ if (!d)
+ return NULL;
+
+ while ((ent = readdir(d)) != NULL) {
+ char linkpath[PATH_MAX];
+ char resolved[PATH_MAX];
+
+ if (strncmp(ent->d_name, "mmcblk", 6) != 0)
+ continue;
+ if (strchr(ent->d_name + 6, 'p'))
+ continue;
+
+ snprintf(linkpath, sizeof(linkpath),
+ "/sys/class/block/%s/device", ent->d_name);
+ if (realpath(linkpath, resolved) == NULL)
+ continue;
+ if (strcmp(resolved, sysfs_devpath) == 0) {
+ closedir(d);
+ return strdup(ent->d_name);
+ }
+ }
+
+ closedir(d);
+ return NULL;
+}
+
+
/* MMC/SD file parsing functions */
static char *read_file_at(const char *dir, const char *name)
{
@@ -2335,7 +2368,6 @@ int do_list(int nargs, char **argv)
return 0;
}
-
int do_read_csd(int argc, char **argv)
{
return do_read_reg(argc, argv, CSD);
diff --git a/mmc.c b/mmc.c
index 077e901..01ad181 100644
--- a/mmc.c
+++ b/mmc.c
@@ -292,6 +292,11 @@ static struct Command commands[] = {
"4. The MMC will perform a soft reset, if your system cannot handle that do not use the boot operation from mmc-utils.\n",
NULL
},
+ { do_list, 0,
+ "list", "\n"
+ "List all MMC/SD devices with their /dev path and CID info.",
+ NULL
+ },
{ NULL, 0, NULL, NULL }
};
@@ -567,4 +572,3 @@ int main(int ac, char **av )
exit(func(nargs, args));
}
-
diff --git a/mmc_cmds.h b/mmc_cmds.h
index 407cbe6..508776c 100644
--- a/mmc_cmds.h
+++ b/mmc_cmds.h
@@ -49,6 +49,7 @@ int do_opt_ffu4(int nargs, char **argv);
int do_read_scr(int argc, char **argv);
int do_read_cid(int argc, char **argv);
int do_read_csd(int argc, char **argv);
+int do_list(int nargs, char **argv);
int do_erase(int nargs, char **argv);
int do_general_cmd_read(int nargs, char **argv);
int do_softreset(int nargs, char **argv);
--
2.53.0
next prev parent reply other threads:[~2026-05-15 21:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 21:37 [PATCH v2 0/5] mmc-utils: improve lsmmc usability Torstein Eide
2026-05-15 21:37 ` [PATCH v2 1/5] mmc-utils: lsmmc: Refactor CID parsing into shared structs Torstein Eide
2026-05-15 21:37 ` [PATCH v2 2/5] mmc-utils: lsmmc: Use external .ids files for manufacturer lookup Torstein Eide
2026-05-15 21:37 ` [PATCH v2 3/5] mmc-utils: lsmmc: Accept /dev and /sys/block paths for register reads Torstein Eide
2026-05-15 21:37 ` Torstein Eide [this message]
2026-05-15 21:37 ` [PATCH v2 5/5] mmc-utils: Add bash completion Torstein Eide
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260515213747.1452692-5-torsteine+linux@gmail.com \
--to=torsteine@gmail.com \
--cc=linux-mmc@vger.kernel.org \
--cc=torsteine+linux@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox