blob: c3a1ab7692d0a85c271ff09e16c340ee082cd2d6 [file] [log] [blame] [view]
Garret Kelly9eebde02019-10-22 15:36:49 -04001---
2title: "Quickstart"
3---
4
Greg Chadwick573a7e32019-11-04 12:43:06 +00005## Install required packages
6
7To 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 Wagnerd4d65a12019-11-28 16:59:19 +000015* libelf1
Greg Chadwick573a7e32019-11-04 12:43:06 +000016
17Under Ubuntu these can be installed with:
18```console
Philipp Wagnerd4d65a12019-11-28 16:59:19 +000019$ sudo apt-get install xz-utils screen fdisk libftdi1-2 libusb-1.0-0 usbutils libelf1
Greg Chadwick573a7e32019-11-04 12:43:06 +000020```
21
Greg Chadwick7c2b7072019-11-01 14:41:13 +000022## Extract the release
23
Philipp Wagner14a3fee2019-11-21 10:07:02 +000024Download a release bitstream from the [OpenTitan GitHub Releases page](https://github.com/lowRISC/opentitan/releases) and extract it.
Greg Chadwick7c2b7072019-11-01 14:41:13 +000025`$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 Contributors802543a2019-08-31 12:12:56 +010033
34## Simulation with Verilator
35
Greg Chadwick7c2b7072019-11-01 14:41:13 +000036Run 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 Contributors802543a2019-08-31 12:12:56 +010040
Greg Chadwick7c2b7072019-11-01 14:41:13 +000041Simulation of OpenTitan Earl Grey
42=================================
43
44Tracing can be toggled by sending SIGUSR1 to this process:
45$ kill -USR1 19351
46
47Rom initialized with program at ./sw/device/sim/boot_rom/rom.vmem
48
49Flash initialized with program at ./sw/device/sim/examples/hello_world/sw.vmem
50
51GPIO: 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
53to observe the output.
54
55JTAG: Virtual JTAG interface jtag0 is listening on port 44853. Use
56OpenOCD and the following configuration to connect:
57 interface remote_bitbang
58 remote_bitbang_host localhost
59 remote_bitbang_port 44853
60
61SPI: Created /dev/pts/4 for spi0. Connect to it with any terminal program, e.g.
62$ screen /dev/pts/4
63NOTE: a SPI transaction is run for every 4 characters entered.
64SPI: 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
67UART: Created /dev/pts/6 for uart0. Connect to it with any terminal program, e.g.
68$ screen /dev/pts/6
69
70Simulation running, end by pressing CTRL-c.
71TOP.top_earlgrey_verilator.top_earlgrey.core.ibex_tracer_i: Writing execution trace to trace_core_00000000.log
72```
73
74Note the UART output will be available on `/dev/pts/N`, `/dev/pts/6` in this example.
75Use `cat` to view the UART output to see everything that has been output since simulation start.
lowRISC Contributors802543a2019-08-31 12:12:56 +010076
77```console
Greg Chadwick7c2b7072019-11-01 14:41:13 +000078$ cat /dev/pts/6
79Commit ID: 1d0d927693c2ef60d7880ab306beb25115a53dcb
80Build Date: 2019-11-01, 15:57:42
81Jump!
82Hello World! Nov 1 2019 15:57:49
83Watch the LEDs!
84Try out the switches on the board
85or type anything into the console window.
86The LEDs show the ASCII code of the last character.
lowRISC Contributors802543a2019-08-31 12:12:56 +010087```
88
Garret Kelly9eebde02019-10-22 15:36:49 -040089See the [Getting Started with Verilator Guide]({{< relref "getting_started_verilator.md" >}}) for more information.
lowRISC Contributors802543a2019-08-31 12:12:56 +010090
91## Running on an FPGA
92
Philipp Wagnerbe2293d2019-10-24 17:21:27 +010093Do you want to try out the design without installing EDA tools and waiting for a long build?
94Then you have come to the right place!
lowRISC Contributors802543a2019-08-31 12:12:56 +010095
Philipp Wagnerbe2293d2019-10-24 17:21:27 +010096You need the following things:
lowRISC Contributors802543a2019-08-31 12:12:56 +010097
Philipp Wagnerbe2293d2019-10-24 17:21:27 +010098* 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 Russoe76fadc2019-10-29 12:34:21 -0700100* An empty USB pen drive or microSD card (at least 16 MB)
101* `fdisk` utility installed on your machine.
lowRISC Contributors802543a2019-08-31 12:12:56 +0100102
Philipp Wagnerbe2293d2019-10-24 17:21:27 +0100103Once you have obtained these things, follow these steps to get started.
104
Ohad Russoe76fadc2019-10-29 12:34:21 -0700105### Prepare a storage device with the FPGA bitstream
Philipp Wagnerbe2293d2019-10-24 17:21:27 +0100106
Ohad Russoe76fadc2019-10-29 12:34:21 -0700107**Note**: you may need to be an admin on your machine in order to mount and format external storage devices.
108If you are, and some of the commands run into permission errors, run them in `sudo` mode.
109
Greg Chadwick7c2b7072019-11-01 14:41:13 +00001101. Insert microSD/USB pen to your machine.
1112. Run `fdisk -l` to find where the device was mapped.
Ohad Russoe76fadc2019-10-29 12:34:21 -0700112 See an example mapping below, where an SD device was mapped as */dev/mmcblk0p1*.
113
Greg Chadwick573a7e32019-11-04 12:43:06 +0000114 ```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 Russoe76fadc2019-10-29 12:34:21 -0700123
Greg Chadwick573a7e32019-11-04 12:43:06 +0000124 Device Boot Start End Sectors Size Id Type
125 /dev/mmcblk0p1 8192 31116287 31108096 14.9G c W95 FAT32 (LBA)
126 ```
Ohad Russoe76fadc2019-10-29 12:34:21 -0700127
Greg Chadwick7c2b7072019-11-01 14:41:13 +00001283. Format the device to *FAT32* format.
Greg Chadwick573a7e32019-11-04 12:43:06 +0000129 ```console
130 $ mkfs.fat -F 32 /dev/mmcblk0p1
Ohad Russoe76fadc2019-10-29 12:34:21 -0700131 ```
132
Greg Chadwick7c2b7072019-11-01 14:41:13 +00001334. Mount the device by running the following commands:
Ohad Russoe76fadc2019-10-29 12:34:21 -0700134
Greg Chadwick573a7e32019-11-04 12:43:06 +0000135 ```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 Russoe76fadc2019-10-29 12:34:21 -0700138 ```
139
Greg Chadwick7c2b7072019-11-01 14:41:13 +00001405. Make sure the device is empty. `ls ~/ot-img-mount` should not print anything.
1416. Copy the bit file image to the storage device.
Greg Chadwick573a7e32019-11-04 12:43:06 +0000142 ```console
143 $ cd $OT_TOP
144 $ cp hw/top_earlgrey/lowrisc_systems_top_earlgrey_nexysvideo_0.1.bit ~/ot-img-mount/
Ohad Russoe76fadc2019-10-29 12:34:21 -0700145 ```
146
Greg Chadwick7c2b7072019-11-01 14:41:13 +0000147For 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 Russoe76fadc2019-10-29 12:34:21 -0700149### Program the FPGA with a bitstream from the storage device
150
1511. 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 Chadwick7c2b7072019-11-01 14:41:13 +00001532. Place JP4 on the pins marked USB/SD.
1543. Place JP3 according to the selected device (marked either USB or SD).
Greg Chadwick573a7e32019-11-04 12:43:06 +00001554. Push the PROG button. The BUSY LED (LD14) should be steadily on.
1565. Wait for the BUSY LED to turn off, DONE (LD15) should turn on.
Ohad Russoe76fadc2019-10-29 12:34:21 -0700157
158### Run software on the FPGA
159
160**Note**: Your user account needs to have access to connected USB devices.
Greg Chadwick7c2b7072019-11-01 14:41:13 +0000161See [the section udev rules of the installation guide]({{< relref "install_instructions#device-permissions-udev-rules" >}}) for more details.
Ohad Russoe76fadc2019-10-29 12:34:21 -0700162
Greg Chadwick573a7e32019-11-04 12:43:06 +00001631. Connect a micro USB cable from your machine to the UART connector (J13) on Nexys Video board.
1642. Use `dmesg` to determine which serial port was assigned:
Ohad Russoe76fadc2019-10-29 12:34:21 -0700165
Greg Chadwick7c2b7072019-11-01 14:41:13 +0000166 ```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 Chadwick573a7e32019-11-04 12:43:06 +00001803. Open a serial console (use the device file determined before) and connect.
Ohad Russoe76fadc2019-10-29 12:34:21 -0700181 Settings: 230400 baud, 8N1, no hardware or software flow control.
Greg Chadwick573a7e32019-11-04 12:43:06 +0000182 `screen` needs to be installed first.
Ohad Russoe76fadc2019-10-29 12:34:21 -0700183
Greg Chadwick573a7e32019-11-04 12:43:06 +0000184 ```console
185 $ screen /dev/ttyUSB0 230400
Ohad Russoe76fadc2019-10-29 12:34:21 -0700186 ```
187
Greg Chadwick573a7e32019-11-04 12:43:06 +00001884. On the Nexys Video board, press the red button labeled CPU_RESET.
1895. Observe the terminal output, it should show a ROM boot message like this:
Ohad Russoe76fadc2019-10-29 12:34:21 -0700190
191 ```
Greg Chadwick7c2b7072019-11-01 14:41:13 +0000192 Commit ID: 1d0d927693c2ef60d7880ab306beb25115a53dcb
193 Build Date: 2019-11-01, 15:57:43
Ohad Russoe76fadc2019-10-29 12:34:21 -0700194 Jump!
195 ```
Greg Chadwick7c2b7072019-11-01 14:41:13 +0000196 (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 Chadwick573a7e32019-11-04 12:43:06 +00001976. 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).
1987. Use the `spiflash` tool to write the hello_world binary:
Greg Chadwick7c2b7072019-11-01 14:41:13 +0000199 ```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 Russoe76fadc2019-10-29 12:34:21 -0700214
Greg Chadwick7c2b7072019-11-01 14:41:13 +0000215 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 Chadwick573a7e32019-11-04 12:43:06 +00002268. The hello_world binary will output the following:
Greg Chadwick7c2b7072019-11-01 14:41:13 +0000227 ```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 Russoe76fadc2019-10-29 12:34:21 -0700235
Greg Chadwick7c2b7072019-11-01 14:41:13 +0000236 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 Russoe76fadc2019-10-29 12:34:21 -0700237
Greg Chadwick573a7e32019-11-04 12:43:06 +0000238To 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 Chadwick7c2b7072019-11-01 14:41:13 +0000239See the [Getting Started on FPGAs Guide]({{< relref "getting_started_fpga.md" >}}) for full instructions how to build your own bitstream.