grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 5/5] efi: Use generic EFI loader for x86_64


From: Ard Biesheuvel
Subject: Re: [PATCH 5/5] efi: Use generic EFI loader for x86_64
Date: Wed, 10 May 2023 12:40:30 +0200

On Tue, 9 May 2023 at 18:53, Ard Biesheuvel <ardb@kernel.org> wrote:
>
> 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;

This change breaks the build for i386_efi. Any suggestions on how to
rephrase this?

>    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
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]