This page is about using (booting/running from) [http://en.wikipedia.org/wiki/Flash_Memory#NAND_flash NAND] memory on [[BeagleBoard]]. Parts of this page are inspired by [http://www.sakoman.net/omap3/flash%20procedure.txt Steve's flash procedure] document.

This page is about using (booting/running from) [http://en.wikipedia.org/wiki/Flash_Memory#NAND_flash NAND] memory on [[BeagleBoard]]. Parts of this page are inspired by [http://www.sakoman.net/omap3/flash%20procedure.txt Steve's flash procedure] document.

To be able to write something to (empty) NAND, you first need to boot from an other source, e.g. [[BeagleBoard#MMC.2FSD_boot|MMC/SD card boot]]. Besides the files you need for MMC/SD card boot (MLO & U-Boot), put the files you want to flash into first FAT partition of MMC/SD card, too. Then you can read them from there and write them to NAND.

+

To be able to write something to (empty) NAND, you first need to boot from another source, e.g. [[BeagleBoard#MMC.2FSD_boot|MMC/SD card boot]]. In addition to the files you need for MMC/SD card boot (MLO & U-Boot), put the files you want to flash into the first FAT partition of MMC/SD card. Then you can read them from there and write them to NAND.

−

Note: If something goes wrong writing the initial X-Loader, your board might not boot any more without pressing the [[BeagleBoard#User_button|user button]]. See [[BeagleBoardRecovery|BeagleBoard recovery]] article how to fix this, then.

+

Note: If something goes wrong writing the initial X-Loader, your board might not boot any more without pressing the [[BeagleBoard#User_button|user button]]. See [[BeagleBoardRecovery|BeagleBoard recovery]] article how to fix this.

==X-Loader==

==X-Loader==

−

[http://code.google.com/p/beagleboard/wiki/BeagleSoftCompile Build] or download [http://code.google.com/p/beagleboard/downloads/list binary] (x-load.bin.ift_for_NAND) X-Loader. Put it at first (boot) FAT partition of MMC/SD card and boot from card. Then start boot from card and use the following to write X-Loader to NAND:

+

[http://code.google.com/p/beagleboard/wiki/BeagleSoftCompile Build] or download [http://code.google.com/p/beagleboard/downloads/list binary] (x-load_revc_v3.bin.ift) X-Loader. Put it at the first (boot) FAT partition of MMC/SD card and boot from the card. Then start boot from card and use the following to write X-Loader to NAND:

(Note - if you are using a more recent version of U-Boot, '''nand unlock''' is missing

+

simply skip this step. i.e. U-boot 2009.08)

device 0 whole chip

device 0 whole chip

nand_unlock: start: 00000000, length: 268435456!

nand_unlock: start: 00000000, length: 268435456!

NAND flash successfully unlocked

NAND flash successfully unlocked

−

OMAP3 beagleboard.org # '''nand ecc hw'''

+

OMAP3 beagleboard.org # '''nandecc hw'''

OMAP3 beagleboard.org # '''nand erase 0 80000'''

OMAP3 beagleboard.org # '''nand erase 0 80000'''

Line 77:

Line 82:

OMAP3 beagleboard.org #

OMAP3 beagleboard.org #

−

Note: The command ''nand ecc hw'' is essential here! X-Loader is started by OMAP3 boot rom. This uses HW ECC while reading the NAND, so while writing, we have to use OMAP3 HW ECC, too. If you don't use HW ECC boot rom [[BeagleBoardRecovery|can't boot from NAND]] any more.

−

==U-Boot==

+

Note: The command ''nandecc hw'' is essential here! X-Loader is started by OMAP3 boot ROM. This uses HW ECC while reading the NAND, so while writing, we have to use OMAP3 HW ECC, too. If you don't use HW ECC boot ROM [[BeagleBoardRecovery|can't boot from NAND]] any more.

+

+

==U-Boot prior to v2011.12==

[http://elinux.org/BeagleBoard#U-Boot Build] or download [http://code.google.com/p/beagleboard/downloads/list binary] (flash-uboot.bin) U-Boot. Put it at first (boot) FAT partition of MMC/SD card and boot from card. Then start boot from card and use the following to write U-Boot to NAND:

[http://elinux.org/BeagleBoard#U-Boot Build] or download [http://code.google.com/p/beagleboard/downloads/list binary] (flash-uboot.bin) U-Boot. Put it at first (boot) FAT partition of MMC/SD card and boot from card. Then start boot from card and use the following to write U-Boot to NAND:

−

OMAP3 beagleboard.org # '''mmcinit'''

+

OMAP3 beagleboard.org # '''mmc init'''

OMAP3 beagleboard.org # '''fatload mmc 0:1 80000000 u-boot.bin'''

OMAP3 beagleboard.org # '''fatload mmc 0:1 80000000 u-boot.bin'''

reading u-boot.bin

reading u-boot.bin

Line 89:

Line 95:

147424 bytes read

147424 bytes read

OMAP3 beagleboard.org # '''nand unlock'''

OMAP3 beagleboard.org # '''nand unlock'''

+

(Note - if you are using a more recent version of U-Boot, '''nand unlock''' is missing

+

simply skip this step. i.e. U-boot 2009.08)

device 0 whole chip

device 0 whole chip

nand_unlock: start: 00000000, length: 268435456!

nand_unlock: start: 00000000, length: 268435456!

NAND flash successfully unlocked

NAND flash successfully unlocked

+

OMAP3 beagleboard.org # '''nandecc sw'''

OMAP3 beagleboard.org # '''nand erase 80000 160000'''

OMAP3 beagleboard.org # '''nand erase 80000 160000'''

Line 105:

Line 114:

Note: You can use the same u-boot.bin you use to boot from MMC/SD card for NAND. There are no differences between U-Boot used for MMC/SD card boot and NAND boot.

Note: You can use the same u-boot.bin you use to boot from MMC/SD card for NAND. There are no differences between U-Boot used for MMC/SD card boot and NAND boot.

−

Note: Here, you don't need the ''nand ecc hw'' option. X-Loader which loads & starts U-Boot is able to understand SW ECC written by U-Boot.

+

Note: Here, you don't need the ''nandecc hw'' option. X-Loader which loads & starts U-Boot is able to understand SW ECC written by U-Boot.

+

+

==U-Boot v2011.12 or newer==

+

+

Starting with v2011.12 of U-Boot the functionality provided by X-Loader is now included in U-Boot. Also starting with this release the same ECC scheme is used in all parts of the NAND and the sw layout is NOT used. To build see [http://elinux.org/BeagleBoard#U-Boot Build]. Copy both the MLO and u-boot.img files to the first (boot) FAT partition of MMC/SD card and boot from card. Then start boot from card and use the following to write U-Boot to NAND:

+

+

OMAP3 beagleboard.org # '''mmc rescan'''

+

OMAP3 beagleboard.org # '''fatload mmc 0 80000000 MLO'''

+

reading MLO

+

+

46840 bytes read

+

OMAP3 beagleboard.org # '''nand erase 0 80000'''

+

+

NAND erase: device 0 offset 0x0, size 0x80000

+

Erasing at 0x60000 -- 100% complete.

+

OK

+

OMAP3 beagleboard.org # '''nandecc hw'''

+

OMAP3 beagleboard.org # '''cp.b 80000000 80020000 20000'''

+

OMAP3 beagleboard.org # '''cp.b 80000000 80040000 20000'''

+

OMAP3 beagleboard.org # '''cp.b 80000000 80060000 20000'''

+

OMAP3 beagleboard.org # '''nand write 80000000 0 80000'''

+

+

NAND write: device 0 offset 0x0, size 0x80000

+

524288 bytes written: OK

+

OMAP3 beagleboard.org # '''nand erase 80000 160000'''

+

+

NAND erase: device 0 offset 0x80000, size 0x160000

+

Erasing at 0x1c0000 -- 100% complete.

+

OK

+

OMAP3 beagleboard.org # '''fatload mmc 0 80000000 u-boot.img'''

+

reading u-boot.img

+

+

341152 bytes read

+

OMAP3 beagleboard.org # '''nand write 80000000 80000 160000'''

+

+

NAND write: device 0 offset 0x80000, size 0x160000

+

1441792 bytes written: OK

+

OMAP3 beagleboard.org #

+

+

Note: You can use the same u-boot.img you use to boot from MMC/SD card for NAND. There are no differences between U-Boot used for MMC/SD card boot and NAND boot.

==Kernel==

==Kernel==

−

tbd.

+

While X-Loader and U-Boot can be written only by U-Boot, for kernel and file system there are two ways to write them to NAND: Either by U-Boot (similar way as for X-Loader and U-Boot above) or from running kernel (e.g. booted from MMC card).

+

+

Note: X-Loader and U-Boot can't be written from already running kernel, too, because from kernel point of view X-loader and U-Boot NAND partitions are marked as write only. See ''omap3beagle_nand_partitions[]'' configuration structure in kernel's arch/arm/mach-omap2 directory.

+

+

===Writing kernel with U-Boot===

+

+

OMAP3 beagleboard.org # '''mmc init'''

+

OMAP3 beagleboard.org # '''fatload mmc 0:1 80000000 uImage'''

+

reading uImage

+

+

OMAP3 beagleboard.org # '''nandecc sw'''

+

OMAP3 beagleboard.org # '''nand erase 280000 400000'''

+

+

NAND erase: device 0 offset 0x280000, size 0x400000

+

Erasing at 0x660000 -- 100% complete.

+

OK

+

OMAP3 beagleboard.org # '''nand write 80000000 280000 400000'''

+

+

NAND write: device 0 offset 0x280000, size 0x400000

+

4194304 bytes written: OK

+

OMAP3 beagleboard.org #

+

+

Once you did this, use U-Boot commands to boot kernel (uImage) from NAND:

+

+

nand read 80000000 280000 400000 ; bootm 80000000

+

+

These, you can e.g. store as bootcmd and your board will automagically boot uImage from NAND.

+

+

===Writing kernel with kernel===

+

+

Once you have a kernel booted, e.g. from MMC card, you can use it to write the kernel itself (uImage) to NAND and then switch from MMC boot to kernel NAND boot. For this, observe the kernel's boot messages. These should have something like:

At kernel's prompt command ''cat /proc/mtd'' will give you similar output:

+

+

root@beagleboard:~# cat /proc/mtd

+

dev: size erasesize name

+

mtd0: 00080000 00020000 "X-Loader"

+

mtd1: 001e0000 00020000 "U-Boot"

+

mtd2: 00020000 00020000 "U-Boot Env"

+

'''mtd3''': 00400000 00020000 "Kernel"

+

mtd4: 0f980000 00020000 "File System"

+

+

While the first three partitions (X-Loader, U-Boot and U-Boot Env) are read only from kernel point of view, Kernel and File System partition can be written by the kernel itself. To do this, you need [http://www.linux-mtd.infradead.org/doc/general.html MTD User modules] in your kernel's root file system.

+

+

In this example we mount boot (FAT) partition of MMC card (using a dual boot card) to read kernel image (uImage) from. If you have network connection in your kernel, you can use this, too. Or you put uImage in your root file system. Goal is to have access to uImage from running kernel to be able to write it to NAND.

+

+

root@beagleboard:~# '''mkdir -p /mnt/fat'''

+

root@beagleboard:~# '''mount /dev/mmcblk0p1 /mnt/fat/'''

+

root@beagleboard:~# ls -la /mnt/fat

+

-rwxr-xr-x 1 root root 16740 Jul 7 17:28 mlo

+

-rwxr-xr-x 1 root root 717116 Jul 24 2008 u-boot.bin

+

-rwxr-xr-x 1 root root 2106940 Jul 26 2008 uImage

+

root@beagleboard:~# '''cp /mnt/fat/uImage .'''

+

root@beagleboard:~# ls -la

+

-rwxr-xr-x 1 root root 2106940 Jul 22 00:30 uImage

+

root@beagleboard:~# '''flash_eraseall /dev/mtd3'''

+

Erasing 128 Kibyte @ 3e0000 -- 96 % complete.

+

root@beagleboard:~# '''nandwrite -p /dev/mtd3 uImage'''

+

Writing data to block 0 at offset 0x0

+

<...>

+

Writing data to block 20 at offset 0x280000

+

root@beagleboard:~#

==File system==

==File system==

−

tbd.

+

As with kernel, while X-Loader and U-Boot can be written only by U-Boot, for file system there are two ways to write them to NAND: Either by U-Boot (similar way as for X-Loader and U-Boot above) or from running kernel (e.g. booted from MMC card). A lot of users report they have issues with writing (root) file system with U-Boot. Main issue is that U-Boot has to write file system ''exactly'' in format kernel expects. If there are minor incompatibilities, kernel will later not be able to read file system written by U-Boot.

+

+

So, while we document here how to write file system with U-Boot, '''recommended''' way is to write (root) file system by kernel itself. With this, it is ensured that kernel writes a file system it will later be able to read.

For more info see [http://www.sakoman.net/omap3/flash%20procedure.txt Steve's flash procedure].

+

+

===Writing file system with kernel===

+

+

This is the ''recommended'' way. See above.

+

+

First, we boot kernel with (root) file system on SD card, write (root) file system using file system image at SD card to Beagle's NAND with running kernel. After this is done, we switch kernel's boot arguments to take root file system from NAND instead of SD card, then.

+

+

To be able to manipulate/erase/write NAND from kernel's user space, we need [http://www.linux-mtd.infradead.org/ MTD] Utils (e.g. flash_eraseall).

+

+

If you don't have them already, you can get them

+

+

* using the [[BeagleBoard#Binaries|angstrom demo]], you can install via

For file system in Beagle's NAND, we use [http://sourceware.org/jffs2/ JFFS2]. As JFFS2 is part of the standard git kernel, only thing is to configure kernel to be able to use JFFS2 is to enable in make menuconfig (check if already enabled):

+

+

CONFIG_JFFS2_FS=y

+

CONFIG_JFFS2_FS_DEBUG=0

+

CONFIG_JFFS2_FS_WRITEBUFFER=y

+

CONFIG_JFFS2_ZLIB=y

+

CONFIG_JFFS2_RTIME=y

+

+

Having kernel supporting JFFS2 and MTD Utils, we now first erase file system partition and create JFFS2 into it:

To be able to write something to (empty) NAND, you first need to boot from another source, e.g. MMC/SD card boot. In addition to the files you need for MMC/SD card boot (MLO & U-Boot), put the files you want to flash into the first FAT partition of MMC/SD card. Then you can read them from there and write them to NAND.

Note: If something goes wrong writing the initial X-Loader, your board might not boot any more without pressing the user button. See BeagleBoard recovery article how to fix this.

X-Loader

Build or download binary (x-load_revc_v3.bin.ift) X-Loader. Put it at the first (boot) FAT partition of MMC/SD card and boot from the card. Then start boot from card and use the following to write X-Loader to NAND:

Note: The command nandecc hw is essential here! X-Loader is started by OMAP3 boot ROM. This uses HW ECC while reading the NAND, so while writing, we have to use OMAP3 HW ECC, too. If you don't use HW ECC boot ROM can't boot from NAND any more.

U-Boot prior to v2011.12

Build or download binary (flash-uboot.bin) U-Boot. Put it at first (boot) FAT partition of MMC/SD card and boot from card. Then start boot from card and use the following to write U-Boot to NAND:

Note: You can use the same u-boot.bin you use to boot from MMC/SD card for NAND. There are no differences between U-Boot used for MMC/SD card boot and NAND boot.

Note: Here, you don't need the nandecc hw option. X-Loader which loads & starts U-Boot is able to understand SW ECC written by U-Boot.

U-Boot v2011.12 or newer

Starting with v2011.12 of U-Boot the functionality provided by X-Loader is now included in U-Boot. Also starting with this release the same ECC scheme is used in all parts of the NAND and the sw layout is NOT used. To build see Build. Copy both the MLO and u-boot.img files to the first (boot) FAT partition of MMC/SD card and boot from card. Then start boot from card and use the following to write U-Boot to NAND:

Note: You can use the same u-boot.img you use to boot from MMC/SD card for NAND. There are no differences between U-Boot used for MMC/SD card boot and NAND boot.

Kernel

While X-Loader and U-Boot can be written only by U-Boot, for kernel and file system there are two ways to write them to NAND: Either by U-Boot (similar way as for X-Loader and U-Boot above) or from running kernel (e.g. booted from MMC card).

Note: X-Loader and U-Boot can't be written from already running kernel, too, because from kernel point of view X-loader and U-Boot NAND partitions are marked as write only. See omap3beagle_nand_partitions[] configuration structure in kernel's arch/arm/mach-omap2 directory.

Once you did this, use U-Boot commands to boot kernel (uImage) from NAND:

nand read 80000000 280000 400000 ; bootm 80000000

These, you can e.g. store as bootcmd and your board will automagically boot uImage from NAND.

Writing kernel with kernel

Once you have a kernel booted, e.g. from MMC card, you can use it to write the kernel itself (uImage) to NAND and then switch from MMC boot to kernel NAND boot. For this, observe the kernel's boot messages. These should have something like:

While the first three partitions (X-Loader, U-Boot and U-Boot Env) are read only from kernel point of view, Kernel and File System partition can be written by the kernel itself. To do this, you need MTD User modules in your kernel's root file system.

In this example we mount boot (FAT) partition of MMC card (using a dual boot card) to read kernel image (uImage) from. If you have network connection in your kernel, you can use this, too. Or you put uImage in your root file system. Goal is to have access to uImage from running kernel to be able to write it to NAND.

File system

As with kernel, while X-Loader and U-Boot can be written only by U-Boot, for file system there are two ways to write them to NAND: Either by U-Boot (similar way as for X-Loader and U-Boot above) or from running kernel (e.g. booted from MMC card). A lot of users report they have issues with writing (root) file system with U-Boot. Main issue is that U-Boot has to write file system exactly in format kernel expects. If there are minor incompatibilities, kernel will later not be able to read file system written by U-Boot.

So, while we document here how to write file system with U-Boot, recommended way is to write (root) file system by kernel itself. With this, it is ensured that kernel writes a file system it will later be able to read.

Writing file system with kernel

This is the recommended way. See above.

First, we boot kernel with (root) file system on SD card, write (root) file system using file system image at SD card to Beagle's NAND with running kernel. After this is done, we switch kernel's boot arguments to take root file system from NAND instead of SD card, then.

To be able to manipulate/erase/write NAND from kernel's user space, we need MTD Utils (e.g. flash_eraseall).

For file system in Beagle's NAND, we use JFFS2. As JFFS2 is part of the standard git kernel, only thing is to configure kernel to be able to use JFFS2 is to enable in make menuconfig (check if already enabled):