From 7b0564ba57a14c3eb1ab1420ab3bda55b593fec8 Mon Sep 17 00:00:00 2001 From: Andrea Bolognani Date: Tue, 19 Nov 2024 23:42:57 +0100 Subject: [PATCH] Fix RISC-V build and re-enable all previously disabled patches Signed-off-by: Andrea Bolognani --- 0282-loader-efi-Fix-RISC-V-build.patch | 72 ++++++++++++++++++++++++++ grub.patches | 9 +--- grub2.spec | 6 ++- 3 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 0282-loader-efi-Fix-RISC-V-build.patch diff --git a/0282-loader-efi-Fix-RISC-V-build.patch b/0282-loader-efi-Fix-RISC-V-build.patch new file mode 100644 index 0000000..91ccb60 --- /dev/null +++ b/0282-loader-efi-Fix-RISC-V-build.patch @@ -0,0 +1,72 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Andrea Bolognani +Date: Tue, 19 Nov 2024 15:42:01 +0000 +Subject: [PATCH] loader/efi: Fix RISC-V build + +Some struct definitions are currently limited to 32-bit and +64-bit Arm architectures, but they actually apply to other +architectures as well, specifically 32-bit and 64-bit RISC-V +respectively. + +Update the preprocessor checks guarding their definition, and +change their names to make them more accurate by replacing the +word "arm" with the word "efi". + +Signed-off-by: Andrea Bolognani +--- + grub-core/loader/efi/linux.c | 2 +- + include/grub/efi/efi.h | 12 ++++++------ + 2 files changed, 7 insertions(+), 7 deletions(-) + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index 5889e3f36f8..ef55556f2d9 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -684,7 +684,7 @@ parse_pe_header (void *kernel, grub_uint64_t *total_size, + grub_uint32_t *alignment, grub_uint32_t *code_size) + { + struct linux_arch_kernel_header *lh = kernel; +- struct grub_armxx_linux_pe_header *pe; ++ struct grub_efixx_linux_pe_header *pe; + grub_uint16_t i; + struct grub_pe32_section_table *sections; + +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index 7eed1bd791d..81daf6bead1 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -36,28 +36,28 @@ struct linux_arch_kernel_header { + struct grub_pe_image_header pe_image_header; + }; + +-struct grub_arm_linux_pe_header ++struct grub_efi32_linux_pe_header + { + grub_uint32_t magic; + struct grub_pe32_coff_header coff; + struct grub_pe32_optional_header opt; + }; + +-struct grub_arm64_linux_pe_header ++struct grub_efi64_linux_pe_header + { + grub_uint32_t magic; + struct grub_pe32_coff_header coff; + struct grub_pe64_optional_header opt; + }; + +-#if defined(__arm__) ++#if defined(__arm__) || (defined(__riscv) && (__riscv_xlen == 32)) + # define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE32_MAGIC +-# define grub_armxx_linux_pe_header grub_arm_linux_pe_header ++# define grub_efixx_linux_pe_header grub_efi32_linux_pe_header + #endif + +-#if defined(__aarch64__) ++#if defined(__aarch64__) || (defined(__riscv) && (__riscv_xlen == 64)) + # define GRUB_PE32_PEXX_MAGIC GRUB_PE32_PE64_MAGIC +-# define grub_armxx_linux_pe_header grub_arm64_linux_pe_header ++# define grub_efixx_linux_pe_header grub_efi64_linux_pe_header + #endif + + #define GRUB_EFI_GRUB_VARIABLE_GUID \ diff --git a/grub.patches b/grub.patches index c589454..8597988 100644 --- a/grub.patches +++ b/grub.patches @@ -250,26 +250,20 @@ Patch0249: 0249-grub-set-bootflag-Conservative-partial-fix-for-CVE-2.patch Patch0250: 0250-grub-set-bootflag-More-complete-fix-for-CVE-2024-104.patch Patch0251: 0251-grub-set-bootflag-Exit-calmly-when-not-running-as-ro.patch Patch0252: 0252-Makefile.core.def-fix-linux-module.patch -%ifnarch riscv64 Patch0253: 0253-Add-support-for-Linux-EFI-stub-loading-on-arm-archit.patch Patch0254: 0254-arm-arm64-loader-Better-memory-allocation-and-error-.patch Patch0255: 0255-arm64-Fix-EFI-loader-kernel-image-allocation.patch -%endif Patch0256: 0256-pe-add-the-DOS-header-struct-and-fix-some-bad-naming.patch -%ifnarch riscv64 Patch0257: 0257-Correct-BSS-zeroing-on-aarch64.patch Patch0258: 0258-arm64-Use-proper-memory-type-for-kernel-allocation.patch -%endif Patch0259: 0259-normal-Remove-grub_env_set-prefix-in-grub_try_normal.patch Patch0260: 0260-fs-xfs-Handle-non-continuous-data-blocks-in-director.patch Patch0261: 0261-Ignore-warnings-for-incompatible-types.patch Patch0262: 0262-cmd-search-Rework-of-CVE-2023-4001-fix.patch -%ifnarch riscv64 Patch0263: 0263-loader-efi-linux.c-read-the-kernel-image-before-head.patch Patch0264: 0264-nx-set-attrs-in-our-kernel-loaders.patch Patch0265: 0265-efi-Provide-wrappers-for-load_image-start_image.patch Patch0266: 0266-efi-Disallow-fallback-to-legacy-Linux-loader-when-sh.patch -%endif Patch0267: 0267-Set-non-executable-stack-sections-on-EFI-assembly-fi.patch Patch0268: 0268-grub-mkconfig.in-turn-off-executable-owner-bit.patch Patch0269: 0269-kern-ieee1275-init-Add-IEEE-1275-Radix-support-for-K.patch @@ -279,11 +273,10 @@ Patch0272: 0272-grub-mkconfig-Remove-check-for-mount-point-for-grub-.patch Patch0273: 0273-efi-api.h-include-missing-__grub_efi_api-macros-on-E.patch Patch0274: 0274-grub-core-net-arp.c-fix-variable-name.patch Patch0275: 0275-load-EFI-commands-inside-test-expressions.patch -%ifnarch riscv64 Patch0276: 0276-efi-loader-Check-if-NX-is-required-in-grub_efi_linux.patch -%endif Patch0277: 0277-Stop-grub.efi-from-always-printing-dynamic_load_symb.patch Patch0278: 0278-acpi-Fix-out-of-bounds-access-in-grub_acpi_xsdt_find.patch Patch0279: 0279-cmd-search-Fix-a-possible-NULL-ptr-dereference.patch Patch0280: 0280-kern-riscv-efi-init-Use-time-register-in-grub_efi_ge.patch Patch0281: 0281-Use-medany-instead-of-large-model-for-RISCV.patch +Patch0282: 0282-loader-efi-Fix-RISC-V-build.patch diff --git a/grub2.spec b/grub2.spec index f159e50..f3a7af0 100644 --- a/grub2.spec +++ b/grub2.spec @@ -17,7 +17,7 @@ Name: grub2 Epoch: 1 Version: 2.12 -Release: 11.0.riscv64%{?dist} +Release: 11.1.riscv64%{?dist} Summary: Bootloader with support for Linux, Multiboot and more License: GPL-3.0-or-later URL: http://www.gnu.org/software/grub/ @@ -560,6 +560,10 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg %endif %changelog +* Tue Nov 19 2024 Andrea Bolognani - 2.12-11.1.riscv64 +- Fix RISC-V build +- Re-enable all previously disabled patches + * Fri Nov 08 2024 Jason Montleon - 2.12-11.0.riscv64 - Add RISC-V specific patches - Disable ARM patches on RISC-V that break builds