Project: Read, Collect & Decode SD Card CSD Register Data

As a followup to yesterday’s post of collecting and decoding the Card Identification Register data from various SD cards, I couldn’t resist the challenge to try and decipher the Card Specific Data Register (CSD).

Interestingly, I pored over datasheets for hours and drew out bit definitions for the data in order to develop a Javascript based decoder for the CSD data one can get from cat /sys/block/mmcblk1/device/csd on a Chromebook.

As I started coding before I had finished parsing the whole datasheets – I came up with a very messy and sub-optimal solution. I’m not proud of the code, but it seems to work. I won’t guarantee it, of course, so use at your own risk, although seeing as it’s the second Javascript attempt, I’m happy that I at least got something to work! Everything is ugly and hand-coded, as is my nature.

If I had to do it again, I would decompose the whole thing into a string of binary bits before dealing with it, as I didn’t realize beforehand just how many of the fields are not nibble aligned making working in hex on the original string moot!

On doing so, I realized that there are several versions of the CSD – one for SD Standard Capacity (SDSC) and the other for SD High Capacity (SDHC) which has resulted in two separate versions of the decoder being developed.

As usual, I also went to lengths to collect the CSD data from my cards – note the first is an MMC card, so the definitions may not hold true for MMC cards!

d00f00320f5903ffffffffff92404011 CHROMEBOOK INTERNAL EMMC
400e00325b5900001d697f800a40008b RASPBMC SDHC CARD
400e00325b590000e9e57f800a4040f1 SAMSUNG 32Gb CLASS 10 SDHC
400e00325b590000ee9d7f800a400013 TEAM 32Gb CLASS 10
400e00325b590003a5df7f800a400007 KINGSTON 128Gb SDXC CLASS 10
002d00325b5a83d5fefbff80168000cf KINGSTON 2Gb SDSC
002600325f5a83c93efbcfff928040cb SANDISK 2Gb Blue SDSC
400e00325b590000ef377f800a400025 PATRIOT 32Gb CLASS 10 SDHC
400e00325b590000edc87f800a4040c3 SANDISK 32Gb CLASS 4 MicroSDHC
002600325f5983c8addbcfffd24040a5 SANDISK ULTRA II 1Gb MicroSDSC
400e00325b590001dbd37f800a4040df SANDISK ULTRA 64Gb UHS-I MicroSDXC
007f00325b5a83af7fffcf801680006f UNBRANDED 2Gb MicroSDSC
007f00325b5a83bfffffcf8016800037 PRETEC 2Gb MicroSDSC

The decoders are quite long, so instead of embedding them, they’ve been linked here:

While trawling online, I came across a similar decoder for MMC, although it seems to implement an older register definition but it has the same idea.

I hope it comes in handy for readers – it certainly lets me understand some more about my SD cards, and gives me a surprising insight into just how much manufacturer encoded information exists on these cards, mostly hard-coded from the factory. There are other registers, but they aren’t as informative or useful as the CID and CSD pair.

About lui_gough

I'm a bit of a nut for electronics, computing, photography, radio, satellite and other technical hobbies. Click for more about me!
This entry was posted in Computing, Electronics, Flash Memory and tagged , , , . Bookmark the permalink.

