Using SD Card in Linux Print

 

This application note explains how to use SD Card in Linux on the Emcraft Systems i.MX 6ULL System-On-Module (SOM) plugged into the development baseboard (IMX6ULL-SOM-BSB). Support for the SD Card is enabled in the standard rootfs project available from the Emcraft software distribution and installed on each module shipped by Emcraft.

Insert a pre-formatted card with an MS-DOS file system to the SD Card slot on the development baseboard. When you boot the uImage on the i.MX 6ULL, there should be messages similar to the ones shown below. In the below example, Linux has detected an SD Card with a single partition on it:

...... [1.731948] mmc0: SDHCI controller on 2190000.usdhc [2190000.usdhc] using ADMA
...
[2.186654] mmc0: host does not support reading read-only switch, assuming write-enable
[2.198000] mmc0: new SD card at address 0001
...
[2.203605] mmcblk0: mmc0:0001 SD8GB 7.28 GiB
[2.209426] mmcblk0: p1
...
init started: BusyBox v1.17.0 (2018-10-12 19:52:29 MSK)
~ #

At this point you are ready to mount the MS-DOS file system on the SD Card. This is done as follows:

~ # mount /dev/mmcblk0p1 /mnt

Check that the file system has indeed been mounted (refer to the last line in the below output):

~ # mount
ubi0:rootfs on / type ubifs (rw,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=123812k,nr_inodes=30953,mode=755)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,relatime,size=32768k)
tmpfs on /run type tmpfs (rw,nosuid,nodev,relatime,mode=755)
tmpfs on /var/volatile type tmpfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,mode=600,ptmxmode=000)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
/dev/mmcblk0p1 on /mnt type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro)

Now you can write something to the SD Card. In the below example, we store the current date and time to a log file, although in real-life applications you will probably want to do something more meaningful:

~ # date > /mnt/log.file

Verify the written content by reading the log file back:

~ # cat /mnt/log.file Wed Oct 17 19:46:36 UTC 2018 ~ #

Write throughput to an 8GB Kingston SDHC card class 4 is measured to be the following:

~ # mount -o remount,sync /mnt ~ # dd if=/dev/zero of=/mnt/10m bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10.0MB) copied, 5.012077 seconds, 2.0MB/s ~ #

Read throughput using the same SDHC card as follows:

~ # echo 3 > /proc/sys/vm/drop_caches [ 253.103581] hush (126): drop_caches: 3 ~ # dd if=/mnt/10m of=/dev/null bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10.0MB) copied, 0.566297 seconds, 17.7MB/s ~ #

Ok, you have validated that we can write data to the SD Card. Now you remove the card from the embedded target. Unmount the file system and then extract the card from the SD Card slot:

~ # umount /mnt ~ # [ 518.809614] mmc0: card 0001 removed

At this point, you can take the card to your PC or notebook and process data stored in the MS-DOS filesystem. As a final step in this application note, validate hot insertion of SD Card on the target. Insert the card back into the SD Card slot on the baseboard with Linux up and running on the i.MX 6ULL. Messages similar to the ones shown below should appear on the Linux console:

[ 592.320241] mmc0: host does not support reading read-only switch, assuming write-enable [ 592.334771] mmc0: new high speed SDHC card at address 0001 [ 592.342162] mmcblk0: mmc0:0001 SD8GB 7.28 GiB [ 592.350238] mmcblk0: p1

Mount the MS-DOS file system and verify the content of the previously created log file:

~ # mount /dev/mmcblk0p1 /mnt ~ # ls -lt /mnt -rwxr-xr-x 1 root root 10485760 Oct 17 2018 10m -rwxr-xr-x 1 root root 29 Oct 17 2018 log.file ~ # cat /mnt/log.file Wed Oct 17 19:46:36 UTC 2018 ~ #