SD-Card Protocol

One of the early goals of BitThunder was to be able to replace U-Boot by loading a Linux kernel from an SD-card. Unfortunately documentation and examples are a little, well sparse. So I’ve decided to write a blog post which describes the protocol, and how the BitThunder sd-card subsystem works.

Note, this post discusses the SDIO protocol, not the SPI protocol.

Initialising the Card.

In many small devices, like micro-controllers, the sd-card will be used directly from power-on but in more complex system the sd-card could be in an undefined state left over from a boot-loader or bootrom.

The following sequence will allow you to get the card into a reset known state.

Is the controller reset?

On the Xilinx Zynq platform, the SDIO controller is itself left in an undefined state after being used by the BootROM. We found that using the SDHCI reset register left the peripheral in a pseudo-functional state, whereby some data transfers would always contain the data of the previous transfer. To solve this we asserted a peripheral reset signal using the processors system-level control registers. If you have problems, make sure your controller is completely reset. See the commit for details.

Step 1. Send GO_IDLE_STATE (CMD0).

Send CMD0, it requires 0 arguments, and returns NO response. This command is only required to be sent ONCE. (Some forums using SPI mention this should be repeated, but for SDIO its not necessary).

This command will ALWAYS cause a card to enter the IDLE state, no matter the current state of the card.

Step 2. Send SEND_IF_COND (CMD8).

This is the “send interface condition” command.

Loading Applications Demo

Just for interest, here is the output of BitThunder 0.6.0, loading the previous version from an SD-card. The 8 second delay is completely artificial caused by a call to BT_ThreadSleep();

This demonstration is running on the Zynq ZED BOARD from Digilent.

[    0.000] : BitThunder v0.6.0-stable (Incomplete Turing)
[    0.000] : Start Loading kernel modules...
[    0.000] : Module loaded: SD/MMC Manager
[    0.000] : Module loaded: SoftIRQ
[    0.000] : Module loaded: Filesystem Manager
[    0.000] : Module loaded: FullFAT Filesystem
[    0.000] : Module loaded: Process Manager
[    0.000] : Module loaded: Alive Led
[    0.000] : Module loaded: Tasklets
[    0.000] : Module loaded: Block-device Manager
[    0.000] : Module loaded: Volume and Partition Manager
[    0.000] : Module loaded: Device Filesystem
[    0.000] : Enumerate integrated devices
[    0.000] : Registered zynq,gpio with Zynq GPIO driver
[    0.000] : Registered zynq,mmc,sdhci with Generic SDHCI Controller Driver driver
[    0.000] : Enter user-mode, and start user-space application...
[    0.000] : Relinquish control of the boot UART device...(Goodbye)
[    0.010] : SDCARD: SDCard was inserted
[    0.020] : SDCARD: Sent GO_IDLE
[    0.020] : SDCARD: Sent SEND_IF_COND, response = 000001aa
[    0.022] : SDCARD: SDHC card support detected
[    0.026] : SDCARD: CID reg 00685359:4e436172:64100000:0d4a00ac
[    0.032] : SDCARD: Placed SDCARD into data state. (resp: b3680520)
[    0.038] : SDCARD: Relative Card Address (RCA): b368
[    0.043] : SDCARD: Selected card mmc0:b368
[    0.047] : SDCARD: Configured card for 4-bit data width. (resp: 00000920)
[    0.054] : SDCARD: sucessfully initialised... registering block device
[    8.000] : Mounting mmc00
[    8.001] : Done
[    8.001] : Opening zImage
[    8.001] : Reading file...
[    8.017] : Done



[    0.000] : BitThunder v0.5.0-stable (Heisenberg's Cat)
[    0.000] : Start Loading kernel modules...
[    0.000] : Module loaded: SD/MMC Manager
[    0.000] : Module loaded: SoftIRQ
[    0.000] : Module loaded: Filesystem Manager
[    0.000] : Module loaded: FullFAT Filesystem
[    0.000] : Module loaded: Process Manager
[    0.000] : Module loaded: Alive Led
[    0.000] : Module loaded: Tasklets
[    0.000] : Module loaded: Block-device Manager
[    0.000] : Module loaded: Volume and Partition Manager
[    0.000] : Module loaded: Device Filesystem
[    0.000] : Enumerate integrated devices
[    0.000] : Registered zynq,gpio with Zynq GPIO driver
[    0.000] : Registered zynq,mmc,sdhci with Generic SDHCI Controller Driver driver
[    0.000] : Registered zynq,mmc,sdhci with Generic SDHCI Controller Driver driver
[    0.000] : Enter user-mode, and start user-space application...
[    0.000] : Relinquish control of the boot UART device...(Goodbye)
[    0.000] : Started application
[    0.010] : SDCARD: SDCard was inserted
[    0.045] : SDCARD: Sent GO_IDLE
[    0.045] : SDCARD: Sent SEND_IF_COND, response = 000001aa
[    0.047] : SDCARD: SDHC card support detected
[    0.051] : SDCARD: CID reg 00685359:4e436172:64100000:0d4a00ac
[    0.057] : SDCARD: Placed SDCARD into data state. (resp: b3680520)
[    0.063] : SDCARD: Relative Card Address (RCA): b368
[    0.068] : SDCARD: Selected card mmc0:b368
[    0.072] : SDCARD: Configured card for 4-bit data width. (resp: 00000920)
[    0.079] : SDCARD: sucessfully initialised... registering block device
[    2.000] : Exited the sleep (from application).
Back
Next

Posted by: James Walmsley.

Published on: 2013-06-01 00:00:00 +0000

comments powered by Disqus