
* Update to QEMU v9.0.0 --------- Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Fabiano Rosas <farosas@suse.de> Signed-off-by: Peter Xu <peterx@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Cédric Le Goater <clg@redhat.com> Signed-off-by: Zheyu Ma <zheyuma97@gmail.com> Signed-off-by: Ido Plat <ido.plat@ibm.com> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Signed-off-by: David Hildenbrand <david@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> Signed-off-by: Gregory Price <gregory.price@memverge.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Lorenz Brun <lorenz@brun.one> Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com> Signed-off-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> Signed-off-by: Inès Varhol <ines.varhol@telecom-paris.fr> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu> Signed-off-by: Igor Mammedov <imammedo@redhat.com> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Sven Schnelle <svens@stackframe.org> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com> Signed-off-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Helge Deller <deller@gmx.de> Signed-off-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Benjamin Gray <bgray@linux.ibm.com> Signed-off-by: Avihai Horon <avihaih@nvidia.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Signed-off-by: Joonas Kankaala <joonas.a.kankaala@gmail.com> Signed-off-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org> Signed-off-by: Stefan Weil <sw@weilnetz.de> Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Glenn Miles <milesg@linux.ibm.com> Signed-off-by: Oleg Sviridov <oleg.sviridov@red-soft.ru> Signed-off-by: Artem Chernyshev <artem.chernyshev@red-soft.ru> Signed-off-by: Yajun Wu <yajunw@nvidia.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Signed-off-by: Pierre-Clément Tosi <ptosi@google.com> Signed-off-by: Lei Wang <lei4.wang@intel.com> Signed-off-by: Wei Wang <wei.w.wang@intel.com> Signed-off-by: Martin Hundebøll <martin@geanix.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Signed-off-by: Wafer <wafer@jaguarmicro.com> Signed-off-by: Yuxue Liu <yuxue.liu@jaguarmicro.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com> Signed-off-by: Zack Buhman <zack@buhman.org> Signed-off-by: Keith Packard <keithp@keithp.com> Signed-off-by: Yuquan Wang wangyuquan1236@phytium.com.cn Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com> Signed-off-by: Cindy Lu <lulu@redhat.com> Co-authored-by: Peter Maydell <peter.maydell@linaro.org> Co-authored-by: Fabiano Rosas <farosas@suse.de> Co-authored-by: Peter Xu <peterx@redhat.com> Co-authored-by: Thomas Huth <thuth@redhat.com> Co-authored-by: Cédric Le Goater <clg@redhat.com> Co-authored-by: Zheyu Ma <zheyuma97@gmail.com> Co-authored-by: Ido Plat <ido.plat@ibm.com> Co-authored-by: Ilya Leoshkevich <iii@linux.ibm.com> Co-authored-by: Markus Armbruster <armbru@redhat.com> Co-authored-by: Marc-André Lureau <marcandre.lureau@redhat.com> Co-authored-by: Paolo Bonzini <pbonzini@redhat.com> Co-authored-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> Co-authored-by: David Hildenbrand <david@redhat.com> Co-authored-by: Kevin Wolf <kwolf@redhat.com> Co-authored-by: Stefan Reiter <s.reiter@proxmox.com> Co-authored-by: Fiona Ebner <f.ebner@proxmox.com> Co-authored-by: Gregory Price <gregory.price@memverge.com> Co-authored-by: Lorenz Brun <lorenz@brun.one> Co-authored-by: Yao Xingtao <yaoxt.fnst@fujitsu.com> Co-authored-by: Philippe Mathieu-Daudé <philmd@linaro.org> Co-authored-by: Arnaud Minier <arnaud.minier@telecom-paris.fr> Co-authored-by: BALATON Zoltan <balaton@eik.bme.hu> Co-authored-by: Igor Mammedov <imammedo@redhat.com> Co-authored-by: Akihiko Odaki <akihiko.odaki@daynix.com> Co-authored-by: Richard Henderson <richard.henderson@linaro.org> Co-authored-by: Sven Schnelle <svens@stackframe.org> Co-authored-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> Co-authored-by: Helge Deller <deller@kernel.org> Co-authored-by: Harsh Prateek Bora <harshpb@linux.ibm.com> Co-authored-by: Benjamin Gray <bgray@linux.ibm.com> Co-authored-by: Nicholas Piggin <npiggin@gmail.com> Co-authored-by: Avihai Horon <avihaih@nvidia.com> Co-authored-by: Michael Tokarev <mjt@tls.msk.ru> Co-authored-by: Joonas Kankaala <joonas.a.kankaala@gmail.com> Co-authored-by: Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org> Co-authored-by: Stefan Weil <sw@weilnetz.de> Co-authored-by: Dayu Liu <liu.dayu@zte.com.cn> Co-authored-by: Zhao Liu <zhao1.liu@intel.com> Co-authored-by: Glenn Miles <milesg@linux.vnet.ibm.com> Co-authored-by: Artem Chernyshev <artem.chernyshev@red-soft.ru> Co-authored-by: Yajun Wu <yajunw@nvidia.com> Co-authored-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk> Co-authored-by: Pierre-Clément Tosi <ptosi@google.com> Co-authored-by: Wei Wang <wei.w.wang@intel.com> Co-authored-by: Martin Hundebøll <martin@geanix.com> Co-authored-by: Michael S. Tsirkin <mst@redhat.com> Co-authored-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org> Co-authored-by: Wafer <wafer@jaguarmicro.com> Co-authored-by: lyx634449800 <yuxue.liu@jaguarmicro.com> Co-authored-by: Gerd Hoffmann <kraxel@redhat.com> Co-authored-by: Nguyen Dinh Phi <phind.uet@gmail.com> Co-authored-by: Zack Buhman <zack@buhman.org> Co-authored-by: Keith Packard <keithp@keithp.com> Co-authored-by: Yuquan Wang <wangyuquan1236@phytium.com.cn> Co-authored-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com> Co-authored-by: Cindy Lu <lulu@redhat.com>
227 lines
7.7 KiB
ReStructuredText
227 lines
7.7 KiB
ReStructuredText
'virt' Generic Virtual Platform (``virt``)
|
||
==========================================
|
||
|
||
The ``virt`` board is a platform which does not correspond to any real hardware;
|
||
it is designed for use in virtual machines. It is the recommended board type
|
||
if you simply want to run a guest such as Linux and do not care about
|
||
reproducing the idiosyncrasies and limitations of a particular bit of
|
||
real-world hardware.
|
||
|
||
Supported devices
|
||
-----------------
|
||
|
||
The ``virt`` machine supports the following devices:
|
||
|
||
* Up to 512 generic RV32GC/RV64GC cores, with optional extensions
|
||
* Core Local Interruptor (CLINT)
|
||
* Platform-Level Interrupt Controller (PLIC)
|
||
* CFI parallel NOR flash memory
|
||
* 1 NS16550 compatible UART
|
||
* 1 Google Goldfish RTC
|
||
* 1 SiFive Test device
|
||
* 8 virtio-mmio transport devices
|
||
* 1 generic PCIe host bridge
|
||
* The fw_cfg device that allows a guest to obtain data from QEMU
|
||
|
||
The hypervisor extension has been enabled for the default CPU, so virtual
|
||
machines with hypervisor extension can simply be used without explicitly
|
||
declaring.
|
||
|
||
Hardware configuration information
|
||
----------------------------------
|
||
|
||
The ``virt`` machine automatically generates a device tree blob ("dtb")
|
||
which it passes to the guest, if there is no ``-dtb`` option. This provides
|
||
information about the addresses, interrupt lines and other configuration of
|
||
the various devices in the system. Guest software should discover the devices
|
||
that are present in the generated DTB.
|
||
|
||
If users want to provide their own DTB, they can use the ``-dtb`` option.
|
||
These DTBs should have the following requirements:
|
||
|
||
* The number of subnodes of the /cpus node should match QEMU's ``-smp`` option
|
||
* The /memory reg size should match QEMU’s selected ram_size via ``-m``
|
||
* Should contain a node for the CLINT device with a compatible string
|
||
"riscv,clint0" if using with OpenSBI BIOS images
|
||
|
||
Boot options
|
||
------------
|
||
|
||
The ``virt`` machine can start using the standard -kernel functionality
|
||
for loading a Linux kernel, a VxWorks kernel, an S-mode U-Boot bootloader
|
||
with the default OpenSBI firmware image as the -bios. It also supports
|
||
the recommended RISC-V bootflow: U-Boot SPL (M-mode) loads OpenSBI fw_dynamic
|
||
firmware and U-Boot proper (S-mode), using the standard -bios functionality.
|
||
|
||
Using flash devices
|
||
-------------------
|
||
|
||
By default, the first flash device (pflash0) is expected to contain
|
||
S-mode firmware code. It can be configured as read-only, with the
|
||
second flash device (pflash1) available to store configuration data.
|
||
|
||
For example, booting edk2 looks like
|
||
|
||
.. code-block:: bash
|
||
|
||
$ qemu-system-riscv64 \
|
||
-blockdev node-name=pflash0,driver=file,read-only=on,filename=<edk2_code> \
|
||
-blockdev node-name=pflash1,driver=file,filename=<edk2_vars> \
|
||
-M virt,pflash0=pflash0,pflash1=pflash1 \
|
||
... other args ....
|
||
|
||
For TCG guests only, it is also possible to boot M-mode firmware from
|
||
the first flash device (pflash0) by additionally passing ``-bios
|
||
none``, as in
|
||
|
||
.. code-block:: bash
|
||
|
||
$ qemu-system-riscv64 \
|
||
-bios none \
|
||
-blockdev node-name=pflash0,driver=file,read-only=on,filename=<m_mode_code> \
|
||
-M virt,pflash0=pflash0 \
|
||
... other args ....
|
||
|
||
Firmware images used for pflash must be exactly 32 MiB in size.
|
||
|
||
Machine-specific options
|
||
------------------------
|
||
|
||
The following machine-specific options are supported:
|
||
|
||
- aclint=[on|off]
|
||
|
||
When this option is "on", ACLINT devices will be emulated instead of
|
||
SiFive CLINT. When not specified, this option is assumed to be "off".
|
||
This option is restricted to the TCG accelerator.
|
||
|
||
- acpi=[on|off|auto]
|
||
|
||
When this option is "on" (which is the default), ACPI tables are generated and
|
||
exposed as firmware tables etc/acpi/rsdp and etc/acpi/tables.
|
||
|
||
- aia=[none|aplic|aplic-imsic]
|
||
|
||
This option allows selecting interrupt controller defined by the AIA
|
||
(advanced interrupt architecture) specification. The "aia=aplic" selects
|
||
APLIC (advanced platform level interrupt controller) to handle wired
|
||
interrupts whereas the "aia=aplic-imsic" selects APLIC and IMSIC (incoming
|
||
message signaled interrupt controller) to handle both wired interrupts and
|
||
MSIs. When not specified, this option is assumed to be "none" which selects
|
||
SiFive PLIC to handle wired interrupts.
|
||
|
||
- aia-guests=nnn
|
||
|
||
The number of per-HART VS-level AIA IMSIC pages to be emulated for a guest
|
||
having AIA IMSIC (i.e. "aia=aplic-imsic" selected). When not specified,
|
||
the default number of per-HART VS-level AIA IMSIC pages is 0.
|
||
|
||
Running Linux kernel
|
||
--------------------
|
||
|
||
Linux mainline v5.12 release is tested at the time of writing. To build a
|
||
Linux mainline kernel that can be booted by the ``virt`` machine in
|
||
64-bit mode, simply configure the kernel using the defconfig configuration:
|
||
|
||
.. code-block:: bash
|
||
|
||
$ export ARCH=riscv
|
||
$ export CROSS_COMPILE=riscv64-linux-
|
||
$ make defconfig
|
||
$ make
|
||
|
||
To boot the newly built Linux kernel in QEMU with the ``virt`` machine:
|
||
|
||
.. code-block:: bash
|
||
|
||
$ qemu-system-riscv64 -M virt -smp 4 -m 2G \
|
||
-display none -serial stdio \
|
||
-kernel arch/riscv/boot/Image \
|
||
-initrd /path/to/rootfs.cpio \
|
||
-append "root=/dev/ram"
|
||
|
||
To build a Linux mainline kernel that can be booted by the ``virt`` machine
|
||
in 32-bit mode, use the rv32_defconfig configuration. A patch is required to
|
||
fix the 32-bit boot issue for Linux kernel v5.12.
|
||
|
||
.. code-block:: bash
|
||
|
||
$ export ARCH=riscv
|
||
$ export CROSS_COMPILE=riscv64-linux-
|
||
$ curl https://patchwork.kernel.org/project/linux-riscv/patch/20210627135117.28641-1-bmeng.cn@gmail.com/mbox/ > riscv.patch
|
||
$ git am riscv.patch
|
||
$ make rv32_defconfig
|
||
$ make
|
||
|
||
Replace ``qemu-system-riscv64`` with ``qemu-system-riscv32`` in the command
|
||
line above to boot the 32-bit Linux kernel. A rootfs image containing 32-bit
|
||
applications shall be used in order for kernel to boot to user space.
|
||
|
||
Running U-Boot
|
||
--------------
|
||
|
||
U-Boot mainline v2021.04 release is tested at the time of writing. To build an
|
||
S-mode U-Boot bootloader that can be booted by the ``virt`` machine, use
|
||
the qemu-riscv64_smode_defconfig with similar commands as described above for Linux:
|
||
|
||
.. code-block:: bash
|
||
|
||
$ export CROSS_COMPILE=riscv64-linux-
|
||
$ make qemu-riscv64_smode_defconfig
|
||
|
||
Boot the 64-bit U-Boot S-mode image directly:
|
||
|
||
.. code-block:: bash
|
||
|
||
$ qemu-system-riscv64 -M virt -smp 4 -m 2G \
|
||
-display none -serial stdio \
|
||
-kernel /path/to/u-boot.bin
|
||
|
||
To test booting U-Boot SPL which in M-mode, which in turn loads a FIT image
|
||
that bundles OpenSBI fw_dynamic firmware and U-Boot proper (S-mode) together,
|
||
build the U-Boot images using riscv64_spl_defconfig:
|
||
|
||
.. code-block:: bash
|
||
|
||
$ export CROSS_COMPILE=riscv64-linux-
|
||
$ export OPENSBI=/path/to/opensbi-riscv64-generic-fw_dynamic.bin
|
||
$ make qemu-riscv64_spl_defconfig
|
||
|
||
The minimal QEMU commands to run U-Boot SPL are:
|
||
|
||
.. code-block:: bash
|
||
|
||
$ qemu-system-riscv64 -M virt -smp 4 -m 2G \
|
||
-display none -serial stdio \
|
||
-bios /path/to/u-boot-spl \
|
||
-device loader,file=/path/to/u-boot.itb,addr=0x80200000
|
||
|
||
To test 32-bit U-Boot images, switch to use qemu-riscv32_smode_defconfig and
|
||
riscv32_spl_defconfig builds, and replace ``qemu-system-riscv64`` with
|
||
``qemu-system-riscv32`` in the command lines above to boot the 32-bit U-Boot.
|
||
|
||
Enabling TPM
|
||
------------
|
||
|
||
A TPM device can be connected to the virt board by following the steps below.
|
||
|
||
First launch the TPM emulator:
|
||
|
||
.. code-block:: bash
|
||
|
||
$ swtpm socket --tpm2 -t -d --tpmstate dir=/tmp/tpm \
|
||
--ctrl type=unixio,path=swtpm-sock
|
||
|
||
Then launch QEMU with some additional arguments to link a TPM device to the backend:
|
||
|
||
.. code-block:: bash
|
||
|
||
$ qemu-system-riscv64 \
|
||
... other args .... \
|
||
-chardev socket,id=chrtpm,path=swtpm-sock \
|
||
-tpmdev emulator,id=tpm0,chardev=chrtpm \
|
||
-device tpm-tis-device,tpmdev=tpm0
|
||
|
||
The TPM device can be seen in the memory tree and the generated device
|
||
tree and should be accessible from the guest software.
|