Table of contents

  1. Can I boot from NAND flash?
  2. Is there support for 32-bit wide NAND flash ?
  3. How do I erase my MTD partition on NAND flash?
  4. Can I copy a JFFS2 image to NAND via /dev/mtdX?
  5. Can I use seek/read/write on /dev/mtdX?
  6. Must my boot-loader be aware of NAND flash?
  7. Can I program NAND via JTAG?
  8. How do I use NAND simulator?

Can I boot from NAND flash?

Not from a bare NAND chip. You need a glue logic around, which gives you memory access to the chip on boot-up, like the DiskOnChip devices do. This will be a quite complex CPLD. An alternative is to use a small e.g. 1MB NOR flash, which contains the boot code and maybe a compressed kernel image. Then you can use JFFS2 or UBIFS on NAND as your root file-system.

Some chips have internal circuitry which is capable of reading and booting from the first page of NAND after power up. This allows you to boot a small (e.g. 256/512/2048 byte) boot code, which can initialize SDRAM, then read and execute a more complete bootloader from subsequent NAND blocks. An example is U-Boot, which can be built as a 2-stage "initial" and "secondary" bootloader for use with NAND.

Samson's S3C2410 ARM based SOC-CPU provides a mechanism to boot from NAND flash.

Is there support for 32-bit wide NAND flash?

No. The generic NAND driver supports 8/16 bit wide NAND flash only. 32 bit NAND flash can be built by using 2 or 4 chips and connect them to D0-7, D8-D15, D16-D23 and D24-D31 on the data bus. You can tie all corresponding control signals together. But you have to build a new nand16 or nand32 driver, which can be derived from the existing nand.c. Be aware, that the write-buffer size is 2 or 4 times as big as on 8 bit NAND. This means, if you flush the buffer to ensure, that your data are on disk, you may waste much more memory space than on 8 bit NAND. Another point is bad block handling. When a block on 1 chip is bad, the corresponding blocks on the other chips are lost too, as you present them as one big block to the file-system driver. The JFFS2 code, which handles the write-buffer and the out of band (spare) area of NAND doesn't support 32 bit neither.

How do I erase my MTD partition on NAND flash?

flash_erase (erase one eraseblock) or flash_eraseall utilities may be used. If you are going to use this partition with JFFS2, then it is recommended to use -j or --jffs2 options. This will write the so called "clean-marker" to the out of band area, so you can mount the file-system and no further formatting is needed. This is also necessary before you copy a filesystem image to the chip.

Can I copy a JFFS2 image to NAND via /dev/mtdX?

Technically yes, as long as this MTD partition does not contain bad blocks. But it is generally a bad idea. For bad block aware copying, use nandwrite from the mtd-utils package.

Also, make sure, that the erasesize you set to mkfs.jffs2 is the same as the erasesize of your chip. Data will only be written with ECC, if your default settings for OOB-layout selection are set for JFFS2.

Can I use seek/read/write on /dev/mtdX?

Yes, as long as your program is aware of bad blocks. Make sure to set the desired ECC layout by ioctl (MEMSETOOBSEL). A example for bad block handling and usage of ioctl (MEMOOBSEL) can be found in the nandwrite utility.

Must my bootloader be aware of NAND flash?

Yes, if you use your bootloader to erase the flash chip and copy a file-system image to it. For erase make sure, that you don't erase factory-marked bad blocks. They are marked in the 6th byte (offset 0x5) in the out of band area of the first page of a block. The block is bad, if any bit in this byte is zero. If you erase such a block, the bad block information is erased too and lost. Further use of this block will lead to erroneous results.

For JFFS2 file-systems it's recommended to program the JFFS2 erased marker into the out of band area of the first page in each erased block after erasing the block. Do not program it into the data area of the page!

For (obsolete) 256 byte page size devices program the following data into the out of band area:

Offset0x060x07
Data0x850x19

For 512 byte page size devices program the following data into the out of band area:

Offset0x080x090x0a0x0b0x0c0x0d 0x0e0x0f
Data0x850x190x030x200x080x00 0x000x00

If you copy a file-system image to the chip, it's recommended to write it with ECC. You can use the ECC code in the nand driver to do this. If you have a bad block on your chip, just skip this block and copy the data to the next block. JFFS2 and other NAND flash aware file-systems handle this gap.

Can I program NAND via JTAG?

Yes, you can. The requirements are the same as for boot-loaders (see here).

How do I use NAND simulator?

NAND simulator (nandsim) is an extremely useful debugging and development tool which simulates NAND flashes in RAM or a file. To select the simulated flash type one should specify ID bytes of your flash - the ones which are returned by the "Read ID" command (0x90) - consult the flash manual. The following are examples of input parameters:

  1. modprobe nandsim first_id_byte=0x20 second_id_byte=0x33 - 16MiB, 512 bytes page;
  2. modprobe nandsim first_id_byte=0x20 second_id_byte=0x35 - 32MiB, 512 bytes page;
  3. modprobe nandsim first_id_byte=0x20 second_id_byte=0x36 - 64MiB, 512 bytes page;
  4. modprobe nandsim first_id_byte=0x20 second_id_byte=0x78 - 128MiB, 512 bytes page;
  5. modprobe nandsim first_id_byte=0x20 second_id_byte=0x71 - 256MiB, 512 bytes page;
  6. modprobe nandsim first_id_byte=0x20 second_id_byte=0xa2 third_id_byte=0x00 fourth_id_byte=0x15 - 64MiB, 2048 bytes page;
  7. modprobe nandsim first_id_byte=0xec second_id_byte=0xa1 third_id_byte=0x00 fourth_id_byte=0x15 - 128MiB, 2048 bytes page;
  8. modprobe nandsim first_id_byte=0x20 second_id_byte=0xaa third_id_byte=0x00 fourth_id_byte=0x15 - 256MiB, 2048 bytes page;
  9. modprobe nandsim first_id_byte=0x20 second_id_byte=0xac third_id_byte=0x00 fourth_id_byte=0x15 - 512MiB, 2048 bytes page;
  10. modprobe nandsim first_id_byte=0xec second_id_byte=0xd3 third_id_byte=0x51 fourth_id_byte=0x95 - 1GiB, 2048 bytes page;

If you do not have enough RAM, you can make nandsim emulate the flash on top of a file. Please, use the cache_file nandsim module parameter.

nandsim can emulate various errors and report wear statistics, which is extremely useful when testing how flash software handles errors (e.g., what does JFFS2 do in case of bit-flips or write errors).

Note, theoretically nandsim can emulate 16-bit bus width devices, but it may not work.

Valid XHTML 1.0! Valid CSS!