Working With Embedded Multimediacard (Emmc)
Working With Embedded Multimediacard (Emmc)
Working With Embedded Multimediacard (Emmc)
Embedded Artists AB
Jörgen Ankersgatan 12
SE-211 45 Malmö
Sweden
http://www.EmbeddedArtists.com
Disclaimer
Embedded Artists AB makes no representation or warranties with respect to the contents hereof and
specifically disclaim any implied warranties or merchantability or fitness for any particular purpose.
Information in this publication is subject to change without notice and does not represent a
commitment on the part of Embedded Artists AB.
Feedback
We appreciate any feedback you may have for improvements on this document. Send your comments
by using the contact form: www.embeddedartists.com/contact.
Trademarks
All brand and product names mentioned herein are trademarks, services marks, registered
trademarks, or registered service marks of their respective owners and should be treated as such.
Table of Contents
1 Document Revision History ................................. 4
2 Introduction ........................................................... 5
2.1 Additional information ................................................................... 5
2.2 Conventions in this document ...................................................... 5
2 Introduction
Most embedded devices need some kind of storage area for firmware and data files. Many different
solutions exist, but this document will focus on embedded MultiMediaCard normally referred to as
eMMC.
An eMMC consists of two parts; the flash memory (of type NAND) and the memory controller. Having
the memory controller integrated simplifies the usage of the storage device. Without this controller the
software driver on the host would have to handle the low-level flash memory management, such as
wear levelling and error correction.
2.1 Additional information
Additional documentation you might need is.
• “TN-52-07: e.MMC Partitioning”, from Micron
• “TN-FC-40: Configuring the Embedded e.MMC Device”, from Micron
• “TN-FC-06: Booting from Embedded MMC”, from Micron
• Introduction of eMMC by Yejin Moon at Samsung Electronics
3 Default configuration
3.1 Memory areas
When the eMMC component is delivered from the manufacturer it is normally divided into four areas as
shown in Figure 1 below.
Area Description
Boot Typically used to store firmware and data needed during booting of the device. Two boot
areas are normally available and these are of type SLC NAND (enhanced mode)
RPMB Replay-protected memory-block area. This area is typically used to store secure data such
as encryption keys. This area is of type SLC NAND (enhanced mode).
User This area is used to store user data such as a file system. This is the area that is normally
divided into several partitions. By default, it is of type MLC NAND, but can be changed to
SLC NAND (enhanced mode), see chapter 6
Area Description
Boot area 1 The bootloader images (such as SPL and u-boot) are stored in this area. The boot
area is not formatted and contains no file system. The images are instead stored at
fixed offsets. When SPL and u-boot are used SPL will be stored at an offset of 1024
bytes (1 Kbyte) and u-boot will be stored at an offset of 69 Kbytes.
The area also contains the u-boot environment which is stored at an offset of 2 Mbytes
minus 8 Kbytes (2MB – 8KB).
User area The user area is divided into two partitions. The first partition will be FAT32 formatted
Partition 1 and contain the Linux kernel and device tree files.
User area The second partition contains the root file system and is by default ext3 formatted.
Partition 2
# ls -la /dev/mmcblk*
brw-rw---- 1 root disk 179, 0 Dec 23 11:57 /dev/mmcblk2
brw-rw---- 1 root disk 179, 32 Dec 23 11:57 /dev/mmcblk2boot0
brw-rw---- 1 root disk 179, 64 Dec 23 11:57 /dev/mmcblk2boot1
brw-rw---- 1 root disk 179, 1 Dec 23 11:57 /dev/mmcblk2p1
brw-rw---- 1 root disk 179, 2 Dec 23 11:57 /dev/mmcblk2p2
brw-rw---- 1 root disk 179, 96 Dec 23 11:57 /dev/mmcblk2rpmb
In the above example there is one MMC device (mmcblk2) which has 5 partitions.
4.2 mmc-utils
The tool mmc-utils is by default installed in the root file system when using Embedded Artists Yocto
image. This tool can be used not only to retrieve information about the eMMC device, but also change
its configuration.
4.2.1 Check eMMC version
4.3 fdisk
The tool fdisk can be used to manage partitions in Linux. In the example below the available
partition are listed. In the example you can see that one disk (device) is available (mmcblk2) and a
total of 5 partitions (same as was listed in section 4.1 above). You can also see the file system type
being used (mmcblk2p1 is for example FAT32 formatted) and the size of the partition.
# fdisk -l
Disk /dev/mmcblk2: 7456 MB, 7818182656 bytes, 15269888 sectors
238592 cylinders, 4 heads, 16 sectors/track
Units: cylinders of 64 * 512 = 32768 bytes
4.4 df
The tool df (disk free) can be used to see available storage space. In this example the root file system
has 5.8 GByte available.
# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 6.5G 416.3M 5.8G 7% /
devtmpfs 173.9M 0 173.9M 0% /dev
tmpfs 494.2M 0 494.2M 0% /dev/shm
tmpfs 494.2M 16.4M 477.9M 3% /run
tmpfs 494.2M 0 494.2M 0% /sys/fs/cgroup
tmpfs 494.2M 756.0K 493.5M 0% /tmp
tmpfs 494.2M 24.0K 494.2M 0% /var/volatile
tmpfs 98.8M 88.0K 98.8M 0% /run/user/0
4.5 mount
With the tool mount you can see which partitions that have been mounted in the file system. In the
example below we see that partition 2 of the mmcblk2 device (eMMC) is mounted and has an ext3
filesystem.
The tool sfdisk is used to do the partitioning and it is given a string with two lines. Each line will
create a partition. In this example each line contains three arguments: <start>, <size>, and <id>.
10M,500M,0c means start at offset 10 MB with a size of 500 MB. The id is 0x0c which means
FAT32. This first partition will in the default setup contain Kernel and device tree files.
600M,..,83 means start at offset 600 MB and the size will be the remaining size of the user area.
The id is 0x83 which means Linux native partition. This second partition will in the default setup contain
the root file system.
Partition type IDs:
https://en.wikipedia.org/wiki/Partition_type
5.2 Switch boot partition
The default setup from Embedded Artists is to have boot partition 1 enabled for boot. See section 4.2.4
for how to get information about current boot configuration.
Changing boot configuration can be done from Linux by using mmc-utils and more specifically mmc
bootpart enable <boot_partition> <send_ack> <device>. In the example below
boot partition 1 is enabled with boot acknowledgement for device /dev/mmcblk2.
Please note that you must also make sure to program the boot partition with bootable image(s). There
are different ways to do this, but you could for example use the UUU scripts provided by Embedded
Artists for the board you are using.
The excerpt below is from the bootloader.uuu script for the iMX7 Dual uCOM board. You can in this
example see that boot partition 1 is used (the device name ends with boot0). You can also see that
mmc utils is used to enable boot partition 1 for boot.
If you instead want to use boot partition 2 you can replace boot0 with boot1 and make sure mmc-
utils enable partition 2 (mmc bootpart enable 2 1 /dev/mmcblk${mmc}).
Note: All boot0 must be changed to boot1 and not just the highlighted parts.
6.2.3 Instructions
NOTE: The instructions are irreversible. Once you have converted a partition to enhanced
mode you can never undo this operation. Double check your parameters before executing a
command!
These instructions will convert the entire user area to enhanced mode. If you want to convert only a
portion of the area you need to modify the start and the length arguments.
1. Find the eMMC device
By default, the eMMC device is mounted as root device. If you run the mount command you can in
this example see that MMC block device 2 (mmcblk2p2) and more specifically partition 2 (mmcblk2p2)
is mounted as root device.
NOTE: When converting the user area to enhanced mode you will only get half the size of
the original area.
NOTE: The instructions are irreversible. Once you have converted a partition to enhanced
mode you can never undo this operation. Double check your parameters before executing a
command!
These instructions will convert the entire user area to enhanced mode. If you want to convert only a
portion of the area you need to modify the start and the cnt arguments.
1. Find the eMMC device
In this example you can see that eMMC is available on mmc device 1.
NOTE: When converting the user area to enhanced mode you will only get half the size of
the original area
The best way to find this value is from within Linux as described in section 6.2.3 above.
Using mmc info doesn’t give an accurate value. As seen below the value for User Capacity is
rounded to one decimal (3.6GiB). An accurate value would have been 3.640625 GiB (3728 MiB or
3817472 KiB) which could then be use to get the maximum value of the enhanced area, that is, half
the value of the original area. Note that when using the mmc hwpartition command you need to
give all values in 512-byte blocks.
Partition configuration:
User Enhanced Start: 0 Bytes
User Enhanced Size: 1.8 GiB
No GP1 partition
No GP2 partition
No GP3 partition
No GP4 partition