No renderer 'pdf' found for mode 'pdf'
world leader in high performance signal processing
Trace: » nand-flash

NAND Flash and U-Boot

U-Boot supports NAND flashes hooked up a variety of ways. It may be via the asynchronous memory bank (such as the CF/NAND card) or the on-chip NAND controller that exists on some Blackfins like the BF52x or BF54x.

In terms of the command line interface, the nand command is the interface to all NAND flash operations. It allows you to read/write a sequential range of bytes as well as query the NAND flash. Bad block handling is optionally supported.

In terms of U-Boot code, U-Boot provides similar infrastructure to the Linux kernel MTD layer. People who wish to hook up their own NAND flash in their way just has to write the backend driver. You can refer to:

  • drivers/mtd/nand/nand_plat.c the driver for NAND on the asynchronous memory bus
  • drivers/mtd/nand/bfin_nand.c the driver for Blackfin's with an on-chip NAND controller

Configuration

You will need these options selected in your board configuration file in order to enable support for NAND flashes.

  • define the config option that corresponds to the NAND driver you're using
  • define CONFIG_CMD_NAND

Boot ROM Support

Since the Blackfin on-chip Boot ROM expects a different ECC layout, you need to tell U-Boot to use the different layout when booting U-Boot directly from NAND. This is the only time you should enable this option. Simply define CONFIG_BFIN_NFC_BOOTROM_ECC in your board configuration file.

You will need to have these settings enabled both in the U-Boot that programs the NAND flash as well as the U-Boot that boots out of the NAND flash.

Querying

At runtime, you can interrogate the NAND flash to make sure things are detected properly.

bfin> nand info
Device 0: NAND 256MiB 3,3V 8-bit, sector size 128 KiB

Here we can see that there is a 2 gigabit NAND flash hooked up. Good times.

Reading

You use the nand read command to read a range of bytes from the NAND flash into memory. From there, you can do anything you like with it. For example, if we want to read 0x1000 bytes at an offset of 0x300 bytes from the start of the NAND flash into external memory at 0x20000, we'd simply run:

bfin> nand read 0x20000 0x300 0x1000

NAND read: device 0 offset 0x300, size 0x1000
 4096 bytes read: OK

The nand read command does not support bad blocks. If you want to include bad block handling, just append .jffs2 to the command.

bfin> nand read.jffs2 0x20000 0x300 0x1000

NAND read: device 0 offset 0x300, size 0x1000

Reading data from 0xb00 -- 100% complete.
 4096 bytes read: OK

Erasing

Like all other flash devices, you need to erase things before you write them. The nand erase command will do this for you.

Writing

You use the nand write command to write a range of bytes from memory into the NAND flash. This command does not handle bad blocks, so if you want that, just append .jffs2 to the write as in the nand read example.

The write.jffs2 command has nothing to do with jffs2 and is poorly named - it just means skip bad blocks.

Writes also need to be paged aligned, so make sure you round up the write size accordingly.

Booting

To make your life easier, you can use the nboot command to boot a kernel image straight out of the NAND flash without having to read it into external memory first. The first argument is the scratch space in external memory while the second argument is the offset into the NAND flash.

bfin> nboot 0x2000000 0

Loading from NAND 256MiB 3,3V 8-bit, offset 0x0
   Image Name:   uClinux Kernel and Filesystem
   Created:      2006-02-08  10:07:01 UTC
   Image Type:   Blackfin Linux Kernel Image (gzip compressed)
   Data Size:    2713804 Bytes =  2.6 MB
   Load Address: 00001000
   Entry Point:  00001000
Automatic boot of image at addr 0x02000000 ...
## Booting image at 02000000 ...
   Image Name:   uClinux Kernel and Filesystem
   Created:      2006-02-08  10:07:01 UTC
   Image Type:   Blackfin Linux Kernel Image (gzip compressed)
   Data Size:    2713804 Bytes =  2.6 MB
   Load Address: 00001000
   Entry Point:  00001000
   Verifying Checksum ... OK
   Uncompressing Kernel Image ... OK
Starting Kernel at = 1000
Linux version 2.6.12.1 (aubrey@linux) (gcc version 3.4.5) #2 Wed Feb 8 17:42:00 CST 2006
...........

Examples

bfin> tftp 0x1000000 uImage
Using Blackfin EMAC device
TFTP from server 10.100.4.174; our IP address is 10.100.4.50
Filename 'uImage'.
Load address: 0x1000000
Loading: #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #################################################################
         #########################
done
Bytes transferred = 2454059 (25722b hex)

bfin> help nand
nand info                  - show available NAND devices
nand device [dev]     - show or set current device
nand read[.jffs2]     - addr off|partition size
nand write[.jffs2]    - addr off|partiton size - read/write `size' bytes starting
    at offset `off' to/from memory address `addr'
nand erase [clean] [off size] - erase `size' bytes from
    offset `off' (entire device if not specified)
nand bad - show bad blocks
nand dump[.oob] off - dump page
nand scrub - really clean NAND erasing bad blocks (UNSAFE)
nand markbad off - mark bad block at offset (UNSAFE)
nand biterr off - make a bit error at offset (UNSAFE)
nand lock [tight] [status] - bring nand to lock state or display locked pages
nand unlock [offset] [size] - unlock section

bfin> nand erase clean

NAND erase: device 0 whole chip
Erasing at 0x7fe0000 -- 100% complete. Cleanmarker written at 0x7fe0000.
OK

bfin> nand write.jffs2 0x1000000 0x0 0x260000

NAND write: device 0 offset 0x0, size 0x260000
 2490368 bytes written: OK

bfin> help nboot
nboot [partition] | [[[loadAddr] dev] offset]

bfin> nand device

Device 0: NAND 128MiB 3,3V 8-bit

bfin> nboot 0x2000000 0x0
Loading from NAND 128MiB 3,3V 8-bit, offset 0x0
   Image Name:   uClinux Kernel and ext2
   Created:      2007-03-27   0:24:27 UTC
   Image Type:   Blackfin Linux Kernel Image (gzip compressed)
   Data Size:    2453995 Bytes =  2.3 MB
   Load Address: 00001000
   Entry Point:  00001000
Automatic boot of image at addr 0x02000000 ...
## Booting image at 02000000 ...
   Image Name:   uClinux Kernel and ext2
   Created:      2007-03-27   0:24:27 UTC
   Image Type:   Blackfin Linux Kernel Image (gzip compressed)
   Data Size:    2453995 Bytes =  2.3 MB
   Load Address: 00001000
   Entry Point:  00001000
   Verifying Checksum ... OK
   Uncompressing Kernel Image ... OK
Starting Kernel at = 1000
Linux version 2.6.19.3-ADI-2007R1-pre-svn2931 (test@linux) (gcc version 4.1.1 (ADI 07R1)) #5 Mon Ma7
.............