mmc-utils: lsmmc: add 'mmc list' command
Subsystems (2)
v6 cover mmc-utils: lsmmc: add 'mmc list' command
This series adds a 'mmc list' command to lsmmc that scans /sys/bus/mmc/devices/ and prints a one-line summary per MMC/SD device (device name, /dev path, bus type, manufacturer, product, revision, serial number, and manufacturing date), and teaches the existing register-read commands to accept /dev and /sys/block paths directly instead of only sysfs device directories.
Changes since v5:
- Patch 1 (Use external .ids files ...): carried forward the 0x09 "ATP" sd_database entry from the mainline-only fix in d64cb08 ("mmc-utils: lsmmc.c: Add ATP to SD Card Manufacturer ID database") into the new sdcard.ids, so the manufacturer ID isn't lost in the move to external ID files.
- Picked up Reviewed-by: Avri Altman <[email protected]> on all three patches.
Torstein Eide (3):
mmc-utils: lsmmc: Use external .ids files and accept /dev, /sys/block
paths
mmc-utils: lsmmc: Factor out CID month/year helpers
mmc-utils: lsmmc: Add mmc list command
Makefile | 8 +- docs/HOWTO.rst | 71 ++++- lsmmc.c | 649 ++++++++++++++++++++++++++------------------- mmc.c | 6 +- mmc_cmds.h | 1 + multimediacard.ids | 16 ++ sdcard.ids | 24 ++ 7 files changed, 486 insertions(+), 289 deletions(-) create mode 100644 multimediacard.ids create mode 100644 sdcard.ids
--
2.53.0
PATCH v6 1/3 mmc-utils: lsmmc: Use external .ids files and accept /dev, /sys/block paths
Similar to pci.ids and usb.ids, move the statically defined manufacturer ID arrays out of the source and into external sdcard.ids and multimediacard.ids files. This allows other programs to use the same database without an API, ABI, or cmd interface.
Make the program able to read from the base directory to test without installing.
Make it possible from the Makefile to change the install directory of the database.
Also accept /dev and /sys/block paths for register reads. 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.
--- Makefile | 8 +- docs/HOWTO.rst | 59 +++++- lsmmc.c | 480 ++++++++++++++++++++------------------------- multimediacard.ids | 16 ++ sdcard.ids | 24 +++ 5 files changed, 309 insertions(+), 278 deletions(-) create mode 100644 multimediacard.ids create mode 100644 sdcard.ids
Makefile +7 -1
@@ -3,7 +3,9 @@ CC ?= gcc # e.g., v1.0-5-2023-10-01 GIT_VERSION := "$(shell git describe --abbrev=0 --tags)-$$(git rev-list --count $$(git describe --abbrev=0 --tags)..HEAD)-$$(git log -1 --format=%cd --date=short)" AM_CFLAGS = -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 \ - -DVERSION=\"$(GIT_VERSION)\" + -DVERSION=\"$(GIT_VERSION)\" \ + -DSD_IDS_PATH=\"$(idsdir)/sdcard.ids\" \ + -DMMC_IDS_PATH=\"$(idsdir)/multimediacard.ids\" CFLAGS ?= -g -O2 objects = \ mmc.o \
@@ -21,6 +23,7 @@ override CFLAGS := $(CHECKFLAGS) $(AM_CFLAGS) $(CFLAGS) INSTALL = install prefix ?= /usr/local bindir = $(prefix)/bin +idsdir ?= /usr/share/misc LIBS= RESTORE_LIBS= mandir = /usr/share/man
@@ -57,6 +60,9 @@ install: $(progs) $(INSTALL) $(progs) $(DESTDIR)$(bindir) $(INSTALL) -m755 -d $(DESTDIR)$(mandir)/man1 $(INSTALL) -m 644 mmc.1 $(DESTDIR)$(mandir)/man1 + $(INSTALL) -m755 -d $(DESTDIR)$(idsdir) + $(INSTALL) -m 644 sdcard.ids $(DESTDIR)$(idsdir) + $(INSTALL) -m 644 multimediacard.ids $(DESTDIR)$(idsdir) -include $(foreach obj,$(objects), $(dir $(obj))/.$(notdir $(obj)).d)
docs/HOWTO.rst +50 -9
69 lines not on this page · raw message
lsmmc.c +212 -268
627 lines not on this page · raw message
multimediacard.ids new file +16 -0
@@ -0,0 +1,16 @@ +# MMC manufacturer IDs +# This file is maintained at: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git +0x00 SanDisk +0x02 Kingston/SanDisk +0x03 Toshiba +0x05 Unknown +0x06 Unknown +0x11 Toshiba +0x13 Micron +0x15 Samsung/SanDisk/LG +0x37 KingMax +0x44 ATP +0x45 SanDisk Corporation +0x2c Kingston +0x70 Kingston +0xfe Micron
sdcard.ids new file +24 -0
@@ -0,0 +1,24 @@ +# SD card (secure digital) manufacturer IDs +# This file is maintained at: https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git +0x01 Panasonic +0x02 Toshiba/Kingston/Viking +0x03 SanDisk +0x08 Silicon Power +0x09 ATP +0x18 Infineon +0x1b Transcend/Samsung +0x1c Transcend +0x1d Corsair/AData +0x1e Transcend +0x1f Kingston +0x27 Delkin/Phison +0x28 Lexar +0x30 SanDisk +0x31 Silicon Power +0x33 STMicroelectronics +0x41 Kingston +0x6f STMicroelectronics +0x74 Transcend +0x76 Patriot +0x82 Gobe/Sony +0x89 Unknown
Signature · 1 line
2.53.0
PATCH v6 2/3 mmc-utils: lsmmc: Factor out CID month/year helpers
In reply to Torstein Eideprint_sd_cid() and print_mmc_cid() each keep their own copy of the month-name table, and print_mmc_cid() open-codes the ext_csd_rev based base-year adjustment inline. Extract both into shared helpers, month_name(), sd_cid_year() and mmc_cid_year(), so there is a single place to fix or extend the manufacturing-date decoding.
No functional change.
--- lsmmc.c | 66 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 25 deletions(-)
lsmmc.c +41 -25
@@ -490,13 +490,45 @@ static void parse_mmc_cid(char *raw, struct mmc_cid *c) }/* MMC/SD information parsing functions */ -static void print_sd_cid (struct config *config,char *cid) +static const char *month_name (unsigned int month) {static const char *months[] = {"invalid0" ,"jan" ,"feb" ,"mar" ,"apr" ,"may" ,"jun" ,"jul" ,"aug" ,"sep" ,"oct" ,"nov" ,"dec" ,"invalid1" ,"invalid2" ,"invalid3" , }; + +if (month >=ARRAY_SIZE (months)) +return "invalid" ; + +return months[month]; +} + +static unsigned int sd_cid_year (const struct sd_cid *c) +{ +return 2000 + c->mdt_year; +} + +static unsigned int mmc_cid_year (const struct mmc_cid *c,unsigned int ext_csd_rev) +{ +unsigned int base_year =1997 ; + +if (ext_csd_rev) { +/* Adjust base year according to ext_csd_rev */ +if (ext_csd_rev >8 ) { + base_year =2029 ; +if (c->mdt_year >=13 ) + base_year =2013 ; + }else if (ext_csd_rev >4 ) { + base_year =2013 ; + } + } + +return base_year + c->mdt_year; +} + +static void print_sd_cid (struct config *config,char *cid) +{struct sd_cid c;char *manufacturer;
@@ -514,15 +546,15 @@ static void print_sd_cid(struct config *config, char *cid)printf ("(%u.%u)\n" , c.prv_major, c.prv_minor);printf ("\tPSN: 0x%08x\n" , c.psn);printf ("\tMDT: 0x%02x%01x %u %s\n" , c.mdt_year, c.mdt_month, -2000 + c.mdt_year, months[c.mdt_month]); +sd_cid_year (&c),month_name (c.mdt_month));printf ("\tCRC: 0x%02x\n" , c.crc); }else {printf ("manufacturer: '%s' '%s'\n" , manufacturer, c.oid);printf ("product: '%s' %u.%u\n" , c.pnm, c.prv_major, c.prv_minor);printf ("serial: 0x%08x\n" , c.psn); -printf ("manufacturing date: %u %s\n" ,2000 + c.mdt_year, - months[c.mdt_month]); +printf ("manufacturing date: %u %s\n" ,sd_cid_year (&c), +month_name (c.mdt_month)); }free (manufacturer);
@@ -530,29 +562,13 @@ static void print_sd_cid(struct config *config, char *cid)static void print_mmc_cid (struct config *config,char *cid) { -static const char *months[] = {"invalid0" , -"jan" ,"feb" ,"mar" ,"apr" ,"may" ,"jun" , -"jul" ,"aug" ,"sep" ,"oct" ,"nov" ,"dec" , -"invalid1" ,"invalid2" ,"invalid3" , - };struct mmc_cid c;char *manufacturer; -int base_year =1997 ; +unsigned int year;parse_mmc_cid (cid, &c); manufacturer =get_manufacturer (config, c.mid); - -if (config->ext_csd_rev) { -/* Adjust base year according to ext_csd_rev */ -if (config->ext_csd_rev >8 ) { - base_year =2029 ; -if (c.mdt_year >=13 ) - base_year =2013 ; - }else if (config->ext_csd_rev >4 ) { - base_year =2013 ; - } - } - + year =mmc_cid_year (&c, config->ext_csd_rev);if (config->verbose) {printf ("======MMC/CID======\n" );
@@ -581,7 +597,7 @@ static void print_mmc_cid(struct config *config, char *cid)printf ("(%u.%u)\n" , c.prv_major, c.prv_minor);printf ("\tPSN: 0x%08x\n" , c.psn);printf ("\tMDT: 0x%01x%01x %u %s\n" , c.mdt_month, c.mdt_year, - base_year + c.mdt_year, months[c.mdt_month]); + year,month_name (c.mdt_month));if (!config->ext_csd_rev)printf ("\tWarn: ext_csd_rev not provided, " "manufacturing date year may be wrong.\n" );
@@ -592,8 +608,8 @@ static void print_mmc_cid(struct config *config, char *cid)printf ("product: '%s' %u.%u\n" , c.pnm, c.prv_major, c.prv_minor);printf ("serial: 0x%08x\n" , c.psn); -printf ("manufacturing date: %u %s\n" , base_year + c.mdt_year, - months[c.mdt_month]); +printf ("manufacturing date: %u %s\n" , year, +month_name (c.mdt_month));if (!config->ext_csd_rev)printf ("Warn: ext_csd_rev not provided, " "manufacturing date year may be wrong.\n" );
Signature · 1 line
2.53.0
PATCH v6 3/3 mmc-utils: lsmmc: Add mmc list command
In reply to Torstein EideAdd 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.
--- docs/HOWTO.rst | 12 +++++ lsmmc.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++ mmc.c | 6 ++- mmc_cmds.h | 1 + 4 files changed, 151 insertions(+), 1 deletion(-)
docs/HOWTO.rst +12 -0
@@ -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.
lsmmc.c +133 -0
145 lines not on this page · raw message
mmc.c +5 -1
@@ -306,6 +306,11 @@ static struct Command commands[] = { "3. Only up to 512K bytes of boot data will be transferred.\n" "4. The MMC will perform a soft reset, if your system cannot handle that do not use the boot operation from mmc-utils.\n", }, + { do_list,0 , +"list" ,"\n" +"List all MMC/SD devices with their /dev path and CID info." , +NULL + }, { NULL, 0, NULL, NULL } };
@@ -590,4 +595,3 @@ int main(int ac, char **av )exit (func (nargs, args)); } -
mmc_cmds.h +1 -0
@@ -62,6 +62,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);
Signature · 1 line
2.53.0
Quoted 34 lines · Torstein Eide
This series adds a 'mmc list' command to lsmmc that scans
/sys/bus/mmc/devices/and prints a one-line summary per MMC/SD device (device name, /dev path, bus type, manufacturer, product, revision, serial number, and manufacturing date), and teaches the existing register-read commands to accept /dev and/sys/blockpaths directly instead of only sysfs device directories.Changes since v5:
- Patch 1 (Use external .ids files ...): carried forward the0x09"ATP"sd_databaseentry from the mainline-only fix in d64cb08 ("mmc-utils:lsmmc.c: Add ATP to SD Card Manufacturer ID database") into the new sdcard.ids, so the manufacturer ID isn't lost in the move to external ID files.
- Picked up Reviewed-by: Avri Altman <[email protected]> on all three patches.Torstein Eide (3):
mmc-utils: lsmmc: Use external .ids files and accept /dev,/sys/block
paths
mmc-utils: lsmmc: Factor out CID month/year helpers
mmc-utils: lsmmc: Add mmc list commandMakefile | 8 +- docs/HOWTO.rst | 71 ++++- lsmmc.c | 649 ++++++++++++++++++++++++++------------------- mmc.c | 6 +- mmc_cmds.h | 1 + multimediacard.ids | 16 ++ sdcard.ids | 24 ++ 7 files changed, 486 insertions(+), 289 deletions(-) create mode 100644 multimediacard.ids create mode 100644 sdcard.ids
Quoted 2 lines
--
2.53.0
The series applied for mmc-utils master, thanks!
Kind regards
Uffe