Home ·

- SAM-BA nandflash applet

# SAM-BA nandflash applet

The nandflash applet drives the Static Memory Controller (SMC) or the NAND Flash Controller (NFC) to program an external raw NAND flash memory embedded on the board and connected to the SAM MPU device.

## Applet initialization

The list of parameters to initialize the nandflash applet can be displayed with the following command:

    sam-ba -p <port> -d <device> -a nandflash:help

    $ sam-ba -p serial -d sama5d2 -a nandflash:help
    Syntax: nandflash:[<ioset>]:[<bus_width>]:[<header>]
    Parameters:
        ioset      I/O set
        bus_width  NAND bus width (8/16)
        header     NAND header value
    Examples:
        nandflash                 use default board settings
        nandflash:2:8:0xc0098da5  use fully custom settings (IOSET2, 8-bit bus, header is 0xc0098da5)
        nandflash:::0xc0098da5    use default board settings but force header to 0xc0098da5

### I/O Set

The ioset parameter is an index that represents a group of I/O pins muxed to the SMC/NFC. The I/O set values are device specific; please refer to the nandflash section of the device configuration:

- SAM9xx5 configuration
- SAM9X60 configuration
- SAMA5D2 configuration
- SAMA5D3 configuration
- SAMA5D4 configuration
- SAMA7G5 configuration
- SAM9X7 configuration

### Bus Width

The bus_width parameter represents the number of data pins of the NAND flash. Supported values are either 8 (8-bit NAND flash) or 16 (16-bit NAND flash).

### PMECC Header

The header parameter is a 32-bit word descirbed below:

31 | 30 | 29 | 28 | 27 | 26 | 25 | 24
key | - | eccOffset
23 | 22 | 21 | 20 | 19 | 18 | 17 | 16
eccOffset | sectorSize
15 | 14 | 13 | 12 | 11 | 10 | 9 | 8
eccBitReq | spareSize
7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
spareSize | nbSectorPerPage | usePmecc

#### usePmecc bits[0]

- 0: Do not use PMECC to detect and correct the data.
- 1: use PMECC to detect and correct the data.

#### nbSectorPerPage bits[3:1]

Number of Sectors per Page

- 0: 1 sector per page
- 1: 2 sectors per page
- 2: 4 sectors per page
- 3: 8 sectors per page
- 4: 16 sectors per page

#### spareSize bits[12:4]

Size of the spare zone in bytes

#### eccBitReq bits[15:13]

Number of ECC bits required

- 0: 2-bit ECC
- 1: 4-bit ECC
- 2: 8-bit ECC
- 3: 12-bit ECC
- 4: 24-bit ECC
- 5: 32-bit ECC

#### sectorSize bits[17:16]

Size of the Sector

- 0: For 512 bytes per sector
- 1: For 1024 bytes per sector

#### eccOffset bits[26:18]

Offset of the first ECC byte in the spare zone. A value below 2 is not allowed and is considred as 2.

#### key bits[31:28]

Value 0xC must be written here to validate the content of the whole word.

## Supported commands

The list of commands supported by the nandflash applet can be displayed with the following commands:

    sam-ba -p <port> -d <device> -a nandflash -c help

    $ sam-ba -p serial -d sama5d2 -a nandflash -c help

### The erase command

The erase command resets to 0xFF a range of erase blocks. The size of those erase blocks depends on the manufacturer and memory part. Typical erase block sizes are 128KiB or 256KiB of data, not including their associated spare.

    $ sam-ba -p serial -b sam9x60-ek -a nandflash -c erase:help
    * erase - erase all or part of the memory
    Syntax:
        erase:[<addr>]:[<length>]
    Examples:
        erase                 erase all
        erase:4096            erase from 4096 to end
        erase:0x1000:0x10000  erase from 0x1000 to 0x11000
        erase::0x1000         erase from 0 to 0x1000

### The write and writeboot commands

The write and writeboot commands program data from a binary file into the NAND flash pages. The blocks containing the pages to be programmed should be erased first with the erase command. Padding bytes are added to align programmed data to the page boundary. The page size is computed from the PMECC header. Prior to what both comamnds do, the writeboot command also modifies the relevant unused ARM exception vector to store the size of the bootstrap binary, as required by the ROM code during the boot process.

    $ sam-ba -p serial -b sam9x60-ek -a nandflash -c write:help
    * write - write to memory from a file
    Syntax:
        write:<filename>:[<addr>]
    Examples:
        write:bootstrap.bin         write bootstrap.bin to start of memory
        write:u-boot.bin:0x10000    write u-boot.bin at offset 0x10000

    $ sam-ba -p serial -b sam9x60-ek -a nandflash -c writeboot:help
    Syntax:
        writeboot:<filename>
    Example:
        writeboot:bootstrap.bin     write bootstrap.bin as boot program at start of memory

### The read command

The read command loads data from the NAND flash into a binary file.

    $ sam-ba -p serial -b sam9x60-ek -a nandflash -c read:help
    * read - read from memory to a file
    Syntax:
        read:<filename>:[<addr>]:[<length>]
    Examples:
        read:firmware.bin              read all to firmware.bin
        read:firmware.bin:0x1000       read from 0x1000 to end into firmware.bin
        read:firmware.bin:0x1000:1024  read 1024 bytes from 0x1000 into firmware.bin
        read:firmware.bin::1024        read 1024 bytes from start of memory into firmware.bin

### The verify and verifyboot commands

The verify and verifyboot compare the data programmed in the NAND flash with the content of a given binary file. Unlike the verify command, the verifyboot command ignores the actual value of the relevant unused ARM exception vector in the binary file and does as if the value were the size of the binary file.

    $ sam-ba -p serial -b sam9x60-ek -a nandflash -c verify:help
    * verify - verify memory from a file
    Syntax:
        verify:<filename>:[<addr>]
    Examples:
        verify:firmware.bin         verify that start of memory matches firmware.bin
        verify:firmware.bin:0x1000  verify that memory at offset 0x1000 matches firmware.bin

    $ sam-ba -p serial -b sam9x60-ek -a nandflash -c verifyboot:help
    * verifyboot - verify boot program from a file
    Syntax:
        verifyboot:<filename>
    Example:
        verifyboot:bootstrap.bin    verify that start of memory matches boot program bootstrap.bin