blob: 782f37251c39eef57cfee2923fd5f7a2b00ec57d [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
134You will have to run 'scsi scan' to use it.
Heinrich Schuchardt216a19f2022-04-05 16:14:27 +0200135
136Debug UART
137----------
138
139The following settings provide a debug UART for the virt machine::
140
141 CONFIG_DEBUG_UART=y
142 CONFIG_DEBUG_UART_NS16550=y
143 CONFIG_DEBUG_UART_BASE=0x10000000
144 CONFIG_DEBUG_UART_CLOCK=3686400