All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: grub-devel@gnu.org
Cc: dkiper@net-space.pl, Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH 5/5] efi: Use generic EFI loader for x86_64
Date: Tue,  9 May 2023 18:53:41 +0200	[thread overview]
Message-ID: <20230509165341.1609558-6-ardb@kernel.org> (raw)
In-Reply-To: <20230509165341.1609558-1-ardb@kernel.org>

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 <ardb@kernel.org>
---
 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/file.h>
 grub_err_t grub_arch_efi_linux_load_image_header(grub_file_t file,
-- 
2.39.2



  parent reply	other threads:[~2023-05-09 16:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-09 16:53 [PATCH 0/5] efi: Implement generic EFI boot for x86_64 Ard Biesheuvel
2023-05-09 16:53 ` [PATCH 1/5] efi: Make EFI PXE protocol methods non-callable Ard Biesheuvel
2023-05-09 16:53 ` [PATCH 2/5] efi: Add calling convention annotation to all prototypes Ard Biesheuvel
2023-05-09 16:53 ` [PATCH 3/5] efi: Drop all uses of efi_call_XX wrappers Ard Biesheuvel
2023-05-09 16:53 ` [PATCH 4/5] efi: Remove x86_64 call wrappers Ard Biesheuvel
2023-05-09 16:53 ` Ard Biesheuvel [this message]
2023-05-10 10:40   ` [PATCH 5/5] efi: Use generic EFI loader for x86_64 Ard Biesheuvel
2023-05-10 12:17     ` Daniel Kiper
2023-05-10 17:40       ` Ard Biesheuvel
2023-05-11  8:15         ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230509165341.1609558-6-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=dkiper@net-space.pl \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.