From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1pwQbG-0000bZ-L1 for mharc-grub-devel@gnu.org; Tue, 09 May 2023 12:54:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwQbF-0000bP-AK for grub-devel@gnu.org; Tue, 09 May 2023 12:54:05 -0400 Received: from dfw.source.kernel.org ([139.178.84.217]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwQbD-0003af-IV for grub-devel@gnu.org; Tue, 09 May 2023 12:54:05 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4DCA162979; Tue, 9 May 2023 16:53:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B69DCC4339C; Tue, 9 May 2023 16:53:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683651237; bh=A282cLcT6nQ/2+HsWiqlWjyIoFEvOP9lK2As050psIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fNsffW812xGPNJPytK24bBk+1cw59B+pII/CPIe1dCs6LWngiRucV+AqiS8BHc0Jy nIWte6hOizDBl6hV2iQ8gi3/w+YJ1yZ3dowT8y/kdfsSndWCXcBRr+5S3LCv6z5iEF /P2+DK3LwgQzqLHHJ/QURjpEBl1o+FMLspZsvqmj0uV1whvlj4Ri4sXzP90yAc6Qgg Ivf+NWA+HomNfjlPwlBhYM+ScACAkGoCaIvh1K8BkZsegy2QZWC7GPxry8JrEc4OTv 4Pb1VRNPQQT89IrzAQnFK+KDcGc5QtwC6Sm418uoXb75KbcCyjlyldHSruXld82f3w bQOXksArEYFmA== From: Ard Biesheuvel To: grub-devel@gnu.org Cc: dkiper@net-space.pl, Ard Biesheuvel Subject: [PATCH 5/5] efi: Use generic EFI loader for x86_64 Date: Tue, 9 May 2023 18:53:41 +0200 Message-Id: <20230509165341.1609558-6-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230509165341.1609558-1-ardb@kernel.org> References: <20230509165341.1609558-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4348; i=ardb@kernel.org; h=from:subject; bh=A282cLcT6nQ/2+HsWiqlWjyIoFEvOP9lK2As050psIQ=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JISWqauq6u3Wrwl4Wu7Sa/i2sLJSftYyXOfv9gR27Dt3Zq X6s9v68jlIWBjEOBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjCRtQKMDMt8TZXl391WdNA4 kGv5UuFGocOpzETGySZ/p/352Xa0WImRYf4njh0TcvTYZ/7hOuDB0ZnFrCN6Vz9qjvMz4++T9mu dYgIA X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=139.178.84.217; envelope-from=ardb@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -70 X-Spam_score: -7.1 X-Spam_bar: ------- X-Spam_report: (-7.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 May 2023 16:54:05 -0000 Switch the x86_64 build to the generic EFI loader, which exposes the initrd via the LoadFile2 protocol instead of the x86-specific setup header. This will launch the Linux kernel via its EFI stub, which performs its own initialization in the EFI boot services context before calling ExitBootServices() and performing the bare metal Linux boot. Signed-off-by: Ard Biesheuvel --- grub-core/Makefile.core.def | 6 +----- grub-core/kern/efi/mm.c | 2 +- grub-core/loader/efi/linux.c | 12 ++++++++++++ include/grub/efi/efi.h | 2 ++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index c17d022195b3fdca..f9e89a0cc4389dd0 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1822,7 +1822,6 @@ module = { module = { name = linux; - x86 = loader/i386/linux.c; i386_xen_pvh = loader/i386/linux.c; xen = loader/i386/xen.c; i386_pc = lib/i386/pc/vesa_modes_table.c; @@ -1832,11 +1831,8 @@ module = { sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; ia64_efi = loader/ia64/efi/linux.c; arm_coreboot = loader/arm/linux.c; - arm_efi = loader/efi/linux.c; + efi = loader/efi/linux.c; arm_uboot = loader/arm/linux.c; - arm64 = loader/efi/linux.c; - riscv32 = loader/efi/linux.c; - riscv64 = loader/efi/linux.c; emu = loader/emu/linux.c; common = loader/linux.c; common = lib/cmdline.c; diff --git a/grub-core/kern/efi/mm.c b/grub-core/kern/efi/mm.c index 09225a7c08e4d066..9ba0b8814fe16cc9 100644 --- a/grub-core/kern/efi/mm.c +++ b/grub-core/kern/efi/mm.c @@ -653,7 +653,7 @@ grub_efi_mm_init (void) grub_mm_add_region_fn = grub_efi_mm_add_regions; } -#if defined (__aarch64__) || defined (__arm__) || defined (__riscv) +#if defined (__aarch64__) || defined (__arm__) || defined (__riscv) || defined(__x86_64__) grub_err_t grub_efi_get_ram_base(grub_addr_t *base_addr) { diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c index 15e0686549d7ecca..3cf596f56e8eac4f 100644 --- a/grub-core/loader/efi/linux.c +++ b/grub-core/loader/efi/linux.c @@ -125,6 +125,7 @@ grub_arch_efi_linux_load_image_header (grub_file_t file, return GRUB_ERR_NONE; } +#ifndef __x86_64__ static grub_err_t finalize_params_linux (void) { @@ -169,6 +170,7 @@ failure: grub_fdt_unload(); return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); } +#endif grub_err_t grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) @@ -231,8 +233,10 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) static grub_err_t grub_linux_boot (void) { +#ifndef __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)); @@ -253,7 +257,9 @@ grub_linux_unload (void) if (kernel_addr) grub_efi_free_pages ((grub_addr_t) kernel_addr, GRUB_EFI_BYTES_TO_PAGES (kernel_size)); +#ifndef __x86_64__ grub_fdt_unload (); +#endif if (initrd_lf2_handle != NULL) { @@ -391,6 +397,12 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), return GRUB_ERR_NONE; } +#ifdef __x86_64__ + grub_error (GRUB_ERR_INVALID_COMMAND, + N_("selected Linux kernel does not support loadfile2 initrd loading")); + goto fail; +#endif + initrd_size = grub_get_initrd_size (&initrd_ctx); grub_dprintf ("linux", "Loading initrd\n"); diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h index 444bf5b0b53e31fe..c56abfbd6ba45ab8 100644 --- a/include/grub/efi/efi.h +++ b/include/grub/efi/efi.h @@ -112,6 +112,8 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd, #if defined(__arm__) || defined(__aarch64__) || defined(__riscv) void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void); +#endif +#if defined(__arm__) || defined(__aarch64__) || defined(__riscv) || defined(__x86_64__) 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, -- 2.39.2