blob: 3409fff8117ea5d0e18942d70b8e96d5fcc89e55 [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
Simon Glasseb284942021-12-16 20:59:09 -070016
17See :doc:`../../develop/devicetree/dt_qemu` for information on how to see
18the devicetree actually generated by QEMU.
Bin Meng8a8694d2018-09-26 06:55:21 -070019architecture spec v1.10.
20
21Building U-Boot
22---------------
23Set the CROSS_COMPILE environment variable as usual, and run:
24
Bin Mengf712f2a2019-07-18 00:34:16 -070025- For 32-bit RISC-V::
26
Bin Meng8a8694d2018-09-26 06:55:21 -070027 make qemu-riscv32_defconfig
28 make
29
Bin Mengf712f2a2019-07-18 00:34:16 -070030- For 64-bit RISC-V::
31
Bin Meng8a8694d2018-09-26 06:55:21 -070032 make qemu-riscv64_defconfig
33 make
34
Lukas Auereaa2b662019-08-21 21:14:50 +020035This will compile U-Boot for machine mode. To build supervisor mode binaries,
36use the configurations qemu-riscv32_smode_defconfig and
37qemu-riscv64_smode_defconfig instead. Note that U-Boot running in supervisor
38mode requires a supervisor binary interface (SBI), such as RISC-V OpenSBI.
39
Bin Meng8a8694d2018-09-26 06:55:21 -070040Running U-Boot
41--------------
42The minimal QEMU command line to get U-Boot up and running is:
43
Bin Mengf712f2a2019-07-18 00:34:16 -070044- For 32-bit RISC-V::
45
Bin Menga33888f2020-06-23 05:23:15 -070046 qemu-system-riscv32 -nographic -machine virt -bios u-boot
Bin Meng8a8694d2018-09-26 06:55:21 -070047
Bin Mengf712f2a2019-07-18 00:34:16 -070048- For 64-bit RISC-V::
49
Bin Menga33888f2020-06-23 05:23:15 -070050 qemu-system-riscv64 -nographic -machine virt -bios u-boot
Bin Meng8a8694d2018-09-26 06:55:21 -070051
52The commands above create targets with 128MiB memory by default.
53A freely configurable amount of RAM can be created via the '-m'
54parameter. For example, '-m 2G' creates 2GiB memory for the target,
55and the memory node in the embedded DTB created by QEMU reflects
56the new setting.
57
Lukas Auereaa2b662019-08-21 21:14:50 +020058For instructions on how to run U-Boot in supervisor mode on QEMU
59with OpenSBI, see the documentation available with OpenSBI:
60https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
61
Bin Menga33888f2020-06-23 05:23:15 -070062These have been tested in QEMU 5.0.0.
Lukas Auereaa2b662019-08-21 21:14:50 +020063
64Running U-Boot SPL
65------------------
66In the default SPL configuration, U-Boot SPL starts in machine mode. U-Boot
67proper and OpenSBI (FW_DYNAMIC firmware) are bundled as FIT image and made
68available to U-Boot SPL. Both are then loaded by U-Boot SPL and the location
69of U-Boot proper is passed to OpenSBI. After initialization, U-Boot proper is
70started in supervisor mode by OpenSBI.
71
72OpenSBI must be compiled before compiling U-Boot. Version 0.4 and higher is
73supported by U-Boot. Clone the OpenSBI repository and run the following command.
74
75.. code-block:: console
76
77 git clone https://github.com/riscv/opensbi.git
78 cd opensbi
Atish Patra1d4d6ad2020-12-22 11:50:01 -080079 make PLATFORM=generic
Lukas Auereaa2b662019-08-21 21:14:50 +020080
81See the OpenSBI documentation for full details:
82https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
83
84To make the FW_DYNAMIC binary (build/platform/qemu/virt/firmware/fw_dynamic.bin)
85available to U-Boot, either copy it into the U-Boot root directory or specify
86its location with the OPENSBI environment variable. Afterwards, compile U-Boot
87with the following commands.
88
89- For 32-bit RISC-V::
90
91 make qemu-riscv32_spl_defconfig
92 make
93
94- For 64-bit RISC-V::
95
96 make qemu-riscv64_spl_defconfig
97 make
98
99The minimal QEMU commands to run U-Boot SPL in both 32-bit and 64-bit
100configurations are:
101
102- For 32-bit RISC-V::
103
Bin Menga33888f2020-06-23 05:23:15 -0700104 qemu-system-riscv32 -nographic -machine virt -bios spl/u-boot-spl \
Lukas Auereaa2b662019-08-21 21:14:50 +0200105 -device loader,file=u-boot.itb,addr=0x80200000
106
107- For 64-bit RISC-V::
108
Bin Menga33888f2020-06-23 05:23:15 -0700109 qemu-system-riscv64 -nographic -machine virt -bios spl/u-boot-spl \
Lukas Auereaa2b662019-08-21 21:14:50 +0200110 -device loader,file=u-boot.itb,addr=0x80200000
Heinrich Schuchardt7ba34202020-11-04 12:59:13 +0100111
112An attached disk can be emulated by adding::
113
114 -device ich9-ahci,id=ahci \
115 -drive if=none,file=riscv64.img,format=raw,id=mydisk \
116 -device ide-hd,drive=mydisk,bus=ahci.0
117
118You will have to run 'scsi scan' to use it.