15 Responses to Project: Read, Collect & Decode SD Card CSD Register Data

  1. Aardvark says:

    Have you been able to check SDXC versus SDHC. They are supposed to be closer to each other than SDHC and the original SD spec. I myself have not yet had a chance to play with an SDXC card (they start at 64GB) but I have SDXC capable readers on both my MacBook Pro and a relatively new Windows laptop.

    • lui_gough says:

      I have the CSD of an SDXC 128Gb and 64Gb in this post, and it follows the SDHC 2.0 specifications and decodes correctly.

      – Gough

      • Andrew says:

        Hi, lui,
        A hypothetical: i have a touch screen GPS navigation unit in my car, the maps for it are on a small SD card which is loaded into the front of the unit.
        The problem is that the maps are a little pathetic and lack detail, is it possible to install Maps from Google or others on to my SD card and make it work in the car unit. I now down load an app from the internet on to my phone and use the phone, but I would like to download the app to my SD card and use it through the car unit – is this possible.

        • lui_gough says:

          It will depend on what software is running on said GPS navigation unit as every software has a different expectation as to the format of mapping data, none of which are interchangeable. Even within the same vendor, the data is often not interchangeable between different series of GPS. Many of such navigation only units use proprietary software of which their custom map formats are not understood and “generating” compatible maps say from Openstreetmap where data is freely available is hence not possible.

          Also, often such navigation units run odd operating systems too, making installation of apps difficult to impossible. Some run variants of Windows CE/Windows Mobile, but locked down, whereas others have custom operating systems. Installing apps is generally not a possibility, unless the vendor chooses to provide them.

          – Gough

          • Andris Ford says:

            Hi Gough,
            At last I get an educated comment, from someone who knows something, thank you.
            One last thought, my SD card is inserted into the face of the car GPS unit, Im guessing that is a sd card reader, would it be possible for me to download an app with maps on it and then write it to a new SD card and then to purchase an SD card reader and disconnect the present card reader from my car GPS unit and plug in my new card reader to the car unit with the SD card with the new maps.

          • lui_gough says:

            This is unlikely to be possible, as depending on the GPS, some manufacturers have gone to great lengths to secure their maps against copying and tampering by using the “secure” encryption features of secure digital cards, which both prevents them from being accessed using regular card readers and computers and also prevents making a compatible card. Further to that, most GPS units don’t have the software (i.e. operating system + app) stored on the card itself, instead, having it stored inside the internal flash memory within the unit which is likely only upgradeable using the manufacturer’s images only (and may be encrypted, or protected by other means). The units are not generally capable of running third party apps, nor running them from external storage. If there are any USB ports or other interfaces, they’re often only available to play music or videos as “additional features” and not for providing maps or apps.

            – Gough

  2. Darkstar says:

    You can handle arbitrary bit positions just fine without using bitstrings.
    Each field has 2 an offset (first bit) and a length (number of bits).
    You shift the whole data right #offset bits, then AND it with (1<<(#bits)) – 1 and you have your data. Much easier and faster than using bitstrings

  3. Darkstar says:

    Damn, my first comment was eaten by the system. So let’s try that again.

    You don’t need bitstrings, just do SHIFT_RIGHT(data, offset), and then BIT_AND(data, 1<<length – 1), where offset and length are the bit position and bit-length of the field you want to extract

    • lui_gough says:

      That’s generally the approach I use in C and when coding for ARM assembly, although never having used Javascript before, I didn’t know it was also available there (and if it was, the function and syntax). At least I have something that works for when I need to get a quick answer – if others are willing to do their own, I’d be happy to use theirs. In fact, it was because I was looking for one online and didn’t find one that I actually decided to embark on the adventure.

      – Gough

  4. Barry says:

    Hi, wondering if anyone can point me in the right direction. Have a Sandisk 16GB Extreme Pro 45MB/s card. On and off for the last 6 mnths been trying to get it to work with my PC (Dell Studio 540, Win7) but variously have had “need to format” / “cannot write from source disk” to SDHC card for large files (>~4mb) / “cannot format write protected” errors.
    Have used various tools and then tried industry’s SDFormatter v4, which gave the “write protected” error. Looked at and focussed on the prog’s users manual where it says on p3 “Cards have “Protected Area” in the card for SD security function: and “Please use appropriate application software or SD host device
    which provides SD security function to format the “Protected Area” in the card.” A search brought me to this site after I put in “protected area etc”. Am a reasonably competent informed PC user and tried searches and tools to try to id the problem. It strikes me that this may be relevant. The manual unfortunately doesn’t help with how to fix a “protected area” problem (overwritten perhaps) or say where to go for appropriate software or host device. Any guidance would be appreciated. Thanks

    • lui_gough says:

      You may have been a victim of a fake card, rather than a protected area problem. Many users seem to believe their cards are protected because of a failure to write (under Linux) or a message that the card is write protected (even though it isn’t, or hasn’t got a write protect switch in the case of microSD when running SDFormatter), but actually, many times it’s because the flash media has failed to such an extent that it is not possible to write any further without risk of data loss, thus rendering the card “read only”. The controller on the card itself is refusing the writes. The DRM secure area features are rarely used, if at all, and are only used by very very few phones and specific MP3 players that support downloadable content.

      For example, this Lexar which is “inconclusively” fake managed to go from writeable to write protected in about eight full cycles due to flash failure.

      It’s not the only one, as this week, I’ve had a four year old Team Group Inc. 32Gb Class 10 card go from working just fine to being read only as well.

      If it is actually a protected mode issue, the only device that can unlock it is the device that generated the lock in the first place due to the locking key. In some cases, certain older Windows Mobile phones that needed to use the DRM rendered their cards unusable for any other purpose as they could not be unlocked. However, according to Wikipedia ( it may be possible to perform an unlock using certain specific Symbian based Nokia handsets. I don’t know as to the actual details behind the commands issued, however.

      Best of luck with your problem.

      – Gough

      • Barry says:

        Thanks for your response. I don’t think the cards (see below) are fake as I bought them through US stores and they have worked fine in my Canon DSLR. The other card is a 16gb Sandisk 95MB/s card and putting it in the card reader gave similar results to the first. I’m starting to think that the problem is the card reader or driver ( 2008, which apparently does not have any updates). Cannot find out what make the reader is (multicard) either from Dell or forums so hard to pin this one down. I’ll maybe borrow or buy a card reader to test. Again appreciate the help

        • lui_gough says:

          An incompatibility with the reader is possible especially if the reader does not support SDHC/SDXC cards – in which case, I would recommend the Transcend RDF8 as a reasonably priced, high performing card reader with few to no compatibility issues in my experience. You could try formatting with the camera or device as well. Many laptops have integrated SD card slots as well, with most recent laptops having a decent reader in them, so you could also try that in a pinch.

          – Gough

  5. Matjaž says:

    Hello, does anybody know if Windows 10 can read CID (with native Microsoft driver) of microSD card inserted into REALTEK PCIE card reader on HP elitebook 840G?

Error: Comment is Missing!