2019-07-18 07:34:16 +00:00
|
|
|
.. SPDX-License-Identifier: GPL-2.0+
|
|
|
|
.. Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
|
2018-09-26 13:55:21 +00:00
|
|
|
|
2019-07-18 07:34:16 +00:00
|
|
|
QEMU RISC-V
|
|
|
|
===========
|
2018-09-26 13:55:21 +00:00
|
|
|
|
2022-01-27 06:11:10 +00:00
|
|
|
QEMU for RISC-V supports a special 'virt' machine and 'spike' machine designed
|
|
|
|
for emulation and virtualization purposes. This document describes how to run
|
|
|
|
U-Boot under it. Both 32-bit and 64-bit targets are supported, running in
|
|
|
|
either machine or supervisor mode.
|
2018-09-26 13:55:21 +00:00
|
|
|
|
|
|
|
The QEMU virt machine models a generic RISC-V virtual machine with support for
|
|
|
|
the VirtIO standard networking and block storage devices. It has CLINT, PLIC,
|
|
|
|
16550A UART devices in addition to VirtIO and it also uses device-tree to pass
|
2022-01-27 06:11:10 +00:00
|
|
|
configuration information to guest software. It implements the latest RISC-V
|
|
|
|
privileged architecture.
|
2021-12-17 03:59:09 +00:00
|
|
|
|
|
|
|
See :doc:`../../develop/devicetree/dt_qemu` for information on how to see
|
|
|
|
the devicetree actually generated by QEMU.
|
2022-01-27 06:11:10 +00:00
|
|
|
|
|
|
|
The QEMU spike machine models a minimalistic RISC-V virtual machine with
|
|
|
|
only CLINT and HTIF devices. It also uses device-tree to pass configuration
|
|
|
|
information to guest software and implements the latest RISC-V privileged
|
|
|
|
architecture.
|
2018-09-26 13:55:21 +00:00
|
|
|
|
|
|
|
Building U-Boot
|
|
|
|
---------------
|
|
|
|
Set the CROSS_COMPILE environment variable as usual, and run:
|
|
|
|
|
2019-07-18 07:34:16 +00:00
|
|
|
- For 32-bit RISC-V::
|
|
|
|
|
2018-09-26 13:55:21 +00:00
|
|
|
make qemu-riscv32_defconfig
|
|
|
|
make
|
|
|
|
|
2019-07-18 07:34:16 +00:00
|
|
|
- For 64-bit RISC-V::
|
|
|
|
|
2018-09-26 13:55:21 +00:00
|
|
|
make qemu-riscv64_defconfig
|
|
|
|
make
|
|
|
|
|
2019-08-21 19:14:50 +00:00
|
|
|
This will compile U-Boot for machine mode. To build supervisor mode binaries,
|
|
|
|
use the configurations qemu-riscv32_smode_defconfig and
|
|
|
|
qemu-riscv64_smode_defconfig instead. Note that U-Boot running in supervisor
|
|
|
|
mode requires a supervisor binary interface (SBI), such as RISC-V OpenSBI.
|
|
|
|
|
2018-09-26 13:55:21 +00:00
|
|
|
Running U-Boot
|
|
|
|
--------------
|
|
|
|
The minimal QEMU command line to get U-Boot up and running is:
|
|
|
|
|
2022-01-27 06:11:10 +00:00
|
|
|
- For 32-bit RISC-V virt machine::
|
2019-07-18 07:34:16 +00:00
|
|
|
|
2022-01-27 06:11:10 +00:00
|
|
|
qemu-system-riscv32 -nographic -machine virt -bios u-boot.bin
|
2018-09-26 13:55:21 +00:00
|
|
|
|
2022-01-27 06:11:10 +00:00
|
|
|
- For 64-bit RISC-V virt machine::
|
|
|
|
|
|
|
|
qemu-system-riscv64 -nographic -machine virt -bios u-boot.bin
|
|
|
|
|
|
|
|
- For 64-bit RISC-V spike machine::
|
2019-07-18 07:34:16 +00:00
|
|
|
|
2022-01-27 06:11:10 +00:00
|
|
|
qemu-system-riscv64 -nographic -machine spike -bios u-boot.bin
|
2018-09-26 13:55:21 +00:00
|
|
|
|
|
|
|
The commands above create targets with 128MiB memory by default.
|
|
|
|
A freely configurable amount of RAM can be created via the '-m'
|
|
|
|
parameter. For example, '-m 2G' creates 2GiB memory for the target,
|
|
|
|
and the memory node in the embedded DTB created by QEMU reflects
|
|
|
|
the new setting.
|
|
|
|
|
2019-08-21 19:14:50 +00:00
|
|
|
For instructions on how to run U-Boot in supervisor mode on QEMU
|
|
|
|
with OpenSBI, see the documentation available with OpenSBI:
|
|
|
|
https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
|
2022-01-27 06:11:10 +00:00
|
|
|
https://github.com/riscv/opensbi/blob/master/docs/platform/spike.md
|
2019-08-21 19:14:50 +00:00
|
|
|
|
2020-06-23 12:23:15 +00:00
|
|
|
These have been tested in QEMU 5.0.0.
|
2019-08-21 19:14:50 +00:00
|
|
|
|
|
|
|
Running U-Boot SPL
|
|
|
|
------------------
|
|
|
|
In the default SPL configuration, U-Boot SPL starts in machine mode. U-Boot
|
|
|
|
proper and OpenSBI (FW_DYNAMIC firmware) are bundled as FIT image and made
|
|
|
|
available to U-Boot SPL. Both are then loaded by U-Boot SPL and the location
|
|
|
|
of U-Boot proper is passed to OpenSBI. After initialization, U-Boot proper is
|
|
|
|
started in supervisor mode by OpenSBI.
|
|
|
|
|
|
|
|
OpenSBI must be compiled before compiling U-Boot. Version 0.4 and higher is
|
|
|
|
supported by U-Boot. Clone the OpenSBI repository and run the following command.
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
git clone https://github.com/riscv/opensbi.git
|
|
|
|
cd opensbi
|
2020-12-22 19:50:01 +00:00
|
|
|
make PLATFORM=generic
|
2019-08-21 19:14:50 +00:00
|
|
|
|
|
|
|
See the OpenSBI documentation for full details:
|
|
|
|
https://github.com/riscv/opensbi/blob/master/docs/platform/qemu_virt.md
|
2022-01-27 06:11:10 +00:00
|
|
|
https://github.com/riscv/opensbi/blob/master/docs/platform/spike.md
|
2019-08-21 19:14:50 +00:00
|
|
|
|
2022-01-27 06:11:10 +00:00
|
|
|
To make the FW_DYNAMIC binary (build/platform/generic/firmware/fw_dynamic.bin)
|
2019-08-21 19:14:50 +00:00
|
|
|
available to U-Boot, either copy it into the U-Boot root directory or specify
|
|
|
|
its location with the OPENSBI environment variable. Afterwards, compile U-Boot
|
|
|
|
with the following commands.
|
|
|
|
|
|
|
|
- For 32-bit RISC-V::
|
|
|
|
|
|
|
|
make qemu-riscv32_spl_defconfig
|
|
|
|
make
|
|
|
|
|
|
|
|
- For 64-bit RISC-V::
|
|
|
|
|
|
|
|
make qemu-riscv64_spl_defconfig
|
|
|
|
make
|
|
|
|
|
|
|
|
The minimal QEMU commands to run U-Boot SPL in both 32-bit and 64-bit
|
|
|
|
configurations are:
|
|
|
|
|
2022-01-27 06:11:10 +00:00
|
|
|
- For 32-bit RISC-V virt machine::
|
2019-08-21 19:14:50 +00:00
|
|
|
|
2022-01-27 06:11:10 +00:00
|
|
|
qemu-system-riscv32 -nographic -machine virt -bios spl/u-boot-spl.bin \
|
2019-08-21 19:14:50 +00:00
|
|
|
-device loader,file=u-boot.itb,addr=0x80200000
|
|
|
|
|
2022-01-27 06:11:10 +00:00
|
|
|
- For 64-bit RISC-V virt machine::
|
|
|
|
|
|
|
|
qemu-system-riscv64 -nographic -machine virt -bios spl/u-boot-spl.bin \
|
|
|
|
-device loader,file=u-boot.itb,addr=0x80200000
|
|
|
|
|
|
|
|
- For 64-bit RISC-V spike machine::
|
2019-08-21 19:14:50 +00:00
|
|
|
|
2022-01-27 06:11:10 +00:00
|
|
|
qemu-system-riscv64 -nographic -machine spike -bios spl/u-boot-spl.bin \
|
2019-08-21 19:14:50 +00:00
|
|
|
-device loader,file=u-boot.itb,addr=0x80200000
|
2020-11-04 11:59:13 +00:00
|
|
|
|
2022-01-27 06:11:10 +00:00
|
|
|
An attached disk can be emulated in RISC-V virt machine by adding::
|
2020-11-04 11:59:13 +00:00
|
|
|
|
|
|
|
-device ich9-ahci,id=ahci \
|
|
|
|
-drive if=none,file=riscv64.img,format=raw,id=mydisk \
|
|
|
|
-device ide-hd,drive=mydisk,bus=ahci.0
|
|
|
|
|
|
|
|
You will have to run 'scsi scan' to use it.
|
2022-04-05 14:14:27 +00:00
|
|
|
|
|
|
|
Debug UART
|
|
|
|
----------
|
|
|
|
|
|
|
|
The following settings provide a debug UART for the virt machine::
|
|
|
|
|
|
|
|
CONFIG_DEBUG_UART=y
|
|
|
|
CONFIG_DEBUG_UART_NS16550=y
|
|
|
|
CONFIG_DEBUG_UART_BASE=0x10000000
|
|
|
|
CONFIG_DEBUG_UART_CLOCK=3686400
|