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 (1). 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:

So I check the CID using the adb tool from the Android SDK (rooting is not necessary):

On my Olimex iMX233 OLinuXino embedded Linux board I call the following (directly on the board):

The resulting hexadecimal number contains the following information:

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. What do you think, is there a need for such a card-reader? Your comments are welcome in the comment section below.

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

Share Button
The following two tabs change content below.

Mike Bergmann

Technical software developer loving low level, bit peeking, embedded development as well as GUI, OO, and X-platform development.