Skip to main content.

Topic UBootCmdGroupNand not in WebOrder NAND devices

U-Boot allows us to directly work with NAND devices attached directly or through a NAND controller. The commands are grouped under the nand subsystem:

=> help nand
nand - NAND sub-system

Usage:
nand info - show available NAND devices
nand device [dev] - show or set current device
nand read - addr off|partition size
nand write - addr off|partition size
    read/write 'size' bytes starting at offset 'off'
    to/from memory address 'addr', skipping bad blocks.
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(s) at offset (UNSAFE)
nand biterr off - make a bit error at offset (UNSAFE)
=>

Topic UBootCmdGroupNand not in WebOrder nand bad - show bad block information

As NAND devices can develop bad blocks over their lifetime and usually even are delivered with bad blocks already, the NAND commands need to be aware of this fact. Getting information of the current bad block list is easy:

=> nand bad

Device 0 bad blocks:
=>

Topic UBootCmdGroupNand not in WebOrder nand erase - erase region

Ensuring that the NAND device functions properly, we will use the basic commands to construct a testpattern in memory, write that to the device, of course erasing it first, and read the data back. A final comparison will show if all data was transferred correctly.

We begin be erasing 64k at the start of the NAND device:

=> nand erase 0 0x10000

NAND erase: device 0 offset 0x0, size 0x10000
Warning: Erase size 0x00010000 smaller than one erase block 0x00020000
    Erasing 0x00020000 instead
Erasing at 0x0 -- 100% complete.
OK
=>

Topic UBootCmdGroupNand not in WebOrder nand write - write to NAND device

Let's create a testpattern in memory and write that to the previously erased NAND area:

=> mw 0x100000 0x55aa55aa 0x4000
=> nand write 0x100000 0 0x10000

NAND write: device 0 offset 0x0, size 0x10000
 65536 bytes written: OK
=>

Topic UBootCmdGroupNand not in WebOrder nand read - read from NAND device

As everything worked ok, we ensure everything was fine by transferring the data to a different location in RAM and check this against the original written content:

=> nand read 0x200000 0 0x10000

NAND read: device 0 offset 0x0, size 0x10000
 65536 bytes read: OK
=> md 0x200000
00200000: 55aa55aa 55aa55aa 55aa55aa 55aa55aa    U.U.U.U.U.U.U.U.
00200010: 55aa55aa 55aa55aa 55aa55aa 55aa55aa    U.U.U.U.U.U.U.U.
=> cmp 0x100000 0x200000 0x4000
Total of 16384 words were the same
=>