Introduction.
In some cases, such as development stages, testing, validate flash process from zero, etc. It is needed to erase the eMMC storage device, here is described the process and the required equipment:
Required equipment.
i.MX93 FRDM board (this is the selected board for this post, it works for others).
Debug USB-C cable.
Data USB-C cable.
Micro SD (16GB recommended).
Personal computer.
How to erase the eMMC?
This method will use another boot source (Micro SD) to erase the eMMC so, it is needed to flash the Micro SD with at least the bootloader (U-boot), you can use a prebuilt image for the EVK board, it can be downloaded from the following link.
But, in the case of i.MX93 FRDM board, there is no pre-built image available and needs to be build:
The FRDM-IMX93 BSP release is based on i.MX SW 2024 Q3 release with Yocto Project 5.0 (Scarthgap). To build FRDM-IMX93 image from source code, please first check i.MX Yocto Project User's Guide to get familiar with Yocto project and Yocto build. Then please follow below steps to build image for FRDM-IMX93.
1. Download i.MX SW 2024 Q3 BSP Release:
$ repo init -u https://github.com/nxp-imx/imx-manifest -b imx-linux-scarthgap -m imx-6.6.36-2.1.0.xml
$ repo sync
2. Integrate FRDM-MX93 layer into Yocto code base:
$ cd ${MY_YOCTO}/sources
$ git clone https://github.com/nxp-imx-support/meta-imx-frdm.git
3. Yocto Project Setup:
$ MACHINE=imx93frdm DISTRO=fsl-imx-xwayland source sources/meta-imx-frdm/tools/imx-frdm-setup.sh -b frdm-imx93
4. Build images:
$ bitbake imx-image-full
The flashing process can be consulted here.
Once the board is flashed, we need to change the boot switches to boot from Micro SD and turn-on the board.
To debug this process, we will use Tera Term terminal with the board connected from the Micro USB debug cable to the PC and select the next configuration:
Please verify that you are selecting the corresponding COM for Cortex-A debug.
After boot we need to press a key, and the board will enter to U-boot. So, then we need to select the partition of the eMMC with the next command:
u-boot=> mmc dev <storage device> <partition>
In the case of the eMMC, the storage device corresponds to the device "0" and if the device has an image flashed into the eMMC e.g. Linux, the device will have three partitions from 0 to 2. The next command will select the eMMC and the boot partition area:
u-boot=> mmc dev 0 0
switch to partitions #0, OK
mmc0(part 0) is current device
Depending on the device, image, etc. This partition size can vary so, we need to know how many blocks it has. We can use the next command that will let us know the max address value that is assigned to this partition by getting an error on the address that is out of the range.
u-boot=> mmc read ${loadaddr} 0x7fffffff 1
MMC read: dev # 0, block # 2147483647, count 1 ... MMC: block number 0x80000000 exceeds max(0x1d5a000)
0 blocks read: ERROR
Now, with this information, we are able to erase the entire partition with the next command:
u-boot=> mmc erase 0 0x1d5a000
MMC erase: dev # 0, block # 0, count 30777344 ... 30777344 blocks erased: OK
As mentioned before, the device has multiple partitions so, this process needs to be done in each partition
Boot area Partition.
User Area 1 Partition.
User Area 2 Partition.
But the process is the same, let's change the partition to User Area 1:
u-boot=> mmc dev 0 1
switch to partitions #1, OK
mmc0(part 1) is current device
Confirm the size of the partition:
u-boot=> mmc read ${loadaddr} 0x7fffffff 1
MMC read: dev # 0, block # 2147483647, count 1 ... MMC: block number 0x80000000 exceeds max(0x2000)
0 blocks read: ERROR
And erase it:
u-boot=> mmc erase 0 0x2000
MMC erase: dev # 0, block # 0, count 8192 ... 8192 blocks erased: OK
And let's finish with User Area 2 Partition:
u-boot=> mmc dev 0 2
switch to partitions #2, OK
mmc0(part 2) is current device
u-boot=> mmc read ${loadaddr} 0x7fffffff 1
MMC read: dev # 0, block # 2147483647, count 1 ... MMC: block number 0x80000000 exceeds max(0x2000)
0 blocks read: ERROR
u-boot=> mmc erase 0 0x2000
MMC erase: dev # 0, block # 0, count 8192 ... 8192 blocks erased: OK
With this done, the eMMC is completely erased and you can confirm it by turning off the board, change the boot switched to eMMC, remove the SD card and turn-on the board.
Since there is not a bootable image into the boot source, the board will jump to serial download mode and you can verify connecting the USB data cable to the board and run the next command in UUU:
Conclusion.
Erasing the eMMC of the board is optional step in your development stage but also helpful for testing or system recovery (e.g. test manufacture mode). By using a Micro SD you can access to the eMMC and do all the modifications in the partitions that you want without issues. With this you can go to a clean storage state into the boot device and test a new image from scratch or test recovery methods in your design.
View full article