1 | # Support for RISC-V QEMU virt platform
|
---|
2 |
|
---|
3 | ## Overview
|
---|
4 | RISC-V QEMU 'virt' is a generic platform which does not correspond to any real
|
---|
5 | hardware.
|
---|
6 |
|
---|
7 | EDK2 for RISC-V virt platform is a payload (S-mode) for the previous stage M-mode
|
---|
8 | firmware like OpenSBI. It follows PEI less design.
|
---|
9 |
|
---|
10 | The minimum QEMU version required is
|
---|
11 | **[8.1](https://wiki.qemu.org/Planning/8.1)** or with commit
|
---|
12 | [7efd65423a](https://github.com/qemu/qemu/commit/7efd65423ab22e6f5890ca08ae40c84d6660242f)
|
---|
13 | which supports separate pflash devices for EDK2 code and variable storage.
|
---|
14 |
|
---|
15 | ## Get edk2 sources
|
---|
16 |
|
---|
17 | git clone --recurse-submodule git@github.com:tianocore/edk2.git
|
---|
18 |
|
---|
19 | ## Build
|
---|
20 |
|
---|
21 | ### Using GCC toolchain
|
---|
22 | **Prerequisite**: RISC-V GNU compiler toolchain should be installed.
|
---|
23 |
|
---|
24 | export WORKSPACE=`pwd`
|
---|
25 | export GCC5_RISCV64_PREFIX=riscv64-linux-gnu-
|
---|
26 | export PACKAGES_PATH=$WORKSPACE/edk2
|
---|
27 | export EDK_TOOLS_PATH=$WORKSPACE/edk2/BaseTools
|
---|
28 | source edk2/edksetup.sh --reconfig
|
---|
29 | make -C edk2/BaseTools
|
---|
30 | source edk2/edksetup.sh BaseTools
|
---|
31 | build -a RISCV64 --buildtarget RELEASE -p OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc -t GCC5
|
---|
32 |
|
---|
33 | ### Using CLANGDWARF toolchain (clang + lld)
|
---|
34 | **Prerequisite**: LLVM toolchain with clang and lld should be installed.
|
---|
35 |
|
---|
36 | export WORKSPACE=`pwd`
|
---|
37 | export CLANGDWARF_BIN=/usr/bin/
|
---|
38 | export PACKAGES_PATH=$WORKSPACE/edk2
|
---|
39 | export EDK_TOOLS_PATH=$WORKSPACE/edk2/BaseTools
|
---|
40 | source edk2/edksetup.sh --reconfig
|
---|
41 | make -C edk2/BaseTools
|
---|
42 | source edk2/edksetup.sh BaseTools
|
---|
43 | build -a RISCV64 --buildtarget RELEASE -p OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc -t CLANGDWARF
|
---|
44 |
|
---|
45 | After a successful build, two files namely **RISCV_VIRT_CODE.fd** and **RISCV_VIRT_VARS.fd** are created.
|
---|
46 |
|
---|
47 | ## Test
|
---|
48 | Below example shows how to boot openSUSE Tumbleweed E20.
|
---|
49 |
|
---|
50 | 1) RISC-V QEMU pflash devices should be of of size 32MiB.
|
---|
51 |
|
---|
52 | `truncate -s 32M RISCV_VIRT_CODE.fd`
|
---|
53 |
|
---|
54 | `truncate -s 32M RISCV_VIRT_VARS.fd`
|
---|
55 |
|
---|
56 | 2) Running QEMU
|
---|
57 |
|
---|
58 | qemu-system-riscv64 \
|
---|
59 | -M virt,pflash0=pflash0,pflash1=pflash1,acpi=off \
|
---|
60 | -m 4096 -smp 2 \
|
---|
61 | -serial mon:stdio \
|
---|
62 | -device virtio-gpu-pci -full-screen \
|
---|
63 | -device qemu-xhci \
|
---|
64 | -device usb-kbd \
|
---|
65 | -device virtio-rng-pci \
|
---|
66 | -blockdev node-name=pflash0,driver=file,read-only=on,filename=RISCV_VIRT_CODE.fd \
|
---|
67 | -blockdev node-name=pflash1,driver=file,filename=RISCV_VIRT_VARS.fd \
|
---|
68 | -netdev user,id=net0 \
|
---|
69 | -device virtio-net-pci,netdev=net0 \
|
---|
70 | -device virtio-blk-device,drive=hd0 \
|
---|
71 | -drive file=openSUSE-Tumbleweed-RISC-V-E20-efi.riscv64.raw,format=raw,id=hd0
|
---|
72 |
|
---|
73 | Note: the `acpi=off` machine property is specified because Linux guest
|
---|
74 | support for ACPI (that is, the ACPI consumer side) is a work in progress.
|
---|
75 | Currently, `acpi=off` is recommended unless you are developing ACPI support
|
---|
76 | yourself.
|
---|
77 |
|
---|
78 | 3) Running QEMU with direct kernel boot
|
---|
79 |
|
---|
80 | The following example boots the same guest, but loads the kernel image and
|
---|
81 | the initial RAM disk (which were extracted from
|
---|
82 | `openSUSE-Tumbleweed-RISC-V-E20-efi.riscv64.raw`) from the host filesystem.
|
---|
83 | It also sets the guest kernel command line on the QEMU command line.
|
---|
84 |
|
---|
85 | CMDLINE=(root=UUID=76d9b92d-09e9-4df0-8262-c1a7a466f2bc
|
---|
86 | systemd.show_status=1
|
---|
87 | ignore_loglevel
|
---|
88 | console=ttyS0
|
---|
89 | earlycon=uart8250,mmio,0x10000000)
|
---|
90 |
|
---|
91 | qemu-system-riscv64 \
|
---|
92 | -M virt,pflash0=pflash0,pflash1=pflash1,acpi=off \
|
---|
93 | -m 4096 -smp 2 \
|
---|
94 | -serial mon:stdio \
|
---|
95 | -device virtio-gpu-pci -full-screen \
|
---|
96 | -device qemu-xhci \
|
---|
97 | -device usb-kbd \
|
---|
98 | -device virtio-rng-pci \
|
---|
99 | -blockdev node-name=pflash0,driver=file,read-only=on,filename=RISCV_VIRT_CODE.fd \
|
---|
100 | -blockdev node-name=pflash1,driver=file,filename=RISCV_VIRT_VARS.fd \
|
---|
101 | -netdev user,id=net0 \
|
---|
102 | -device virtio-net-pci,netdev=net0 \
|
---|
103 | -device virtio-blk-device,drive=hd0 \
|
---|
104 | -drive file=openSUSE-Tumbleweed-RISC-V-E20-efi.riscv64.raw,format=raw,id=hd0 \
|
---|
105 | -kernel Image-6.5.2-1-default \
|
---|
106 | -initrd initrd-6.5.2-1-default \
|
---|
107 | -append "${CMDLINE[*]}"
|
---|
108 |
|
---|
109 | ## Test with your own OpenSBI binary
|
---|
110 | Using the above QEMU command lines, **RISCV_VIRT_CODE.fd** is launched by the
|
---|
111 | OpenSBI binary that is bundled with QEMU. You can build your own OpenSBI binary
|
---|
112 | as well:
|
---|
113 |
|
---|
114 | OPENSBI_DIR=...
|
---|
115 | git clone https://github.com/riscv/opensbi.git $OPENSBI_DIR
|
---|
116 | make -C $OPENSBI_DIR \
|
---|
117 | -j $(getconf _NPROCESSORS_ONLN) \
|
---|
118 | CROSS_COMPILE=riscv64-linux-gnu- \
|
---|
119 | PLATFORM=generic
|
---|
120 |
|
---|
121 | then specify that binary for QEMU, with the following additional command line
|
---|
122 | option:
|
---|
123 |
|
---|
124 | -bios $OPENSBI_DIR/build/platform/generic/firmware/fw_dynamic.bin
|
---|
125 |
|
---|
126 | Note that the above only makes a difference with software emulation (which you
|
---|
127 | can force with `-M accel=tcg`). With hardware virtualization (`-M accel=kvm`),
|
---|
128 | KVM services the SBI (Supervisor Binary Interface) calls internally, therefore
|
---|
129 | any OpenSBI binary specified with `-bios` is rejected.
|
---|