• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. SPDX-License-Identifier: GPL-2.0+
2.. Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
3
4QEMU RISC-V
5===========
6
7QEMU for RISC-V supports a special 'virt' machine designed for emulation and
8virtualization purposes. This document describes how to run U-Boot under it.
9Both 32-bit and 64-bit targets are supported, running in either machine or
10supervisor mode.
11
12The QEMU virt machine models a generic RISC-V virtual machine with support for
13the VirtIO standard networking and block storage devices. It has CLINT, PLIC,
1416550A UART devices in addition to VirtIO and it also uses device-tree to pass
15configuration information to guest software. It implements RISC-V privileged
16architecture spec v1.10.
17
18Building U-Boot
19---------------
20Set the CROSS_COMPILE environment variable as usual, and run:
21
22- For 32-bit RISC-V::
23
24    make qemu-riscv32_defconfig
25    make
26
27- For 64-bit RISC-V::
28
29    make qemu-riscv64_defconfig
30    make
31
32This will compile U-Boot for machine mode. To build supervisor mode binaries,
33use the configurations qemu-riscv32_smode_defconfig and
34qemu-riscv64_smode_defconfig instead. Note that U-Boot running in supervisor
35mode requires a supervisor binary interface (SBI), such as RISC-V OpenSBI.
36
37Running U-Boot
38--------------
39The minimal QEMU command line to get U-Boot up and running is:
40
41- For 32-bit RISC-V::
42
43    qemu-system-riscv32 -nographic -machine virt -kernel u-boot
44
45- For 64-bit RISC-V::
46
47    qemu-system-riscv64 -nographic -machine virt -kernel u-boot
48
49The commands above create targets with 128MiB memory by default.
50A freely configurable amount of RAM can be created via the '-m'
51parameter. For example, '-m 2G' creates 2GiB memory for the target,
52and the memory node in the embedded DTB created by QEMU reflects
53the new setting.
54
55For instructions on how to run U-Boot in supervisor mode on QEMU
56with OpenSBI, see the documentation available with OpenSBI:
57https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
58
59These have been tested in QEMU 3.0.0.
60
61Running U-Boot SPL
62------------------
63In the default SPL configuration, U-Boot SPL starts in machine mode. U-Boot
64proper and OpenSBI (FW_DYNAMIC firmware) are bundled as FIT image and made
65available to U-Boot SPL. Both are then loaded by U-Boot SPL and the location
66of U-Boot proper is passed to OpenSBI. After initialization, U-Boot proper is
67started in supervisor mode by OpenSBI.
68
69OpenSBI must be compiled before compiling U-Boot. Version 0.4 and higher is
70supported by U-Boot. Clone the OpenSBI repository and run the following command.
71
72.. code-block:: console
73
74    git clone https://github.com/riscv/opensbi.git
75    cd opensbi
76    make PLATFORM=qemu/virt
77
78See the OpenSBI documentation for full details:
79https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
80
81To make the FW_DYNAMIC binary (build/platform/qemu/virt/firmware/fw_dynamic.bin)
82available to U-Boot, either copy it into the U-Boot root directory or specify
83its location with the OPENSBI environment variable. Afterwards, compile U-Boot
84with the following commands.
85
86- For 32-bit RISC-V::
87
88    make qemu-riscv32_spl_defconfig
89    make
90
91- For 64-bit RISC-V::
92
93    make qemu-riscv64_spl_defconfig
94    make
95
96The minimal QEMU commands to run U-Boot SPL in both 32-bit and 64-bit
97configurations are:
98
99- For 32-bit RISC-V::
100
101    qemu-system-riscv32 -nographic -machine virt -kernel spl/u-boot-spl \
102    -device loader,file=u-boot.itb,addr=0x80200000
103
104- For 64-bit RISC-V::
105
106    qemu-system-riscv64 -nographic -machine virt -kernel spl/u-boot-spl \
107    -device loader,file=u-boot.itb,addr=0x80200000
108