SD controller (CM-i.MX27): Unterschied zwischen den Versionen

Aus BECOM Systems Support
Zur Navigation springen Zur Suche springen
en>Peter
K (1 Version importiert)
 
K (1 Version importiert)
 
(kein Unterschied)

Aktuelle Version vom 31. Oktober 2023, 09:03 Uhr

The i.MX27 contains an SD host controller that supports MMC, SD and SD I/O standards. SDHC1 of the processor is connected to the SD cards lot on the DEV board.

Linux kernel configuration

Device Drivers  --->
  <*> MMC/SD card support  --->
    <*>   MMC block device driver
    [*]     Use bounce buffer for simple hosts
    <*>   Freescale MXC Multimedia Card Interface support

Test in Linux

  • Insert an SD card into the slot on the DEV board. You will see similar messages on the terminal:
root@btmxc27:~# mmc0: host does not support reading read-only switch. assuming write-enable.
mmc0: new SD card at address fcd9
mmcblk0: mmc0:fcd9 SD02G 1985024KiB 
 mmcblk0:
FAT: bogus number of reserved sectors
VFS: Can't find a valid FAT filesystem on dev mmcblk0.
  • We will now start fdisk and create 1 partition on the card that uses up the full available space:
root@btmxc27:~# fdisk /dev/mmcblk0 

The number of cylinders for this disk is set to 62032.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/mmcblk0: 2032 MB, 2032664576 bytes
4 heads, 16 sectors/track, 62032 cylinders
Units = cylinders of 64 * 512 = 32768 bytes

        Device Boot      Start         End      Blocks  Id System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-62032, default 1): Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-62032, default 62032): Using default value 62032

Command (m for help): p

Disk /dev/mmcblk0: 2032 MB, 2032664576 bytes
4 heads, 16 sectors/track, 62032 cylinders
Units = cylinders of 64 * 512 = 32768 bytes

        Device Boot      Start         End      Blocks  Id System
/dev/mmcblk0p1               1       62032     1985016  83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table
 mmcblk0: p1
root@btmxc27:~# FAT: bogus number of reserved sectors
VFS: Can't find a valid FAT filesystem on dev mmcblk0p1.
  • Now we will create an ext3 file system in this partition:
root@btmxc27:~# mkfs.ext3 /dev/mmcblk0p1 
mke2fs 1.41.4 (27-Jan-2009)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
124160 inodes, 496254 blocks
24812 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=511705088
16 block groups
32768 blocks per group, 32768 fragments per group
7760 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
  • Mount the SD card (first partition) to /media/card. Numbering of mmc block devices and partitions is mmcblk[card_nr]p[partition_nr], where the first possible card_nr is 0 and the first possible partition_nr is 1.
root@btmxc27:~# mount /dev/mmcblk0p1 /media/card/
kjournald starting.  Commit interval 5 seconds
EXT3 FS on mmcblk0p1, internal journal
EXT3-fs: mounted filesystem with ordered data mode.
  • For measuring the performance, we will transfer a file from RAM to the SD card. Therefore, we also create an ext3 file system on the ram disk:
root@btmxc27:~# mkfs.ext3 /dev/ram0 
mke2fs 1.41.4 (27-Jan-2009)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
16384 inodes, 65536 blocks
3276 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67108864
8 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
  • ...and mount it to /media/ram:
root@btmxc27:~# mount /dev/ram0 /media/ram/
kjournald starting.  Commit interval 5 seconds
EXT3 FS on ram0, internal journal
EXT3-fs: mounted filesystem with ordered data mode.
  • Now we change to this directory and download a random file of 32 MiB size:
root@btmxc27:~# cd /media/ram/
root@btmxc27:/media/ram# tftp -r 32MBrandomfile -g 192.168.5.1
root@btmxc27:/media/ram# ls
32MBrandomfile  lost+found
  • Let's transfer this file to the SD card and measure the time. The complete time can be calculated by adding both "real" times.
root@btmxc27:/media/ram# cd /media/card/
root@btmxc27:/media/card# ls
lost+found
root@btmxc27:/media/card# cd /
root@btmxc27:/# time cp /media/ram/32MBrandomfile /media/card/ ; time umount /me
dia/card/
real	0m 10.72s
user	0m 0.10s
sys	0m 5.41s
real	0m 5.97s
user	0m 0.00s
sys	0m 0.40s
  • To measure read performance, we mount the SD card again and read the 32 MiB file to /dev/null (i.e., nowhere).
root@btmxc27:/# mount /dev/mmcblk0p1 /media/card/
kjournald starting.  Commit interval 5 seconds
EXT3 FS on mmcblk0p1, internal journal
EXT3-fs: mounted filesystem with ordered data mode.
root@btmxc27:/# time cat /media/card/32MBrandomfile > /dev/null ; time umount /m
edia/card/
real	0m 9.51s
user	0m 0.02s
sys	0m 1.40s
real	0m 0.08s
user	0m 0.01s
sys	0m 0.04s
root@btmxc27:/#
  • To check if the data was written correctly, you may check the md5sums of both files:
root@btmxc27:/# md5sum /media/ram/32MBrandomfile 
f507996f89cd0d6ff3f5e0edcf5aa0a1  /media/ram/32MBrandomfile
root@btmxc27:/# md5sum /media/card/32MBrandomfile 
f507996f89cd0d6ff3f5e0edcf5aa0a1  /media/card/32MBrandomfile


Performance

Measured in Linux, using a SanDisk Extreme III 2.0GB card:

  • Write: 1.92 MiB/s
  • Read: 3.34 MiB/s

Remarks

  • If you remove the card very slowly, the removal may not be detected correctly.

At removal, the CD (card detect) IRQ is triggered. But at this time, the SD card is yet readable and the MMC driver does not detect the removal. We have increased the wait time from IRQ to checking for removal to 1 second. If you are extremely slow at removing the card, the removal may not be detected correctly, though.

  • Don't enable CONFIG_DEBUG_SHIRQ in your kernel configuration. The SD Card will refuse to work!