Introduction
There are some cases where it is needed to flash the image from a removable boot source (e.g. an SD card) to another boot source (e.g. eMMC), according to our documentation this can be done via dd but this does not work in the case you would like to do all the process in the board caused by the eMMC partition structure.
Required equipment.
The default partition configuration for an eMMC device is as follows:
Where:
- Boot areas are used for bootloader and environment configurations.
- Replay-protected memory-block area (RPMB) is used to store secure data.
- User area used for application data such as file system, usually divided in two or more partitions.
In the case of an image, the eMMC is organized according to the next diagram:
- Boot area 1 is used to store SPL and U-boot with no file system in a fixed offset according to each processor as mentioned in i.MX Linux User's Guide section 4.3 Preparing an SD/MMC card to boot.
- User area partition 1 uses a FAT format where Kernel and Device Tree files are stored.
- User area partition 2 is used for root file system with Ext3/Ext4 format.
Exception
Our documentation has a method to flash .wic image which contains all the mentioned above or each part manually using an SD card connected to a host Linux machine via dd command:
sudo dd if=<image name>.wic of=/dev/sdx bs=1M && sync
Or set up the partitions manually such as bootloader:
sudo dd if=<U-Boot image> of=/dev/sdx bs=1k seek=<offset> conv=fsync
Also, copying the kernel image and DTB file and the root file system as mentioned in i.MX Linux User's Guide.
This method works for SD card since the data is stored in user area and the offset changes to burn the bootloader. This fails when we try to flash the image from SD card to eMMC.
How to reproduce the issue?
First, we need to erase the eMMC, here a post to achieve this task.
Format boot partition of eMMC from U-boot - NXP Community
How to flash image from SD card to eMMC?
With the eMMC erased, we need a boot source to store and flash the image, in this case the SD card.
Once the image is flashed into the Micro SD, we need to copy the necessary files such as bootloader and image. By default, our BSP has a User Area space of <>GB and we need to increase it to save the bootloader and the image, here the steps:
Verify the device and partition numeration:
lsblk
The command to increase the size of the partition is the next:
parted /dev/<storage unit> unit MiB resizepart <partition> <size in bytes>
And the command to apply the changes is:
resize2fs /dev/<storage and partition unit>
In this case, the device and partition we need to change is mmcblk0p2 so, the command is as follows:
parted /dev/mmcblk0 unit MiB resizepart 2 10000
I increased the partition size by 10000 MB; this will be enough to store the required files.
And now, we need to apply the changes:
resize2fs /dev/mmcblk0p2
In the board will look like this:
Now, let's copy the bootloader and root file system in SD. In this post we will use SCP:
Now, we need to boot from SD card and run the next commands:
As is mentioned in Linux User's guide, we need to flash the .wic image. This contains all the necessary data to flash the entire image but when flashing from SD card to eMMC we need to follow additional steps to unlock the partition used to store the bootloader:
sudo dd if=<image name>.wic of=/dev/sdx bs=1M && sync
Disable write protection:
echo 0 > /sys/block/<storage and partition unit>/force_ro
And flash the bootloader:
dd if=<bootloader> of=/dev/<storage and partition unit> bs=1K seek=0
In the board will look like this:
With this process now it is needed to reboot the board, change boot mode switches to boot from eMMC, and the board will boot normally, the user can perform an image flashing to simplify development workflow and also an alternative to update OS without external host dependencies.