blob: 8a5eb1eda567a26a87853cfaae67c59ef4b106e1 [file] [log] [blame]
Bin Mengf712f2a2019-07-18 00:34:16 -07001.. SPDX-License-Identifier: GPL-2.0+
2.. Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
Bin Meng8a8694d2018-09-26 06:55:21 -07003
Bin Mengf712f2a2019-07-18 00:34:16 -07004QEMU RISC-V
5===========
Bin Meng8a8694d2018-09-26 06:55:21 -07006
Anup Patelf650a2c2022-01-27 11:41:10 +05307QEMU 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.
Bin Meng8a8694d2018-09-26 06:55:21 -070011
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
Anup Patelf650a2c2022-01-27 11:41:10 +053015configuration information to guest software. It implements the latest RISC-V
16privileged architecture.
Simon Glasseb284942021-12-16 20:59:09 -070017
18See :doc:`../../develop/devicetree/dt_qemu` for information on how to see
19the devicetree actually generated by QEMU.
Anup Patelf650a2c2022-01-27 11:41:10 +053020
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.
Bin Meng8a8694d2018-09-26 06:55:21 -070025
26Building U-Boot
27---------------
28Set the CROSS_COMPILE environment variable as usual, and run:
29
Bin Mengf712f2a2019-07-18 00:34:16 -070030- For 32-bit RISC-V::
31
Bin Meng8a8694d2018-09-26 06:55:21 -070032 make qemu-riscv32_defconfig
33 make
34
Bin Mengf712f2a2019-07-18 00:34:16 -070035- For 64-bit RISC-V::
36
Bin Meng8a8694d2018-09-26 06:55:21 -070037 make qemu-riscv64_defconfig
38 make
39
Lukas Auereaa2b662019-08-21 21:14:50 +020040This 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
Bin Meng8a8694d2018-09-26 06:55:21 -070045Running U-Boot
46--------------
47The minimal QEMU command line to get U-Boot up and running is:
48
Anup Patelf650a2c2022-01-27 11:41:10 +053049- For 32-bit RISC-V virt machine::
Bin Mengf712f2a2019-07-18 00:34:16 -070050
Anup Patelf650a2c2022-01-27 11:41:10 +053051 qemu-system-riscv32 -nographic -machine virt -bios u-boot.bin
Bin Meng8a8694d2018-09-26 06:55:21 -070052
Anup Patelf650a2c2022-01-27 11:41:10 +053053- 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::
Bin Mengf712f2a2019-07-18 00:34:16 -070058
Anup Patelf650a2c2022-01-27 11:41:10 +053059 qemu-system-riscv64 -nographic -machine spike -bios u-boot.bin
Bin Meng8a8694d2018-09-26 06:55:21 -070060
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
Lukas Auereaa2b662019-08-21 21:14:50 +020067For 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
Anup Patelf650a2c2022-01-27 11:41:10 +053070https://github.com/riscv/opensbi/blob/master/docs/platform/spike.md
Lukas Auereaa2b662019-08-21 21:14:50 +020071
Bin Menga33888f2020-06-23 05:23:15 -070072These have been tested in QEMU 5.0.0.
Lukas Auereaa2b662019-08-21 21:14:50 +020073
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
Atish Patra1d4d6ad2020-12-22 11:50:01 -080089 make PLATFORM=generic
Lukas Auereaa2b662019-08-21 21:14:50 +020090
91See the OpenSBI documentation for full details:
92https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
Anup Patelf650a2c2022-01-27 11:41:10 +053093https://github.com/riscv/opensbi/blob/master/docs/platform/spike.md
Lukas Auereaa2b662019-08-21 21:14:50 +020094
Anup Patelf650a2c2022-01-27 11:41:10 +053095To make the FW_DYNAMIC binary (build/platform/generic/firmware/fw_dynamic.bin)
Lukas Auereaa2b662019-08-21 21:14:50 +020096available 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
Anup Patelf650a2c2022-01-27 11:41:10 +0530113- For 32-bit RISC-V virt machine::
Lukas Auereaa2b662019-08-21 21:14:50 +0200114
Anup Patelf650a2c2022-01-27 11:41:10 +0530115 qemu-system-riscv32 -nographic -machine virt -bios spl/u-boot-spl.bin \
Lukas Auereaa2b662019-08-21 21:14:50 +0200116 -device loader,file=u-boot.itb,addr=0x80200000
117
Anup Patelf650a2c2022-01-27 11:41:10 +0530118- 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::
Lukas Auereaa2b662019-08-21 21:14:50 +0200124
Anup Patelf650a2c2022-01-27 11:41:10 +0530125 qemu-system-riscv64 -nographic -machine spike -bios spl/u-boot-spl.bin \
Lukas Auereaa2b662019-08-21 21:14:50 +0200126 -device loader,file=u-boot.itb,addr=0x80200000
Heinrich Schuchardt7ba34202020-11-04 12:59:13 +0100127
Anup Patelf650a2c2022-01-27 11:41:10 +0530128An attached disk can be emulated in RISC-V virt machine by adding::
Heinrich Schuchardt7ba34202020-11-04 12:59:13 +0100129
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
Bin Meng93031d82023-10-11 21:15:52 +0800134or alternatively attach an emulated UFS::
135
136 -device ufs,id=ufs0 \
137 -drive if=none,file=test.img,format=raw,id=lun0 \
138 -device ufs-lu,drive=lun0,bus=ufs0
139
140You will have to run 'scsi scan' to use them.
Heinrich Schuchardt216a19f2022-04-05 16:14:27 +0200141
Bin Mengcbb84f32023-07-23 12:40:33 +0800142A video console can be emulated in RISC-V virt machine by removing "-nographic"
143and adding::
144
145 -serial stdio -device VGA
146
Bin Mengf6809fb2023-07-23 12:40:41 +0800147In addition, a usb keyboard can be attached to an emulated xHCI controller in
148RISC-V virt machine as an option of input devices by adding::
149
150 -device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0
151
Heinrich Schuchardt04d4b7c2022-08-14 16:13:49 +0200152Running with KVM
153----------------
154
155Running with QEMU using KVM requires an S-mode U-Boot binary as created by
156qemu-riscv64_smode_defconfig.
157
158Provide the U-Boot S-mode ELF image as *-kernel* parameter and do not add a
159*-bios* parameter, e.g.
160
161.. code-block:: bash
162
163 qemu-system-riscv64 -accel kvm -nographic -machine virt -kernel u-boot
164
Heinrich Schuchardt216a19f2022-04-05 16:14:27 +0200165Debug UART
166----------
167
168The following settings provide a debug UART for the virt machine::
169
170 CONFIG_DEBUG_UART=y
171 CONFIG_DEBUG_UART_NS16550=y
172 CONFIG_DEBUG_UART_BASE=0x10000000
173 CONFIG_DEBUG_UART_CLOCK=3686400