How to use SD/MMC Card for Diagnostic

From ESS-WIKI
Jump to: navigation, search

SD/MMC cards which use the MMC subsystem are available as block device through /dev/mmcblk{id}. The kernel normally parses the partition table and exports the partitions of the card using the appendix p{x}, e.g. /dev/mmcblk{id}p{x}.

SD/MMC driver initialisation

The following bootlog shows the detection of a SDHCI controller:

root@:~# dmesg | egrep "(sdhci|mmc)"
[    1.880782] sdhci: Secure Digital Host Controller Interface driver
[    1.890679] sdhci: Copyright(c) Pierre Ossman
[    1.898540] sdhci-pltfm: SDHCI platform and OF driver helper
[    1.909980] sdhci-esdhc-imx 2190000.usdhc: Got CD GPIO
[    1.984346] mmc0: SDHCI controller on 2190000.usdhc [2190000.usdhc] using ADMA

Before inserting any card no interrupts are generated yet:

root@:~# cat /proc/interrupts | egrep "(mmc|cd)"
 58:          0       GPC  22 Level     mmc0
200:          0  gpio-mxc   0 Edge      2190000.usdhc cd

And the IOs debugging information is not valid yet:

root@:~# cat /sys/kernel/debug/mmc0/ios
clock:          0 Hz
vdd:            0 (invalid)
bus mode:       2 (push-pull)
chip select:    0 (don't care)
power mode:     0 (off)
bus width:      0 (1 bits)
timing spec:    0 (legacy)
signal voltage: 0 (3.30 V)
driver type:    0 (driver type B)

With the MMC_CD card detection GPIO pin still being pulled-up:

root@:~# cat /sys/kernel/debug/gpio | grep cd
 gpio-128 (                    |cd                  ) in  hi IRQ

SD/MMC Card Insertion

On insertion, the kernel starts scanning the card in order to create devices for each partition. Depending on the Automount configuration the detected file systems get mounted automatically.

[  286.140413] mmc0: new high speed SDHC card at address 0007
[  286.150926] mmcblk0: mmc0:0007 SDCIT 7.29 GiB
[  286.170497]  mmcblk0: p1 p2
[  287.691840] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Opts: (null)

Interrupts are happening (note one card detect GPIO interrupt thereof):

root@:~# cat /proc/interrupts | egrep "(mmc|cd)"
 58:        375       GPC  22 Level     mmc0
200:          1  gpio-mxc   0 Edge      2190000.usdhc cd

And the IOs debugging information should now show valid information about the inserted card:

root@:~# cat /sys/kernel/debug/mmc0/ios
clock:          50000000 Hz
actual clock:   49500000 Hz
vdd:            21 (3.3 ~ 3.4 V)
bus mode:       2 (push-pull)
chip select:    0 (don't care)
power mode:     2 (on)
bus width:      2 (4 bits)
timing spec:    2 (sd high-speed)
signal voltage: 0 (3.30 V)
driver type:    0 (driver type B)

With the MMC_CD card detection GPIO pin now being pulled to ground:

root@:~# cat /sys/kernel/debug/gpio | grep cd
 gpio-128 (                    |cd                  ) in  lo IRQ

More specifics about the inserted card can be found in its CID/CSD:

root@:~# cat /sys/bus/mmc/devices/mmc0\:0007/cid
413432534443495430002e35cf012800
root@:~# cat /sys/bus/mmc/devices/mmc0\:0007/csd
400e00325b5900003a4f7f800a400000

The utility df shows the usage of the SD/MMC card:

root@:~# df | grep mmc
/dev/mmcblk0p2         1467980    903468    470664  66% /media/mmcblk0p2
/dev/mmcblk0p1           85010     22894     62116  27% /media/mmcblk0p1

And mount shows the mounting status:

root@:~# mount | grep mmc
/dev/mmcblk0p2 on /media/mmcblk0p2 type ext4 (rw,relatime,data=ordered)
/dev/mmcblk0p1 on /media/mmcblk0p1 type vfat (rw,relatime,gid=6,fmask=0007,dmask=0007,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)

From regular SD cards one should be able to read with sustained data rates of around 10 to 20 MB/sec:

root@:~# hdparm -t /dev/mmcblk0

/dev/mmcblk0:
 Timing buffered disk reads:  66 MB in  3.04 seconds =  21.70 MB/sec

SD/MMC Card Removal

Kernel message:

[  441.027332] mmc0: card 0007 removed

Triggered by another card detection interrupt:

root@:~# cat /proc/interrupts | egrep "(mmc|cd)"
 58:        641       GPC  22 Level     mmc0
200:          2  gpio-mxc   0 Edge      2190000.usdhc cd