U-boot and Flash (NOR, NAND & SPI)

U-boot now has support for 3 different flash technologies:
  • NOR flash (traditional parallel 8-bit or 16-bit wide data bus, with a dedicated address bus).
  • NAND flash (newer technology 8-bit or 16-bit data bus, which is multiplexed with the address bus).
  • SPI serial flash (newer technology, simple 4-wire serial bus).

These different flash technologies require different device drivers to communicate with them, due to the different ways they are wired to the CPU. As a result, there are different U-boot commands used to access them. It is important to use the correct command for each type of flash device.

Which Flash command sets to use?

The following table shows the appropriate command sets for each type of flash.

Action NOR NAND SPI
Copy Flash to RAM cp.[bwl] nand read eeprom read
Write to Flash from RAM cp.[bwl] nand write eeprom write
Dump Flash md.[bwl] nand dump eeprom read ; md.[bwl]
Ease Flash erase nand erase n/a
Write Protection protect on
protect off
nand lock
nand unlock
n/a
Additional Info flinfo
imls
nand info
nand bad
n/a

For more information on each of these U-boot commands, then please use the help command, for example:

MB680> help cp
MB680> help nand
MB680> help eeprom

Writing data to Flash

The following are examples of how to burn U-boot into flash, so it may be booted from flash. In all cases, we assume that the binary to be burned is in a NFS server, and that both the NFS server, and U-boot's networking are correctly set up. In addition, we assume that we want to burn the U-boot image into the first block in flash (i.e. offset zero).

NOTE: The following commands may need to be changed for your specific board, configuration, environment, etc. - they are just examples!

For NOR Flash

In the case of NOR flash, the flash should be explicitly erased (and if necessary unprotected), prior to writing to it.

MB680> nfs $load_addr /export/u-boot.bin
MB680> protect off 1:0-4
MB680> erase 1:0-4
MB680> cp.b $load_addr A0000000 $filesize
MB680> protect on 1:0-4

It should be noted that by default, U-boot has 2 environment variables (unprot, and update) which should be automatically defined which help with burning U-boot into NOR flash. These may be used instead of the above code, as follows:

MB680> nfs $load_addr /export/u-boot.bin
MB680> run unprot
MB680> run update

For NAND Flash

In the case of NAND flash, the flash should be explicitly erased, prior to writing to it.

In the case of NAND, then most access operations need to be multiples of certain page/block sizes. For simplicity, the following code assumes that u-boot.bin fits in 256 KiB (0x40000). However, you may use smallest figures that are appropriately aligned.

MB680> nfs $load_addr /export/u-boot.bin
MB680> nand erase 0 40000
MB680> nand write $load_addr 0 40000

For SPI Serial Flash

In the case of SPI serial flash, U-boot will automatically erase the flash, prior to writing to it. Hence, users may just use the eeprom write command without explicitly having to erase the SPI serial flash device at all.

MB680> nfs $load_addr /export/u-boot.bin
MB680> eeprom write $load_addr 0 $filesize