tree: 598c03043fb683fd36a39ec808156fcce00e99bc [search]
  1. Drivers/
  2. Feature/
  3. Library/
  4. PlatformPei/
  5. Sec/
  6. LoongArchVirt.fdf.inc
  7. LoongArchVirtQemu.dsc
  8. LoongArchVirtQemu.fdf
  9. Readme.md
  10. VarStore.fdf.inc
OvmfPkg/LoongArchVirt/Readme.md

LoongArch QEMU virt platform

Overview

LoongArch QEMU virt is a generic platform that does not require any actual hardware. The minimum required QEMU version is 8.1, the minimum required GCC version is GCC13, the minimum required Binutils version is 2.40.

Prepare (X86 Linux Environment)

Fedora39 and higher

Install LoongArch64 cross compiler, LoongArch system QEMU.

yum install gcc-loongarch64-linux-gnu
yum install qemu-system-loongarch64

Others X86 OS ENV

Configure cross-tools

Download:

wget https://github.com/loongson/build-tools/releases/download/2023.08.08/x86_64-cross-tools-loongarch64-binutils_2.41-gcc_13.2.0.tar.xz

Configure the cross-tools environment:

mkdir /opt/loongarch64_cross-toolchain/
tar -vxf x86_64-cross-tools-loongarch64-binutils_2.41-gcc_13.2.0.tar.xz -C /opt/loongarch64_cross-toolchain/
export PATH=/opt/loongarch64_cross-toolchain/cross-tools/bin:$PATH

Note: Please obtain the latest cross-compilation toolchains.

Build QEMU

git clone https://gitlab.com/qemu-project/qemu.git

Note: Please refer to QEMU compilation rules, located in qemu/doc/system/loongarch/virt.rst.

Build LoongArch QEMU virtual machine firmware

Get edk2 resouces

git clone --recurse-submodule https://github.com/tianocore/edk2.git

Building LoongArch QEMU virt FW with GCC

export WORKSPACE=`pwd`
export GCC_LOONGARCH64_PREFIX=loongarch64-unknown-linux-gnu-
export PACKAGES_PATH=$WORKSPACE/edk2
export EDK_TOOLS_PATH=$WORKSPACE/edk2/BaseTools
source edk2/edksetup.sh --reconfig
make -C edk2/BaseTools
source edk2/edksetup.sh BaseTools
build -b RELEASE -t GCC -a LOONGARCH64 -p OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc

Secure Boot

LoongArchVirt Secure Boot builds that are intended to keep Secure Boot state locked from the guest should use the QEMU UEFI variable store:

build -b RELEASE -t GCC -a LOONGARCH64 \
  -p OvmfPkg/LoongArchVirt/LoongArchVirtQemu.dsc \
  -D SECURE_BOOT_ENABLE=TRUE \
  -D QEMU_PV_VARS=TRUE

When using QEMU_PV_VARS=TRUE, configure the QEMU uefi-vars-sysbus device with policy options that keep Secure Boot enabled and prevent guest-side Custom Mode changes:

-device uefi-vars-sysbus,jsonfile=/path/to/varstore.json,\

disable-custom-mode=on,force-secure-boot=on

Without these QEMU-side policy options, the VM manager does not lock the guest out of Custom Mode or Secure Boot state changes through UEFI variable services. LoongArchVirt does not provide a hardware-backed physical-presence mechanism, so locked Secure Boot deployments must express this policy in the QEMU configuration.

Refer to OvmfPkg/QEMU_PV_VARS.md for more information about the QEMU UEFI variable store.

Test LoongArch QEMU virtual machine firmware

qemu-system-loongarch64 \
-m 4G \
-M virt \
-smp 2 \
-cpu la464 \
-bios Build/LoongArchVirtQemu/RELEASE_GCC/FV/QEMU_EFI.fd \
-serial stdio

Test LoongArch QEMU virtual machine OS