Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 1 | --- |
| 2 | title: "Quickstart" |
| 3 | --- |
| 4 | |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 5 | ## Install required packages |
| 6 | |
| 7 | To follow the guide below the following things must be installed: |
| 8 | |
| 9 | * xz-utils |
| 10 | * screen |
| 11 | * fdisk |
| 12 | * libusb 1.x |
| 13 | * libftdi1 1.x |
| 14 | * usbutils |
Philipp Wagner | d4d65a1 | 2019-11-28 16:59:19 +0000 | [diff] [blame] | 15 | * libelf1 |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 16 | |
| 17 | Under Ubuntu these can be installed with: |
| 18 | ```console |
Philipp Wagner | d4d65a1 | 2019-11-28 16:59:19 +0000 | [diff] [blame] | 19 | $ sudo apt-get install xz-utils screen fdisk libftdi1-2 libusb-1.0-0 usbutils libelf1 |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 20 | ``` |
| 21 | |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 22 | ## Extract the release |
| 23 | |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 24 | Download a release bitstream from the [OpenTitan GitHub Releases page](https://github.com/lowRISC/opentitan/releases) and extract it. |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 25 | `$OT_TOP` refers to the location where it is extracted. |
| 26 | |
| 27 | ```console |
| 28 | $ mkdir -p $OT_TOP |
| 29 | $ tar -C $OT_TOP -xvf opentitan-snapshot-20191101-1.tar.xz --strip-components=1 |
| 30 | ``` |
| 31 | |
| 32 | (Replace opentitan-snapshot-20191101-1.tar.xz with the release you downloaded if you have downloaded a different version) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 33 | |
| 34 | ## Simulation with Verilator |
| 35 | |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 36 | Run the provided simulator binary with |
| 37 | ```console |
| 38 | $ cd $OT_TOP |
| 39 | $ ./hw/top_earlgrey/Vtop_earlgrey_verilator --rominit=./sw/device/sim/boot_rom/rom.vmem --flashinit=./sw/device/sim/examples/hello_world/sw.vmem |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 40 | |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 41 | Simulation of OpenTitan Earl Grey |
| 42 | ================================= |
| 43 | |
| 44 | Tracing can be toggled by sending SIGUSR1 to this process: |
| 45 | $ kill -USR1 19351 |
| 46 | |
| 47 | Rom initialized with program at ./sw/device/sim/boot_rom/rom.vmem |
| 48 | |
| 49 | Flash initialized with program at ./sw/device/sim/examples/hello_world/sw.vmem |
| 50 | |
| 51 | GPIO: FIFO pipe created at /home/greg/work/opentitan_builds/ot/gpio0 for 32 bit wide GPIO. Run |
| 52 | $ cat /home/greg/work/opentitan_builds/ot/gpio0 |
| 53 | to observe the output. |
| 54 | |
| 55 | JTAG: Virtual JTAG interface jtag0 is listening on port 44853. Use |
| 56 | OpenOCD and the following configuration to connect: |
| 57 | interface remote_bitbang |
| 58 | remote_bitbang_host localhost |
| 59 | remote_bitbang_port 44853 |
| 60 | |
| 61 | SPI: Created /dev/pts/4 for spi0. Connect to it with any terminal program, e.g. |
| 62 | $ screen /dev/pts/4 |
| 63 | NOTE: a SPI transaction is run for every 4 characters entered. |
| 64 | SPI: Monitor output file created at /home/greg/work/opentitan_builds/ot/spi0.log. Works well with tail: |
| 65 | $ tail -f /home/greg/work/opentitan_builds/ot/spi0.log |
| 66 | |
| 67 | UART: Created /dev/pts/6 for uart0. Connect to it with any terminal program, e.g. |
| 68 | $ screen /dev/pts/6 |
| 69 | |
| 70 | Simulation running, end by pressing CTRL-c. |
| 71 | TOP.top_earlgrey_verilator.top_earlgrey.core.ibex_tracer_i: Writing execution trace to trace_core_00000000.log |
| 72 | ``` |
| 73 | |
| 74 | Note the UART output will be available on `/dev/pts/N`, `/dev/pts/6` in this example. |
| 75 | Use `cat` to view the UART output to see everything that has been output since simulation start. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 76 | |
| 77 | ```console |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 78 | $ cat /dev/pts/6 |
| 79 | Commit ID: 1d0d927693c2ef60d7880ab306beb25115a53dcb |
| 80 | Build Date: 2019-11-01, 15:57:42 |
| 81 | Jump! |
| 82 | Hello World! Nov 1 2019 15:57:49 |
| 83 | Watch the LEDs! |
| 84 | Try out the switches on the board |
| 85 | or type anything into the console window. |
| 86 | The LEDs show the ASCII code of the last character. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 87 | ``` |
| 88 | |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 89 | See the [Getting Started with Verilator Guide]({{< relref "getting_started_verilator.md" >}}) for more information. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 90 | |
| 91 | ## Running on an FPGA |
| 92 | |
Philipp Wagner | be2293d | 2019-10-24 17:21:27 +0100 | [diff] [blame] | 93 | Do you want to try out the design without installing EDA tools and waiting for a long build? |
| 94 | Then you have come to the right place! |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 95 | |
Philipp Wagner | be2293d | 2019-10-24 17:21:27 +0100 | [diff] [blame] | 96 | You need the following things: |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 97 | |
Philipp Wagner | be2293d | 2019-10-24 17:21:27 +0100 | [diff] [blame] | 98 | * A [Nexys Video FPGA board](https://store.digilentinc.com/nexys-video-artix-7-fpga-trainer-board-for-multimedia-applications/) |
| 99 | (Unfortunately we do not provide presynthesized bitstreams for other FPGA boards right now.) |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 100 | * An empty USB pen drive or microSD card (at least 16 MB) |
| 101 | * `fdisk` utility installed on your machine. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 102 | |
Philipp Wagner | be2293d | 2019-10-24 17:21:27 +0100 | [diff] [blame] | 103 | Once you have obtained these things, follow these steps to get started. |
| 104 | |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 105 | ### Prepare a storage device with the FPGA bitstream |
Philipp Wagner | be2293d | 2019-10-24 17:21:27 +0100 | [diff] [blame] | 106 | |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 107 | **Note**: you may need to be an admin on your machine in order to mount and format external storage devices. |
| 108 | If you are, and some of the commands run into permission errors, run them in `sudo` mode. |
| 109 | |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 110 | 1. Insert microSD/USB pen to your machine. |
| 111 | 2. Run `fdisk -l` to find where the device was mapped. |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 112 | See an example mapping below, where an SD device was mapped as */dev/mmcblk0p1*. |
| 113 | |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 114 | ```console |
| 115 | $ fdisk -l |
| 116 | ... |
| 117 | Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors |
| 118 | Units: sectors of 1 * 512 = 512 bytes |
| 119 | Sector size (logical/physical): 512 bytes / 512 bytes |
| 120 | I/O size (minimum/optimal): 512 bytes / 512 bytes |
| 121 | Disklabel type: dos |
| 122 | Disk identifier: 0x00000000 |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 123 | |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 124 | Device Boot Start End Sectors Size Id Type |
| 125 | /dev/mmcblk0p1 8192 31116287 31108096 14.9G c W95 FAT32 (LBA) |
| 126 | ``` |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 127 | |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 128 | 3. Format the device to *FAT32* format. |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 129 | ```console |
| 130 | $ mkfs.fat -F 32 /dev/mmcblk0p1 |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 131 | ``` |
| 132 | |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 133 | 4. Mount the device by running the following commands: |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 134 | |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 135 | ```console |
| 136 | $ mkdir -p ~/ot-img-mount # Can be a different name |
| 137 | $ mount -t vfat /dev/mmcblk0p1 ~/ot-img-mount # Change according to mount/dev |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 138 | ``` |
| 139 | |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 140 | 5. Make sure the device is empty. `ls ~/ot-img-mount` should not print anything. |
| 141 | 6. Copy the bit file image to the storage device. |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 142 | ```console |
| 143 | $ cd $OT_TOP |
| 144 | $ cp hw/top_earlgrey/lowrisc_systems_top_earlgrey_nexysvideo_0.1.bit ~/ot-img-mount/ |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 145 | ``` |
| 146 | |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 147 | For more information on programming the Nexsys Video FPGA board refer to Section 2.3 of [Nexys Video reference manual](https://reference.digilentinc.com/_media/reference/programmable-logic/nexys-video/nexysvideo_rm.pdf). |
| 148 | |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 149 | ### Program the FPGA with a bitstream from the storage device |
| 150 | |
| 151 | 1. Connect the USB pen drive or the microSD card to the Nexys Video board. |
| 152 | The microSD slot sits on the bottom of the board and marked "SD MICRO", USB header is in the top and marked "USB HOST". |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 153 | 2. Place JP4 on the pins marked USB/SD. |
| 154 | 3. Place JP3 according to the selected device (marked either USB or SD). |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 155 | 4. Push the PROG button. The BUSY LED (LD14) should be steadily on. |
| 156 | 5. Wait for the BUSY LED to turn off, DONE (LD15) should turn on. |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 157 | |
| 158 | ### Run software on the FPGA |
| 159 | |
| 160 | **Note**: Your user account needs to have access to connected USB devices. |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 161 | See [the section udev rules of the installation guide]({{< relref "install_instructions#device-permissions-udev-rules" >}}) for more details. |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 162 | |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 163 | 1. Connect a micro USB cable from your machine to the UART connector (J13) on Nexys Video board. |
| 164 | 2. Use `dmesg` to determine which serial port was assigned: |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 165 | |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 166 | ```console |
| 167 | $ dmesg |
| 168 | [23426.869858] usb 1-3: new full-speed USB device number 27 using xhci_hcd |
| 169 | [23427.023299] usb 1-3: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00 |
| 170 | [23427.023301] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3 |
| 171 | [23427.023301] usb 1-3: Product: FT232R USB UART |
| 172 | [23427.023302] usb 1-3: Manufacturer: FTDI |
| 173 | [23427.023303] usb 1-3: SerialNumber: A503XQQS |
| 174 | [23427.026674] ftdi_sio 1-3:1.0: FTDI USB Serial Device converter detected |
| 175 | [23427.026691] usb 1-3: Detected FT232RL |
| 176 | [23427.027019] usb 1-3: FTDI USB Serial Device converter now attached to ttyUSB0 |
| 177 | ``` |
| 178 | |
| 179 | It should be named `/dev/ttyUSB*` in this example it is `/dev/ttyUSB0`. |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 180 | 3. Open a serial console (use the device file determined before) and connect. |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 181 | Settings: 230400 baud, 8N1, no hardware or software flow control. |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 182 | `screen` needs to be installed first. |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 183 | |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 184 | ```console |
| 185 | $ screen /dev/ttyUSB0 230400 |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 186 | ``` |
| 187 | |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 188 | 4. On the Nexys Video board, press the red button labeled CPU_RESET. |
| 189 | 5. Observe the terminal output, it should show a ROM boot message like this: |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 190 | |
| 191 | ``` |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 192 | Commit ID: 1d0d927693c2ef60d7880ab306beb25115a53dcb |
| 193 | Build Date: 2019-11-01, 15:57:43 |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 194 | Jump! |
| 195 | ``` |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 196 | (To exit `screen` press <kbd>CTRL</kbd>+<kbd>A</kbd> keys together, then press <kbd>K</kbd>, and then confirm exit by pressing <kbd>y</kbd>.) |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 197 | 6. Connect a micro USB cable from your machine to the PROG connector (J12) on the Nexsys Video board (noting you need to also have a connection to the UART connector to see serial output). |
| 198 | 7. Use the `spiflash` tool to write the hello_world binary: |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 199 | ```console |
| 200 | $ cd $OT_TOP |
| 201 | $ ./sw/host/spiflash/spiflash --input=sw/device/fpga/examples/hello_world/sw.bin |
| 202 | ``` |
| 203 | You should see output from the `spiflash` tool showing the progress: |
| 204 | ```console |
| 205 | Running SPI flash update. |
| 206 | Image divided into 6 frames. |
| 207 | frame: 0x00000000 to offset: 0x00000000 |
| 208 | frame: 0x00000001 to offset: 0x000003d8 |
| 209 | frame: 0x00000002 to offset: 0x000007b0 |
| 210 | frame: 0x00000003 to offset: 0x00000b88 |
| 211 | frame: 0x00000004 to offset: 0x00000f60 |
| 212 | frame: 0x80000005 to offset: 0x00001338 |
| 213 | ``` |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 214 | |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 215 | and matching output from the serial console from the boot rom loading the program: |
| 216 | ```console |
| 217 | Processing frame no: 00000000 exp no: 00000000 |
| 218 | Processing frame no: 00000001 exp no: 00000001 |
| 219 | Processing frame no: 00000002 exp no: 00000002 |
| 220 | Processing frame no: 00000003 exp no: 00000003 |
| 221 | Processing frame no: 00000004 exp no: 00000004 |
| 222 | Processing frame no: 80000005 exp no: 00000005 |
| 223 | bootstrap: DONE! |
| 224 | Jump! |
| 225 | ``` |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 226 | 8. The hello_world binary will output the following: |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 227 | ```console |
| 228 | Hello World! Oct 31 2019 16:28:03 |
| 229 | Watch the LEDs! |
| 230 | Try out the switches on the board |
| 231 | or type anything into the console window. |
| 232 | The LEDs show the ASCII code of the last character. |
| 233 | FTDI control changed. Enable JTAG |
| 234 | ``` |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 235 | |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 236 | Press some keys in the serial console and you should see the ASCII values of the characters sent shown in binary on the LEDs of the Nexsys Video FPGA board. |
Ohad Russo | e76fadc | 2019-10-29 12:34:21 -0700 | [diff] [blame] | 237 | |
Greg Chadwick | 573a7e3 | 2019-11-04 12:43:06 +0000 | [diff] [blame] | 238 | To build the software yourself follow the instructions in [Testing the demo design]({{< relref "getting_started_fpga.md#testing-the-demo-design" >}}) (note the software tools must be installed and a clone of the OpenTitan repository made, this is explained in the [Install Instructions]({{< relref "install_instructions" >}})). |
Greg Chadwick | 7c2b707 | 2019-11-01 14:41:13 +0000 | [diff] [blame] | 239 | See the [Getting Started on FPGAs Guide]({{< relref "getting_started_fpga.md" >}}) for full instructions how to build your own bitstream. |