xref: /qemu/docs/system/riscv/sifive_u.rst (revision 01153d2b606ccef3414cbedd3309e7c965902b6b)
1*01153d2bSBin MengSiFive HiFive Unleashed (``sifive_u``)
2*01153d2bSBin Meng======================================
3*01153d2bSBin Meng
4*01153d2bSBin MengSiFive HiFive Unleashed Development Board is the ultimate RISC-V development
5*01153d2bSBin Mengboard featuring the Freedom U540 multi-core RISC-V processor.
6*01153d2bSBin Meng
7*01153d2bSBin MengSupported devices
8*01153d2bSBin Meng-----------------
9*01153d2bSBin Meng
10*01153d2bSBin MengThe ``sifive_u`` machine supports the following devices:
11*01153d2bSBin Meng
12*01153d2bSBin Meng * 1 E51 / E31 core
13*01153d2bSBin Meng * Up to 4 U54 / U34 cores
14*01153d2bSBin Meng * Core Level Interruptor (CLINT)
15*01153d2bSBin Meng * Platform-Level Interrupt Controller (PLIC)
16*01153d2bSBin Meng * Power, Reset, Clock, Interrupt (PRCI)
17*01153d2bSBin Meng * L2 Loosely Integrated Memory (L2-LIM)
18*01153d2bSBin Meng * DDR memory controller
19*01153d2bSBin Meng * 2 UARTs
20*01153d2bSBin Meng * 1 GEM Ethernet controller
21*01153d2bSBin Meng * 1 GPIO controller
22*01153d2bSBin Meng * 1 One-Time Programmable (OTP) memory with stored serial number
23*01153d2bSBin Meng * 1 DMA controller
24*01153d2bSBin Meng * 2 QSPI controllers
25*01153d2bSBin Meng * 1 ISSI 25WP256 flash
26*01153d2bSBin Meng * 1 SD card in SPI mode
27*01153d2bSBin Meng
28*01153d2bSBin MengPlease note the real world HiFive Unleashed board has a fixed configuration of
29*01153d2bSBin Meng1 E51 core and 4 U54 core combination and the RISC-V core boots in 64-bit mode.
30*01153d2bSBin MengWith QEMU, one can create a machine with 1 E51 core and up to 4 U54 cores. It
31*01153d2bSBin Mengis also possible to create a 32-bit variant with the same peripherals except
32*01153d2bSBin Mengthat the RISC-V cores are replaced by the 32-bit ones (E31 and U34), to help
33*01153d2bSBin Mengtesting of 32-bit guest software.
34*01153d2bSBin Meng
35*01153d2bSBin MengHardware configuration information
36*01153d2bSBin Meng----------------------------------
37*01153d2bSBin Meng
38*01153d2bSBin MengThe ``sifive_u`` machine automatically generates a device tree blob ("dtb")
39*01153d2bSBin Mengwhich it passes to the guest. This provides information about the addresses,
40*01153d2bSBin Menginterrupt lines and other configuration of the various devices in the system.
41*01153d2bSBin MengGuest software should discover the devices that are present in the generated
42*01153d2bSBin MengDTB instead of using a DTB for the real hardware, as some of the devices are
43*01153d2bSBin Mengnot modeled by QEMU and trying to access these devices may cause unexpected
44*01153d2bSBin Mengbehavior.
45*01153d2bSBin Meng
46*01153d2bSBin MengBoot options
47*01153d2bSBin Meng------------
48*01153d2bSBin Meng
49*01153d2bSBin MengThe ``sifive_u`` machine can start using the standard -kernel functionality
50*01153d2bSBin Mengfor loading a Linux kernel, a VxWorks kernel, a modified U-Boot bootloader
51*01153d2bSBin Meng(S-mode) or ELF executable with the default OpenSBI firmware image as the
52*01153d2bSBin Meng-bios. It also supports booting the unmodified U-Boot bootloader using the
53*01153d2bSBin Mengstandard -bios functionality.
54*01153d2bSBin Meng
55*01153d2bSBin MengMachine-specific options
56*01153d2bSBin Meng------------------------
57*01153d2bSBin Meng
58*01153d2bSBin MengThe following machine-specific options are supported:
59*01153d2bSBin Meng
60*01153d2bSBin Meng- serial=nnn
61*01153d2bSBin Meng
62*01153d2bSBin Meng  The board serial number. When not given, the default serial number 1 is used.
63*01153d2bSBin Meng
64*01153d2bSBin Meng  SiFive reserves the first 1 KiB of the 16 KiB OTP memory for internal use.
65*01153d2bSBin Meng  The current usage is only used to store the serial number of the board at
66*01153d2bSBin Meng  offset 0xfc. U-Boot reads the serial number from the OTP memory, and uses
67*01153d2bSBin Meng  it to generate a unique MAC address to be programmed to the on-chip GEM
68*01153d2bSBin Meng  Ethernet controller. When multiple QEMU ``sifive_u`` machines are created
69*01153d2bSBin Meng  and connected to the same subnet, they all have the same MAC address hence
70*01153d2bSBin Meng  it creates an unusable network. In such scenario, user should give different
71*01153d2bSBin Meng  values to serial= when creating different ``sifive_u`` machines.
72*01153d2bSBin Meng
73*01153d2bSBin Meng- start-in-flash
74*01153d2bSBin Meng
75*01153d2bSBin Meng  When given, QEMU's ROM codes jump to QSPI memory-mapped flash directly.
76*01153d2bSBin Meng  Otherwise QEMU will jump to DRAM or L2LIM depending on the msel= value.
77*01153d2bSBin Meng  When not given, it defaults to direct DRAM booting.
78*01153d2bSBin Meng
79*01153d2bSBin Meng- msel=[6|11]
80*01153d2bSBin Meng
81*01153d2bSBin Meng  Mode Select (MSEL[3:0]) pins value, used to control where to boot from.
82*01153d2bSBin Meng
83*01153d2bSBin Meng  The FU540 SoC supports booting from several sources, which are controlled
84*01153d2bSBin Meng  using the Mode Select pins on the chip. Typically, the boot process runs
85*01153d2bSBin Meng  through several stages before it begins execution of user-provided programs.
86*01153d2bSBin Meng  These stages typically include the following:
87*01153d2bSBin Meng
88*01153d2bSBin Meng  1. Zeroth Stage Boot Loader (ZSBL), which is contained in an on-chip mask
89*01153d2bSBin Meng     ROM and provided by QEMU. Note QEMU implemented ROM codes are not the
90*01153d2bSBin Meng     same as what is programmed in the hardware. The QEMU one is a simplified
91*01153d2bSBin Meng     version, but it provides the same functionality as the hardware.
92*01153d2bSBin Meng  2. First Stage Boot Loader (FSBL), which brings up PLLs and DDR memory.
93*01153d2bSBin Meng     This is U-Boot SPL.
94*01153d2bSBin Meng  3. Second Stage Boot Loader (SSBL), which further initializes additional
95*01153d2bSBin Meng     peripherals as needed. This is U-Boot proper combined with an OpenSBI
96*01153d2bSBin Meng     fw_dynamic firmware image.
97*01153d2bSBin Meng
98*01153d2bSBin Meng  msel=6 means FSBL and SSBL are both on the QSPI flash. msel=11 means FSBL
99*01153d2bSBin Meng  and SSBL are both on the SD card.
100*01153d2bSBin Meng
101*01153d2bSBin MengRunning Linux kernel
102*01153d2bSBin Meng--------------------
103*01153d2bSBin Meng
104*01153d2bSBin MengLinux mainline v5.10 release is tested at the time of writing. To build a
105*01153d2bSBin MengLinux mainline kernel that can be booted by the ``sifive_u`` machine in
106*01153d2bSBin Meng64-bit mode, simply configure the kernel using the defconfig configuration:
107*01153d2bSBin Meng
108*01153d2bSBin Meng.. code-block:: bash
109*01153d2bSBin Meng
110*01153d2bSBin Meng  $ export ARCH=riscv
111*01153d2bSBin Meng  $ export CROSS_COMPILE=riscv64-linux-
112*01153d2bSBin Meng  $ make defconfig
113*01153d2bSBin Meng  $ make
114*01153d2bSBin Meng
115*01153d2bSBin MengTo boot the newly built Linux kernel in QEMU with the ``sifive_u`` machine:
116*01153d2bSBin Meng
117*01153d2bSBin Meng.. code-block:: bash
118*01153d2bSBin Meng
119*01153d2bSBin Meng  $ qemu-system-riscv64 -M sifive_u -smp 5 -m 2G \
120*01153d2bSBin Meng      -display none -serial stdio \
121*01153d2bSBin Meng      -kernel arch/riscv/boot/Image \
122*01153d2bSBin Meng      -initrd /path/to/rootfs.ext4 \
123*01153d2bSBin Meng      -append "root=/dev/ram"
124*01153d2bSBin Meng
125*01153d2bSBin MengTo build a Linux mainline kernel that can be booted by the ``sifive_u`` machine
126*01153d2bSBin Mengin 32-bit mode, use the rv32_defconfig configuration. A patch is required to
127*01153d2bSBin Mengfix the 32-bit boot issue for Linux kernel v5.10.
128*01153d2bSBin Meng
129*01153d2bSBin Meng.. code-block:: bash
130*01153d2bSBin Meng
131*01153d2bSBin Meng  $ export ARCH=riscv
132*01153d2bSBin Meng  $ export CROSS_COMPILE=riscv64-linux-
133*01153d2bSBin Meng  $ curl https://patchwork.kernel.org/project/linux-riscv/patch/20201219001356.2887782-1-atish.patra@wdc.com/mbox/ > riscv.patch
134*01153d2bSBin Meng  $ git am riscv.patch
135*01153d2bSBin Meng  $ make rv32_defconfig
136*01153d2bSBin Meng  $ make
137*01153d2bSBin Meng
138*01153d2bSBin MengReplace ``qemu-system-riscv64`` with ``qemu-system-riscv32`` in the command
139*01153d2bSBin Mengline above to boot the 32-bit Linux kernel. A rootfs image containing 32-bit
140*01153d2bSBin Mengapplications shall be used in order for kernel to boot to user space.
141*01153d2bSBin Meng
142*01153d2bSBin MengRunning VxWorks kernel
143*01153d2bSBin Meng----------------------
144*01153d2bSBin Meng
145*01153d2bSBin MengVxWorks 7 SR0650 release is tested at the time of writing. To build a 64-bit
146*01153d2bSBin MengVxWorks mainline kernel that can be booted by the ``sifive_u`` machine, simply
147*01153d2bSBin Mengcreate a VxWorks source build project based on the sifive_generic BSP, and a
148*01153d2bSBin MengVxWorks image project to generate the bootable VxWorks image, by following the
149*01153d2bSBin MengBSP documentation instructions.
150*01153d2bSBin Meng
151*01153d2bSBin MengA pre-built 64-bit VxWorks 7 image for HiFive Unleashed board is available as
152*01153d2bSBin Mengpart of the VxWorks SDK for testing as well. Instructions to download the SDK:
153*01153d2bSBin Meng
154*01153d2bSBin Meng.. code-block:: bash
155*01153d2bSBin Meng
156*01153d2bSBin Meng  $ wget https://labs.windriver.com/downloads/wrsdk-vxworks7-sifive-hifive-1.01.tar.bz2
157*01153d2bSBin Meng  $ tar xvf wrsdk-vxworks7-sifive-hifive-1.01.tar.bz2
158*01153d2bSBin Meng  $ ls bsps/sifive_generic_1_0_0_0/uboot/uVxWorks
159*01153d2bSBin Meng
160*01153d2bSBin MengTo boot the VxWorks kernel in QEMU with the ``sifive_u`` machine, use:
161*01153d2bSBin Meng
162*01153d2bSBin Meng.. code-block:: bash
163*01153d2bSBin Meng
164*01153d2bSBin Meng  $ qemu-system-riscv64 -M sifive_u -smp 5 -m 2G \
165*01153d2bSBin Meng      -display none -serial stdio \
166*01153d2bSBin Meng      -nic tap,ifname=tap0,script=no,downscript=no \
167*01153d2bSBin Meng      -kernel /path/to/vxWorks \
168*01153d2bSBin Meng      -append "gem(0,0)host:vxWorks h=192.168.200.1 e=192.168.200.2:ffffff00 u=target pw=vxTarget f=0x01"
169*01153d2bSBin Meng
170*01153d2bSBin MengIt is also possible to test 32-bit VxWorks on the ``sifive_u`` machine. Create
171*01153d2bSBin Menga 32-bit project to build the 32-bit VxWorks image, and use exact the same
172*01153d2bSBin Mengcommand line options with ``qemu-system-riscv32``.
173*01153d2bSBin Meng
174*01153d2bSBin MengRunning U-Boot
175*01153d2bSBin Meng--------------
176*01153d2bSBin Meng
177*01153d2bSBin MengU-Boot mainline v2021.01 release is tested at the time of writing. To build a
178*01153d2bSBin MengU-Boot mainline bootloader that can be booted by the ``sifive_u`` machine, use
179*01153d2bSBin Mengthe sifive_fu540_defconfig with similar commands as described above for Linux:
180*01153d2bSBin Meng
181*01153d2bSBin Meng.. code-block:: bash
182*01153d2bSBin Meng
183*01153d2bSBin Meng  $ export CROSS_COMPILE=riscv64-linux-
184*01153d2bSBin Meng  $ export OPENSBI=/path/to/opensbi-riscv64-generic-fw_dynamic.bin
185*01153d2bSBin Meng  $ make sifive_fu540_defconfig
186*01153d2bSBin Meng
187*01153d2bSBin MengYou will get spl/u-boot-spl.bin and u-boot.itb file in the build tree.
188*01153d2bSBin Meng
189*01153d2bSBin MengTo start U-Boot using the ``sifive_u`` machine, prepare an SPI flash image, or
190*01153d2bSBin MengSD card image that is properly partitioned and populated with correct contents.
191*01153d2bSBin Menggenimage_ can be used to generate these images.
192*01153d2bSBin Meng
193*01153d2bSBin MengA sample configuration file for a 128 MiB SD card image is:
194*01153d2bSBin Meng
195*01153d2bSBin Meng.. code-block:: bash
196*01153d2bSBin Meng
197*01153d2bSBin Meng  $ cat genimage_sdcard.cfg
198*01153d2bSBin Meng  image sdcard.img {
199*01153d2bSBin Meng          size = 128M
200*01153d2bSBin Meng
201*01153d2bSBin Meng          hdimage {
202*01153d2bSBin Meng                  gpt = true
203*01153d2bSBin Meng          }
204*01153d2bSBin Meng
205*01153d2bSBin Meng          partition u-boot-spl {
206*01153d2bSBin Meng                  image = "u-boot-spl.bin"
207*01153d2bSBin Meng                  offset = 17K
208*01153d2bSBin Meng                  partition-type-uuid = 5B193300-FC78-40CD-8002-E86C45580B47
209*01153d2bSBin Meng          }
210*01153d2bSBin Meng
211*01153d2bSBin Meng          partition u-boot {
212*01153d2bSBin Meng                  image = "u-boot.itb"
213*01153d2bSBin Meng                  offset = 1041K
214*01153d2bSBin Meng                  partition-type-uuid = 2E54B353-1271-4842-806F-E436D6AF6985
215*01153d2bSBin Meng          }
216*01153d2bSBin Meng  }
217*01153d2bSBin Meng
218*01153d2bSBin MengSPI flash image has slightly different partition offsets, and the size has to
219*01153d2bSBin Mengbe 32 MiB to match the ISSI 25WP256 flash on the real board:
220*01153d2bSBin Meng
221*01153d2bSBin Meng.. code-block:: bash
222*01153d2bSBin Meng
223*01153d2bSBin Meng  $ cat genimage_spi-nor.cfg
224*01153d2bSBin Meng  image spi-nor.img {
225*01153d2bSBin Meng          size = 32M
226*01153d2bSBin Meng
227*01153d2bSBin Meng          hdimage {
228*01153d2bSBin Meng                  gpt = true
229*01153d2bSBin Meng          }
230*01153d2bSBin Meng
231*01153d2bSBin Meng          partition u-boot-spl {
232*01153d2bSBin Meng                  image = "u-boot-spl.bin"
233*01153d2bSBin Meng                  offset = 20K
234*01153d2bSBin Meng                  partition-type-uuid = 5B193300-FC78-40CD-8002-E86C45580B47
235*01153d2bSBin Meng          }
236*01153d2bSBin Meng
237*01153d2bSBin Meng          partition u-boot {
238*01153d2bSBin Meng                  image = "u-boot.itb"
239*01153d2bSBin Meng                  offset = 1044K
240*01153d2bSBin Meng                  partition-type-uuid = 2E54B353-1271-4842-806F-E436D6AF6985
241*01153d2bSBin Meng          }
242*01153d2bSBin Meng  }
243*01153d2bSBin Meng
244*01153d2bSBin MengAssume U-Boot binaries are put in the same directory as the config file,
245*01153d2bSBin Mengwe can generate the image by:
246*01153d2bSBin Meng
247*01153d2bSBin Meng.. code-block:: bash
248*01153d2bSBin Meng
249*01153d2bSBin Meng  $ genimage --config genimage_<boot_src>.cfg --inputpath .
250*01153d2bSBin Meng
251*01153d2bSBin MengBoot U-Boot from SD card, by specifying msel=11 and pass the SD card image
252*01153d2bSBin Mengto QEMU ``sifive_u`` machine:
253*01153d2bSBin Meng
254*01153d2bSBin Meng.. code-block:: bash
255*01153d2bSBin Meng
256*01153d2bSBin Meng  $ qemu-system-riscv64 -M sifive_u,msel=11 -smp 5 -m 8G \
257*01153d2bSBin Meng      -display none -serial stdio \
258*01153d2bSBin Meng      -bios /path/to/u-boot-spl.bin \
259*01153d2bSBin Meng      -drive file=/path/to/sdcard.img,if=sd
260*01153d2bSBin Meng
261*01153d2bSBin MengChanging msel= value to 6, allows booting U-Boot from the SPI flash:
262*01153d2bSBin Meng
263*01153d2bSBin Meng.. code-block:: bash
264*01153d2bSBin Meng
265*01153d2bSBin Meng  $ qemu-system-riscv64 -M sifive_u,msel=6 -smp 5 -m 8G \
266*01153d2bSBin Meng      -display none -serial stdio \
267*01153d2bSBin Meng      -bios /path/to/u-boot-spl.bin \
268*01153d2bSBin Meng      -drive file=/path/to/spi-nor.img,if=mtd
269*01153d2bSBin Meng
270*01153d2bSBin MengNote when testing U-Boot, QEMU automatically generated device tree blob is
271*01153d2bSBin Mengnot used because U-Boot itself embeds device tree blobs for U-Boot SPL and
272*01153d2bSBin MengU-Boot proper. Hence the number of cores and size of memory have to match
273*01153d2bSBin Mengthe real hardware, ie: 5 cores (-smp 5) and 8 GiB memory (-m 8G).
274*01153d2bSBin Meng
275*01153d2bSBin MengAbove use case is to run upstream U-Boot for the SiFive HiFive Unleashed
276*01153d2bSBin Mengboard on QEMU ``sifive_u`` machine out of the box. This allows users to
277*01153d2bSBin Mengdevelop and test the recommended RISC-V boot flow with a real world use
278*01153d2bSBin Mengcase: ZSBL (in QEMU) loads U-Boot SPL from SD card or SPI flash to L2LIM,
279*01153d2bSBin Mengthen U-Boot SPL loads the combined payload image of OpenSBI fw_dynamic
280*01153d2bSBin Mengfirmware and U-Boot proper. However sometimes we want to have a quick test
281*01153d2bSBin Mengof booting U-Boot on QEMU without the needs of preparing the SPI flash or
282*01153d2bSBin MengSD card images, an alternate way can be used, which is to create a U-Boot
283*01153d2bSBin MengS-mode image by modifying the configuration of U-Boot:
284*01153d2bSBin Meng
285*01153d2bSBin Meng.. code-block:: bash
286*01153d2bSBin Meng
287*01153d2bSBin Meng  $ make menuconfig
288*01153d2bSBin Meng
289*01153d2bSBin Mengthen manually select the following configuration in U-Boot:
290*01153d2bSBin Meng
291*01153d2bSBin Meng  Device Tree Control > Provider of DTB for DT Control > Prior Stage bootloader DTB
292*01153d2bSBin Meng
293*01153d2bSBin MengThis lets U-Boot to use the QEMU generated device tree blob. During the build,
294*01153d2bSBin Menga build error will be seen below:
295*01153d2bSBin Meng
296*01153d2bSBin Meng.. code-block:: none
297*01153d2bSBin Meng
298*01153d2bSBin Meng  MKIMAGE u-boot.img
299*01153d2bSBin Meng  ./tools/mkimage: Can't open arch/riscv/dts/hifive-unleashed-a00.dtb: No such file or directory
300*01153d2bSBin Meng  ./tools/mkimage: failed to build FIT
301*01153d2bSBin Meng  make: *** [Makefile:1440: u-boot.img] Error 1
302*01153d2bSBin Meng
303*01153d2bSBin MengThe above errors can be safely ignored as we don't run U-Boot SPL under QEMU
304*01153d2bSBin Mengin this alternate configuration.
305*01153d2bSBin Meng
306*01153d2bSBin MengBoot the 64-bit U-Boot S-mode image directly:
307*01153d2bSBin Meng
308*01153d2bSBin Meng.. code-block:: bash
309*01153d2bSBin Meng
310*01153d2bSBin Meng  $ qemu-system-riscv64 -M sifive_u -smp 5 -m 2G \
311*01153d2bSBin Meng      -display none -serial stdio \
312*01153d2bSBin Meng      -kernel /path/to/u-boot.bin
313*01153d2bSBin Meng
314*01153d2bSBin MengIt's possible to create a 32-bit U-Boot S-mode image as well.
315*01153d2bSBin Meng
316*01153d2bSBin Meng.. code-block:: bash
317*01153d2bSBin Meng
318*01153d2bSBin Meng  $ export CROSS_COMPILE=riscv64-linux-
319*01153d2bSBin Meng  $ make sifive_fu540_defconfig
320*01153d2bSBin Meng  $ make menuconfig
321*01153d2bSBin Meng
322*01153d2bSBin Mengthen manually update the following configuration in U-Boot:
323*01153d2bSBin Meng
324*01153d2bSBin Meng  Device Tree Control > Provider of DTB for DT Control > Prior Stage bootloader DTB
325*01153d2bSBin Meng  RISC-V architecture > Base ISA > RV32I
326*01153d2bSBin Meng  Boot images > Text Base > 0x80400000
327*01153d2bSBin Meng
328*01153d2bSBin MengUse the same command line options to boot the 32-bit U-Boot S-mode image:
329*01153d2bSBin Meng
330*01153d2bSBin Meng.. code-block:: bash
331*01153d2bSBin Meng
332*01153d2bSBin Meng  $ qemu-system-riscv32 -M sifive_u -smp 5 -m 2G \
333*01153d2bSBin Meng      -display none -serial stdio \
334*01153d2bSBin Meng      -kernel /path/to/u-boot.bin
335*01153d2bSBin Meng
336*01153d2bSBin Meng.. _genimage: https://github.com/pengutronix/genimage
337