* [PATCH v3 1/4] mmc-utils: lsmmc: Use external .ids files for manufacturer lookup
2026-06-17 17:24 [PATCH v3 0/4] mmc-utils: improve lsmmc usability Torstein Eide
@ 2026-06-17 17:24 ` Torstein Eide
2026-06-17 17:24 ` [PATCH v3 2/4] mmc-utils: lsmmc: Accept /dev and /sys/block paths for register reads Torstein Eide
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Torstein Eide @ 2026-06-17 17:24 UTC (permalink / raw)
To: linux-mmc; +Cc: Torstein Eide, Avri Altman
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.
Signed-off-by: Torstein Eide <torsteine+linux@gmail.com>
Reviewed-by: Avri Altman <avri.altman@sandisk.com>
---
Makefile | 8 +-
lsmmc.c | 490 +++++++++++++++++++++------------------------
multimediacard.ids | 16 ++
sdcard.ids | 23 +++
4 files changed, 272 insertions(+), 265 deletions(-)
create mode 100644 multimediacard.ids
create mode 100644 sdcard.ids
diff --git a/Makefile b/Makefile
index 7631524..bf8c006 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
diff --git a/lsmmc.c b/lsmmc.c
index e9df5e1..afcf446 100644
--- a/lsmmc.c
+++ b/lsmmc.c
@@ -57,6 +57,13 @@
#define IDS_MAX 256
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#ifndef SD_IDS_PATH
+#define SD_IDS_PATH "/usr/share/misc/sdcard.ids"
+#endif
+#ifndef MMC_IDS_PATH
+#define MMC_IDS_PATH "/usr/share/misc/multimediacard.ids"
+#endif
+
enum bus_type {
MMC = 1,
SD,
@@ -77,157 +84,6 @@ enum REG_TYPE {
SCR,
};
-struct ids_database {
- int id;
- char *manufacturer;
-};
-
-static struct ids_database sd_database[] = {
- {
- .id = 0x01,
- .manufacturer = "Panasonic",
- },
- {
- .id = 0x02,
- .manufacturer = "Toshiba/Kingston/Viking",
- },
- {
- .id = 0x03,
- .manufacturer = "SanDisk",
- },
- {
- .id = 0x08,
- .manufacturer = "Silicon Power",
- },
- {
- .id = 0x18,
- .manufacturer = "Infineon",
- },
- {
- .id = 0x1b,
- .manufacturer = "Transcend/Samsung",
- },
- {
- .id = 0x1c,
- .manufacturer = "Transcend",
- },
- {
- .id = 0x1d,
- .manufacturer = "Corsair/AData",
- },
- {
- .id = 0x1e,
- .manufacturer = "Transcend",
- },
- {
- .id = 0x1f,
- .manufacturer = "Kingston",
- },
- {
- .id = 0x27,
- .manufacturer = "Delkin/Phison",
- },
- {
- .id = 0x28,
- .manufacturer = "Lexar",
- },
- {
- .id = 0x30,
- .manufacturer = "SanDisk",
- },
- {
- .id = 0x31,
- .manufacturer = "Silicon Power",
- },
- {
- .id = 0x33,
- .manufacturer = "STMicroelectronics",
- },
- {
- .id = 0x41,
- .manufacturer = "Kingston",
- },
- {
- .id = 0x6f,
- .manufacturer = "STMicroelectronics",
- },
- {
- .id = 0x74,
- .manufacturer = "Transcend",
- },
- {
- .id = 0x76,
- .manufacturer = "Patriot",
- },
- {
- .id = 0x82,
- .manufacturer = "Gobe/Sony",
- },
- {
- .id = 0x89,
- .manufacturer = "Unknown",
- },
-};
-
-static struct ids_database mmc_database[] = {
- {
- .id = 0x00,
- .manufacturer = "SanDisk",
- },
- {
- .id = 0x02,
- .manufacturer = "Kingston/SanDisk",
- },
- {
- .id = 0x03,
- .manufacturer = "Toshiba",
- },
- {
- .id = 0x05,
- .manufacturer = "Unknown",
- },
- {
- .id = 0x06,
- .manufacturer = "Unknown",
- },
- {
- .id = 0x11,
- .manufacturer = "Toshiba",
- },
- {
- .id = 0x13,
- .manufacturer = "Micron",
- },
- {
- .id = 0x15,
- .manufacturer = "Samsung/SanDisk/LG",
- },
- {
- .id = 0x37,
- .manufacturer = "KingMax",
- },
- {
- .id = 0x44,
- .manufacturer = "ATP",
- },
- {
- .id = 0x45,
- .manufacturer = "SanDisk Corporation",
- },
- {
- .id = 0x2c,
- .manufacturer = "Kingston",
- },
- {
- .id = 0x70,
- .manufacturer = "Kingston",
- },
- {
- .id = 0xfe,
- .manufacturer = "Micron",
- },
-};
-
/* Command line parsing functions */
static void usage(char *progname)
{
@@ -323,37 +179,73 @@ static int parse_opts(int argc, char **argv, struct config *config)
static char *get_manufacturer(struct config *config, unsigned int manid)
{
- struct ids_database *db;
- unsigned int ids_cnt;
- int i;
+ char local_path[PATH_MAX];
+ const char *system_path;
+ FILE *f;
+ char name[256];
+ char line[256];
+ const char *local_name;
- if (config->bus == MMC) {
- db = mmc_database;
- ids_cnt = ARRAY_SIZE(mmc_database);
- } else {
- db = sd_database;
- ids_cnt = ARRAY_SIZE(sd_database);
+ local_name = (config->bus == MMC) ? "multimediacard.ids" : "sdcard.ids";
+ system_path = (config->bus == MMC) ? MMC_IDS_PATH : SD_IDS_PATH;
+ snprintf(local_path, sizeof(local_path), "%s", local_name);
+
+ f = fopen(local_path, "r");
+ if (!f)
+ f = fopen(system_path, "r");
+ if (!f) {
+ static bool warned;
+
+ if (!warned) {
+ fprintf(stderr, "Warning: ids file not found (%s or %s)\n",
+ local_path, system_path);
+ warned = true;
+ }
+ goto fallback;
}
- for (i = 0; i < ids_cnt; i++) {
- if (db[i].id == manid)
- return db[i].manufacturer;
+ while (fgets(line, sizeof(line), f)) {
+ unsigned int id;
+ char *nl;
+
+ nl = strchr(line, '\n');
+ if (nl)
+ *nl = '\0';
+
+ if (line[0] == '#' || line[0] == '\0')
+ continue;
+
+ if (sscanf(line, "0x%x %255[^\n]", &id, name) == 2) {
+ if (id == manid) {
+ fclose(f);
+ return strdup(name);
+ }
+ }
}
- return NULL;
+ fclose(f);
+fallback:
+ snprintf(name, sizeof(name), "0x%02x", manid);
+ return strdup(name);
}
/* MMC/SD file parsing functions */
-static char *read_file(char *name)
+static char *read_file_at(const char *dir, const char *name)
{
+ char path[PATH_MAX];
char line[4096];
char *preparsed, *start = line;
int len;
FILE *f;
- f = fopen(name, "r");
+ if (snprintf(path, sizeof(path), "%s/%s", dir, name) >= PATH_MAX) {
+ fprintf(stderr, "Path too long: %s/%s\n", dir, name);
+ return NULL;
+ }
+
+ f = fopen(path, "r");
if (!f) {
- fprintf(stderr, "Could not open MMC/SD file '%s'.\n", name);
+ fprintf(stderr, "Could not open MMC/SD file '%s'.\n", path);
return NULL;
}
@@ -361,20 +253,20 @@ static char *read_file(char *name)
if (!preparsed) {
if (ferror(f))
fprintf(stderr, "Could not read MMC/SD file '%s'.\n",
- name);
+ path);
else
fprintf(stderr,
"Could not read data from MMC/SD file '%s'.\n",
- name);
+ path);
if (fclose(f))
fprintf(stderr, "Could not close MMC/SD file '%s'.\n",
- name);
+ path);
return NULL;
}
if (fclose(f)) {
- fprintf(stderr, "Could not close MMC/SD file '%s'.\n", name);
+ fprintf(stderr, "Could not close MMC/SD file '%s'.\n", path);
return NULL;
}
@@ -511,63 +403,85 @@ static void parse_bin(char *hexstr, char *fmt, ...)
free(origstr);
}
-/* MMC/SD information parsing functions */
-static void print_sd_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 sd_cid {
unsigned int mid;
char oid[3];
char pnm[6];
unsigned int prv_major;
unsigned int prv_minor;
unsigned int psn;
+ unsigned int mdt_year;
unsigned int mdt_month;
+ unsigned int crc;
+};
+
+struct mmc_cid {
+ unsigned int mid;
+ unsigned int cbx;
+ unsigned int oid;
+ char pnm[7];
+ unsigned int prv_major;
+ unsigned int prv_minor;
+ unsigned int psn;
unsigned int mdt_year;
+ unsigned int mdt_month;
unsigned int crc;
- char *manufacturer = NULL;
+};
- parse_bin(cid, "8u16a40a4u4u32u4r8u4u7u1r",
- &mid, &oid[0], &pnm[0], &prv_major, &prv_minor, &psn,
- &mdt_year, &mdt_month, &crc);
+static void parse_sd_cid(char *raw, struct sd_cid *c)
+{
+ parse_bin(raw, "8u16a40a4u4u32u4r8u4u7u1r",
+ &c->mid, &c->oid[0], &c->pnm[0], &c->prv_major, &c->prv_minor,
+ &c->psn, &c->mdt_year, &c->mdt_month, &c->crc);
+ c->oid[2] = '\0';
+ c->pnm[5] = '\0';
+}
+
+static void parse_mmc_cid(char *raw, struct mmc_cid *c)
+{
+ parse_bin(raw, "8u6r2u8u48a4u4u32u4u4u7u1r",
+ &c->mid, &c->cbx, &c->oid, &c->pnm[0], &c->prv_major,
+ &c->prv_minor, &c->psn, &c->mdt_year, &c->mdt_month, &c->crc);
+ c->pnm[6] = '\0';
+}
- oid[2] = '\0';
- pnm[5] = '\0';
+/* MMC/SD information parsing functions */
+static void print_sd_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 sd_cid c;
+ char *manufacturer;
- manufacturer = get_manufacturer(config, mid);
+ parse_sd_cid(cid, &c);
+ manufacturer = get_manufacturer(config, c.mid);
if (config->verbose) {
printf("======SD/CID======\n");
- printf("\tMID: 0x%02x (", mid);
- if (manufacturer)
- printf("%s)\n", manufacturer);
- else
- printf("Unlisted)\n");
-
- printf("\tOID: %s\n", oid);
- printf("\tPNM: %s\n", pnm);
- printf("\tPRV: 0x%01x%01x ", prv_major, prv_minor);
- printf("(%u.%u)\n", prv_major, prv_minor);
- printf("\tPSN: 0x%08x\n", psn);
- printf("\tMDT: 0x%02x%01x %u %s\n", mdt_year, mdt_month,
- 2000 + mdt_year, months[mdt_month]);
- printf("\tCRC: 0x%02x\n", crc);
+ printf("\tMID: 0x%02x (%s)\n", c.mid, manufacturer);
+
+ printf("\tOID: %s\n", c.oid);
+ printf("\tPNM: %s\n", c.pnm);
+ printf("\tPRV: 0x%01x%01x ", c.prv_major, c.prv_minor);
+ 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]);
+ printf("\tCRC: 0x%02x\n", c.crc);
} else {
- if (manufacturer)
- printf("manufacturer: '%s' '%s'\n",
- manufacturer, oid);
- else
- printf("manufacturer: 'Unlisted' '%s'\n", oid);
+ printf("manufacturer: '%s' '%s'\n", manufacturer, c.oid);
- printf("product: '%s' %u.%u\n", pnm, prv_major, prv_minor);
- printf("serial: 0x%08x\n", psn);
- printf("manufacturing date: %u %s\n", 2000 + mdt_year,
- months[mdt_month]);
+ 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]);
}
+
+ free(manufacturer);
}
static void print_mmc_cid(struct config *config, char *cid)
@@ -577,32 +491,18 @@ static void print_mmc_cid(struct config *config, char *cid)
"jul", "aug", "sep", "oct", "nov", "dec",
"invalid1", "invalid2", "invalid3",
};
- unsigned int mid;
- unsigned int cbx;
- unsigned int oid;
- char pnm[7];
- unsigned int prv_major;
- unsigned int prv_minor;
- unsigned int psn;
- unsigned int mdt_month;
- unsigned int mdt_year;
- unsigned int crc;
- char *manufacturer = NULL;
+ struct mmc_cid c;
+ char *manufacturer;
int base_year = 1997;
- parse_bin(cid, "8u6r2u8u48a4u4u32u4u4u7u1r",
- &mid, &cbx, &oid, &pnm[0], &prv_major, &prv_minor, &psn,
- &mdt_month, &mdt_year, &crc);
-
- pnm[6] = '\0';
-
- manufacturer = get_manufacturer(config, mid);
+ 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 (mdt_year >= 13)
+ if (c.mdt_year >= 13)
base_year = 2013;
} else if (config->ext_csd_rev > 4) {
base_year = 2013;
@@ -613,14 +513,10 @@ static void print_mmc_cid(struct config *config, char *cid)
if (config->verbose) {
printf("======MMC/CID======\n");
- printf("\tMID: 0x%02x (", mid);
- if (manufacturer)
- printf("%s)\n", manufacturer);
- else
- printf("Unlisted)\n");
+ printf("\tMID: 0x%02x (%s)\n", c.mid, manufacturer);
- printf("\tCBX: 0x%01x (", cbx);
- switch (cbx) {
+ printf("\tCBX: 0x%01x (", c.cbx);
+ switch (c.cbx) {
case 0:
printf("card)\n");
break;
@@ -635,32 +531,31 @@ static void print_mmc_cid(struct config *config, char *cid)
break;
}
- printf("\tOID: 0x%01x\n", oid);
- printf("\tPNM: %s\n", pnm);
- printf("\tPRV: 0x%01x%01x ", prv_major, prv_minor);
- printf("(%u.%u)\n", prv_major, prv_minor);
- printf("\tPSN: 0x%08x\n", psn);
- printf("\tMDT: 0x%01x%01x %u %s\n", mdt_month, mdt_year,
- base_year + mdt_year, months[mdt_month]);
+ printf("\tOID: 0x%01x\n", c.oid);
+ printf("\tPNM: %s\n", c.pnm);
+ printf("\tPRV: 0x%01x%01x ", c.prv_major, c.prv_minor);
+ 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]);
if (!config->ext_csd_rev)
printf("\tWarn: ext_csd_rev not provided, "
"manufacturing date year may be wrong.\n");
- printf("\tCRC: 0x%02x\n", crc);
+ printf("\tCRC: 0x%02x\n", c.crc);
} else {
- if (manufacturer)
- printf("manufacturer: 0x%02x (%s) oid: 0x%01x\n",
- mid, manufacturer, oid);
- else
- printf("manufacturer: 0x%02x (Unlisted) oid: 0x%01x\n", mid, oid);
+ printf("manufacturer: 0x%02x (%s) oid: 0x%01x\n",
+ c.mid, manufacturer, c.oid);
- printf("product: '%s' %u.%u\n", pnm, prv_major, prv_minor);
- printf("serial: 0x%08x\n", psn);
- printf("manufacturing date: %u %s\n", base_year + mdt_year,
- months[mdt_month]);
+ 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]);
if (!config->ext_csd_rev)
printf("Warn: ext_csd_rev not provided, "
"manufacturing date year may be wrong.\n");
}
+
+ free(manufacturer);
}
static void print_sd_csd(struct config *config, char *csd)
@@ -2244,12 +2139,12 @@ static int process_reg_from_file(struct config *config, enum REG_TYPE reg)
switch (reg) {
case CID:
- reg_content = read_file("cid");
+ reg_content = read_file_at(config->dir, "cid");
ret = process_reg(config, reg_content, CID);
break;
case CSD:
- reg_content = read_file("csd");
+ reg_content = read_file_at(config->dir, "csd");
ret = process_reg(config, reg_content, CSD);
break;
@@ -2257,7 +2152,7 @@ static int process_reg_from_file(struct config *config, enum REG_TYPE reg)
if (config->bus != SD)
break;
- reg_content = read_file("scr");
+ reg_content = read_file_at(config->dir, "scr");
ret = process_reg(config, reg_content, SCR);
break;
@@ -2276,19 +2171,13 @@ static int process_dir(struct config *config, enum REG_TYPE reg)
char *type = NULL;
int ret = 0;
- if (chdir(config->dir) < 0) {
- fprintf(stderr,
- "MMC/SD information directory '%s' does not exist.\n",
- config->dir);
- return -1;
- }
-
- type = read_file("type");
+ type = read_file_at(config->dir, "type");
if (!type) {
fprintf(stderr,
"Could not read card interface type in directory '%s'.\n",
config->dir);
- return -1;
+ ret = -1;
+ goto err;
}
if (strcmp(type, "MMC") && strcmp(type, "SD")) {
@@ -2326,6 +2215,79 @@ static int do_read_reg(int argc, char **argv, enum REG_TYPE reg)
return ret;
}
+static const char *month_name(unsigned int month)
+{
+ static const char *months[] = {
+ "jan", "feb", "mar", "apr", "may", "jun",
+ "jul", "aug", "sep", "oct", "nov", "dec",
+ "invalid0", "invalid1", "invalid2", "invalid3",
+ };
+
+ if (month >= ARRAY_SIZE(months))
+ return "invalid";
+
+ return months[month];
+}
+
+int do_list(int nargs, char **argv)
+{
+ const char *bus_path = "/sys/bus/mmc/devices";
+ DIR *d;
+ struct dirent *ent;
+ bool header_printed = false;
+
+ d = opendir(bus_path);
+ if (!d) {
+ fprintf(stderr, "Cannot open %s\n", bus_path);
+ return -1;
+ }
+
+ struct config cfg = {};
+
+ while ((ent = readdir(d)) != NULL) {
+ char devpath[PATH_MAX];
+ char resolved[PATH_MAX];
+ char *type, *cid, *blkdev;
+
+ if (!strchr(ent->d_name, ':'))
+ continue;
+
+ snprintf(devpath, sizeof(devpath), "%s/%s", bus_path, ent->d_name);
+ if (realpath(devpath, resolved) == NULL)
+ continue;
+
+ type = read_file_at(resolved, "type");
+ if (!type)
+ continue;
+
+ cid = read_file_at(resolved, "cid");
+ if (!cid) {
+ free(type);
+ continue;
+ }
+
+ blkdev = find_block_devname(resolved);
+ cfg.bus = strcmp(type, "MMC") ? SD : MMC;
+
+ if (!header_printed) {
+ printf("%-14s %-14s %-5s%-20s %-10s %-5s %-12s %s\n",
+ "DEVICE", "DEV", "TYPE", "MANUFACTURER", "PRODUCT",
+ "REV", "SERIAL", "DATE");
+ header_printed = true;
+ }
+
+ print_list_entry(&cfg, ent->d_name, blkdev, cid);
+
+ free(blkdev);
+ free(cid);
+ free(type);
+ }
+
+ closedir(d);
+ return 0;
+}
+
+
int do_read_csd(int argc, char **argv)
{
return do_read_reg(argc, argv, CSD);
diff --git a/multimediacard.ids b/multimediacard.ids
new file mode 100644
index 0000000..0c91118
--- /dev/null
+++ b/multimediacard.ids
@@ -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
diff --git a/sdcard.ids b/sdcard.ids
new file mode 100644
index 0000000..cbddcae
--- /dev/null
+++ b/sdcard.ids
@@ -0,0 +1,23 @@
+# 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
+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
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v3 3/4] mmc-utils: lsmmc: Add mmc list command
2026-06-17 17:24 [PATCH v3 0/4] mmc-utils: improve lsmmc usability Torstein Eide
2026-06-17 17:24 ` [PATCH v3 1/4] mmc-utils: lsmmc: Use external .ids files for manufacturer lookup Torstein Eide
2026-06-17 17:24 ` [PATCH v3 2/4] mmc-utils: lsmmc: Accept /dev and /sys/block paths for register reads Torstein Eide
@ 2026-06-17 17:24 ` Torstein Eide
2026-06-17 17:24 ` [PATCH v3 4/4] mmc-utils: Add bash completion Torstein Eide
3 siblings, 0 replies; 5+ messages in thread
From: Torstein Eide @ 2026-06-17 17:24 UTC (permalink / raw)
To: linux-mmc; +Cc: Torstein Eide
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 | 76 +++++++++++++++++++++++++++++++++++++++++++++++++-
mmc.c | 6 +++-
mmc_cmds.h | 1 +
4 files changed, 93 insertions(+), 2 deletions(-)
diff --git a/docs/HOWTO.rst b/docs/HOWTO.rst
index 3739a0a..0b486e4 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 d42e121..bc43004 100644
--- a/lsmmc.c
+++ b/lsmmc.c
@@ -229,6 +229,39 @@ fallback:
return strdup(name);
}
+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)
{
@@ -2288,6 +2321,37 @@ static const char *month_name(unsigned int month)
return months[month];
}
+static void print_list_entry(struct config *cfg, const char *devname,
+ const char *blkdev, char *cid)
+{
+ char *mfr;
+ char devnode[32];
+
+ snprintf(devnode, sizeof(devnode), "/dev/%s", blkdev ? blkdev : "?");
+
+ if (cfg->bus == SD) {
+ struct sd_cid c;
+
+ parse_sd_cid(cid, &c);
+ mfr = get_manufacturer(cfg, c.mid);
+ printf("%-14s %-14s SD %-20s %-10s %u.%u 0x%08x %u-%s\n",
+ devname, devnode, mfr ? mfr : "Unlisted", c.pnm,
+ c.prv_major, c.prv_minor, c.psn, 2000 + c.mdt_year,
+ month_name(c.mdt_month));
+ } else {
+ struct mmc_cid c;
+
+ parse_mmc_cid(cid, &c);
+ mfr = get_manufacturer(cfg, c.mid);
+ printf("%-14s %-14s MMC %-20s %-10s %u.%u 0x%08x %u-%s\n",
+ devname, devnode, mfr ? mfr : "Unlisted", c.pnm,
+ c.prv_major, c.prv_minor, c.psn, 1997 + c.mdt_year,
+ month_name(c.mdt_month));
+ }
+
+ free(mfr);
+}
+
int do_list(int nargs, char **argv)
{
const char *bus_path = "/sys/bus/mmc/devices";
@@ -2303,6 +2367,12 @@ int do_list(int nargs, char **argv)
struct config cfg = {};
+ /* Probe ids files so any warning appears before table output */
+ cfg.bus = SD;
+ free(get_manufacturer(&cfg, ~0u));
+ cfg.bus = MMC;
+ free(get_manufacturer(&cfg, ~0u));
+
while ((ent = readdir(d)) != NULL) {
char devpath[PATH_MAX];
char resolved[PATH_MAX];
@@ -2319,6 +2389,11 @@ int do_list(int nargs, char **argv)
if (!type)
continue;
+ if (strcmp(type, "MMC") != 0 && strcmp(type, "SD") != 0) {
+ free(type);
+ continue;
+ }
+
cid = read_file_at(resolved, "cid");
if (!cid) {
free(type);
@@ -2346,7 +2421,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 fce7eef..b0f1f9b 100644
--- a/mmc.c
+++ b/mmc.c
@@ -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));
}
-
diff --git a/mmc_cmds.h b/mmc_cmds.h
index 9d5f944..033cc09 100644
--- a/mmc_cmds.h
+++ b/mmc_cmds.h
@@ -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);
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread