Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 1 | --- |
| 2 | title: "FPGA Reference Manual" |
| 3 | --- |
| 4 | |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 5 | This manual provides additional usage details about the FPGA. |
Timothy Chen | a55ef66 | 2019-10-29 20:23:02 -0700 | [diff] [blame] | 6 | Specifically, it provides instructions on SW development flows and testing procedures. |
Jade Philipoom | 35f1fdb | 2022-03-21 22:42:34 +0000 | [diff] [blame] | 7 | Refer to the [FPGA Setup]({{< relref "doc/getting_started/setup_fpga" >}}) guide for more information on initial setup. |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 8 | |
| 9 | ## FPGA SW Development Flow |
| 10 | |
| 11 | The FPGA is meant for both boot ROM and general software development. |
| 12 | The 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 Trippel | 961b2cd | 2021-12-14 22:28:58 +0000 | [diff] [blame] | 16 | The FPGA bitstream is built after compiling whatever code is sitting in `sw/device/lib/testing/test_rom`. |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 17 | This binary is used to initialize internal FPGA memory and is part of the bitstream directly. |
| 18 | |
| 19 | To update this content without rebuilding the FPGA, a flow is required to splice a new boot ROM binary into the bitstream. |
| 20 | There are two prerequisites in order for this flow to work: |
Timothy Chen | 7fc62ce | 2019-10-22 11:27:01 -0700 | [diff] [blame] | 21 | * The boot ROM during the build process must be correctly inferred by the tool. |
Pirmin Vogel | e2e24c9 | 2021-09-10 16:04:27 +0200 | [diff] [blame] | 22 | * 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 Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 25 | |
| 26 | With these steps in place, a script can be invoked to take a new binary and push its contents into an existing bitfile. |
Pirmin Vogel | e2e24c9 | 2021-09-10 16:04:27 +0200 | [diff] [blame] | 27 | For details, please see the [`splice_rom.sh`](https://github.com/lowRISC/opentitan/blob/master/util/fpga/splice_rom.sh) script. |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 28 | |
| 29 | See example below: |
| 30 | |
| 31 | ```console |
| 32 | $ cd $REPO_TOP |
Pirmin Vogel | e2e24c9 | 2021-09-10 16:04:27 +0200 | [diff] [blame] | 33 | $ ./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 Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 35 | ``` |
| 36 | |
Jade Philipoom | 35f1fdb | 2022-03-21 22:42:34 +0000 | [diff] [blame] | 37 | The 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 Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 38 | |
Timothy Trippel | 961b2cd | 2021-12-14 22:28:58 +0000 | [diff] [blame] | 39 | The 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 Vogel | e2e24c9 | 2021-09-10 16:04:27 +0200 | [diff] [blame] | 40 | The 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 Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 41 | |
Pirmin Vogel | e2e24c9 | 2021-09-10 16:04:27 +0200 | [diff] [blame] | 42 | The `cw310_loader.py` can then be used to directly flash the updated bitstream to the FPGA. |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 43 | |
| 44 | ### General Software Development |
| 45 | |
| 46 | After building, the FPGA bitstream contains only the boot ROM. |
| 47 | Using 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 Vogel | d3b26c3 | 2021-09-08 23:04:03 +0200 | [diff] [blame] | 48 | To load additional software, the `cw310_loader.py` is required. |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 49 | |
Pirmin Vogel | d3b26c3 | 2021-09-08 23:04:03 +0200 | [diff] [blame] | 50 | Also the binary you wish to load needs to be built first. |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 51 | For 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. |
| 52 | The example below builds the `hello_world` image and loads it onto the FPGA. |
| 53 | The loading output is also shown. |
| 54 | |
| 55 | ```console |
| 56 | $ cd ${REPO_TOP} |
Miguel Young de la Sota | 8ff30b8 | 2019-11-25 12:58:34 -0600 | [diff] [blame] | 57 | $ ./meson_init.sh |
Pirmin Vogel | d3b26c3 | 2021-09-08 23:04:03 +0200 | [diff] [blame] | 58 | $ 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 Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 60 | |
Pirmin Vogel | d3b26c3 | 2021-09-08 23:04:03 +0200 | [diff] [blame] | 61 | CW310 Loader: Attemping to find CW310 FPGA Board: |
| 62 | No bitstream specified |
| 63 | CW310 Board Found: |
| 64 | INFO: Programming firmware file: build-bin/sw/device/examples/hello_world/hello_world_fpga_cw310.bin |
| 65 | Programming OpenTitan with "build-bin/sw/device/examples/hello_world/hello_world_fpga_cw310.bin"... |
| 66 | Transferring frame 0x00000000 @ 0x00000000. |
| 67 | Transferring frame 0x00000001 @ 0x000007D8. |
| 68 | Transferring frame 0x00000002 @ 0x00000FB0. |
| 69 | Transferring frame 0x00000003 @ 0x00001788. |
| 70 | Transferring frame 0x00000004 @ 0x00001F60. |
| 71 | Transferring frame 0x00000005 @ 0x00002738. |
| 72 | Transferring frame 0x80000006 @ 0x00002F10. |
| 73 | Loading done. |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 74 | ``` |
| 75 | |
Timothy Trippel | 961b2cd | 2021-12-14 22:28:58 +0000 | [diff] [blame] | 76 | For 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" >}}). |