From 8b9ca6628faab89c1ac8b626f6b39524dac2a470 Mon Sep 17 00:00:00 2001 From: Xiaotian Wu Date: Wed, 15 Nov 2023 03:14:56 +0000 Subject: [PATCH] Support LoongArch64 Virtual Machine Signed-off-by: Xiaotian Wu --- 50-edk2-loongarch64.json | 31 ++++++++++++++ 51-edk2-loongarch64-verbose.json | 31 ++++++++++++++ edk2-build | 34 ++++++++++++++++ edk2-relax-loong64.patch | 51 +++++++++++++++++++++++ edk2.spec | 70 ++++++++++++++++++++++++++++++-- 5 files changed, 214 insertions(+), 3 deletions(-) create mode 100644 50-edk2-loongarch64.json create mode 100644 51-edk2-loongarch64-verbose.json create mode 100644 edk2-relax-loong64.patch diff --git a/50-edk2-loongarch64.json b/50-edk2-loongarch64.json new file mode 100644 index 0000000..6234417 --- /dev/null +++ b/50-edk2-loongarch64.json @@ -0,0 +1,31 @@ +{ + "description": "UEFI firmware for LoongArch64 virtual machines", + "interface-types": [ + "uefi" + ], + "mapping": { + "device": "flash", + "executable": { + "filename": "/usr/share/edk2/loongarch64/QEMU_EFI-silent-pflash.raw", + "format": "raw" + }, + "nvram-template": { + "filename": "/usr/share/edk2/loongarch64/vars-template-pflash.raw", + "format": "raw" + } + }, + "targets": [ + { + "architecture": "loongarch64", + "machines": [ + "virt-*" + ] + } + ], + "features": [ + + ], + "tags": [ + + ] +} diff --git a/51-edk2-loongarch64-verbose.json b/51-edk2-loongarch64-verbose.json new file mode 100644 index 0000000..601f88a --- /dev/null +++ b/51-edk2-loongarch64-verbose.json @@ -0,0 +1,31 @@ +{ + "description": "UEFI firmware for LoongArch64 virtual machines, verbose logs", + "interface-types": [ + "uefi" + ], + "mapping": { + "device": "flash", + "executable": { + "filename": "/usr/share/edk2/loongarch64/QEMU_EFI-pflash.raw", + "format": "raw" + }, + "nvram-template": { + "filename": "/usr/share/edk2/loongarch64/vars-template-pflash.raw", + "format": "raw" + } + }, + "targets": [ + { + "architecture": "loongarch64", + "machines": [ + "virt-*" + ] + } + ], + "features": [ + "verbose-static" + ], + "tags": [ + + ] +} diff --git a/edk2-build b/edk2-build index 5865fd2..16fcc7d 100644 --- a/edk2-build +++ b/edk2-build @@ -117,3 +117,37 @@ dest = edk2-build-dir/aarch64 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 64m + +##################################################################### +# loongarch64 builds + +[build.loongarch64.verbose] +desc = LoongArch build for qemu, 64-bit, verbose +conf = Platform/Loongson/LoongArchQemuPkg/Loongson.dsc +arch = LOONGARCH64 +opts = ovmf.common + ovmf.4m +tgts = DEBUG +pcds = nx.broken.grub +plat = LoongArchQemu +dest = edk2-build-dir/loongarch64 +cpy1 = FV/QEMU_EFI.fd +cpy2 = FV/QEMU_VARS.fd +cpy3 = FV/QEMU_EFI.fd QEMU_EFI-pflash.raw +cpy4 = FV/QEMU_VARS.fd vars-template-pflash.raw +pad3 = QEMU_EFI-pflash.raw 4m +pad4 = vars-template-pflash.raw 4m + +[build.loongarch64.silent] +desc = LoongArch build for qemu, 64-bit, silent +conf = Platform/Loongson/LoongArchQemuPkg/Loongson.dsc +arch = LOONGARCH64 +opts = ovmf.common + ovmf.4m +tgts = RELEASE +pcds = nx.broken.grub +plat = LoongArchQemu +dest = edk2-build-dir/loongarch64 +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 diff --git a/edk2-relax-loong64.patch b/edk2-relax-loong64.patch new file mode 100644 index 0000000..dca5900 --- /dev/null +++ b/edk2-relax-loong64.patch @@ -0,0 +1,51 @@ +From 0a8a52066da1f9d6fe3f6550cb7e19370a32fcb2 Mon Sep 17 00:00:00 2001 +From: Qian Dongyan +Date: Fri, 25 Feb 2022 14:25:11 +0800 +Subject: [PATCH] loongarch64: add relax relocation support + +Add relax relocation support for LoongArch64 + +diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c +index d53ecb1767..8018d68db1 100644 +--- a/BaseTools/Source/C/GenFw/Elf64Convert.c ++++ b/BaseTools/Source/C/GenFw/Elf64Convert.c +@@ -1778,7 +1778,11 @@ WriteSections64 ( + case R_LARCH_TLS_LD64_HI20: + case R_LARCH_TLS_GD_PC_HI20: + case R_LARCH_TLS_GD64_HI20: ++ case R_LARCH_32_PCREL: + case R_LARCH_RELAX: ++ case R_LARCH_DELETE: ++ case R_LARCH_ALIGN: ++ case R_LARCH_PCREL20_S2: + // + // These types are not used or do not require fixup. + // +@@ -2185,7 +2189,11 @@ WriteRelocations64 ( + case R_LARCH_TLS_LD64_HI20: + case R_LARCH_TLS_GD_PC_HI20: + case R_LARCH_TLS_GD64_HI20: ++ case R_LARCH_32_PCREL: + case R_LARCH_RELAX: ++ case R_LARCH_DELETE: ++ case R_LARCH_ALIGN: ++ case R_LARCH_PCREL20_S2: + // + // These types are not used or do not require fixup in PE format files. + // +diff --git a/BaseTools/Source/C/GenFw/elf_common.h b/BaseTools/Source/C/GenFw/elf_common.h +index ccd32804b0..d3a5303953 100644 +--- a/BaseTools/Source/C/GenFw/elf_common.h ++++ b/BaseTools/Source/C/GenFw/elf_common.h +@@ -1144,5 +1144,10 @@ typedef struct { + #define R_LARCH_TLS_LD64_HI20 96 + #define R_LARCH_TLS_GD_PC_HI20 97 + #define R_LARCH_TLS_GD64_HI20 98 +-#define R_LARCH_RELAX 99 ++#define R_LARCH_32_PCREL 99 ++#define R_LARCH_RELAX 100 ++#define R_LARCH_DELETE 101 ++#define R_LARCH_ALIGN 102 ++#define R_LARCH_PCREL20_S2 103 ++ + #endif /* !_SYS_ELF_COMMON_H_ */ diff --git a/edk2.spec b/edk2.spec index 15b9b60..e33f9b8 100644 --- a/edk2.spec +++ b/edk2.spec @@ -1,7 +1,7 @@ -%define anolis_release 3 +%define anolis_release 4 %undefine _auto_set_build_flags -ExclusiveArch: x86_64 aarch64 +ExclusiveArch: x86_64 aarch64 loongarch64 # edk2-stable202302 %define GITDATE 20230303 @@ -11,12 +11,16 @@ ExclusiveArch: x86_64 aarch64 %define build_ovmf 0 %define build_aarch64 0 +%define build_loongarch64 0 %ifarch x86_64 %define build_ovmf 1 %endif %ifarch aarch64 %define build_aarch64 1 %endif +%ifarch loongarch64 + %define build_loongarch64 1 +%endif %define build_riscv64 0 %global softfloat_version 20180726-gitb64af41 @@ -50,6 +54,9 @@ Source42: 50-edk2-ovmf-x64-nosb.json Source43: 60-edk2-ovmf-x64-amdsev.json Source44: 60-edk2-ovmf-x64-inteltdx.json +Source50: 50-edk2-loongarch64.json +Source51: 51-edk2-loongarch64-verbose.json + Source80: https://gitlab.com/kraxel/edk2-build-config/-/blob/master/bin/edk2-build.py Source81: edk2-build @@ -64,10 +71,13 @@ Patch0008: 0008-anolis-OvmfPkg-Add-CsvDxe-driver.patch Patch0009: 0009-anolis-OvmfPkg-IoMmuDxe-Add-CsvIoMmu-protocol.patch Patch0010: 0010-anolis-OvmfPkg-Reserve-a-CPUID-table-page-for-CSV-gu.patch Patch0011: 0011-anolis-OvmfPkg-Use-classic-mmio-window-for-CSV-guest.patch +Patch0012: edk2-relax-loong64.patch BuildRequires: python3-devel BuildRequires: libuuid-devel +%ifnarch loongarch64 BuildRequires: /usr/bin/iasl +%endif BuildRequires: binutils gcc git gcc-c++ make BuildRequires: qemu-img @@ -114,6 +124,24 @@ platform that enables UEFI support for QEMU/KVM ARM Virtual Machines. This package contains a 64-bit build. +%package loongarch64 +Summary: UEFI firmware for loongarch64 virtual machines +BuildArch: noarch + +# No Secure Boot for LoongArch yet, but we include OpenSSL for the IPv6 stack. +Provides: bundled(openssl) = %{OPENSSL_VER} +License: BSD-2-Clause-Patent and OpenSSL + +# URL taken from the Maintainers.txt file. +URL: https://github.com/tianocore/tianocore.github.io/wiki/LoongArchQemuPkg + + +%description loongarch64 +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 tools Summary: EFI Development Kit II Tools License: BSD-2-Clause-Patent @@ -193,7 +221,7 @@ chmod -Rf a+rX,u+w,g-w,o-w . cp -a -- \ %{SOURCE10} %{SOURCE11} \ %{SOURCE40} %{SOURCE41} %{SOURCE42} %{SOURCE43} %{SOURCE44} \ - %{SOURCE80} %{SOURCE81} \ + %{SOURCE50} %{SOURCE51} %{SOURCE80} %{SOURCE81} \ . %build @@ -253,6 +281,14 @@ for raw in */aarch64/*.raw; do done %endif +%if %{build_loongarch64} +./edk2-build.py --config edk2-build --release-date "$RELEASE_DATE" -m loongarch64 +for raw in */loongarch64/*.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 @@ -322,6 +358,16 @@ install -m 0644 \ # endif build_aarch64 %endif +%if %{build_loongarch64} +# json description files +install -m 0644 \ + 50-edk2-loongarch64.json \ + 51-edk2-loongarch64-verbose.json \ + %{buildroot}%{_datadir}/qemu/firmware + +# endif build_loongarch64 +%endif + %generate_compatibility_deps %global common_files \ @@ -377,6 +423,21 @@ install -m 0644 \ # endif build_aarch64 %endif +%if %{build_loongarch64} +%files loongarch64 +%common_files +%dir %{_datadir}/%{name}/loongarch64/ +%{_datadir}/%{name}/loongarch64/QEMU_EFI-pflash.* +%{_datadir}/%{name}/loongarch64/QEMU_EFI-silent-pflash.* +%{_datadir}/%{name}/loongarch64/vars-template-pflash.* +%{_datadir}/%{name}/loongarch64/QEMU_EFI.fd +%{_datadir}/%{name}/loongarch64/QEMU_EFI.silent.fd +%{_datadir}/%{name}/loongarch64/QEMU_VARS.fd +%{_datadir}/qemu/firmware/50-edk2-loongarch64.json +%{_datadir}/qemu/firmware/51-edk2-loongarch64-verbose.json +# endif build_loongarch64 +%endif + %files tools %license License.txt %license License-History.txt @@ -405,6 +466,9 @@ install -m 0644 \ %changelog +* Wed Nov 15 2023 Xiaotian Wu - 202302-4 +- Support LoongArch64 Virtual Machine + * Tue Aug 15 2023 Xin Jiang - 202302-3 - 0001-anolis-UefiCpuPkg-Add-StandardSignatureIsHygonGenuin.patch - 0002-anolis-UefiCpuPkg-LocalApicLib-Exclude-second-SendIp.patch -- Gitee