Skip to content

Instantly share code, notes, and snippets.

@rct
Last active November 3, 2024 18:50
Show Gist options
  • Save rct/2307aeba1f7486fa36c248523fb3b931 to your computer and use it in GitHub Desktop.
Save rct/2307aeba1f7486fa36c248523fb3b931 to your computer and use it in GitHub Desktop.
Reading SD/microSD card info, Available Utilities

Available Utilities for Reading SD/microSD Card info under Linux

Useful metadata for indentifying/distinguishing an SD card

  • Manufacturer
  • Product Code (short)
  • Product Name (long)
  • Size
  • Serial Number
  • Manufacturering Date
  • Class info

Card(s) used for testing:

Primary card: Samsung Pro Plus 128GB FD4Q9, manufactureed 8/2023 (or 9/2023?), HW Rev 3, FW Rev 0, Claimed 180MB/s Read / 130MB/s write.

Amazon Description: SAMSUNG PRO Plus microSD Memory Card, 128GB microSDXC, Up to 180 MB/s, Full HD & 4K UHD, UHS I, C10, U3, V30, A2

Challenges

Long Product Name isn't readily available (Pro, Ultra, Etc.)

Might be marketing name, printed on product, but manufactured by someone else

Claimed/marketed size GB vs. GiB vs. rounded up blocks:

119 GiB vs marketed 128 GB vs. actual bytes 127,775,277,056

Rounding does work in some cases: round(127_775_277_056 / 1000000000.0)

dmesg

Has product short code and size (GiB)

# dmesg | grep mmcblk
mmcblk0: mmc0:0001 FD4Q9 119 GiB

udevadmin info

Provides easy access to Product Code and Serial Number. /dev/disks/by-id link contains both: disk/by-id/mmc-FD4Q9_0x3cc25ec5

$ udevadm info /dev/mmcblk0
P: /devices/pci0000:00/0000:00:1d.4/0000:3f:00.0/rtsx_pci_sdmmc.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0
M: mmcblk0
R: 0
U: block
T: disk
D: b 179:0
N: mmcblk0
L: 0
S: disk/by-uuid/6667-4134
S: disk/by-id/mmc-FD4Q9_0x3cc25ec5
S: disk/by-path/pci-0000:3f:00.0-platform-rtsx_pci_sdmmc.0
S: disk/by-diskseq/4
Q: 4
E: DEVPATH=/devices/pci0000:00/0000:00:1d.4/0000:3f:00.0/rtsx_pci_sdmmc.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0
E: DEVNAME=/dev/mmcblk0
E: DEVTYPE=disk
E: DISKSEQ=4
E: MAJOR=179
E: MINOR=0
E: SUBSYSTEM=block
E: USEC_INITIALIZED=13860654186
E: ID_NAME=FD4Q9
E: ID_SERIAL=0x3cc25ec5
E: ID_PATH=pci-0000:3f:00.0-platform-rtsx_pci_sdmmc.0
E: ID_PATH_TAG=pci-0000_3f_00_0-platform-rtsx_pci_sdmmc_0
E: ID_FS_UUID=6667-4134
E: ID_FS_UUID_ENC=6667-4134
E: ID_FS_VERSION=FAT32
E: ID_FS_BLOCKSIZE=32768
E: ID_FS_SIZE=128177930240
E: ID_FS_TYPE=vfat
E: ID_FS_USAGE=filesystem
E: NVME_HOST_IFACE=none
E: MMC_TYPE=SD
E: ID_DRIVE_FLASH_SD=1
E: ID_DRIVE_MEDIA_FLASH_SD=1
E: DEVLINKS=/dev/disk/by-uuid/6667-4134 /dev/disk/by-id/mmc-FD4Q9_0x3cc25ec5 /dev/disk/by-path/pci-0000:3f:00.0-platform-rtsx_pci_sdmmc.0 /dev/disk/by-diskseq/4
E: TAGS=:systemd:
E: CURRENT_TAGS=:systemd:

