How To Boot from NAND Flash on the NXP/Embedded Artists LPC313x
Table of Contents
NFS-based root file systems are very useful in a development environment. However, once you start to move to a production system, it is no longer a viable option. Instead, you will want your device to boot from some sort of persistent memory, such as NAND flash. This document explains how to boot a complete system from NAND flash on the NXP/Embedded Artists LPC313x.
Prerequisites
- Linux must be running on the LPC313x (either from an SD Card or over NFS) with the following packages:
- mtd-utils (TSWO_SOFTWARE_mtd-utils=y)
- ext2-formatted Secure Digital Card containing the following files:
- Kernel zImage - This file is located at build_armv5l-timesys-linux-<libc>/images/zImage-2.6.28-ts-armv5l on Desktop Factory builds.
- Apex - This file is located at build_armv5l-timesys-linux-<libc>/images/bootloader/apex.bin on Desktop Factory builds.
- Root File System image (either jffs2 or ubifs) - This file is located at build_armv5l-timesys-linux-<libc>/images/rfs/{rootfs.jffs2,rootfs.ubi} on Desktop Factory builds.
- For jffs2, select TSWO_RFS_FS_jffs2=y in your workorder
- For ubifs, select TSWO_RFS_FS_ubifs=y and TSWO_RFS_FS_ubifs_UBINIZE=y in your workorder
- Apex binary on your host machine
Default Flash Partitions
2.6.28 Kernel
Start Offset | End Offset | Size | Name |
---|---|---|---|
0x00000000 | 0x00020000 | 0x00020000 | lpc313x-boot |
0x00020000 | 0x00080000 | 0x00060000 | apex |
0x00080000 | 0x000c0000 | 0x00040000 | apex-prms |
0x000c0000 | 0x004c0000 | 0x00400000 | lpc313x-kernel |
0x004c0000 | 0x014c0000 | 0x01000000 | lpc313x-ramdsk |
0x014c0000 | 0x10000000 | 0x0eb40000 | lpc313x-rootfs |
Writing Files to NAND Flash
Apex Bootloader
You only need to perform this procedure if the bootloader has not already been written to NAND (as in the Getting Started Guide).
- Insert the SD card into the SD slot on the LPC313x board.
- Plug the board the USB port of the computer. Make sure the serial jumpers are in the lower two USB positions.
- Set the boot jumpers on the board to:
GPIO Pin Value BOOT0 L BOOT1 H BOOT2 L - Reset the board.
- Send the bootloader file on your host machine to the serial port using cat.
cat apex.bin > /dev/ttyUSB0
- Wait for the red RX LED to turn off before proceeding any further.
- Open minicom and configure for the board. You should see an apex prompt, or a spinning indicator. If you see the indicator, hit Ctrl-C to get to the prompt.
- Set up the bad block table in NAND flash (This only needs to be done once per board):
apex> lpcnand format
- Copy the apex binary from the SD card to RAM:
apex> copy ext2://1/apex.bin 0x30008000 62664 bytes transferred
- Copy the binary from RAM to NAND:
apex> copy 0x30008000+62664 lnand:128k
Note that 62664 is the actual size of the apex binary, which can be found in the output of the previous command. - Set the boot jumpers on the board to:
GPIO Pin Value BOOT0 L BOOT1 L BOOT2 L
Your board will now load Apex from NAND flash.
Linux Kernel
- Insert the SD card into the SD slot on the LPC313x board.
- Open minicom and configure for the board.
- Plug the board the USB port of the computer.
- In minicom, you should see an apex prompt, or a spinning indicator. If you see the indicator, hit Ctrl-C to get to the prompt.
- Copy the kernel zImage from the SD card to RAM:
apex> copy ext2://1/zImage-2.6.28-ts-armv5l 0x30008000 1427412 bytes transferred
- Copy the binary from RAM to NAND:
apex> copy 0x30008000+1427412 lnand:768k
Note that 1427412 is the actual size of the kernel binary, which can be found in the output of the previous command.
RFS
There are two ways to write an RFS to NAND: using Apex, or using the kernel. The advantage of using Apex is that it does not require a fully-booted system. However, it can only write images that are smaller than the amount of RAM on the board, and the erase function does not properly handle NAND.
For Images Less than 64 MB
This method may not work if there are bad blocks on NAND. In this case, use the second method.
- Insert the SD card into the SD slot on the LPC313x board.
- Open minicom and configure for the board.
- Plug the board the USB port of the computer.
- In minicom, you should see an apex prompt, or a spinning indicator. If you see the indicator, hit Ctrl-C to get to the prompt.
- Copy the rfs image from the SD card to RAM:
apex> copy ext2://1/rootfs.jffs2 0x30008000 2883584 bytes transferred
- Erase the NAND flash region where we are writing the image:
apex> erase nand:21248k+240896k
- Copy the binary from RAM to NAND:
apex> copy 0x30008000+2883584 lnand:21248k
Note that 2883584 is the actual size of the kernel binary, which can be found in the output of the previous command.
For Images Greater than 64 MB
- If you are not booting from SD, you must mount the SD card using the mount command:
mount /dev/mmcblk0p1 /mnt
- Erase the NAND flash partition using flash_eraseall:
# flash_eraseall /dev/mtd5 Erasing 128 Kibyte @ eaa0000 -- 99 % complete
- Copy the image to NAND using nandwrite:
# nandwrite /dev/mtd5 /mnt/rootfs.jffs2 Writing data to block 0 at offset 0x0 Writing data to block 1 at offset 0x20000 Writing data to block 2 at offset 0x40000 ...
Booting from NAND
To set your board up to boot from NAND, you must change some environment variables in Apex. You can do this with the setenv and saveenv commands.
Once these values are set and saved, reset your board, and it will automatically boot from NAND.
jffs2-based RFS
Variable | Value |
---|---|
startup | wait 10;copy lnand:768k+2m 0x30008000; boot |
cmdline | console=ttyS0,115200 rootfstype=jffs2 root=/dev/mtdblock5 rw |
apex> setenv startup wait 10;copy lnand:768k+2m 0x30008000; boot apex> setenv cmdline console=ttyS0,115200 rootfstype=jffs2 root=/dev/mtdblock5 rw apex> saveenv
ubifs-based RFS
Variable | Value |
---|---|
startup | wait 10;copy lnand:768k+2m 0x30008000; boot |
cmdline | console=ttyS0,115200 rootfstype=ubifs root=ubi0_0 rw ubi.mtd=5 |
apex> setenv startup wait 10;copy lnand:768k+2m 0x30008000; boot apex> setenv cmdline console=ttyS0,115200 rootfstype=ubifs root=ubi0_0 rw ubi.mtd=5 apex> saveenv