boot/edk2: add support for RISC-V 64bit architecture

RISC-V 64bit qemu virt machine support has been added in edk2
version "stable202302". See [1].

Since edk2-stable202308, introduced in buildroot in commit 5c9f310
"boot/edk2: bump to version edk2-stable202308", it is now possible
to boot the edk2 UEFI shell in qemu.

This commit adds this early RISC-V support to edk2.

The RISC-V edk2 UEFI shell can be booted in Buildroot with the
following commands:

    # Build EDK2 images
    cat > .config <<EOF
    BR2_riscv=y
    BR2_RISCV_64=y
    BR2_PACKAGE_HOST_QEMU=y
    BR2_PACKAGE_HOST_QEMU_SYSTEM_MODE=y
    BR2_TARGET_EDK2=y
    EOF
    make olddefconfig
    make

    # edk2 image size should fit the 32MB of qemu pflash memories
    truncate -s 32M output/images/RISCV_VIRT_CODE.fd
    truncate -s 32M output/images/RISCV_VIRT_VARS.fd

    # Start qemu:
    output/host/usr/bin/qemu-system-riscv64 \
        -M virt,pflash0=pflash0,pflash1=pflash1,acpi=off \
        -nographic \
        -blockdev node-name=pflash0,driver=file,read-only=on,filename=output/images/RISCV_VIRT_CODE.fd \
        -blockdev node-name=pflash1,driver=file,filename=output/images/RISCV_VIRT_VARS.fd

Note: a Qemu version >= 8.0.0 is needed to properly start edk2. A qemu
version on the host system might not be sufficient. This is why the
Buildroot host-qemu is built in this config example.

[1] https://github.com/tianocore/edk2/releases/tag/edk2-stable202302

Signed-off-by: Julien Olivain <ju.o@free.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Julien Olivain 2023-12-22 11:56:55 +01:00 committed by Thomas Petazzoni
parent e0c8c16259
commit 1b2498fa91
2 changed files with 16 additions and 0 deletions

View File

@ -2,6 +2,7 @@ config BR2_TARGET_EDK2_ARCH_SUPPORTS
bool bool
default y if BR2_aarch64 default y if BR2_aarch64
default y if BR2_i386 default y if BR2_i386
default y if BR2_RISCV_64
default y if BR2_x86_64 default y if BR2_x86_64
config BR2_TARGET_EDK2 config BR2_TARGET_EDK2
@ -20,6 +21,7 @@ if BR2_TARGET_EDK2
choice choice
prompt "Platform" prompt "Platform"
default BR2_TARGET_EDK2_PLATFORM_OVMF_I386 if BR2_i386 default BR2_TARGET_EDK2_PLATFORM_OVMF_I386 if BR2_i386
default BR2_TARGET_EDK2_PLATFORM_OVMF_RISCV if BR2_RISCV_64
default BR2_TARGET_EDK2_PLATFORM_OVMF_X64 if BR2_x86_64 default BR2_TARGET_EDK2_PLATFORM_OVMF_X64 if BR2_x86_64
default BR2_TARGET_EDK2_PLATFORM_ARM_VIRT_QEMU if BR2_aarch64 default BR2_TARGET_EDK2_PLATFORM_ARM_VIRT_QEMU if BR2_aarch64
@ -31,6 +33,14 @@ config BR2_TARGET_EDK2_PLATFORM_OVMF_I386
This platform will boot from flash address 0x0. This platform will boot from flash address 0x0.
It should therefore be used as the first bootloader. It should therefore be used as the first bootloader.
config BR2_TARGET_EDK2_PLATFORM_OVMF_RISCV
bool "RISC-V"
depends on BR2_RISCV_64
help
Platform configuration for RISC-V QEMU targeting the Virt
machine. This platform will only boot from flash address
0x0. It should therefore be used as the first bootloader.
config BR2_TARGET_EDK2_PLATFORM_OVMF_X64 config BR2_TARGET_EDK2_PLATFORM_OVMF_X64
bool "x86-64" bool "x86-64"
depends on BR2_x86_64 depends on BR2_x86_64

View File

@ -136,6 +136,12 @@ define EDK2_PRE_BUILD_QEMU_SBSA
ln -srf $(BINARIES_DIR)/{bl1.bin,fip.bin} $(EDK2_BUILD_PACKAGES)/Platform/Qemu/Sbsa/ ln -srf $(BINARIES_DIR)/{bl1.bin,fip.bin} $(EDK2_BUILD_PACKAGES)/Platform/Qemu/Sbsa/
endef endef
else ifeq ($(BR2_TARGET_EDK2_PLATFORM_OVMF_RISCV),y)
EDK2_ARCH = RISCV64
EDK2_PACKAGE_NAME = OvmfPkg/RiscVVirt
EDK2_PLATFORM_NAME = RiscVVirtQemu
EDK2_BUILD_DIR = $(EDK2_PLATFORM_NAME)
endif endif
EDK2_BASETOOLS_OPTS = \ EDK2_BASETOOLS_OPTS = \