mmc from mmc-utils package

Need to install mmc-utils (Same package name on Debian/Fedora)

Provides: Manufacturer, Product Short, Serial Number, Manufacturing Date

Odditiy, needs /sys/block/mmcblk0/device (directory) as argument

SYSDEV="/sys/block/mmcblk0/device"

for cmd in cid csd scr
do
    echo ==== $cmd ====
    mmc $cmd read $SYSDEV
done

Output:

==== cid ====
manufacturer: 'Transcend/Samsung' 'SM'
product: 'FD4Q9' 3.0
serial: 0x3cc25ec5
manufacturing date: 2023 sep
==== csd ====
card classes: 11 extension, 10 switch, 8 application specific, 7 lock card, 5 erase, 4 block write, 2 block read, 1 reserved, 0 basic,
capacity: 119.38Gbyte (128177930240 bytes, 250347520 sectors, 512 bytes each)
==== scr ====
version: SD 3.0x
bus widths: 4bit, 1bit,

Linux Kernel info from /sys/bus/mmc

Can simply read short code (name), manf. date, serial number, hardware rev, and lots of IDs/Registers that need to be decoded (Manufacturer's ID, OEM id,

$ find /sys/bus/mmc/devices/mmc0\:*/ -type f -not -path "*block*" -print -exec cat {} \;


/sys/bus/mmc/devices/mmc0:0001/fwrev
0x0
/sys/bus/mmc/devices/mmc0:0001/uevent
DRIVER=mmcblk
MMC_TYPE=SD
MMC_NAME=FD4Q9
MODALIAS=mmc:block
/sys/bus/mmc/devices/mmc0:0001/cid
1b534d4644345139303cc25ec5a17801
/sys/bus/mmc/devices/mmc0:0001/rca
0x0001
/sys/bus/mmc/devices/mmc0:0001/csd
400e0032db790003baff7f800a400001
/sys/bus/mmc/devices/mmc0:0001/manfid
0x00001b
/sys/bus/mmc/devices/mmc0:0001/power/runtime_active_time
111165
/sys/bus/mmc/devices/mmc0:0001/power/runtime_status
suspended
/sys/bus/mmc/devices/mmc0:0001/power/autosuspend_delay_ms
3000
/sys/bus/mmc/devices/mmc0:0001/power/runtime_suspended_time
10178820
/sys/bus/mmc/devices/mmc0:0001/power/control
auto
/sys/bus/mmc/devices/mmc0:0001/ocr
0x00300000
/sys/bus/mmc/devices/mmc0:0001/preferred_erase_size
4194304
/sys/bus/mmc/devices/mmc0:0001/type
SD
/sys/bus/mmc/devices/mmc0:0001/hwrev
0x3
/sys/bus/mmc/devices/mmc0:0001/date
08/2023
/sys/bus/mmc/devices/mmc0:0001/dsr
0x404
/sys/bus/mmc/devices/mmc0:0001/erase_size
512
/sys/bus/mmc/devices/mmc0:0001/removable
removable
/sys/bus/mmc/devices/mmc0:0001/oemid
0x534d
/sys/bus/mmc/devices/mmc0:0001/serial
0x3cc25ec5
/sys/bus/mmc/devices/mmc0:0001/ssr
0000000008000000040090000811391e000800000002ff0003000000000000000000000000000000000000000000000000000000000000000000000000000000
/sys/bus/mmc/devices/mmc0:0001/scr
0205848700000000
/sys/bus/mmc/devices/mmc0:0001/name
FD4Q9

Linux kernel info from /sys/block/mmcblk0/device directory

A similar find script for /sys/block/$devname which is easier to find from /dev/mmcblk0:

$ find /sys/block/mmcblk0/device/ -maxdepth 1 -type f -print -exec cat {} \;

/sys/block/mmcblk0/device/fwrev
0x0
/sys/block/mmcblk0/device/uevent
DRIVER=mmcblk
MMC_TYPE=SD
MMC_NAME=FD4Q9
MODALIAS=mmc:block
/sys/block/mmcblk0/device/cid
1b534d4644345139303cc25ec5a17801
/sys/block/mmcblk0/device/rca
0x0001
/sys/block/mmcblk0/device/csd
400e0032db790003baff7f800a400001
/sys/block/mmcblk0/device/manfid
0x00001b
/sys/block/mmcblk0/device/ocr
0x00300000
/sys/block/mmcblk0/device/preferred_erase_size
4194304
/sys/block/mmcblk0/device/type
SD
/sys/block/mmcblk0/device/hwrev
0x3
/sys/block/mmcblk0/device/date
08/2023
/sys/block/mmcblk0/device/dsr
0x404
/sys/block/mmcblk0/device/erase_size
512
/sys/block/mmcblk0/device/removable
removable
/sys/block/mmcblk0/device/oemid
0x534d
/sys/block/mmcblk0/device/serial
0x3cc25ec5
/sys/block/mmcblk0/device/ssr
0000000008000000040090000811391e000800000002ff0003000000000000000000000000000000000000000000000000000000000000000000000000000000
/sys/block/mmcblk0/device/scr
0205848700000000
/sys/block/mmcblk0/device/name
FD4Q9

pibenchmarks.com script

The Raspberry PI storage benchmarking site pibenchmarks.com utility does a pretty good job of identifying SD cards and other storage devices.

Running the site's Storage.sh benchmark gives a bunch of useful info on the benchmarked storage device and host system.

Googling a product short code often turns hits on that site, for example FD4Q9 yields (https://pibenchmarks.com/brand/Samsung_SD_Pro_Plus_(FD4Q9)/)[https://pibenchmarks.com/brand/Samsung_SD_Pro_Plus_(FD4Q9)/]

NOTES:

  • this doesn't use mmc-utils
  • Month of date of manufacture diffes by 1 from mmc-utils (does month start from 0 or 1?)

Drawbacks of Storage.sh

  • Have to run a benchmark to get ID info.
  • Installs things and symlinks on your system without warning
  • Download this bash script and run as root isn't the "safest" thing to do.
  • Benchmark results aren't differentiated by size. A 128GB card might be faster than 32 or 64GB smaller card, probably due to some parallelism in the card (2X or 4X the infrastructure in the card?)

Short output from running script (slightly hacked up version that doesn't do the benchmark, report results, and can be run without root.

Card CSD status register: MID: 1b OID: SM PNM: FD4Q9 PRV: 3.0 MDATE: 8/2023
Card SCR status register: SD Physical Version Specification: 6
Manufacturer: Samsung - Model: FD4Q9 - Vendor:  - Product: SD - HW Version: 0x3 - FW Version: 0x0 - Date Manufactured: 08/2023 - Class: A2 Class 10 V30 U3

Note: the results page displays the follwing info.

Brand:	Samsung SD Pro Plus (FD4Q9)
Manufacturer:	Samsung
Class:	A2 C10 V30 U3
Type:	SD
Popularity:	#243 / 1,585
# Tests:	52
Rank (Overall):	#941 / 1,585
Rank (Type):	#11 / 385

TBD: Where did the long product name and product image come for Samsung Pro Plus? I have to assume that's been user supplied.

Learning from pibenchmark.com's Storage.sh

Info Host's SD card interface

Only works as root, provides clock, bus width

cat /sys/kernel/debug/mmc0/ios

clock:          208000000 Hz
vdd:            21 (3.3 ~ 3.4 V)
bus mode:       2 (push-pull)
chip select:    0 (don't care)
power mode:     2 (on)
bus width:      2 (4 bits)
timing spec:    6 (sd uhs SDR104)
signal voltage: 1 (1.80 V)
driver type:    0 (driver type B)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment