SD

From A110 Wiki
Jump to: navigation, search

To use the SD card reader in the A110 you can either use the kernel from one.de or you can patch your current kernel to include the drivers for the card reader. The best solution is to use the mainline kernel 2.6.31 or later which contains a driver for the VIA card reader.

Contents

Kernel from One (that includes the SD driver)

The SD card reader works if you use the kernel from the One homepage. How to install and use it depends on the Linux distribution you have. See here for reference.

SD driver from One, ported to 2.6.25

Patches for a full kernel build

In order to use the SD driver from one.de on recent kernels (2.6.24 or 2.6.25) you need a patch from Uwe Hermann to make it compile. There are three options:

  • Recommended: You can use this patch, which contains the SD driver from One plus the changes needed to make it build on recent kernels.
  • Or you can use this patch, which only contains the changes required for recent kernels. The patch applies against a kernel where you have already copied Kconfig, Makefile and the via/ subdir into your kernel tree, as explained in the ReadMe.htm file in the one.de driver.
  • Or you can build just the SD driver kernel module (i.e. you don't have to rebuild a complete kernel), see below. This method won't work if you need to have the driver in the kernel image (not as a module), though.

Standalone kernel module

In order to create the driver module (kernel headers have to be installed) you can use this archive. It contains the One driver out of the kernel package, patched by Christian Rothländer, and a patched Makefile which works without the kernel sources. In other words, you won't have to (re-)build a full kernel, only the module itself.

$ wget http://www.a110wiki.de/wiki/images/0/06/Cardreader2.tar.bz2
$ tar xfvj Cardreader2.tar.bz2
$ cd via2
$ make

This archive doesn't seem to build for 2.6.25 out of the box, but it will likely work for 2.6.24.

After building, you can load the module respective *.ko files via insmod.

Debian-specific kernel build HOWTO

Note: It is recommended to perform the kernel building on a powerful (Debian) machine other than the A110, as it will take quite a while and consume lots of disk space.

Get the latest Debian kernel sources (2.6.25-2-686 at the moment) and the build-dependencies needed to build a kernel:

$ apt-get build-dep linux-image-2.6.25-2-686
$ apt-get source linux-image-2.6.25-2-686
$ cd linux-2.6-2.6.25

Get the SD card driver patch and apply it:

$ wget http://www.a110wiki.de/wiki/images/6/6f/A110_sd_driver_ported_for_2.6.25.patch.gz
$ gunzip A110_sd_driver_ported_for_2.6.25.patch.gz
$ patch -p1 < A110_sd_driver_ported_for_2.6.25.patch

This patch includes the full SD card driver from one.de, as well as modifications by Uwe Hermann to make it compile on a 2.6.25 kernel.

Next up, further modifications of the Debian kernel package specifics are recommended.

First, edit debian/changelog and add a paragraph such as the following at the top of the file:

linux-2.6 (2.6.25-4+0sdcard) unstable; urgency=low

* Add VIA driver for A110 SD card reader.
-- Uwe Hermann <uwe@hermann-uwe.de> Mon, 02 Jun 2008 13:26:24 +0200

The changelog rules are very strict. To avoid unnecessary errors i.e. with white spaces you should use debchange from the devscripts package instead of editing directly the changelog file:

# apt-get install devscripts
$ dch --newversion 2.6.25-4+0sdcard

After the asterisk in the upcoming editor you can add the line as shown above.

Note: If you append something like +0sdcard you have to use a + to avoid a conflict with the debian version policies.

Then, edit debian/config/defines and append a string to the abiname value, e.g. abiname: 2sdcard.

Edit debian/config/i386/defines and comment all unneeded flavors (to reduce compile time). As you usually only want the 686 flavor, you can safely remove 486, 686-bigmem and amd64, as well as the vserver, xen and xen-vserver featuresets.

You'll probably also want to disable building the linux-doc* and linux-manual* kernel packages as it takes a very long time. Thus, edit debian/rules.real and comment the following two lines:

#binary-indep: install-doc
#binary-indep: install-manual

Finally, add CONFIG_MMC_VCRDR=m to debian/config/i386/config.686 if you want to build the SD driver as a kernel module, or CONFIG_MMC_VCRDR=y if you want to compile it directly into your kernel.

Now build the kernel:

$ make -f debian/rules source-all
$ mkdir debian/stamps
$ fakeroot make -f debian/rules.gen setup_i386_none_686
$ fakeroot make -f debian/rules.gen binary-arch_i386_none_686 binary-indep

You can now copy the generated linux-image*.deb file to your A110 and install it:

$ dpkg -i linux-image*deb

Reboot into the new kernel.

Note: If you need your kernel headers (i.e. for installing the ndiswrapper module for wlan) there could be unmet dependencies: The linux-headers-2.6.25-2scard-686...deb depends on linux-headers-2.6.25-2scard-common...deb. If the common one has not been generated with the upper procedure you should do:

$ make -f debian/rules binary
$ fakeroot make -f debian/rules.gen setup_i386_none_686
$ fakeroot make -f debian/rules.gen binary-arch_i386_none_686 binary

Mainline kernel SD driver

There is work being done to include an improved driver into mainline Linux: mmc: Add new via-sdmmc host controller driver. This driver is part of 2.6.31 (and later) kernel.

After first tests (with driver as in kernel, no additional corrections or patches), it seems to work much better than the old driver provided by One.

The load while writing is quite low, the write performance acceptable (500MB is large enough to avoid cache effects):

$ dd if=/dev/zero of=test bs=1M count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 59.0516 s, 8.9 MB/s

Reading:

$ dd if=test of=/dev/null bs=1M
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 27.3159 s, 19.2 MB/s

The card used in these tests gives a write speed of less than 100 KB/s with the One driver.

Testing

Insert an SD card into the A110. The kernel should automatically load the required modules — mmc_core, mmc_block, and vcrdrm.

There should be one or more /dev/mmcblk* devices now, which you can mount. If there's one partition on the SD card and a vfat file system on it, do this:

$ mount -t vfat /dev/mmcblk0p1 /mnt

There should be some messages similar to the following in dmesg if everything went right:

via Card Reader driver init():
mmc0: new SD card at address 80ca
mmcblk0: mmc0:80ca SD01G 992000KiB 
 mmcblk0: p1
mmc0: card 80ca removed

Hardware/BIOS/Driver status

It seems the SD card reader and/or BIOS is not able to boot from SD card, or at least it's unclear how to do it.

Both the hardware and the SD driver do support (at least some) SDHC cards, this has been tested on actual A110 hardware.

The card reader or the Linux driver is apparently not capable of reading 4GB non-SDHC cards, though. Whether or not this can be fixed by software is unclear at this point. The upcoming mainline kernel driver should be checked for updates, maybe it fixes this issue.

The error -110 issue

Sometimes correct operation of the driver ends while doing a data transfer (especially high volume such as copying large files or the sync command). In this case, dmesg might show something like:

mmc0: error -110 requesting status

A (at the moment not very well tested) workaround seems to be to increase the retry count in the mmc driver. In drivers/mmc/card/block.c search for

err = mmc_wait_for_cmd(card->host, &cmd, 5);

(should be two occurences) and replace 5 by something bigger (the last argument is the retry counter). 15 seems to work.

Additionally (but just a guess, as those lines to not generate an error at least on the author's machine) it might be wise to increase the MMC-wide retry counter in drivers/mmc/core/core.h as well

#define MMC_CMD_RETRIES        6

This has to be tested, but so far it avoids the error -110 during tests that resulted in -110 before.

Card compatibility list

See SD Cards for a list of supported/unsupported cards, as well as benchmarks.

Personal tools