From 129e40383a2a4e060ddfb8447c4ff2213db90463 Mon Sep 17 00:00:00 2001 From: "taifu.gc" Date: Tue, 23 Apr 2024 02:01:45 +0000 Subject: [PATCH] Revert efi patch on loongarch --- ...d-support-for-Linux-EFI-stub-loading.patch | 425 ++++++++++++++++++ grub.macros | 3 + grub.patches | 1 + grub2.spec | 5 +- 4 files changed, 433 insertions(+), 1 deletion(-) create mode 100644 1004-Revert-Add-support-for-Linux-EFI-stub-loading.patch diff --git a/1004-Revert-Add-support-for-Linux-EFI-stub-loading.patch b/1004-Revert-Add-support-for-Linux-EFI-stub-loading.patch new file mode 100644 index 0000000..dcabb5f --- /dev/null +++ b/1004-Revert-Add-support-for-Linux-EFI-stub-loading.patch @@ -0,0 +1,425 @@ +From b8385cb2d4ec28a15bf61b88534b3d3d950d12ad Mon Sep 17 00:00:00 2001 +From: Fedora Ninjas +Date: Mon, 22 Apr 2024 22:40:44 +0800 +Subject: [PATCH] Revert "Add support for Linux EFI stub loading" + +This reverts commit e419adbbc72fa684581b9864dbe56977a3b3f7ba. +--- + grub-core/Makefile.core.def | 9 +- + grub-core/kern/dl.c | 21 ----- + grub-core/kern/efi/mm.c | 32 ------- + grub-core/loader/arm64/xen_boot.c | 1 + + grub-core/loader/efi/linux.c | 137 ++++++++++++++---------------- + grub-core/loader/i386/pc/linux.c | 10 +-- + include/grub/arm/linux.h | 1 - + include/grub/efi/efi.h | 6 +- + 8 files changed, 76 insertions(+), 141 deletions(-) + +diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def +index 2b22cf39492a..6abde72db932 100644 +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -1830,6 +1830,13 @@ module = { + enable = i386_pc; + }; + ++ ++module = { ++ name = linux16; ++ common = loader/i386/pc/linux.c; ++ enable = x86; ++}; ++ + module = { + name = ntldr; + i386_pc = loader/i386/pc/ntldr.c; +@@ -1886,8 +1893,6 @@ module = { + module = { + name = linux; + x86 = loader/i386/linux.c; +- x86_64_efi = loader/i386/efi/linux.c; +- i386_efi = loader/i386/efi/linux.c; + i386_xen_pvh = loader/i386/linux.c; + xen = loader/i386/xen.c; + i386_pc = lib/i386/pc/vesa_modes_table.c; +diff --git a/grub-core/kern/dl.c b/grub-core/kern/dl.c +index 896dba66e989..660dc11fe524 100644 +--- a/grub-core/kern/dl.c ++++ b/grub-core/kern/dl.c +@@ -39,14 +39,6 @@ + #define GRUB_MODULES_MACHINE_READONLY + #endif + +-#ifdef GRUB_MACHINE_EMU +-#include +-#endif +- +-#ifdef GRUB_MACHINE_EFI +-#include +-#endif +- + + + #pragma GCC diagnostic ignored "-Wcast-align" +@@ -886,19 +878,6 @@ grub_dl_load_file (const char *filename) + void *core = 0; + grub_dl_t mod = 0; + +-#ifdef GRUB_MACHINE_EFI +- if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) +- { +-#if 0 +- /* This is an error, but grub2-mkconfig still generates a pile of +- * insmod commands, so emitting it would be mostly just obnoxious. */ +- grub_error (GRUB_ERR_ACCESS_DENIED, +- "Secure Boot forbids loading module from %s", filename); +-#endif +- return 0; +- } +-#endif +- + grub_boot_time ("Loading module %s", filename); + + file = grub_file_open (filename, GRUB_FILE_TYPE_GRUB_MODULE); +diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c +index 60b28efb039f..0d615fc0542c 100644 +--- a/grub-core/kern/efi/mm.c ++++ b/grub-core/kern/efi/mm.c +@@ -112,38 +112,6 @@ grub_efi_drop_alloc (grub_efi_physical_address_t address, + } + } + +-/* Allocate pages below a specified address */ +-void * +-grub_efi_allocate_pages_max (grub_efi_physical_address_t max, +- grub_efi_uintn_t pages) +-{ +- grub_efi_status_t status; +- grub_efi_boot_services_t *b; +- grub_efi_physical_address_t address = max; +- +- if (max > GRUB_EFI_MAX_USABLE_ADDRESS) +- return 0; +- +- b = grub_efi_system_table->boot_services; +- status = b->allocate_pages(GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address); +- +- if (status != GRUB_EFI_SUCCESS) +- return 0; +- +- if (address == 0) +- { +- /* Uggh, the address 0 was allocated... This is too annoying, +- so reallocate another one. */ +- address = max; +- status = b->allocate_pages(GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA, pages, &address); +- grub_efi_free_pages (0, pages); +- if (status != GRUB_EFI_SUCCESS) +- return 0; +- } +- +- return (void *) ((grub_addr_t) address); +-} +- + /* Allocate pages. Return the pointer to the first of allocated pages. */ + void * + grub_efi_allocate_pages_real (grub_efi_physical_address_t address, +diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c +index 9838a0f878b7..26e1472c9d24 100644 +--- a/grub-core/loader/arm64/xen_boot.c ++++ b/grub-core/loader/arm64/xen_boot.c +@@ -252,6 +252,7 @@ xen_boot (void) + return err; + + return grub_arch_efi_linux_boot_image (xen_hypervisor->start, ++ xen_hypervisor->size, + xen_hypervisor->cmdline); + } + +diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c +index 7447c5bb6d38..7094f7cc5604 100644 +--- a/grub-core/loader/efi/linux.c ++++ b/grub-core/loader/efi/linux.c +@@ -28,7 +28,6 @@ + #include + #include + #include +-#include + #include + #include + #include +@@ -128,7 +127,6 @@ static int loaded; + + static void *kernel_addr; + static grub_uint64_t kernel_size; +-static grub_uint32_t handover_offset; + + static char *linux_args; + static grub_uint32_t cmdline_size; +@@ -227,9 +225,8 @@ grub_arch_efi_linux_load_image_header (grub_file_t file, + static grub_err_t + finalize_params_linux (void) + { +- grub_efi_loaded_image_t *loaded_image = NULL; +- int node, retval, len; +- grub_err_t err = GRUB_ERR_NONE; ++ int node, retval; ++ int err; + void *fdt; + + /* Set initrd info */ +@@ -239,7 +236,7 @@ finalize_params_linux (void) + + if (!fdt) + { +- err = grub_error(GRUB_ERR_BAD_OS, "failed to load FDT"); ++ err = grub_error(GRUB_ERR_BAD_OS, "failed to load FDT"); + goto failure; + } + +@@ -280,30 +277,6 @@ finalize_params_linux (void) + goto failure; + } + +- grub_dprintf ("linux", "Installed/updated FDT configuration table @ %p\n", fdt); +- +- /* Convert command line to UCS-2 */ +- loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); +- if (!loaded_image) +- { +- err = grub_error(grub_errno, "Failed to install fdt"); +- goto failure; +- } +- +- loaded_image->load_options_size = len = +- (grub_strlen (linux_args) + 1) * sizeof (grub_efi_char16_t); +- loaded_image->load_options = +- grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); +- if (!loaded_image->load_options) +- { +- err = grub_error(GRUB_ERR_BAD_OS, "failed to create kernel parameters"); +- goto failure; +- } +- +- loaded_image->load_options_size = +- 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, +- (grub_uint8_t *) linux_args, len, NULL); +- + return GRUB_ERR_NONE; + + failure: +@@ -312,46 +285,81 @@ failure: + } + #endif + +-static void +-free_params (void) +-{ +- grub_efi_loaded_image_t *loaded_image = NULL; +- +- loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); +- if (loaded_image) +- { +- if (loaded_image->load_options) +- grub_efi_free_pages ((grub_efi_physical_address_t)(grub_efi_uintn_t)loaded_image->load_options, +- GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); +- loaded_image->load_options = NULL; +- loaded_image->load_options_size = 0; +- } +-} +- + grub_err_t +-grub_arch_efi_linux_boot_image (grub_addr_t addr, char *args) ++grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) + { +- grub_err_t retval; ++ grub_efi_memory_mapped_device_path_t *mempath; ++ grub_efi_handle_t image_handle; ++ grub_efi_boot_services_t *b; ++ grub_efi_status_t status; ++ grub_efi_loaded_image_t *loaded_image; ++ int len; + +-#if !defined(__i386__) && !defined(__x86_64__) +- retval = finalize_params_linux (); +- if (retval != GRUB_ERR_NONE) ++ mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t)); ++ if (!mempath) + return grub_errno; +-#endif ++ ++ mempath[0].header.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE; ++ mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE; ++ mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath)); ++ mempath[0].memory_type = GRUB_EFI_LOADER_DATA; ++ mempath[0].start_address = addr; ++ mempath[0].end_address = addr + size; ++ ++ mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE; ++ mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; ++ mempath[1].header.length = sizeof (grub_efi_device_path_t); ++ ++ b = grub_efi_system_table->boot_services; ++ status = b->load_image (0, grub_efi_image_handle, ++ (grub_efi_device_path_t *) mempath, ++ (void *) addr, size, &image_handle); ++ if (status != GRUB_EFI_SUCCESS) ++ return grub_error (GRUB_ERR_BAD_OS, "cannot load image"); + + grub_dprintf ("linux", "linux command line: '%s'\n", args); + +- retval = grub_efi_linux_boot ((char *)addr, handover_offset, (void *)addr); ++ /* Convert command line to UCS-2 */ ++ loaded_image = grub_efi_get_loaded_image (image_handle); ++ if (loaded_image == NULL) ++ { ++ grub_error (GRUB_ERR_BAD_FIRMWARE, "missing loaded_image proto"); ++ goto unload; ++ } ++ loaded_image->load_options_size = len = ++ (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t); ++ loaded_image->load_options = ++ grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); ++ if (!loaded_image->load_options) ++ return grub_errno; ++ ++ loaded_image->load_options_size = ++ 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, ++ (grub_uint8_t *) args, len, NULL); ++ ++ grub_dprintf ("linux", "starting image %p\n", image_handle); ++ status = b->start_image (image_handle, 0, NULL); ++ ++ /* When successful, not reached */ ++ grub_error (GRUB_ERR_BAD_OS, "start_image() returned 0x%" PRIxGRUB_EFI_UINTN_T, status); ++ grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, ++ GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); ++unload: ++ b->unload_image (image_handle); + +- /* Never reached... */ +- free_params(); +- return retval; ++ return grub_errno; + } + + static grub_err_t + grub_linux_boot (void) + { +- return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr, linux_args)); ++#if !defined(__i386__) && !defined(__x86_64__) ++ if (finalize_params_linux () != GRUB_ERR_NONE) ++ return grub_errno; ++#endif ++ ++ return grub_arch_efi_linux_boot_image ((grub_addr_t) kernel_addr, ++ kernel_size, linux_args); + } + + static grub_err_t +@@ -565,7 +573,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), + { + grub_file_t file = 0; + struct linux_arch_kernel_header lh; +- struct grub_pe_image_header pe; + grub_err_t err; + int rc; + +@@ -642,20 +649,6 @@ fallback: + + grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); + +- if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED) +- { +- rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size); +- if (rc <= 0) +- { +- grub_error (GRUB_ERR_INVALID_COMMAND, +- N_("%s has invalid signature"), argv[0]); +- goto fail; +- } +- } +- +- pe = lh.pe_image_header; +- handover_offset = pe.optional_header.entry_addr; +- + cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE); + linux_args = grub_malloc (cmdline_size); + if (!linux_args) +diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c +index 54a76504a79d..933a994e969f 100644 +--- a/grub-core/loader/i386/pc/linux.c ++++ b/grub-core/loader/i386/pc/linux.c +@@ -484,7 +484,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), + return grub_errno; + } + +-static grub_command_t cmd_linux, cmd_linux16, cmd_initrd, cmd_initrd16; ++static grub_command_t cmd_linux, cmd_initrd; + + GRUB_MOD_INIT(linux16) + { +@@ -492,15 +492,9 @@ GRUB_MOD_INIT(linux16) + return; + + cmd_linux = +- grub_register_command ("linux", grub_cmd_linux, +- 0, N_("Load Linux.")); +- cmd_linux16 = + grub_register_command ("linux16", grub_cmd_linux, + 0, N_("Load Linux.")); + cmd_initrd = +- grub_register_command ("initrd", grub_cmd_initrd, +- 0, N_("Load initrd.")); +- cmd_initrd16 = + grub_register_command ("initrd16", grub_cmd_initrd, + 0, N_("Load initrd.")); + my_mod = mod; +@@ -512,7 +506,5 @@ GRUB_MOD_FINI(linux16) + return; + + grub_unregister_command (cmd_linux); +- grub_unregister_command (cmd_linux16); + grub_unregister_command (cmd_initrd); +- grub_unregister_command (cmd_initrd16); + } +diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h +index a1d3be70b557..5b8fb14e08c6 100644 +--- a/include/grub/arm/linux.h ++++ b/include/grub/arm/linux.h +@@ -20,7 +20,6 @@ + #ifndef GRUB_ARM_LINUX_HEADER + #define GRUB_ARM_LINUX_HEADER 1 + +-#include + #include "system.h" + + #include +diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h +index 217f536170c3..3670eddc52b6 100644 +--- a/include/grub/efi/efi.h ++++ b/include/grub/efi/efi.h +@@ -75,9 +75,6 @@ EXPORT_FUNC(grub_efi_allocate_fixed) (grub_efi_physical_address_t address, + grub_efi_uintn_t pages); + void * + EXPORT_FUNC(grub_efi_allocate_any_pages) (grub_efi_uintn_t pages); +-void * +-EXPORT_FUNC(grub_efi_allocate_pages_max) (grub_efi_physical_address_t max, +- grub_efi_uintn_t pages); + void EXPORT_FUNC(grub_efi_free_pages) (grub_efi_physical_address_t address, + grub_efi_uintn_t pages); + grub_efi_uintn_t EXPORT_FUNC(grub_efi_find_mmap_size) (void); +@@ -173,7 +170,8 @@ grub_err_t EXPORT_FUNC(grub_efi_get_ram_base)(grub_addr_t *); + #include + grub_err_t grub_arch_efi_linux_load_image_header(grub_file_t file, + struct linux_arch_kernel_header *lh); +-grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, char *args); ++grub_err_t grub_arch_efi_linux_boot_image(grub_addr_t addr, grub_size_t size, ++ char *args); + + grub_addr_t grub_efi_section_addr (const char *section); + +-- +2.43.0 + + diff --git a/grub.macros b/grub.macros index a960267..1166f2b 100644 --- a/grub.macros +++ b/grub.macros @@ -341,6 +341,9 @@ rm -f configure \ git add . \ git commit -a -q -m "%{tarversion} baseline." \ git am --whitespace=nowarn %%{patches} - 2.12-4 +- Revert efi patch on loongarch + * Mon Apr 15 2024 chench -2.12-3 - add hygon tpcm support - embed hygon tpcm module into kernel.img by default -- Gitee