1 .. SPDX-License-Identifier: GPL-2.0+
7 QEMU for RISC-V supports a special 'virt' machine and 'spike' machine designed
8 for emulation and virtualization purposes. This document describes how to run
9 U-Boot under it. Both 32-bit and 64-bit targets are supported, running in
10 either machine or supervisor mode.
12 The QEMU virt machine models a generic RISC-V virtual machine with support for
13 the VirtIO standard networking and block storage devices. It has CLINT, PLIC,
14 16550A UART devices in addition to VirtIO and it also uses device-tree to pass
15 configuration information to guest software. It implements the latest RISC-V
16 privileged architecture.
18 See :doc:`../../develop/devicetree/dt_qemu` for information on how to see
19 the devicetree actually generated by QEMU.
21 The QEMU spike machine models a minimalistic RISC-V virtual machine with
22 only CLINT and HTIF devices. It also uses device-tree to pass configuration
23 information to guest software and implements the latest RISC-V privileged
28 Set the CROSS_COMPILE environment variable as usual, and run:
32 make qemu-riscv32_defconfig
37 make qemu-riscv64_defconfig
40 This will compile U-Boot for machine mode. To build supervisor mode binaries,
41 use the configurations qemu-riscv32_smode_defconfig and
42 qemu-riscv64_smode_defconfig instead. Note that U-Boot running in supervisor
43 mode requires a supervisor binary interface (SBI), such as RISC-V OpenSBI.
47 The minimal QEMU command line to get U-Boot up and running is:
49 - For 32-bit RISC-V virt machine::
51 qemu-system-riscv32 -nographic -machine virt -bios u-boot.bin
53 - For 64-bit RISC-V virt machine::
55 qemu-system-riscv64 -nographic -machine virt -bios u-boot.bin
57 - For 64-bit RISC-V spike machine::
59 qemu-system-riscv64 -nographic -machine spike -bios u-boot.bin
61 The commands above create targets with 128MiB memory by default.
62 A freely configurable amount of RAM can be created via the '-m'
63 parameter. For example, '-m 2G' creates 2GiB memory for the target,
64 and the memory node in the embedded DTB created by QEMU reflects
67 For instructions on how to run U-Boot in supervisor mode on QEMU
68 with OpenSBI, see the documentation available with OpenSBI:
69 https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
70 https://github.com/riscv/opensbi/blob/master/docs/platform/spike.md
72 These have been tested in QEMU 5.0.0.
76 In the default SPL configuration, U-Boot SPL starts in machine mode. U-Boot
77 proper and OpenSBI (FW_DYNAMIC firmware) are bundled as FIT image and made
78 available to U-Boot SPL. Both are then loaded by U-Boot SPL and the location
79 of U-Boot proper is passed to OpenSBI. After initialization, U-Boot proper is
80 started in supervisor mode by OpenSBI.
82 OpenSBI must be compiled before compiling U-Boot. Version 0.4 and higher is
83 supported by U-Boot. Clone the OpenSBI repository and run the following command.
85 .. code-block:: console
87 git clone https://github.com/riscv/opensbi.git
91 See the OpenSBI documentation for full details:
92 https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
93 https://github.com/riscv/opensbi/blob/master/docs/platform/spike.md
95 To make the FW_DYNAMIC binary (build/platform/generic/firmware/fw_dynamic.bin)
96 available to U-Boot, either copy it into the U-Boot root directory or specify
97 its location with the OPENSBI environment variable. Afterwards, compile U-Boot
98 with the following commands.
100 - For 32-bit RISC-V::
102 make qemu-riscv32_spl_defconfig
105 - For 64-bit RISC-V::
107 make qemu-riscv64_spl_defconfig
110 The minimal QEMU commands to run U-Boot SPL in both 32-bit and 64-bit
113 - For 32-bit RISC-V virt machine::
115 qemu-system-riscv32 -nographic -machine virt -bios spl/u-boot-spl.bin \
116 -device loader,file=u-boot.itb,addr=0x80200000
118 - For 64-bit RISC-V virt machine::
120 qemu-system-riscv64 -nographic -machine virt -bios spl/u-boot-spl.bin \
121 -device loader,file=u-boot.itb,addr=0x80200000
123 - For 64-bit RISC-V spike machine::
125 qemu-system-riscv64 -nographic -machine spike -bios spl/u-boot-spl.bin \
126 -device loader,file=u-boot.itb,addr=0x80200000
128 An attached disk can be emulated in RISC-V virt machine by adding::
130 -device ich9-ahci,id=ahci \
131 -drive if=none,file=riscv64.img,format=raw,id=mydisk \
132 -device ide-hd,drive=mydisk,bus=ahci.0
134 or alternatively attach an emulated UFS::
136 -device ufs,id=ufs0 \
137 -drive if=none,file=test.img,format=raw,id=lun0 \
138 -device ufs-lu,drive=lun0,bus=ufs0
140 You will have to run 'scsi scan' to use them.
142 A video console can be emulated in RISC-V virt machine by removing "-nographic"
145 -serial stdio -device VGA
147 In addition, a usb keyboard can be attached to an emulated xHCI controller in
148 RISC-V virt machine as an option of input devices by adding::
150 -device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0
155 Running with QEMU using KVM requires an S-mode U-Boot binary as created by
156 qemu-riscv64_smode_defconfig.
158 Provide the U-Boot S-mode ELF image as *-kernel* parameter and do not add a
159 *-bios* parameter, e.g.
163 qemu-system-riscv64 -accel kvm -nographic -machine virt -kernel u-boot
168 The following settings provide a debug UART for the virt machine::
171 CONFIG_DEBUG_UART_NS16550=y
172 CONFIG_DEBUG_UART_BASE=0x10000000
173 CONFIG_DEBUG_UART_CLOCK=3686400