From 809f0e58208c93ac57493b65629a29509413644e Mon Sep 17 00:00:00 2001 From: Guost123 Date: Tue, 13 May 2025 16:39:26 +0800 Subject: [PATCH 1/4] adapt for riscv64 --- add_support_for_riscv64.patch | 58 +++++++++++++++++++++++++++++++++++ edk2.spec | 48 ++++++++++++++++++++++++++--- 2 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 add_support_for_riscv64.patch diff --git a/add_support_for_riscv64.patch b/add_support_for_riscv64.patch new file mode 100644 index 0000000..5ab44f2 --- /dev/null +++ b/add_support_for_riscv64.patch @@ -0,0 +1,58 @@ +diff -ruN rpm_ori/SOURCES/50-edk2-riscv-qcow2.json SOURCES/50-edk2-riscv-qcow2.json +--- rpm_ori/SOURCES/50-edk2-riscv-qcow2.json 1969-12-31 19:00:00.000000000 -0500 ++++ SOURCES/50-edk2-riscv-qcow2.json 2025-05-09 04:39:33.961317297 -0400 +@@ -0,0 +1,32 @@ ++{ ++ "description": "UEFI firmware for RISC-V virtual machines", ++ "interface-types": [ ++ "uefi" ++ ], ++ "mapping": { ++ "device": "flash", ++ "mode" : "split", ++ "executable": { ++ "filename": "/usr/share/edk2/riscv/RISCV_VIRT_CODE.qcow2", ++ "format": "qcow2" ++ }, ++ "nvram-template": { ++ "filename": "/usr/share/edk2/riscv/RISCV_VIRT_VARS.qcow2", ++ "format": "qcow2" ++ } ++ }, ++ "targets": [ ++ { ++ "architecture": "riscv64", ++ "machines": [ ++ "virt-*" ++ ] ++ } ++ ], ++ "features": [ ++ ++ ], ++ "tags": [ ++ ++ ] ++} +diff -ruN rpm_ori/SOURCES/edk2-build SOURCES/edk2-build +--- rpm_ori/SOURCES/edk2-build 2024-11-30 02:30:46.000000000 -0500 ++++ SOURCES/edk2-build 2025-05-09 04:45:37.862189455 -0400 +@@ -155,3 +155,18 @@ + cpy1 = FV/QEMU_EFI.fd QEMU_EFI.silent.fd + cpy2 = FV/QEMU_EFI.fd QEMU_EFI-silent-pflash.raw + pad2 = QEMU_EFI-silent-pflash.raw 4m ++ ++##################################################################### ++# riscv ++ ++[build.riscv.qemu] ++conf = OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc ++arch = RISCV64 ++plat = RiscVVirtQemu ++dest = edk2-build-dir/riscv ++cpy1 = FV/RISCV_VIRT_CODE.fd ++cpy2 = FV/RISCV_VIRT_CODE.fd RISCV_VIRT_CODE.raw ++cpy3 = FV/RISCV_VIRT_VARS.fd ++cpy4 = FV/RISCV_VIRT_VARS.fd RISCV_VIRT_VARS.raw ++pad1 = RISCV_VIRT_CODE.raw 32m ++pad2 = RISCV_VIRT_VARS.raw 32m diff --git a/edk2.spec b/edk2.spec index 5cbc736..96127f4 100644 --- a/edk2.spec +++ b/edk2.spec @@ -1,7 +1,7 @@ -%define anolis_release 11 +%define anolis_release 12 %undefine _auto_set_build_flags -ExclusiveArch: x86_64 aarch64 loongarch64 +ExclusiveArch: x86_64 aarch64 loongarch64 riscv64 # edk2-stable202402 %define GITDATE 20240214 @@ -12,6 +12,7 @@ ExclusiveArch: x86_64 aarch64 loongarch64 %define build_ovmf 0 %define build_aarch64 0 %define build_loongarch64 0 +%define build_riscv64 0 %ifarch x86_64 %define build_ovmf 1 %endif @@ -21,7 +22,9 @@ ExclusiveArch: x86_64 aarch64 loongarch64 %ifarch loongarch64 %define build_loongarch64 1 %endif -%define build_riscv64 0 +%ifarch riscv64 + %define build_riscv64 1 +%endif %global softfloat_version 20180726-gitb64af41 @@ -57,6 +60,8 @@ Source44: 60-edk2-ovmf-x64-inteltdx.json Source50: 50-edk2-loongarch64.json Source51: 51-edk2-loongarch64-verbose.json +Source61: 50-edk2-riscv-qcow2.json + Source80: https://gitlab.com/kraxel/edk2-build-config/-/blob/master/bin/edk2-build.py Source81: edk2-build @@ -174,6 +179,13 @@ LoongArch Architecture Virtual Machine Firmware is an EFI Development Kit II platform that enables UEFI support for QEMU/KVM LoongArch Virtual Machines. This package contains a 64-bit build. +%package riscv64 +Summary: RISC-V Virtual Machine Firmware +BuildArch: noarch +License: BSD-2-Clause-Patent and OpenSSL +%description riscv64 +EFI Development Kit II +RISC-V UEFI Firmware %package tools Summary: EFI Development Kit II Tools @@ -259,7 +271,7 @@ chmod -Rf a+rX,u+w,g-w,o-w . cp -a -- \ %{SOURCE10} %{SOURCE11} \ %{SOURCE40} %{SOURCE41} %{SOURCE42} %{SOURCE43} %{SOURCE44} \ - %{SOURCE50} %{SOURCE51} %{SOURCE80} %{SOURCE81} \ + %{SOURCE50} %{SOURCE51} %{SOURCE80} %{SOURCE81} %{SOURCE61} \ . # The following patches need to be applied in the Platform directory of edk2-platforms, @@ -331,6 +343,14 @@ for raw in */loongarch64/*.raw; do done %endif +%if %{build_riscv64} +./edk2-build.py --config edk2-build --silent --release-date "$RELEASE_DATE" -m riscv +for raw in */riscv/*.raw; do + qcow2="${raw%.raw}.qcow2" + qemu-img convert -f raw -O qcow2 -o cluster_size=4096 -S 4096 "$raw" "$qcow2" +done +%endif + %install cp -a OvmfPkg/License.txt License.OvmfPkg.txt @@ -410,6 +430,15 @@ install -m 0644 \ # endif build_loongarch64 %endif +%if %{build_riscv64} +install -m 0644 \ + 50-edk2-riscv-qcow2.json \ + %{buildroot}%{_datadir}/qemu/firmware + +rm -f %{buildroot}%{_datadir}/edk2/riscv/*.raw +# endif build_riscv64 +%endif + %generate_compatibility_deps %global common_files \ @@ -480,6 +509,14 @@ install -m 0644 \ # endif build_loongarch64 %endif +%if %{build_riscv64} +%files riscv64 +%common_files +%{_datadir}/%{name}/riscv/*.fd +%{_datadir}/%{name}/riscv/*.qcow2 +%{_datadir}/qemu/firmware/50-edk2-riscv-qcow2.json +%endif + %files tools %license License.txt %license License-History.txt @@ -508,6 +545,9 @@ install -m 0644 \ %changelog +* Tue May 13 2025 Shangtong Guo - 202402-12 +- add support for riscv64 build + * Tue Apr 08 2025 hanliyang - 202402-11 - Build OVMF.fd using AmdSevX64.dsc to support Full Disk Encryption -- Gitee From de9fa0e328687279d16ea97aa9fd06e3985ca15f Mon Sep 17 00:00:00 2001 From: Guost123 Date: Wed, 14 May 2025 10:57:03 +0800 Subject: [PATCH 2/4] adapt for riscv64 --- 50-edk2-riscv-qcow2.json | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 50-edk2-riscv-qcow2.json diff --git a/50-edk2-riscv-qcow2.json b/50-edk2-riscv-qcow2.json new file mode 100644 index 0000000..fabc112 --- /dev/null +++ b/50-edk2-riscv-qcow2.json @@ -0,0 +1,32 @@ +{ + "description": "UEFI firmware for RISC-V virtual machines", + "interface-types": [ + "uefi" + ], + "mapping": { + "device": "flash", + "mode" : "split", + "executable": { + "filename": "/usr/share/edk2/riscv/RISCV_VIRT_CODE.qcow2", + "format": "qcow2" + }, + "nvram-template": { + "filename": "/usr/share/edk2/riscv/RISCV_VIRT_VARS.qcow2", + "format": "qcow2" + } + }, + "targets": [ + { + "architecture": "riscv64", + "machines": [ + "virt-*" + ] + } + ], + "features": [ + + ], + "tags": [ + + ] +} -- Gitee From 707278f3e35adce94c8fcaf7b2cd207c66119e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E4=B8=8A=E9=93=9C=2010332738?= Date: Wed, 28 May 2025 14:06:06 +0800 Subject: [PATCH 3/4] adapt for riscv64 --- edk2.spec | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/edk2.spec b/edk2.spec index 96127f4..4f2ad6b 100644 --- a/edk2.spec +++ b/edk2.spec @@ -179,6 +179,7 @@ LoongArch Architecture Virtual Machine Firmware is an EFI Development Kit II platform that enables UEFI support for QEMU/KVM LoongArch Virtual Machines. This package contains a 64-bit build. +%ifarch riscv64 %package riscv64 Summary: RISC-V Virtual Machine Firmware BuildArch: noarch @@ -186,6 +187,7 @@ License: BSD-2-Clause-Patent and OpenSSL %description riscv64 EFI Development Kit II RISC-V UEFI Firmware +%endif %package tools Summary: EFI Development Kit II Tools @@ -268,11 +270,19 @@ mkdir -p CryptoPkg/Library/MbedTlsLib/mbedtls/library # Done by %setup, but we do not use it for the auxiliary tarballs chmod -Rf a+rX,u+w,g-w,o-w . +%ifarch riscv64 cp -a -- \ %{SOURCE10} %{SOURCE11} \ %{SOURCE40} %{SOURCE41} %{SOURCE42} %{SOURCE43} %{SOURCE44} \ %{SOURCE50} %{SOURCE51} %{SOURCE80} %{SOURCE81} %{SOURCE61} \ . +%else +cp -a -- \ + %{SOURCE10} %{SOURCE11} \ + %{SOURCE40} %{SOURCE41} %{SOURCE42} %{SOURCE43} %{SOURCE44} \ + %{SOURCE50} %{SOURCE51} %{SOURCE80} %{SOURCE81} \ + . +%endif # The following patches need to be applied in the Platform directory of edk2-platforms, # so the patches must be applied after edk2-platforms is unpacked. -- Gitee From e44be583090cf90b6139a757170036abdec17d34 Mon Sep 17 00:00:00 2001 From: Guost123 Date: Tue, 13 May 2025 16:39:26 +0800 Subject: [PATCH 4/4] adapt for riscv64 --- edk2.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/edk2.spec b/edk2.spec index 77dcf78..49315a3 100644 --- a/edk2.spec +++ b/edk2.spec @@ -559,6 +559,7 @@ rm -f %{buildroot}%{_datadir}/edk2/riscv/*.raw %changelog +<<<<<<< HEAD * Tue Jun 03 2025 Shangtong Guo - 202402-13 - add support for riscv64 build -- Gitee