Read SD Card Serial Number from CID
For my current project, I tried to read the SD Card serial number because the number is factory stamped and unchangeable, so it easily could be used to protect embedded firmware from being copied.
The serial number is stored in the Card Identification Register (CID) which is read by \'Command 10\' as stated in the SD Simplified Specifications. Unfortunately, it is not possible to read the CID of the card with a USB adapter — you need a \'direct\' SD interface. My iMX233 based development board has 2 of them, so it was an easy task to improve our firmware to read the CID and extract the serial number, but how do I check if I get the correct information?
Reading SD-Card SID
Luckily the Linux kernel provides the CID via the SD and MMC Block Device Attributes so you may use a Linux device containing a direct SD interface like your Android phone or an embedded Linux board. Unfortunately, you cannot know the real path of the SD card in the /sys file system so I can only give some examples and you have to try out the actual path yourself.
For example, on my Samsung Galaxy Note running Gingerbread, there is a /sys/block/mmcblk0 soft link pointing to:
mmcblk0 -> ../devices/platform/s3c-mshci.0/mmc_host/mmc0/mmc0:0001/block/mmcblk0
mmcblk1 -> ../devices/platform/s3c-sdhci.2/mmc_host/mmc1/mmc1:b368/block/mmcblk1
So I check the CID using the adb tool from the Android SDK (rooting is not necessary):
adb shell
# cat /sys/block/mmcblk0/../../cid
On my Olimex iMX233 OLinuXino embedded Linux board I call the following (directly on the board):
cat /sys/block/mmcblk0/device/cid
The resulting hexadecimal number contains the following information:
Name Field Width CID-bits
------------------------------------------------
Manufacturer ID MID 7 [127:120]
OEM/Application ID OID 15 [119:104]
Product Name PNM 39 [103:64]
Product Revision PRV 7 [63:56]
Product Serial Number PSN 31 [55:24]
reserved -- 3 [23:20]
Manufacturing Date MDT 11 [19:8]
CRC6 Checksum CRC 7 [7:1]
not used, always 0 -- 1 [0:0]
To convert the hexadecimal number to a binary one, please have a look at my multiplatform Binary/Decimal/Hexadecimal Converter.
Based on an iMX233 CPU Board it may be easy to build an intelligent USB card-reader, supporting, for example, CID / CSD information and autonomic card tests.
Update:
I got a few emails pointing out that using the CID as copy protection is not a good idea because there are some cards on the market which are not compliant with the standard. These cards don't prohibit CMD26 in SPI mode and therefore allow writing the CID. However, I\'ve never seen such a card.
Update 2:
You can find an online CID decoder here: Decode SD Card CID Register Data