eMMC
An embedded Multi-Media Card (eMMC) flash device is populated on the phyCORE-AM64x as a programmable nonvolatile storage. The eMMC flash is connected to the MMC0 8-bit interface of the phyCORE-AM64x, which supports the JEDEC eMMC electrical standard v5.1. This guide covers viewing partition information, managing background operations (BKOPS), resizing filesystems, enabling pseudo-SLC mode, erasing the device, and working with eMMC boot partitions. To learn more information about the phyCORE-AM64x eMMC flash memory, please see the eMMC section in Hardware Manual.
Extended CSD Register
eMMC devices have an extensive amount of extra information and settings that are available via the Extended CSD registers. For a detailed list of the registers, see manufacturer datasheets and the JEDEC standard.
In the Linux user space, you can query the registers:
sh-phyboard-electra-am64xx-2:~# mmc extcsd read /dev/mmcblk0
You will see:
=============================================
Extended CSD rev 1.7 (MMC 5.0)
=============================================
Card Supported Command sets [S_CMD_SET: 0x01]
[...]
Enabling Background Operations (BKOPS)
In contrast to raw NAND Flash, an eMMC device contains a Flash Transfer Layer (FTL) that handles the wear leveling, block management, and ECC of the raw MLC or TLC. This requires some maintenance tasks (for example erasing unused blocks) that are performed regularly. These tasks are called Background Operations (BKOPS).
By default (depending on the chip), the background operations may or may not be executed periodically, impacting the worst-case read and write latency.
The JEDEC Standard has specified a method since version v4.41 that the host can issue BKOPS manually. See the JEDEC Standard chapter Background Operations and the description of registers BKOPS_EN (Reg: 163) and BKOPS_START (Reg: 164) in the eMMC datasheet for more details.
Meaning of Register BKOPS_EN (Reg: 163) Bit MANUAL_EN (Bit 0):
Value 0: The host does not support the manual trigger of BKOPS. Device write performance suffers.
Value 1: The host does support the manual trigger of BKOPS. It will issue BKOPS from time to time when it does not need the device.
The mechanism to issue background operations has been implemented in the Linux kernel since v3.7. You only have to enable BKOPS_EN on the eMMC device.
The JEDEC standard v5.1 introduces a new automatic BKOPS feature. It frees the host to trigger the background operations regularly because the device starts BKOPS itself when it is idle (see the description of bit AUTO_EN in register BKOPS_EN (Reg: 163)).
To check whether BKOPS_EN is set, execute:
sh-phyboard-electra-am64xx-2:~# mmc extcsd read /dev/mmcblk0 | grep BKOPS_EN
The output will be, for example:
Enable background operations handshake [BKOPS_EN]: 0x01
#OR
Enable background operations handshake [BKOPS_EN]: 0x00
Where value 0x00 means BKOPS_EN is disabled and device write performance suffers. Where value 0x01 means BKOPS_EN is enabled and the host will issue background operations from time to time.
To enable BKOPS, use:
sh-phyboard-electra-am64xx-2:~# mmc bkops_en manual /dev/mmcblk0
To ensure that the new setting is taken over and the kernel triggers BKOPS by itself, shut down the system:
sh-phyboard-electra-am64xx-2:~# poweroff
Note
The BKOPS_EN bit is one-time programmable only. It cannot be reversed.
Resizing ext4 Root Filesystem
In case you flashed a wic image to the eMMC the root partition is not extended to the end of the eMMC. parted can be used to expand the root partition. The example works for any block device such as eMMC, SD card, or hard disk.
Get the current device size:
sh-phyboard-electra-am64xx-2:~# parted /dev/mmcblk0 print
Use parted to resize the root partition to the max size of the device:
sh-phyboard-electra-am64xx-2:~# parted /dev/mmcblk0 resizepart 2 100%
Resize the filesystem to a new partition size:
sh-phyboard-electra-am64xx-2:~# resize2fs /dev/mmcblk0p2
Increasing the filesystem size can be done while it is mounted. But you can also boot the board from an SD card and then resize the file system on the eMMC partition while it is not mounted.
Enable pseudo-SLC Mode
eMMC devices use MLC or TLC (https://en.wikipedia.org/wiki/Multi-level_cell) to store the data. Compared with SLC used in NAND Flash, MLC or TLC have lower reliability and a higher error rate at lower costs.
If you prefer reliability over storage capacity, you can enable the pseudo-SLC mode or SLC mode. The method used here employs the enhanced attribute, described in the JEDEC standard, which can be set for continuous regions of the device. The JEDEC standard does not specify the implementation details and the guarantees of the enhanced attribute. This is left to the chipmaker. For the Micron chips, the enhanced attribute increases the reliability but also halves the capacity.
Warning
When enabling the enhanced attribute on the device, all data will be lost.
The following sequence shows how to enable the enhanced attribute.
First obtain the current size of the eMMC device with:
sh-phyboard-electra-am64xx-2:~# parted -m /dev/mmcblk0 unit B print
To get the maximum size of the device after pseudo-SLC is enabled use:
sh-phyboard-electra-am64xx-2:~# mmc extcsd read /dev/mmcblk0 | grep ENH_SIZE_MULT -A 1
Now, you can set enhanced attribute for the whole device using the size shown in the previous command:
sh-phyboard-electra-am64xx-2:~# mmc enh_area set -y 0 <size_in_KiB> /dev/mmcblk0
To ensure that the new setting has taken over, shut down the system and perform a power cycle:
sh-phyboard-electra-am64xx-2:~# poweroff
Erasing the Device
It is possible to erase the eMMC device directly rather than overwriting it with zeros. The eMMC block management algorithm will erase the underlying MLC or TLC or mark these blocks as discard. The data on the device is lost and will be read back as zeros.
After booting from SD Card execute:
sh-phyboard-electra-am64xx-2:~# blkdiscard -f --secure /dev/mmcblk0
The option –secure ensures that the command waits until the eMMC device has erased all blocks. The -f (force) option disables all checking before erasing and it is needed when the eMMC device contains existing partitions with data.
Note
dd if=/dev/zero of=/dev/mmcblk|intf-emmc-dev-number| conv=fsync
also destroys all information on the device, but this command is bad for wear leveling and takes much longer!
eMMC Boot Partitions
An eMMC device contains four different hardware partitions: user, boot0, boot1, and rpmb.
The user partition is called the User Data Area in the JEDEC standard and is the main storage partition. The partitions boot0 and boot1 can be used to host the bootloader and are more reliable. PHYTEC SoMs are delivered with the bootloader pre-flashed in the boot0 partition. Which partition the AM64x uses to load the bootloader is controlled by the boot configuration of the eMMC device. The partition rpmb is a small partition and can only be accessed via a trusted mechanism.
Furthermore, the user partition can be divided into four user-defined General Purpose Area Partitions. An explanation of this feature exceeds the scope of this document. For further information, see the JEDEC Standard Chapter Partition Management.
Note
Do not confuse eMMC partitions with partitions of a DOS, MBR, or GPT partition table.
Flashing the eMMC
Detailed instructions on how to flash the eMMC can be found in Flashing the eMMC.