Program External Serial Peripheral Interface (SPI) NOR Flash Memory (serialflash)
The serialflash applet initializes the SPIx or Flexible Serial Communications Controller (FLEXCOMx_SPI) controller and can perform read, write, erase, and verify functions on external SPI NOR Flash memory.
The serialflash applet applies to the following devices. Documentation is available in the ../sam-ba/doc/ directory.
Device | Documentation |
---|---|
SAM9X60 | ../doc/sam9x60.html |
SAM9XX5 | ../doc/sam9xx5.html |
SAMA5D2 Series | ../doc/sama5d2.html |
SAMA5D3 | ../doc/sama5d3.html |
SAMA5D4 | ../doc/sama5d4.html |
Additional documentation is located in the ../doc/serialflash.html document directory.
serialflash Command Structure
The serialflash applet has the following command structure:
$ sam-ba -p <port> -d <device> -a serialflash -c <command>
Initialize Controller
Initialization of the serialflash applet has the following command structure:
$ sam-ba -p <port> -d <device> -a serialflash
A list of parameters to initialize the serialflash applet can be displayed with the following command (using the SAMA5D2 Series device as an example):
$ sam-ba -p serial -d sama5d2 -a serialflash:help
Syntax: serialflash:[<instance>]:[<ioset>]:[<npcs>]:[<frequency>]
Parameters:
instance SPI controller instance
ioset I/O set
npcs SPI chip select number
frequency SPI clock frequency in MHz
Examples:
serialflash use default board settings
serialflash:0:1:0:66 use fully custom settings (SPI0, IOSET1, NPCS0, 66MHz)
serialflash::::20 use default board settings but force frequency to 20MHz
A list of parameters is located in the ../doc/serialflash.html document directory.
Supported Commands
A list of commands supported by serialflash can be displayed with the following command:
$ sam-ba -p <port> -d <device> -a serialflash -c help
read Command
The read command reads data from external SPI NOR Flash memory into a binary file.
$ sam-ba -p serial -b sam9x60-ek -a serialflash -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
erase Command
The erase command erases (resets to 0xFF) a range of erase blocks in the external SPI NOR Flash memory. The size of the erase block depends on the target device (manufacturer and part number).
$ sam-ba -p serial -b sam9x60-ek -a serialflash -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
write and writeboot Command
The write and writeboot commands write data from a binary file into external SPI NOR Flash memory pages.
The blocks containing the pages to be written should be erased first with the erase command.
Padding bytes are added to align programmed data to the page boundary.
$ sam-ba -p serial -b sam9x60-ek -a serialflash -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
The writeboot command should only be used when programming a bootstrap file into an external SPI NOR Flash memory boot partition.
The writeboot command modifies the relevant unused ARM exception vector to store the size of the bootstrap binary, as required by the ROM Boot code during the boot process.
$ sam-ba -p serial -b sam9x60-ek -a serialflash -c writeboot:help
Syntax:
writeboot:<filename>
Example:
writeboot:bootstrap.bin write bootstrap.bin as boot program at start of memory
verify and verifyboot Command
The verify and verifyboot commands compare the data written into external SPI NOR Flash memory with the contents of a binary file.
$ sam-ba -p serial -b sam9x60-ek -a serialflash -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
The verifyboot command ignores the relevant unused ARM exception vector in the binary file.
$ sam-ba -p serial -b sam9x60-ek -a serialflash -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