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. |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 7 | |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 8 | |
| 9 | ## Usage Options |
| 10 | |
| 11 | There are two ways to use OpenTitan on the FPGA. |
Philipp Wagner | be2293d | 2019-10-24 17:21:27 +0100 | [diff] [blame] | 12 | - The first is to build the design from scratch using Vivado. |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 13 | Refer to the [Getting Started FPGA]({{< relref "doc/ug/getting_started_fpga" >}}) guide for more information. |
Philipp Wagner | be2293d | 2019-10-24 17:21:27 +0100 | [diff] [blame] | 14 | - The second is to program the FPGA with a released bitfile using storage devices. |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 15 | Refer to the [Quickstart Guide]({{< relref "doc/ug/quickstart" >}}) guide for instructions on this approach. |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 16 | |
| 17 | ## FPGA SW Development Flow |
| 18 | |
| 19 | The FPGA is meant for both boot ROM and general software development. |
| 20 | The 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 | |
| 24 | The FPGA bitstream is built after compiling whatever code is sitting in `sw/device/boot_rom`. |
| 25 | This binary is used to initialize internal FPGA memory and is part of the bitstream directly. |
| 26 | |
| 27 | To update this content without rebuilding the FPGA, a flow is required to splice a new boot ROM binary into the bitstream. |
| 28 | There are two prerequisites in order for this flow to work: |
Timothy Chen | 7fc62ce | 2019-10-22 11:27:01 -0700 | [diff] [blame] | 29 | * 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^] | 30 | * 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 Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 33 | |
| 34 | 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^] | 35 | 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] | 36 | |
| 37 | See example below: |
| 38 | |
| 39 | ```console |
| 40 | $ cd $REPO_TOP |
Pirmin Vogel | e2e24c9 | 2021-09-10 16:04:27 +0200 | [diff] [blame^] | 41 | $ ./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 Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 43 | ``` |
| 44 | |
Pirmin Vogel | e2e24c9 | 2021-09-10 16:04:27 +0200 | [diff] [blame^] | 45 | 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 [getting_started_fpga]({{< relref "doc/ug/getting_started_fpga" >}})). |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 46 | |
Pirmin Vogel | e2e24c9 | 2021-09-10 16:04:27 +0200 | [diff] [blame^] | 47 | The 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. |
| 48 | 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] | 49 | |
Pirmin Vogel | e2e24c9 | 2021-09-10 16:04:27 +0200 | [diff] [blame^] | 50 | 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] | 51 | |
| 52 | ### General Software Development |
| 53 | |
| 54 | After building, the FPGA bitstream contains only the boot ROM. |
| 55 | 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. |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 56 | To load additional software, a custom load tool named [spiflash]({{< relref "sw/host/spiflash/README.md" >}}) is required. |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 57 | |
| 58 | Once the tool is built, also build the binary you wish to load. |
| 59 | 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. |
| 60 | The example below builds the `hello_world` image and loads it onto the FPGA. |
| 61 | The loading output is also shown. |
| 62 | |
| 63 | ```console |
| 64 | $ cd ${REPO_TOP} |
Miguel Young de la Sota | 8ff30b8 | 2019-11-25 12:58:34 -0600 | [diff] [blame] | 65 | $ ./meson_init.sh |
Miguel Young de la Sota | 76526c3 | 2020-01-28 10:24:41 -0500 | [diff] [blame] | 66 | $ ninja -C build-out |
Michael Schaffner | 93fe50c | 2021-03-31 16:25:42 -0700 | [diff] [blame] | 67 | $ build-bin/sw/host/spiflash/spiflash \ |
Miguel Young de la Sota | 76526c3 | 2020-01-28 10:24:41 -0500 | [diff] [blame] | 68 | --input build-bin/sw/device/examples/hello_world/hello_world_fpga_nexysvideo.bin |
Timothy Chen | 9b4ff65 | 2019-10-21 12:50:30 -0700 | [diff] [blame] | 69 | |
| 70 | Running SPI flash update. |
| 71 | Image divided into 6 frames. |
| 72 | frame: 0x00000000 to offset: 0x00000000 |
| 73 | frame: 0x00000001 to offset: 0x000003d8 |
| 74 | frame: 0x00000002 to offset: 0x000007b0 |
| 75 | frame: 0x00000003 to offset: 0x00000b88 |
| 76 | frame: 0x00000004 to offset: 0x00000f60 |
| 77 | frame: 0x80000005 to offset: 0x00001338 |
| 78 | ``` |
| 79 | |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 80 | 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/boot_rom/README.md" >}}). |