SEARCH
TOOLBOX
LANGUAGES
modified on 26 September 2012 at 17:39 ••• 74,113 views

Flashing filesystems larger than RAM

From Manuals

Jump to: navigation, search

The Electrum User's Manual suggests using the U-Boot bootloader to flash the kernel and root filesystem to NAND. This requires two steps. First the file is copied from the original source (USB, TFTP, microSD) to RAM using the corresponding command (fatload, tftp, etc.). Then it is copied from RAM to NAND using the "nand write" and "nand write.jffs2" commands. This procedure is simple but limits the size of the initial filesystem contents to the available RAM. Files can be added to the root filesystem after Linux boots, but this is more cumbersome when multiple boards need to be flashed.


For larger filesystems a better alternative is to flash from Linux instead of the bootloader. This requires booting the board using a medium other than NAND, such as microSD, USB or NFS. This application note explains the procedure when booting Linux from a microSD card. It can be easily adapted to USB or NFS boots.

Setup mtd-utils

Prepare a microSD card for flashing NAND using mtd-utils. This is a one time setup.

1. Setup a bootable microSD card using the procedure in the Wiki. Erase the current NAND contents by executing "nand erase" from the bootloader.

2. If the board is configured to boot from NAND, change the bootloader configuration to boot from microSD. Press space bar when the bootloader loads to get an ">Electrum" command prompt.

setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p1 rw ip=192.168.1.101:192.168.1.253::255.255.255.0::eth0:none
setenv bootcmd mmcinfo\; ext2load mmc 0:1 0x22000000 uImage-2.6.33.20-1-at91\; bootm
saveenv
reset

NOTE: Substitute 192.168.1.101, 192.168.1.253 and 255.255.255.0 for the corresponding board IP address, gateway address and netmask.

3. Boot from the microSD card. Login as root and verify that the root filesystem uses device mmcblk0p1.

# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mmcblk0p1         1889792    193096   1600700  11% /
tmpfs                    30652         0     30652   0% /lib/init/rw
tmpfs                    30652         0     30652   0% /dev/shm

If not edit /etc/fstab and reboot.

/dev/mmcblk0p1  /               ext2   defaults        0       0

4. Setup your network gateway & install mtd-utils from repository.

# route add default gw 192.168.1.253 eth0

NOTE: Substitute 192.168.1.253 for the corresponding gateway address. You will also need to change /etc/resolv.conf to use the name servers for your network.

# apt-get update
# apt-get install mtd-utils

5. Copy the desired kernel and filesystem to a directory in the microSD card, e.g. /home/electrum100 .

6. Create the NAND character devices. First, verify the NAND partition labels. The default is to use mtd5 for the Linux kernel and mtd6 for the root filesystem. The 512MB NAND uses a page size of 0x800 (2K) and an erase block size of 0x20000 (128K).

# cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00040000 00020000 "bootstrap"
mtd1: 00040000 00020000 "uboot"
mtd2: 00040000 00020000 "env1"
mtd3: 00040000 00020000 "env2"
mtd4: 00100000 00020000 "user"
mtd5: 00200000 00020000 "linux"
mtd6: 1fc00000 00020000 "root"
mtd7: 00042000 00000108 "spi0.1-AT45DB021B"

Then use mknod to create the device nodes

# mknod /dev/mtd0 c 90 0
# mknod /dev/mtd1 c 90 2
# mknod /dev/mtd2 c 90 4
# mknod /dev/mtd3 c 90 6
# mknod /dev/mtd4 c 90 8
# mknod /dev/mtd5 c 90 10
# mknod /dev/mtd6 c 90 12
# mknod /dev/mtd7 c 90 14

Flash filesystem

This procedure writes the filesystem to NAND. It should be executed on each board to be flashed.

1. If the board is configured to boot from NAND, change the bootloader configuration to boot from microSD. Press space bar when the bootloader loads to get an ">Electrum" command prompt.

setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p1 rw ip=192.168.1.101:192.168.1.253::255.255.255.0::eth0:none
setenv bootcmd mmcinfo\; ext2load mmc 0:1 0x22000000 uImage-2.6.33.20-1-at91\; bootm
saveenv
reset

NOTE: Substitute 192.168.1.101, 192.168.1.253 and 255.255.255.0 for the corresponding board IP address, gateway address and netmask.

2. Boot from the microSD card. Login as root and go to the directory containing the files to be flashed.

# cd /home/electrum100

3. Flash the kernel

# flash_erase /dev/mtd5 0 0                      
# nandwrite -p /dev/mtd5 uImage-2.6.33.20-1-at91
  

4. Flash the root filesystem

# flash_eraseall -j /dev/mtd6
# nandwrite -p /dev/mtd6 rootfs.armel.jffs2

5. Configure the bootloader back for NAND boot. Press space bar when the bootloader loads to get an ">Electrum" command prompt.

setenv bootargs console=ttyS0,115200 root=/dev/mtdblock6
  mtdparts=atmel_nand:256k(bootstrap)ro,256k(uboot)ro,256k(env1),256k(env2),1024k(user),2M(linux),-(root)
  rw rootfstype=jffs2
setenv bootcmd nand read 0x22000000 0x200000 0x200000\; bootm
saveenv

NOTE: The bootargs should be entered all in a single line.

Preload option

Micromint offers the option of loading your custom kernel or filesystem in NAND when the board is manufactured. This can be a big time saver, particularly in larger volumes. For larger orders (100 units or above) there is no cost for this option. For smaller orders there is a nominal cost for this service. For larger filesystems (over 62MB compressed) there is also a setup cost (NRE). Please contact our sales team for details.