I understand that Raspberry-Pi uses most open source software. I was not able to find the software stack that is used to access the SD card over SD protocol in the Raspberry-Pi although I did carry out a search on the internet.

In the Raspberry Pi's Software stack, where are the software (driver files, headers etc) related to SD protocol located at?

2 Answers 2


The #1 problem that plagues people here is believing that Raspbian (the "operating system" that is predominantly used on the pi and recommended and distributed, with tweaks, by the manufacturer), was written from the ground up for the device the way that Android was created, for the most part, for the devices it is used on. This is false, not because anyone involved is lazy or dishonest, but primarily because of the economics of scale (it might also be considered totally unnecessary, just as Dell or Toshiba do not produce operating systems for their hardware but instead produce hardware intended to run existing operating systems).

I used quotes on "operating system" because it implies, e.g., that there is some great difference either in technical structure or end user functionality between Raspbian and the much more long standing "operating system" on which it is based, Debian. "Based" as in very very closely based. The differences are primarily superficial, the way that you might live in the exact same model of home as your neighbor but have painted the walls differently and put different furniture in the rooms -- something it might take a few people a few days to swap back and forth convincingly, as opposed having to knock one house down and build it anew in order to replicate the one next door.

Of course a normal, modern computer running Debian is to the pi a bit like a mansion is to a bachelor apartment, which makes a big difference in terms of end-user experience but little or none in terms of operating system structure.

I used quotes in referring to Debian as an "operating system" of its own as well because it is a distribution of GNU/Linux, colloquially "linux", another problematic term since Linux is actually just an operating system kernel also used, e.g., by Android as well as various obscure embedded platforms. Most people have at least one linux based device in their home and do not not know it (clue: they are probably attached to your television and/or the cable that connects your home to the internet, and often run atrociously designed end-user interfaces on top of the kernel).

Those are probably more truly individualized operating systems than say, Debian is from Fedora, or Ubuntu and so on. Although common parlance has come to refer to these as different "operating systems", this is a little bit like saying that Bob's Samsung Galaxy phone runs a different operating system than Sue's HTC One phone and that Ralph's Google Nexus phone runs yet another different operating system. In a sense this is true, but for the most part, they are all variations on the theme of Android.

Fortunately, in the consumer smartphone world, most people are aware of this. They know that while Samsung and HTC may maintain and run slightly different versions/customizations under the conceptual umbrella "Android", that conceptual umbrella is in fact what primarily determines most things about the software on the phone and further, that generally speaking application software is easily inter-operable between them. Hence, there is not a Samsung Playstore and an HTC Playstore and so on. There is a Google Playstore for Android.

Unfortunately, this is not the impression implicitly received by many new (and even long running) pi users, who incorrectly believe there is something more significant than paint and furnishing to distinguish Raspbian from Debian, or, worse yet, that the primary use case for GNU/Linux is the Raspberry Pi, so really they are somehow synonymous with one another.

So to be clear, the conceptual umbrella for the open source operating systems used on the Raspberry Pi is "GNU/Linux" or more informally (and confusingly), just "linux", with the exception of a few things like FreeBSD, which I believe also has a pi port.

Why this is a Serious Problem

This is a serious problem because it then leads people to search online for information such as the "raspberry pi SD card software stack", which will return to you (I'm only going to guess) an incredible pile of assorted garbage. This is not because there is no such thing, but because for the most part, the context in which this software stack exists is on a much, much larger scale than that of the Raspberry Pi. As in at least several orders of magnitude larger: Although there might be 4 or 8 million+ pis in the world, mostly running linux, there could easily be more than a billion other linux powered devices in the same world.

Keep this in mind when you search for things on the internet. You may end up concluding your searches by including the term "raspberry pi", but it is generally foolish to start out that way believing you are going to get to skip some steps instead of going down some random rabbit hole.

With regard to the SD card stack on the pi, it's the SD card stack from the linux kernel, the same kernel used on 30%+ of the world's internet servers, 95% of the supercomputers, etc. Of course, those things probably make little or no use of SD cards, but vastly outnumbering them are the laptops and desktops running some form of GNU/Linux much like Raspbian, albeit in a somewhat fancier package as they tend to run on much higher performing hardware than a $35 dev board, and may account for a few percent of that market (so still outnumbering the pi by an order of magnitude) and then of course all those Android devices, almost all of which do use SD cards (and now we are talking another order of magnitude, well into the hundreds of millions of units).

If we peek into the vanilla linux source, the top of the stack implementing the SD "protocol" (see Millway's answer for a dissection of that) is probably in /drivers/mmc (where "MMC" stands for "multi-media card", which was a term used before "SD", i.e., "secure digital", became the industry standard).

Finally, the Answer You Were Looking For...

The Raspberry Pi, like Android devices, does not run an unadulterated vanilla linux kernel. It includes various low level bits and pieces used for hardware only on the pi (or rather, predominantly, it is not an exclusive limitation), namely the Broadcom SoC at its heart. This shows up in the host subdirectory of the drivers/mmc directory, which in the pi branch of the kernel contains a few additional entries such as:


It also seems to contain a few less for whatever reason -- it doesn't matter because most of the source in that directory isn't compiled into the pi kernel at all, it's just there because it's part of the the vanilla kernel from which the pi kernel is branched and it would be too much (completely pointless) hassle to keep it all pruned out of the source tree.

Anyway, there's 2.5 million bytes of C source, i.e., ~50-100 K LOC in the mmc directory, which should contain the answers to any and all unspecified questions you might have about "the software stack that is used to access the SD card over SD protocol in the Raspberry-Pi". Fortunately, most of that is unrelated hardware brand specific stuff in the host directory; the top part of the tree is only 1/2 million bytes.


The simple answer (in contrast to @goldilocks answer) is that there is NO "SD protocol".

SD Cards actually implement different protocols.

All allow SPI but may include "faster" protocols which can optionally be used. These are used to implement the higher speed access on modern cards. It is comparability simple to implement RAW access to the card using SPI.

There are public Arduino libraries to read/write FAT formatted cards using SPI, although AFAIK not for the Pi (I have searched).

FAT is actually a very simple protocol and is presumably implemented for the GPU to allow the Pi to boot from SD.

GNU/Linux implements higher level protocols which sit on top of the basic raw access to implement filesystems (ext4 and others) which can use any raw block mode device, whether on SD, HD or over a network.

  • Excellent point, sort of -- most of what would seem to count as "SD card standards" looks to be about form factors, but specifying the use of various existing protocols for specific contextual purposes under the umbrella of standardization does amount to a specification in and of itself. It is not as if there is "no protocol" in the sense that I can carve out a piece of wood that fits into an SD slot and say it is just as much an SD card as anything else.
    – goldilocks
    May 30, 2016 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.