blob: fe7505e2019a9687c5790c2ad4d6156aa7a0a6bc [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
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.
Lukas Auereaa2b662019-08-21 21:14:50 +02009Both 32-bit and 64-bit targets are supported, running in either machine or
10supervisor 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
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
Bin Mengf712f2a2019-07-18 00:34:16 -070022- For 32-bit RISC-V::
23
Bin Meng8a8694d2018-09-26 06:55:21 -070024 make qemu-riscv32_defconfig
25 make
26
Bin Mengf712f2a2019-07-18 00:34:16 -070027- For 64-bit RISC-V::
28
Bin Meng8a8694d2018-09-26 06:55:21 -070029 make qemu-riscv64_defconfig
30 make
31
Lukas Auereaa2b662019-08-21 21:14:50 +020032This 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
Bin Meng8a8694d2018-09-26 06:55:21 -070037Running U-Boot
38--------------
39The minimal QEMU command line to get U-Boot up and running is:
40
Bin Mengf712f2a2019-07-18 00:34:16 -070041- For 32-bit RISC-V::
42
Bin Meng8a8694d2018-09-26 06:55:21 -070043 qemu-system-riscv32 -nographic -machine virt -kernel u-boot
44
Bin Mengf712f2a2019-07-18 00:34:16 -070045- For 64-bit RISC-V::
46
Bin Meng8a8694d2018-09-26 06:55:21 -070047 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
Lukas Auereaa2b662019-08-21 21:14:50 +020055For 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
Bin Meng8a8694d2018-09-26 06:55:21 -070059These have been tested in QEMU 3.0.0.
Lukas Auereaa2b662019-08-21 21:14:50 +020060
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