]> Git Repo - J-u-boot.git/blame - doc/board/emulation/qemu-riscv.rst
doc: board: ti: j721e_evm: Use board relative path for include directives
[J-u-boot.git] / doc / board / emulation / qemu-riscv.rst
CommitLineData
40046df7
BM
1.. SPDX-License-Identifier: GPL-2.0+
2.. Copyright (C) 2018, Bin Meng <[email protected]>
510e379c 3
40046df7
BM
4QEMU RISC-V
5===========
510e379c 6
7c08680a
AP
7QEMU for RISC-V supports a special 'virt' machine and 'spike' machine designed
8for emulation and virtualization purposes. This document describes how to run
9U-Boot under it. Both 32-bit and 64-bit targets are supported, running in
10either machine or supervisor mode.
510e379c
BM
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
7c08680a
AP
15configuration information to guest software. It implements the latest RISC-V
16privileged architecture.
c3c16145
SG
17
18See :doc:`../../develop/devicetree/dt_qemu` for information on how to see
19the devicetree actually generated by QEMU.
7c08680a
AP
20
21The QEMU spike machine models a minimalistic RISC-V virtual machine with
22only CLINT and HTIF devices. It also uses device-tree to pass configuration
23information to guest software and implements the latest RISC-V privileged
24architecture.
510e379c
BM
25
26Building U-Boot
27---------------
28Set the CROSS_COMPILE environment variable as usual, and run:
29
40046df7
BM
30- For 32-bit RISC-V::
31
510e379c
BM
32 make qemu-riscv32_defconfig
33 make
34
40046df7
BM
35- For 64-bit RISC-V::
36
510e379c
BM
37 make qemu-riscv64_defconfig
38 make
39
8313fcdb
LA
40This will compile U-Boot for machine mode. To build supervisor mode binaries,
41use the configurations qemu-riscv32_smode_defconfig and
42qemu-riscv64_smode_defconfig instead. Note that U-Boot running in supervisor
43mode requires a supervisor binary interface (SBI), such as RISC-V OpenSBI.
44
510e379c
BM
45Running U-Boot
46--------------
47The minimal QEMU command line to get U-Boot up and running is:
48
7c08680a 49- For 32-bit RISC-V virt machine::
40046df7 50
7c08680a 51 qemu-system-riscv32 -nographic -machine virt -bios u-boot.bin
510e379c 52
7c08680a
AP
53- For 64-bit RISC-V virt machine::
54
55 qemu-system-riscv64 -nographic -machine virt -bios u-boot.bin
56
57- For 64-bit RISC-V spike machine::
40046df7 58
7c08680a 59 qemu-system-riscv64 -nographic -machine spike -bios u-boot.bin
510e379c
BM
60
61The commands above create targets with 128MiB memory by default.
62A freely configurable amount of RAM can be created via the '-m'
63parameter. For example, '-m 2G' creates 2GiB memory for the target,
64and the memory node in the embedded DTB created by QEMU reflects
65the new setting.
66
8313fcdb
LA
67For instructions on how to run U-Boot in supervisor mode on QEMU
68with OpenSBI, see the documentation available with OpenSBI:
69https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
7c08680a 70https://github.com/riscv/opensbi/blob/master/docs/platform/spike.md
8313fcdb 71
ba51269f 72These have been tested in QEMU 5.0.0.
8313fcdb
LA
73
74Running U-Boot SPL
75------------------
76In the default SPL configuration, U-Boot SPL starts in machine mode. U-Boot
77proper and OpenSBI (FW_DYNAMIC firmware) are bundled as FIT image and made
78available to U-Boot SPL. Both are then loaded by U-Boot SPL and the location
79of U-Boot proper is passed to OpenSBI. After initialization, U-Boot proper is
80started in supervisor mode by OpenSBI.
81
82OpenSBI must be compiled before compiling U-Boot. Version 0.4 and higher is
83supported by U-Boot. Clone the OpenSBI repository and run the following command.
84
85.. code-block:: console
86
87 git clone https://github.com/riscv/opensbi.git
88 cd opensbi
24c56894 89 make PLATFORM=generic
8313fcdb
LA
90
91See the OpenSBI documentation for full details:
92https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
7c08680a 93https://github.com/riscv/opensbi/blob/master/docs/platform/spike.md
8313fcdb 94
7c08680a 95To make the FW_DYNAMIC binary (build/platform/generic/firmware/fw_dynamic.bin)
8313fcdb
LA
96available to U-Boot, either copy it into the U-Boot root directory or specify
97its location with the OPENSBI environment variable. Afterwards, compile U-Boot
98with the following commands.
99
100- For 32-bit RISC-V::
101
102 make qemu-riscv32_spl_defconfig
103 make
104
105- For 64-bit RISC-V::
106
107 make qemu-riscv64_spl_defconfig
108 make
109
110The minimal QEMU commands to run U-Boot SPL in both 32-bit and 64-bit
111configurations are:
112
7c08680a 113- For 32-bit RISC-V virt machine::
8313fcdb 114
7c08680a 115 qemu-system-riscv32 -nographic -machine virt -bios spl/u-boot-spl.bin \
8313fcdb
LA
116 -device loader,file=u-boot.itb,addr=0x80200000
117
7c08680a
AP
118- For 64-bit RISC-V virt machine::
119
120 qemu-system-riscv64 -nographic -machine virt -bios spl/u-boot-spl.bin \
121 -device loader,file=u-boot.itb,addr=0x80200000
122
123- For 64-bit RISC-V spike machine::
8313fcdb 124
7c08680a 125 qemu-system-riscv64 -nographic -machine spike -bios spl/u-boot-spl.bin \
8313fcdb 126 -device loader,file=u-boot.itb,addr=0x80200000
f0b18318 127
7c08680a 128An attached disk can be emulated in RISC-V virt machine by adding::
f0b18318
HS
129
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
133
134You will have to run 'scsi scan' to use it.
16736c23 135
71616166
BM
136A video console can be emulated in RISC-V virt machine by removing "-nographic"
137and adding::
138
139 -serial stdio -device VGA
140
02be57ca
BM
141In addition, a usb keyboard can be attached to an emulated xHCI controller in
142RISC-V virt machine as an option of input devices by adding::
143
144 -device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0
145
7556927f
HS
146Running with KVM
147----------------
148
149Running with QEMU using KVM requires an S-mode U-Boot binary as created by
150qemu-riscv64_smode_defconfig.
151
152Provide the U-Boot S-mode ELF image as *-kernel* parameter and do not add a
153*-bios* parameter, e.g.
154
155.. code-block:: bash
156
157 qemu-system-riscv64 -accel kvm -nographic -machine virt -kernel u-boot
158
16736c23
HS
159Debug UART
160----------
161
162The following settings provide a debug UART for the virt machine::
163
164 CONFIG_DEBUG_UART=y
165 CONFIG_DEBUG_UART_NS16550=y
166 CONFIG_DEBUG_UART_BASE=0x10000000
167 CONFIG_DEBUG_UART_CLOCK=3686400
This page took 0.194244 seconds and 4 git commands to generate.