eMMC

This guide will show how to mount, read from, and write to the phyCORE-i.MX7 onboard eMMC.

Note

In order to follow this guide your phyCORE-i.MX7 development kit must be booting from SD Card.

Viewing available eMMC partition information

  • You can verify the eMMC partitions by using the following command to list the partition information of known MMC devices:

    Target (Linux)
     fdisk -l
    
  • The fdisk command line utility will output disk partition information. Search through the list and verify the eMMC is listed. You should find an entry similar to the following:

    Expected Output
    Disk /dev/mmcblk0: 7744 MB, 8120172544 bytes, 15859712 sectors
    123904 cylinders, 4 heads, 32 sectors/track
    Units: sectors of 1 * 512 = 512 bytes
    
    Device       Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
    /dev/mmcblk0p1 *  64,0,1      479,3,32          8192      61439      53248 26.0M  c Win95 FAT32 (LBA)
    /dev/mmcblk0p2    512,0,1     1023,3,32        65536    1099747    1034212  504M 83 Linux
    Disk /dev/mmcblk2: 3672 MB, 3850371072 bytes, 7520256 sectors
    58752 cylinders, 4 heads, 32 sectors/track
    Units: sectors of 1 * 512 = 512 bytes
    
    Device       Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
    /dev/mmcblk2p1    64,0,1      191,3,32          8192      24575      16384 8192K  c Win95 FAT32 (LBA)
    /dev/mmcblk2p2    192,0,1     1023,3,32        24576    2113535    2088960 1020M 83 Linux
    
  • As can be seen in the above Example Output, this eMMC has already been formatted with a data partition, /dev/mmcblk2. To follow the rest of this guide, one data partition will be required.

Creating eMMC Partition

  • If you did not see a /dev/mmcblk2p* partition refer to the following commands in order to create one:

Warning

Be careful using the “fdisk” command. If you aren’t careful, it can easily delete a partition of a flash device you didn’t intend to, and this could be your root filesystem! Just be sure to specify /dev/mmcblk2, not the SD card you are booting from.

Target (Linux)
    fdisk /dev/mmcblk2

    # Enter into fdisk interactive session:
    # Use the following commands in order to create a Linux partition.

    n                         # create new partition
    p                         # partition type
    1                         # partition number
    8192                      # first sector
    2088960                   # last sector
    t                         # change partition type
    83                        # linux filesystem
    w                         # write changes
  • Now reboot the system and you should see the eMMC device mounted automatically in the following steps.

    Target (Linux)
    reboot
    

Setup a Root Filesystem on the eMMC

In order to interact with the eMMC, the eMMC has to be partitioned and a rootfilesystem needs to be setup.

  • Create a ext4 type root filesystem

    Target (Linux)
    mkfs.ext4 /dev/mmcblk2p1
    
    Expected Output
    root@phyboard-zeta-imx7d-1:~# mkfs.ext4 /dev/mmcblk2p1
    mke2fs 1.46.5 (30-Dec-2021)
    /dev/mmcblk2p1 contains a vfat file system labelled 'Boot imx7d-'
    Proceed anyway? (y,N) [   64.536335] cfg80211: failed to load regulatory.db
    y
    Discarding device blocks: done
    Creating filesystem with 260096 4k blocks and 65024 inodes
    Filesystem UUID: 5d28be30-4b59-4491-acbd-ec07c4cd327d
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376
    
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (4096 blocks): done
    Writing superblocks and filesystem accounting information: done
    

Mounting the eMMC

  • Mount the eMMC to a volatile tmp folder

    Target (Linux)
     mkdir /tmp/emmc
     mount /dev/mmcblk2p1 /tmp/emmc
    

Writing to eMMC

  • Create a test file.

    Target (Linux)
     echo "Hello World" > ~/test.txt
    
  • Now you can use copy (cp) command to put this file on the eMMC.

    Target (Linux)
    cp test.txt /tmp/emmc
    
  • Verify that the file was written to the eMMC.

    Target (Linux)
     ls /tmp/emmc
    
    Expected Output
    root@phyboard-zeta-imx7d-1:~# ls /tmp/emmc
    lost+found/  test.txt
    
  • Make sure the file was not corrupted during the transfer using md5sum.

    Target (Linux)
    md5sum test.txt /tmp/emmc/test.txt
    
    Expected Output
    root@phyboard-zeta-imx7d-1:~# md5sum test.txt /tmp/emmc/test.txt
    e59ff97941044f85df5297e1c302d260  test.txt
    e59ff97941044f85df5297e1c302d260  /tmp/emmc/test.txt
    

Reading from the eMMC

  • Use the copy (cp) or move (mv) command to put this file back onto your SD card.

    Target (Linux)
    cp /tmp/emmc/test.txt ~/test-READ.txt
    
  • Make sure the file was not corrupted during the transfer using md5sum.

    Target (Linux)
    md5sum /tmp/emmc/test.txt test-READ.txt
    
    Expected Output
    root@phyboard-zeta-imx7d-1:~# md5sum /tmp/emmc/test.txt test-READ.txt
    e59ff97941044f85df5297e1c302d260  /tmp/emmc/test.txt
    e59ff97941044f85df5297e1c302d260  test-READ.txt