2009/02/08

Fixing a Readonly SD Card Reader in Ubuntu

On one of my laptops running Ubuntu I noticed that my SD card was always mounted in readonly mode. My other Linux-powered laptop mounted the same SD card just fine in read/write mode. As a workaround, I could remove photo's directly from the camera or from the other laptop, but I was intriged and decided to delve deeper into this issue.

A few relevant commands stumbled upon thanks to Google:
$ dmesg | grep -i sdhci
[ 15.122623] sdhci: Secure Digital Host Controller Interface driver
[ 15.122627] sdhci: Copyright(c) Pierre Ossman
[ 15.194747] sdhci-pci 0000:0a:09.1: SDHCI controller found [1180:0822] (rev 19)
[ 15.194768] sdhci-pci 0000:0a:09.1: PCI INT B -> GSI 18 (level, low) -> IRQ 18
[ 15.197935] mmc0: SDHCI controller on PCI [0000:0a:09.1] using PIO

$ lsmod | grep -i sdhci
sdhci_pci 15360 0
sdhci 23940 1 sdhci_pci
mmc_core 58268 2 mmc_block,sdhci

$ lspci | grep -i ricoh
...
0a:09.0 FireWire (IEEE 1394): Ricoh Co Ltd R5C832 IEEE 1394 Controller
0a:09.1 SD Host controller: Ricoh Co Ltd R5C822 SD/SDIO/MMC/MS/MSPro Host Adapter (rev 19)
0a:09.2 System peripheral: Ricoh Co Ltd R5C843 MMC Host Controller (rev 0a)
0a:09.3 System peripheral: Ricoh Co Ltd R5C592 Memory Stick Bus Host Adapter (rev 05)
0a:09.4 System peripheral: Ricoh Co Ltd xD-Picture Card Controller (rev ff)

$ tail -f /var/log/syslog
...
Feb 8 13:48:51 michael-laptop2 kernel: [ 3910.801967] mmc0: card lacks mandatory switch function, performance might suffer.
Feb 8 13:48:51 michael-laptop2 kernel: [ 3910.802543] mmc0: new SD card at address b368
Feb 8 13:48:51 michael-laptop2 kernel: [ 3910.805647] mmcblk0: mmc0:b368 E0421 501248KiB (ro)
Feb 8 13:48:51 michael-laptop2 kernel: [ 3910.806012] mmcblk0: p1
Feb 8 13:48:51 michael-laptop2 hald: mounted /dev/mmcblk0p1 on behalf of uid 1000

$ cat /etc/mtab
/dev/mmcblk0p1 /media/disk vfat ro,nosuid,nodev,uhelper=hal,shortname=mixed,uid=1000,utf8,umask=077,flush 0 0
After a long search on google and in my logs, I couldn't find any clue. The SD read-only-switch was correctly turned off ; my tests on the other laptop confirmed this. Finally I rebooted my laptop under Vista and ... the SD was also mounted read-only. Conclusion: it was not an OS / driver problem and the problem was related to that PC. I then simply blew some air with a "dust remover" into the SD slot and the magic happened: the SD card mounted in read write mode... A trivial solution to a seemingly complex problem.