Can I read SD card serial number connected with USB card reader/writer as mounted sda?
Asked Answered
J

1

5

On Raspberry pi, I can read the serial number of SD card mounted on the built-in SD card drive from cid file under /sys/block/mmcblk0/device folder.

pi@raspberrypi:~ $ ls /sys/block/mmcblk0/device
block  driver      hwrev   oemid                 scr        type
cid    dsr         manfid  power                 serial     uevent
csd    erase_size  name    preferred_erase_size  ssr
date   fwrev       ocr     rca                   subsystem

But, about the SD card connected with USB SD card reader/writer mounted on the device of sda, I can't see the cid file.

pi@raspberrypi:~ $ ls /sys/block/sda/device
blacklist                           evt_soft_threshold_reached  rescan
block                               generic                     rev
bsg                                 inquiry                     scsi_device
delete                              iocounterbits               scsi_disk
device_blocked                      iodone_cnt                  scsi_generic
device_busy                         ioerr_cnt                   scsi_level
driver                              iorequest_cnt               state
eh_timeout                          max_sectors                 subsystem
evt_capacity_change_reported        modalias                    timeout
evt_inquiry_change_reported         model                       type
evt_lun_change_reported             power                       uevent
evt_media_change                    queue_depth                 vendor
evt_mode_parameter_change_reported  queue_type                  wwid

Is there any way to read SD card serial number mounted as sda? Any suggestions are welcome!

Jocular answered 11/6, 2020 at 0:1 Comment(0)
D
10

I ran into this problem just the other day (and stumbled across this question in my search), and it looks like the answer is that it's not really possible.

The CID information is stored on a register on the SD card, and you can only access it through SPI (usually). The driver has to send specific commands to the SD card to read these registers.

When you use a USB SD Card reader on the other hand, it uses the generic "USB mass storage device" interface -- so when your PC is talking to the USB card reader, it [your PC] doesn't even really know it's talking to an SD card specifically, it just treats it like its another generic USB storage device (like a flash drive or something).

The only way this kind of thing would remotely be possible if your USB SD card reader had a mode that let you communicate with it directly by-hand (e.g. send a custom command to it over USB), but AFAIK this kind of thing doesn't exist.

If you're deadset on getting the CID info and don't mind using additional hardware (~ $10), you could buy an SD card breakout board and connect it to an Arduino or whatever, then you'll have access to the pins and you can write your own code to read the CID data.

Credits to this answer, which is what my answer is based off: https://mcmap.net/q/1719557/-read-cid-of-sdcard-connected-to-usb-sd-reader-under-linux

If you're interested, you can check out the SD Card Association's specification (the 'Physical Layer') here https://www.sdcard.org/downloads/pls/ for more info on how the CID information is gathered.

And the Linux kernel's SD card driver: https://github.com/torvalds/linux/blob/master/drivers/mmc/core/sd.c

Deedee answered 31/12, 2020 at 5:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.