From 71a014b54b2f8a53146d21d29f0b1887ba9f2a8a Mon Sep 17 00:00:00 2001 From: Wenlong Zhang Date: Mon, 28 Apr 2025 16:42:31 +0800 Subject: [PATCH] fix Instance of library class RngLib is not found on loongarch64 --- ...n-Remove-minimium-memory-size-limita.patch | 122 ++++++++++++++++++ ...n-Modify-loongarch-uefi-firmware-siz.patch | 62 +++++++++ 0110-fixup-fdt-parse-error.patch | 40 ++++++ edk2.spec | 17 ++- 4 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 0108-Platform-Loongson-Remove-minimium-memory-size-limita.patch create mode 100644 0109-Platform-Loongson-Modify-loongarch-uefi-firmware-siz.patch create mode 100644 0110-fixup-fdt-parse-error.patch diff --git a/0108-Platform-Loongson-Remove-minimium-memory-size-limita.patch b/0108-Platform-Loongson-Remove-minimium-memory-size-limita.patch new file mode 100644 index 0000000..20aba0b --- /dev/null +++ b/0108-Platform-Loongson-Remove-minimium-memory-size-limita.patch @@ -0,0 +1,122 @@ +From ff113b5d376dd9054aefc8452e7ff04459489a44 Mon Sep 17 00:00:00 2001 +From: Bibo Mao +Date: Mon, 25 Mar 2024 10:50:28 +0800 +Subject: [PATCH 1/2] Platform/Loongson: Remove minimium memory size limitation + +Temparory stack memory on PEI is hardcoded now, also minimium memory +size 256M is hardcoded now. Here memory map table from fw cfg can be +parsed. If there is memory map entry contains pei stack, it can be +published as usable memory at PEI stage. + +Cc: Bibo Mao +Cc: Chao Li +Signed-off-by: Bibo Mao +Signed-off-by: Xianglai Li +Reviewed-by: Chao Li +--- + .../Loongson/LoongArchQemuPkg/Loongson.dec | 2 - + .../Loongson/LoongArchQemuPkg/Loongson.dsc | 6 --- + .../LoongArchQemuPkg/PlatformPei/MemDetect.c | 38 ++++++++++++++++++- + .../PlatformPei/PlatformPei.inf | 2 - + 4 files changed, 37 insertions(+), 11 deletions(-) + +diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec +index e638b835e4..c2c6cc9596 100644 +--- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec ++++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec +@@ -48,8 +48,6 @@ + + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase|0|UINT64|0x0000000b + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize|0|UINT32|0x0000000c +- gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop|0x0|UINT64|0x0000000d +- gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom|0x0|UINT64|0x0000000e + gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvBase|0x0|UINT64|0x0000000f + gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvSize|0x0|UINT32|0x00000010 + +diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc +index 58aa16d3a9..aab2ca9b28 100644 +--- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc ++++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc +@@ -356,12 +356,6 @@ + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase | 0x10000 + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize | 0x10000 + gLoongArchQemuPkgTokenSpaceGuid.PcdDeviceTreeBase | 0x100000 +- # +- # minimal memory for uefi bios should be 512M +- # 0x00000000 - 0x10000000 +- # 0x90000000 - 0xA0000000 +- # +- gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop | 0x10000000 + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions | 0x06 + + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile | { 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 } +diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c +index 7e6a4a3aa9..7aa6fdc175 100644 +--- a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c ++++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/MemDetect.c +@@ -40,12 +40,48 @@ PublishPeiMemory ( + UINT64 Base; + UINT64 Size; + UINT64 RamTop; ++ FIRMWARE_CONFIG_ITEM FwCfgItem; ++ UINTN FwCfgSize; ++ UINTN Processed; ++ LOONGARCH_MEMMAP_ENTRY MemoryMapEntry; + + // + // Determine the range of memory to use during PEI + // + Base = PcdGet64 (PcdSecPeiTempRamBase) + PcdGet32 (PcdSecPeiTempRamSize); +- RamTop = PcdGet64 (PcdUefiRamTop); ++ RamTop = 0; ++ ++ Status = QemuFwCfgFindFile ("etc/memmap", &FwCfgItem, &FwCfgSize); ++ if (EFI_ERROR (Status)) { ++ return Status; ++ } ++ ++ if (FwCfgSize % sizeof MemoryMapEntry != 0) { ++ return EFI_PROTOCOL_ERROR; ++ } ++ ++ QemuFwCfgSelectItem (FwCfgItem); ++ for (Processed = 0; Processed < FwCfgSize; Processed += sizeof MemoryMapEntry) { ++ QemuFwCfgReadBytes (sizeof MemoryMapEntry, &MemoryMapEntry); ++ if (MemoryMapEntry.Type != EfiAcpiAddressRangeMemory) { ++ continue; ++ } ++ ++ /* ++ * Find memory map entry where PEI temp stack is located ++ */ ++ if ((MemoryMapEntry.BaseAddr <= Base) && ++ (Base < (MemoryMapEntry.BaseAddr + MemoryMapEntry.Length))) { ++ RamTop = MemoryMapEntry.BaseAddr + MemoryMapEntry.Length; ++ break; ++ } ++ } ++ ++ if (RamTop == 0) { ++ DEBUG ((DEBUG_ERROR, "ERROR: No memory map entry contains temp stack \n")); ++ ASSERT (FALSE); ++ } ++ + Size = RamTop - Base; + + // +diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf +index 6cc3513b63..65591a4d7b 100644 +--- a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf ++++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf +@@ -64,8 +64,6 @@ + [FixedPcd] + gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvBase + gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvSize +- gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom +- gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamBase + gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize + gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize +-- +2.46.0 + diff --git a/0109-Platform-Loongson-Modify-loongarch-uefi-firmware-siz.patch b/0109-Platform-Loongson-Modify-loongarch-uefi-firmware-siz.patch new file mode 100644 index 0000000..2ff691f --- /dev/null +++ b/0109-Platform-Loongson-Modify-loongarch-uefi-firmware-siz.patch @@ -0,0 +1,62 @@ +From c9cb2611ae34a79c28671a703368e88267d6cc24 Mon Sep 17 00:00:00 2001 +From: Xiaotian Wu +Date: Tue, 19 Nov 2024 19:05:49 +0800 +Subject: [PATCH 2/2] Platform/Loongson: Modify loongarch uefi firmware size + +After the loongarch flash block size is changed from 128K to 256K, +qemu requires that the UEFI firmware size be aligned with the flash block size(256K). +Otherwise, the firmware cannot be loaded, +Use the following code to resolve the old firmware loading problem: +mv QEMU_EFI.fd QEMU_EFI.fd-bak +cat QEMU_EFI.fd-bak /dev/zero | head -c 16m > ./QEMU_EFI.fd +mv QEMU_VARS.fd QEMU_VARS.fd-bak +cat QEMU_VARS.fd-bak /dev/zero | head -c 16m > ./QEMU_VARS.fd + +For the new firmware, we refer to other architecture UEFI and +set the UEFI firmware size to align with the flash block size(256K). + +So for this patch, we set the UEFI firmware size to 256K alignment. +--- + Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc | 8 ++++---- + Platform/Loongson/LoongArchQemuPkg/VarStore.fdf.inc | 4 ++-- + 2 files changed, 6 insertions(+), 6 deletions(-) + +diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc +index e30c4629f7..c31909ca9a 100644 +--- a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc ++++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc +@@ -18,12 +18,12 @@ DEFINE FD_SIZE = 0x400000 + #flash code layout + #Set Sec base address and size in flash + DEFINE SECFV_OFFSET = 0x00000000 +-DEFINE SECFV_SIZE = 0x00010000 ++DEFINE SECFV_SIZE = 0x00040000 + + #Set Pei base address and size in flash +-DEFINE PEIFV_OFFSET = 0x00010000 ++DEFINE PEIFV_OFFSET = 0x00040000 + DEFINE PEIFV_SIZE = 0x00040000 + + #Set Dxe base address and size in flash +-DEFINE DXEFV_OFFSET = 0x00050000 +-DEFINE DXEFV_SIZE = 0x00350000 ++DEFINE DXEFV_OFFSET = 0x00080000 ++DEFINE DXEFV_SIZE = 0x00380000 +diff --git a/Platform/Loongson/LoongArchQemuPkg/VarStore.fdf.inc b/Platform/Loongson/LoongArchQemuPkg/VarStore.fdf.inc +index 83ce3d8008..f34901950d 100644 +--- a/Platform/Loongson/LoongArchQemuPkg/VarStore.fdf.inc ++++ b/Platform/Loongson/LoongArchQemuPkg/VarStore.fdf.inc +@@ -10,8 +10,8 @@ + BaseAddress = 0x0 + Size = 0x1000000 + ErasePolarity = 1 +-BlockSize = 0x20000 +-NumBlocks = 128 ++BlockSize = 0x40000 ++NumBlocks = 64 + + 0x00000000|0x00040000 + #NV_VARIABLE_STORE +-- +2.46.0 + diff --git a/0110-fixup-fdt-parse-error.patch b/0110-fixup-fdt-parse-error.patch new file mode 100644 index 0000000..f1ac873 --- /dev/null +++ b/0110-fixup-fdt-parse-error.patch @@ -0,0 +1,40 @@ +From bdbeb6e653d7bbaa5eb4ad104119abfc7030c285 Mon Sep 17 00:00:00 2001 +From: Xianglai Li +Date: Mon, 25 Nov 2024 16:16:39 +0800 +Subject: [PATCH] fixup fdt parse error + +Signed-off-by: Xianglai Li +--- + .../Library/SerialPortLib/EarlySerialPortLib16550.c | 2 +- + Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.c | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/SerialPortLib/EarlySerialPortLib16550.c b/Platform/Loongson/LoongArchQemuPkg/Library/SerialPortLib/EarlySerialPortLib16550.c +index c713c6e9..dd64a000 100644 +--- a/Platform/Loongson/LoongArchQemuPkg/Library/SerialPortLib/EarlySerialPortLib16550.c ++++ b/Platform/Loongson/LoongArchQemuPkg/Library/SerialPortLib/EarlySerialPortLib16550.c +@@ -155,7 +155,7 @@ GetSerialConsolePortAddress ( + } + + // Determine the actual path length, as a colon terminates the path. +- Path = ScanMem8 (Prop, ':', PropSize); ++ Path = ScanMem8 (Prop, PropSize, (UINT8)":"); + if (Path == NULL) { + PathLen = AsciiStrLen (Prop); + } else { +diff --git a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.c b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.c +index 84bb8e8a..02982cd0 100644 +--- a/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.c ++++ b/Platform/Loongson/LoongArchQemuPkg/PlatformPei/Platform.c +@@ -193,7 +193,7 @@ GetSerialConsolePortAddress ( + } + + // Determine the actual path length, as a colon terminates the path. +- Path = ScanMem8 (Prop, ':', PropSize); ++ Path = ScanMem8 (Prop, PropSize, (UINT8)":"); + if (Path == NULL) { + PathLen = AsciiStrLen (Prop); + } else { +-- +2.41.0 + diff --git a/edk2.spec b/edk2.spec index 58c27e5..b44ba9a 100644 --- a/edk2.spec +++ b/edk2.spec @@ -7,7 +7,7 @@ Name: edk2 Version: %{stable_date} -Release: 22 +Release: 23 Summary: EFI Development Kit II License: BSD-2-Clause-Patent and OpenSSL and MIT URL: https://github.com/tianocore/edk2 @@ -166,6 +166,11 @@ patch106: 0106-enable-CC-measurement-for-PE-COFF-image.patch # Fix CVE-2024-38797 patch107: 0107-SecurityPkg-Out-of-bound-read-in-HashPeImageByType.patch +# for loongarch64 +patch108: 0108-Platform-Loongson-Remove-minimium-memory-size-limita.patch +patch109: 0109-Platform-Loongson-Modify-loongarch-uefi-firmware-siz.patch +patch110: 0110-fixup-fdt-parse-error.patch + BuildRequires: acpica-tools gcc gcc-c++ libuuid-devel python3 bc nasm python3-unversioned-command isl %description @@ -239,6 +244,12 @@ tar -xf %{SOURCE7} edk2-platforms/Platform --strip-components=1 %autopatch -p1 +#RngLib is not support on loongarch64 +%ifarch loongarch64 +%patch0066 -R -p1 +%patch0067 -R -p1 +%endif + cp -a -- %{SOURCE4} %{SOURCE5} %{SOURCE6} . %build @@ -437,6 +448,10 @@ chmod +x %{buildroot}%{_bindir}/Rsa2048Sha256GenerateKeys %endif %changelog +* Mon Apr 28 2025 Wenlong Zhang - 202308-23 +- fix Instance of library class RngLib is not found on loongarch64 +- sync from 24.03-lts-sp1 + * Sun Apr 27 2025 huyu - 202308-22 - fix CVE-2024-38797 -- Gitee