blob: 984aa903e918c97ab4b59f055ab98b61270183ec [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.
Jade Philipoom35f1fdb2022-03-21 22:42:34 +00007Refer to the [FPGA Setup]({{< relref "doc/getting_started/setup_fpga" >}}) guide for more information on initial setup.
Timothy Chen9b4ff652019-10-21 12:50:30 -07008
9## FPGA SW Development Flow
10
11The FPGA is meant for both boot ROM and general software development.
12The flow for each is different, as the boot ROM is meant to be fairly static while general software can change very frequently.
13
14### Boot ROM development
15
Timothy Trippel961b2cd2021-12-14 22:28:58 +000016The FPGA bitstream is built after compiling whatever code is sitting in `sw/device/lib/testing/test_rom`.
Timothy Chen9b4ff652019-10-21 12:50:30 -070017This binary is used to initialize internal FPGA memory and is part of the bitstream directly.
18
19To update this content without rebuilding the FPGA, a flow is required to splice a new boot ROM binary into the bitstream.
20There are two prerequisites in order for this flow to work:
Timothy Chen7fc62ce2019-10-22 11:27:01 -070021* The boot ROM during the build process must be correctly inferred by the tool.
Pirmin Vogele2e24c92021-09-10 16:04:27 +020022 * 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).
23* The MMI file outlining the physical boot ROM placement and mapping to FPGA block RAM primitives needs to be generated by the tool.
24 * 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 -070025
26With 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 +020027For 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 -070028
29See example below:
30
31```console
32$ cd $REPO_TOP
Pirmin Vogele2e24c92021-09-10 16:04:27 +020033$ ./util/fpga/splice_rom.sh
34$ ./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 -070035```
36
Jade Philipoom35f1fdb2022-03-21 22:42:34 +000037The 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 [FPGA Setup]({{< relref "doc/getting_started/setup_fpga" >}})).
Timothy Chen9b4ff652019-10-21 12:50:30 -070038
Timothy Trippel961b2cd2021-12-14 22:28:58 +000039The script assumes that there is an existing boot ROM image under `build-bin/sw/device/lib/testing/test_rom` and then creates a new bitfile of the same name at the same location.
Pirmin Vogele2e24c92021-09-10 16:04:27 +020040The 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 -070041
Pirmin Vogele2e24c92021-09-10 16:04:27 +020042The `cw310_loader.py` can then be used to directly flash the updated bitstream to the FPGA.
Timothy Chen9b4ff652019-10-21 12:50:30 -070043
44### General Software Development
45
46After building, the FPGA bitstream contains only the boot ROM.
47Using 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.
Pirmin Vogeld3b26c32021-09-08 23:04:03 +020048To load additional software, the `cw310_loader.py` is required.
Timothy Chen9b4ff652019-10-21 12:50:30 -070049
Pirmin Vogeld3b26c32021-09-08 23:04:03 +020050Also the binary you wish to load needs to be built first.
Timothy Chen9b4ff652019-10-21 12:50:30 -070051For 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.
52The example below builds the `hello_world` image and loads it onto the FPGA.
53The loading output is also shown.
54
55```console
56$ cd ${REPO_TOP}
Miguel Young de la Sota8ff30b82019-11-25 12:58:34 -060057$ ./meson_init.sh
Pirmin Vogeld3b26c32021-09-08 23:04:03 +020058$ ninja -C build-out sw/device/examples/hello_world/hello_world_export_fpga_cw310
59$ ./util/fpga/cw310_loader.py --firmware build-bin/sw/device/examples/hello_world/hello_world_fpga_cw310.bin
Timothy Chen9b4ff652019-10-21 12:50:30 -070060
Pirmin Vogeld3b26c32021-09-08 23:04:03 +020061CW310 Loader: Attemping to find CW310 FPGA Board:
62 No bitstream specified
63CW310 Board Found:
64INFO: Programming firmware file: build-bin/sw/device/examples/hello_world/hello_world_fpga_cw310.bin
65Programming OpenTitan with "build-bin/sw/device/examples/hello_world/hello_world_fpga_cw310.bin"...
66Transferring frame 0x00000000 @ 0x00000000.
67Transferring frame 0x00000001 @ 0x000007D8.
68Transferring frame 0x00000002 @ 0x00000FB0.
69Transferring frame 0x00000003 @ 0x00001788.
70Transferring frame 0x00000004 @ 0x00001F60.
71Transferring frame 0x00000005 @ 0x00002738.
72Transferring frame 0x80000006 @ 0x00002F10.
73Loading done.
Timothy Chen9b4ff652019-10-21 12:50:30 -070074```
75
Timothy Trippel961b2cd2021-12-14 22:28:58 +000076For 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/lib/testing/test_rom/README.md" >}}).