tree: aff69bc2a3dacacda3274be2ab4c0774abf9a11a [path history] [tgz]
  1. .gitignore
  2. ftdi_spi_interface.cc
  3. ftdi_spi_interface.h
  4. Makefile
  5. meson.build
  6. README.md
  7. spi_interface.h
  8. spiflash.cc
  9. updater.cc
  10. updater.h
  11. verilator_spi_interface.cc
  12. verilator_spi_interface.h
sw/host/spiflash/README.md

SPI Flash

spiflash is a tool used to update the firmware stored in OpenTitan's embedded flash. The tool resets OpenTitan and signals the boot ROM to enter bootstrap mode before sending the update payload.

Currently, the tool supports both Verilator and FPGA targets.

Build instructions for spiflash tool

spiflash is written in C++14.

Required packages:

$ sudo apt-get install libssl-dev libftdi1-dev

Build command for tool:

$ cd ${REPO_TOP}
$ ./meson-init.sh -r
$ ninja -C build-fpga sw/host/spiflash/spiflash

Setup instructions for Verilator and FPGA

Please refer to [verilator]({{< relref “doc/ug/getting_started_verilator” >}}) and [fpga]({{< relref “doc/ug/getting_started_fpga” >}}) docs for more information.

Build boot ROM and demo program

If building for verilator, build in build-verilator instead.

Build boot_rom:

$ cd ${REPO_TOP}
$ ninja -C build-fpga sw/boot_rom/boot_rom.vmem

Build the hello_world program:

$ cd ${REPO_TOP}
$ ninja -C build-fpga sw/examples/hello_world/hello_world.bin

Run the tool in Verilator

Run Verilator with boot_rom enabled:

$ cd ${REPO_TOP}
$ build/lowrisc_systems_top_earlgrey_verilator_0.1/sim-verilator/Vtop_earlgrey_verilator \
  --rominit=build-verilator/sw/boot_rom/boot_rom.vmem

Run spiflash. In this example we use SPI device /dev/pts/3 as an example. After the transmission is complete, you should be able to see the hello_world output in the UART console.

$ cd ${REPO_TOP}
$ build-verilator/sw/host/spiflash/spiflash \
  --input=build-verilator/sw/examples/hello_world/hello_world.bin \
  --verilator=/dev/pts/3

Run the tool in FPGA

To run spiflash for an FPGA, the instructions are similar. There is no requirement to enable the FPGA with ROM. Note, for FPGA, the tool simply searches for a valid interface to attach. If there are two FPGAs or multiple valid targets attached at the same time, it is possible for the tool to connect to the incorrect device.

$ cd ${REPO_TOP}
$ build-fpga/sw/host/spiflash/spiflash \
  --input=build-fpga/sw/examples/hello_world/hello_world.bin