We could know the MTD structure of AM335x via

cat /proc/mtd and we will get

dev:   size      erasesize name
mtd0:  00020000  00020000  "SPL" 
mtd1:  00020000  00020000  "SPL.backup1"
mtd2:  00020000  00020000  "SPL.backup2"
mtd3:  00020000  00020000  "SPL.backup3"
mtd4:  001e0000  00020000  "U-Boot"
mtd5:  00020000  00020000  "U-Boot Env"
mtd6:  00500000  00020000  "Kernel"
mtd7:  0f880000  00020000  "File System"

We could use the MTD utility to erase nand flash

flash_eraseall /dev/mtd0
flash_eraseall /dev/mtd1
flash_eraseall /dev/mtd2
flash_eraseall /dev/mtd3
flash_eraseall /dev/mtd4
flash_eraseall /dev/mtd5
flash_eraseall /dev/mtd6
flash_eraseall /dev/mtd7 

Then we need to prepare MLP (SPL) , U-Boot, Kernel , Root FS image and write to flash

nandwrite -p /dev/mtd0 /home/kclin/download/MLO
nandwrite -p /dev/mtd1 /home/kclin/download/MLO
nandwrite -p /dev/mtd2 /home/kclin/download/MLO
nandwrite -p /dev/mtd3 /home/kclin/download/MLO
nandwrite -p /dev/mtd4 /home/kclin/download/u-boot.img
nandwrite -p /dev/mtd6 /home/kclin/download/uImage

For root file system, since we use UBIFS, so we have to use ubiformat, and first we have to use mtdinfo /dev/mtd7 to get the information of subpage

root@am335x-evm:~# cat /proc/mtd
dev: size erasesize name
mtd0: 00020000 00020000 "SPL"
mtd1: 00020000 00020000 "SPL.backup1"
mtd2: 00020000 00020000 "SPL.backup2"
mtd3: 00020000 00020000 "SPL.backup3"
mtd4: 001e0000 00020000 "U-Boot"
mtd5: 00020000 00020000 "U-Boot Env"
mtd6: 00500000 00020000 "Kernel"
mtd7: 0f880000 00020000 "File System"
root@am335x-evm:~# mtdinfo /dev/mtd7
mtd7
Name: File System
Type: nand
Eraseblock size: 131072 bytes, 128.0 KiB
Amount of eraseblocks: 1988 (260571136 bytes, 248.5 MiB)
Minimum input/output unit size: 2048 bytes
Sub-page size: 512 bytes
OOB size: 64 bytes
Character device major/minor: 90:14
Bad blocks are allowed: true
Device is writable: true

The we could do the last step 🙂

ubiformat /dev/mtd7 -f /home/kclin/download/ubi.img -s 512 -O 2048

Leave a Reply