blob: 4b8e104a2151a781b48cf22f9f7e4785cdd6ecfd [file] [log] [blame]
Bin Meng40046df2019-07-18 00:34:16 -07001.. SPDX-License-Identifier: GPL-2.0+
2.. Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
Bin Meng510e3792018-09-26 06:55:21 -07003
Bin Meng40046df2019-07-18 00:34:16 -07004QEMU RISC-V
5===========
Bin Meng510e3792018-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 Auer8313fcd2019-08-21 21:14:50 +02009Both 32-bit and 64-bit targets are supported, running in either machine or
10supervisor mode.
Bin Meng510e3792018-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 Meng40046df2019-07-18 00:34:16 -070022- For 32-bit RISC-V::
23
Bin Meng510e3792018-09-26 06:55:21 -070024 make qemu-riscv32_defconfig
25 make
26
Bin Meng40046df2019-07-18 00:34:16 -070027- For 64-bit RISC-V::
28
Bin Meng510e3792018-09-26 06:55:21 -070029 make qemu-riscv64_defconfig
30 make
31
Lukas Auer8313fcd2019-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 Meng510e3792018-09-26 06:55:21 -070037Running U-Boot
38--------------
39The minimal QEMU command line to get U-Boot up and running is:
40
Bin Meng40046df2019-07-18 00:34:16 -070041- For 32-bit RISC-V::
42
Bin Mengba512692020-06-23 05:23:15 -070043 qemu-system-riscv32 -nographic -machine virt -bios u-boot
Bin Meng510e3792018-09-26 06:55:21 -070044
Bin Meng40046df2019-07-18 00:34:16 -070045- For 64-bit RISC-V::
46
Bin Mengba512692020-06-23 05:23:15 -070047 qemu-system-riscv64 -nographic -machine virt -bios u-boot
Bin Meng510e3792018-09-26 06:55:21 -070048
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 Auer8313fcd2019-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 Mengba512692020-06-23 05:23:15 -070059These have been tested in QEMU 5.0.0.
Lukas Auer8313fcd2019-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
Atish Patra24c56892020-12-22 11:50:01 -080076 make PLATFORM=generic
Lukas Auer8313fcd2019-08-21 21:14:50 +020077
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
Bin Mengba512692020-06-23 05:23:15 -0700101 qemu-system-riscv32 -nographic -machine virt -bios spl/u-boot-spl \
Lukas Auer8313fcd2019-08-21 21:14:50 +0200102 -device loader,file=u-boot.itb,addr=0x80200000
103
104- For 64-bit RISC-V::
105
Bin Mengba512692020-06-23 05:23:15 -0700106 qemu-system-riscv64 -nographic -machine virt -bios spl/u-boot-spl \
Lukas Auer8313fcd2019-08-21 21:14:50 +0200107 -device loader,file=u-boot.itb,addr=0x80200000
Heinrich Schuchardtf0b18312020-11-04 12:59:13 +0100108
109An attached disk can be emulated by adding::
110
111 -device ich9-ahci,id=ahci \
112 -drive if=none,file=riscv64.img,format=raw,id=mydisk \
113 -device ide-hd,drive=mydisk,bus=ahci.0
114
115You will have to run 'scsi scan' to use it.