blob: e05fcfda296ebdf97e6397e55ccb7a135a6c23d3 [file] [log] [blame] [view]
Garret Kelly9eebde02019-10-22 15:36:49 -04001---
2title: "FPGA Reference Manual"
3---
4
Timothy Chen9b4ff652019-10-21 12:50:30 -07005This manual provides additional usage details about the FPGA.
Timothy Chena55ef662019-10-29 20:23:02 -07006Specifically, it provides instructions on SW development flows and testing procedures.
Timothy Chen9b4ff652019-10-21 12:50:30 -07007
Timothy Chen9b4ff652019-10-21 12:50:30 -07008
9## Usage Options
10
11There are two ways to use OpenTitan on the FPGA.
Philipp Wagnerbe2293d2019-10-24 17:21:27 +010012- The first is to build the design from scratch using Vivado.
Garret Kelly9eebde02019-10-22 15:36:49 -040013 Refer to the [Getting Started FPGA]({{< relref "doc/ug/getting_started_fpga" >}}) guide for more information.
Philipp Wagnerbe2293d2019-10-24 17:21:27 +010014- The second is to program the FPGA with a released bitfile using storage devices.
Garret Kelly9eebde02019-10-22 15:36:49 -040015 Refer to the [Quickstart Guide]({{< relref "doc/ug/quickstart" >}}) guide for instructions on this approach.
Timothy Chen9b4ff652019-10-21 12:50:30 -070016
17## FPGA SW Development Flow
18
19The FPGA is meant for both boot ROM and general software development.
20The flow for each is different, as the boot ROM is meant to be fairly static while general software can change very frequently.
21
22### Boot ROM development
23
24The FPGA bitstream is built after compiling whatever code is sitting in `sw/device/boot_rom`.
25This binary is used to initialize internal FPGA memory and is part of the bitstream directly.
26
27To update this content without rebuilding the FPGA, a flow is required to splice a new boot ROM binary into the bitstream.
28There are two prerequisites in order for this flow to work:
Timothy Chen7fc62ce2019-10-22 11:27:01 -070029* The boot ROM during the build process must be correctly inferred by the tool.
Pirmin Vogele2e24c92021-09-10 16:04:27 +020030 * See [prim_rom](https://github.com/lowRISC/opentitan/blob/master/hw/ip/prim_generic/rtl/prim_generic_rom.sv) and [vivado_hook_opt_design_post.tcl](https://github.com/lowRISC/opentitan/blob/master/hw/top_earlgrey/util/vivado_hook_opt_design_post.tcl).
31* The MMI file outlining the physical boot ROM placement and mapping to FPGA block RAM primitives needs to be generated by the tool.
32 * See [vivado_hook_write_bitstream_pre.tcl](https://github.com/lowRISC/opentitan/blob/master/hw/top_earlgrey/util/vivado_hook_write_bitstream_pre.tcl).
Timothy Chen9b4ff652019-10-21 12:50:30 -070033
34With these steps in place, a script can be invoked to take a new binary and push its contents into an existing bitfile.
Pirmin Vogele2e24c92021-09-10 16:04:27 +020035For details, please see the [`splice_rom.sh`](https://github.com/lowRISC/opentitan/blob/master/util/fpga/splice_rom.sh) script.
Timothy Chen9b4ff652019-10-21 12:50:30 -070036
37See example below:
38
39```console
40$ cd $REPO_TOP
Pirmin Vogele2e24c92021-09-10 16:04:27 +020041$ ./util/fpga/splice_rom.sh
42$ ./util/fpga/cw310_loader.py --bitstream build/lowrisc_systems_chip_earlgrey_cw310_0.1/synth-vivado/lowrisc_systems_chip_earlgrey_cw310_0.1.bit
Timothy Chen9b4ff652019-10-21 12:50:30 -070043```
44
Pirmin Vogele2e24c92021-09-10 16:04:27 +020045The script assumes that there is an existing bitfile `build/lowrisc_systems_chip_earlgrey_cw310_0.1/synth-vivado/lowrisc_systems_chip_earlgrey_cw310_0.1.bit` (this is created after following the steps in [getting_started_fpga]({{< relref "doc/ug/getting_started_fpga" >}})).
Timothy Chen9b4ff652019-10-21 12:50:30 -070046
Pirmin Vogele2e24c92021-09-10 16:04:27 +020047The script assumes that there is an existing boot ROM image under `build-bin/sw/device/boot_rom` and then creates a new bitfile of the same name at the same location.
48The original input bitfile is moved to `build/lowrisc_systems_chip_earlgrey_cw310_0.1/synth-vivado/lowrisc_systems_chip_earlgrey_cw310_0.1.bit.orig`.
Timothy Chen9b4ff652019-10-21 12:50:30 -070049
Pirmin Vogele2e24c92021-09-10 16:04:27 +020050The `cw310_loader.py` can then be used to directly flash the updated bitstream to the FPGA.
Timothy Chen9b4ff652019-10-21 12:50:30 -070051
52### General Software Development
53
54After building, the FPGA bitstream contains only the boot ROM.
55Using this boot ROM, the FPGA is able to load additional software to the emulated flash, such as software in the `sw/device/benchmark`, `sw/device/examples` and `sw/device/tests` directories.
Garret Kelly9eebde02019-10-22 15:36:49 -040056To load additional software, a custom load tool named [spiflash]({{< relref "sw/host/spiflash/README.md" >}}) is required.
Timothy Chen9b4ff652019-10-21 12:50:30 -070057
58Once the tool is built, also build the binary you wish to load.
59For the purpose of this demonstration, we will use `sw/device/examples/hello_world`, but it applies to any software image that is able to fit in the emulated flash space.
60The example below builds the `hello_world` image and loads it onto the FPGA.
61The loading output is also shown.
62
63```console
64$ cd ${REPO_TOP}
Miguel Young de la Sota8ff30b82019-11-25 12:58:34 -060065$ ./meson_init.sh
Miguel Young de la Sota76526c32020-01-28 10:24:41 -050066$ ninja -C build-out
Michael Schaffner93fe50c2021-03-31 16:25:42 -070067$ build-bin/sw/host/spiflash/spiflash \
Miguel Young de la Sota76526c32020-01-28 10:24:41 -050068 --input build-bin/sw/device/examples/hello_world/hello_world_fpga_nexysvideo.bin
Timothy Chen9b4ff652019-10-21 12:50:30 -070069
70Running SPI flash update.
71Image divided into 6 frames.
72frame: 0x00000000 to offset: 0x00000000
73frame: 0x00000001 to offset: 0x000003d8
74frame: 0x00000002 to offset: 0x000007b0
75frame: 0x00000003 to offset: 0x00000b88
76frame: 0x00000004 to offset: 0x00000f60
77frame: 0x80000005 to offset: 0x00001338
78```
79
Garret Kelly9eebde02019-10-22 15:36:49 -040080For more details on the exact operation of the loading flow and how the boot ROM processes incoming data, please refer to the [boot ROM readme]({{< relref "sw/device/boot_rom/README.md" >}}).