20060922

SD/MMC FreeBSD Driver Outline

There's many different flash standards in the world today. SD and MMC are two related flash card standards. These cards are used by different cameras. Readers of these cards are available for USB, PC Card and CardBus. In addition, native readers are present on many laptops and other portable devices. Here's a little background on MMC and SD. I'm writing software for MMC/SD for FreeBSD, and this will give some background for people that wish to help.

Many of the readers of MMC and SD cards emulate something else. USB cards look the same as the thumb drives, which are already supported by umass(4). PC Card and CardBus cards tend to look like ata drives, which are supported by ata(4). The native host interfaces have their own interfaces. There's two common ones in laptops, and a bunch of other interfaces in embedded devices. Since the other reads emulate something else, they aren't relevant to my FreeBSD work, so I'll not describe them further.

My efforts will concentrate on two different host adapter interfaces. The first one is the MCI interface present on the Atmel AT91RM9200 (and some newer atmel parts). This interface is relatively simple. The second one is the SD Host Controller Standard conforming host interfaces. This interface was recently documented by the SD Card Association and is present in many laptops.

For FreeBSD the software will have three layers. At the 'bottom' level is the host interface. All host interface drivers present a standard API to the bus layer. The bus layer, for the mmc/sd bus, handles all the device enumeration as well as arbitrating access to the bus. The top layer is for the SD/MMC card as well as SDIO cards that are appearing in the market place.

As a first step towards understanding, Berndt Walter write a quick and dirty driver for mmc. I added sd support for it and am debugging it. Once that's basically working, the next step is to do a proper driver with proper layering. Linux already has a system, and I'll be taking a look at it to see what I can learn from their experiences.

Anyway, back to the standards.

MMC stands for Multi Media Card. This standard was created many years ago as a small form-factor flash card. This standard was invented by the Multi Media Card Association. This standard was popular early on, but was lacking security features. The standards through version 3.31 only specifies a one wire data bus running at 25MHz. While adequate for smaller capacity cards, for large capacity cards, this presented a significant bottleneck.

The SD Association (Secure Digital) based their work on the 2.2 version of the MMC standard. They added a number of incompatible commands (on purpose, so one could tell the cards apart), changed the electrical stuff a little to make things simpler, added three more data lines as well as security features needed to deliver secure content on these cards. The SD Association later defined SDIO cards, which allow for more things than just memory cards. Today, most cards that you'll find in the marketplace today are SD cards. For a long time, this interface was totally undocumented without a nasty NDA. Recently, much of the SD standard has been released, and that's the information I'm using to create the drivers.

3 comments:

Anonymous said...

Very interesting!
I'd love to hear more about that topic and your work in the future :-)

I'm also glad to hear that the NDA has gone away, maybe now I can stop bashing SD Cards ;-)

Anonymous said...

Warner:

I am very interested in your progress\findings. We are trying to see what it would take to get SD\MMC support in NetBSD and there seems to be no info out there. We are looking at it from an embedded memory system perspective to replace expensive NOR FLASH.

Any info ideas appreciated.

Warner Losh said...

The FreeBSD wouldn't be hard to port to NetBSD, nor would the OpenBSD code. For a variety of reasons, the OpenBSD code would be simpler to port to NetBSD. I felt it would be easier to write from scratch the FreeBSD code because of issues I've had porting bus drivers in the past to FreeBSD.