From: Torstein Eide <torsteine@gmail.com>
To: linux-mmc@vger.kernel.org
Cc: Torstein Eide <torsteine+linux@gmail.com>
Subject: [PATCH 2/4] mmc-utils: lsmmc: Accept /dev and /sys/block paths for register reads
Date: Fri, 15 May 2026 10:34:55 +0200 [thread overview]
Message-ID: <20260515083457.3690804-3-torsteine+linux@gmail.com> (raw)
In-Reply-To: <20260515083457.3690804-1-torsteine+linux@gmail.com>
Commands like 'cid read' previously required a raw sysfs device path
such as /sys/bus/mmc/devices/mmc0:0001/. Most users know their block
device as /dev/mmcblk0 or /sys/block/mmcblk0.
Add resolve_dev_path() which follows /sys/class/block/<dev>/device via
realpath() to reach the canonical sysfs device directory. Paths that
start with /dev/ or /sys/block/ are resolved automatically in
do_read_reg() before processing, and the resolved sysfs path is printed
so the caller can see which device was matched.
Signed-off-by: Torstein Eide <torsteine+linux@gmail.com>
---
docs/HOWTO.rst | 59 ++++++++++++++++++++++++++++++++++++++++++--------
lsmmc.c | 42 +++++++++++++++++++++++++++++++++++
2 files changed, 92 insertions(+), 9 deletions(-)
diff --git a/docs/HOWTO.rst b/docs/HOWTO.rst
index 7a27a50..76214a3 100644
--- a/docs/HOWTO.rst
+++ b/docs/HOWTO.rst
@@ -35,19 +35,60 @@ Running mmc-utils
Set user area write protection.
``csd read [-h] [-v] [-b bus_type] [-r register] <device path>``
- Print CSD data from <device path>. The device path should specify the csd sysfs file directory.
- if [bus_type] is passed (mmc or sd) the [register] content must be passed as well, and no need for device path.
- it is useful for cases we are getting the register value without having the actual platform.
+ Print CSD data from <device path>. The device path may be one of the following:
+ - sysfs device directory (/sys/devices/platform/fe310000.mmc/mmc_host/mmc0/mmc0:0001)
+ - device node (/dev/mmcblkN)
+ - sysfs block device entry (/sys/block/mmcblkN)
+ /dev/ and /sys/block/ paths are resolved to the sysfs device
+ directory automatically and the resolved path is printed.
+ If [-b bus_type] is passed (mmc or sd) the [-r register] content must
+ be passed as well, and no device path is required. Useful when the
+ register value is known without access to the actual hardware.
+
+ Example::
+
+ $ mmc csd read /dev/mmcblk0
+ sysfs: /sys/devices/platform/fe310000.mmc/mmc_host/mmc0/mmc0:0001
+ CSD Register: 00000000...
``cid read <device path>``
- Print CID data from <device path>. The device path should specify the cid sysfs file directory.
- if [bus_type] is passed (mmc or sd) the [register] content must be passed as well, and no need for device path.
- it is useful for cases we are getting the register value without having the actual platform.
+ Print CID data from <device path>. The device path may be one of the following:
+ - sysfs device directory (/sys/devices/platform/fe310000.mmc/mmc_host/mmc0/mmc0:0001)
+ - device node (/dev/mmcblkN)
+ - sysfs block device entry (/sys/block/mmcblkN)
+ /dev/ and /sys/block/ paths are resolved to the sysfs device
+ directory automatically and the resolved path is printed.
+ If [-b bus_type] is passed (mmc or sd) the [-r register] content must
+ be passed as well, and no device path is required. Useful when the
+ register value is known without access to the actual hardware.
+
+ Example::
+
+ $ mmc cid read /dev/mmcblk0
+ sysfs: /sys/devices/platform/fe310000.mmc/mmc_host/mmc0/mmc0:0001
+ Manufacturer ID: 0x15
+ OEM ID: 0x0100
+ Product name: MAG4FA
+ Product revision: 1.0
+ Serial number: 0x1a2b3c4d
+ Manufacturing date: 01/2021
``scr read <device path>``
- Print SCR data from <device path>. The device path should specify the scr sysfs file directory.
- if [bus_type] is passed (mmc or sd) the [register] content must be passed as well, and no need for device path.
- it is useful for cases we are getting the register value without having the actual platform.
+ Print SCR data from <device path>. The device path may be one of the following:
+ - sysfs device directory (/sys/devices/platform/fe320000.mmc/mmc_host/mmc1/mmc1:aaaa)
+ - device node (/dev/mmcblkN)
+ - sysfs block device entry (/sys/block/mmcblkN)
+ /dev/ and /sys/block/ paths are resolved to the sysfs device
+ directory automatically and the resolved path is printed.
+ If [-b bus_type] is passed (mmc or sd) the [-r register] content must
+ be passed as well, and no device path is required. Useful when the
+ register value is known without access to the actual hardware.
+
+ Example::
+
+ $ mmc scr read /dev/mmcblk1
+ sysfs: /sys/devices/platform/fe320000.mmc/mmc_host/mmc1/mmc1:aaaa
+ SCR Register: 0235800000000000
``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 113f371..3149409 100644
--- a/lsmmc.c
+++ b/lsmmc.c
@@ -226,6 +226,33 @@ static const char *get_manufacturer(struct config *config, unsigned int manid)
return NULL;
}
+static char *resolve_dev_path(const char *path)
+{
+ const char *devname = strrchr(path, '/');
+ char syspath[PATH_MAX];
+ char *resolved;
+
+ devname = devname ? devname + 1 : path;
+ if (*devname == '\0')
+ return NULL;
+
+ if (snprintf(syspath, sizeof(syspath), "/sys/class/block/%s/device",
+ devname) >= PATH_MAX)
+ return NULL;
+
+ resolved = malloc(PATH_MAX);
+ if (!resolved)
+ return NULL;
+
+ if (realpath(syspath, resolved) == NULL) {
+ fprintf(stderr, "Cannot resolve '%s': %s\n", path, strerror(errno));
+ free(resolved);
+ return NULL;
+ }
+
+ return resolved;
+}
+
/* MMC/SD file parsing functions */
static char *read_file(char *name)
{
@@ -2151,6 +2178,21 @@ static int do_read_reg(int argc, char **argv, enum REG_TYPE reg)
if (ret)
return ret;
+ if (cfg.dir &&
+ (strncmp(cfg.dir, "/dev/", 5) == 0 ||
+ strncmp(cfg.dir, "/sys/block/", 11) == 0)) {
+ char *sysfs = resolve_dev_path(cfg.dir);
+
+ if (!sysfs) {
+ free(cfg.dir);
+ return -1;
+ }
+
+ free(cfg.dir);
+ cfg.dir = sysfs;
+ printf("sysfs: %s\n", cfg.dir);
+ }
+
if (cfg.dir) {
ret = process_dir(&cfg, reg);
free(cfg.dir);
--
2.53.0
next prev parent reply other threads:[~2026-05-15 8:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 8:34 [PATCH 0/4] mmc-utils: improve lsmmc usability Torstein Eide
2026-05-15 8:34 ` [PATCH 1/4] mmc-utils: lsmmc: Use external .ids files for manufacturer lookup Torstein Eide
2026-05-15 15:05 ` Avri Altman
2026-05-15 16:18 ` Torstein Eide
2026-05-15 8:34 ` Torstein Eide [this message]
2026-05-15 15:26 ` [PATCH 2/4] mmc-utils: lsmmc: Accept /dev and /sys/block paths for register reads Avri Altman
2026-05-15 8:34 ` [PATCH 3/4] mmc-utils: lsmmc: Add mmc list command Torstein Eide
2026-05-15 16:38 ` Avri Altman
2026-05-15 20:50 ` Torstein Eide
2026-05-15 8:34 ` [PATCH 4/4] mmc-utils: Add bash completion Torstein Eide
2026-05-15 14:29 ` [PATCH 0/4] mmc-utils: improve lsmmc usability Avri Altman
2026-05-15 16:06 ` Torstein Eide
2026-05-15 16:46 ` Avri Altman
2026-05-15 20:28 ` Torstein Eide
2026-05-15 22:09 ` 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=20260515083457.3690804-3-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.