@@ -48,18 +48,16 @@ static grub_addr_t initrd_start;
static grub_addr_t initrd_end;
grub_err_t
-grub_arm64_uefi_check_image (struct grub_arm64_linux_kernel_header * lh)
+grub_efi_linux_check_image (struct grub_linux_kernel_header * lh)
{
- if (lh->magic != GRUB_ARM64_LINUX_MAGIC)
+ if (lh->magic != GRUB_LINUX_MAGIC_SIGNATURE)
return grub_error(GRUB_ERR_BAD_OS, "invalid magic number");
- if ((lh->code0 & 0xffff) != GRUB_EFI_PE_MAGIC)
+ if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
N_("plain image kernel not supported - rebuild with CONFIG_(U)EFI_STUB enabled"));
grub_dprintf ("linux", "UEFI stub kernel:\n");
- grub_dprintf ("linux", "text_offset = 0x%012llx\n",
- (long long unsigned) lh->text_offset);
grub_dprintf ("linux", "PE/COFF header @ %08x\n", lh->hdr_offset);
return GRUB_ERR_NONE;
@@ -87,8 +85,8 @@ finalize_params_linux (void)
/* Set initrd info */
if (initrd_start && initrd_end > initrd_start)
{
- grub_dprintf ("linux", "Initrd @ 0x%012lx-0x%012lx\n",
- initrd_start, initrd_end);
+ grub_dprintf ("linux", "Initrd @ %p-%p\n",
+ (void *) initrd_start, (void *) initrd_end);
retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start",
initrd_start);
@@ -111,7 +109,7 @@ failure:
}
grub_err_t
-grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size, char *args)
+grub_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
{
grub_efi_memory_mapped_device_path_t *mempath;
grub_efi_handle_t image_handle;
@@ -163,7 +161,7 @@ grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size, char *args)
/* When successful, not reached */
b->unload_image (image_handle);
- grub_efi_free_pages ((grub_efi_physical_address_t) loaded_image->load_options,
+ grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
return grub_errno;
@@ -175,8 +173,8 @@ grub_linux_boot (void)
if (finalize_params_linux () != GRUB_ERR_NONE)
return grub_errno;
- return (grub_arm64_uefi_boot_image((grub_addr_t)kernel_addr,
- kernel_size, linux_args));
+ return (grub_efi_linux_boot_image((grub_addr_t)kernel_addr,
+ kernel_size, linux_args));
}
static grub_err_t
@@ -190,7 +188,7 @@ grub_linux_unload (void)
initrd_start = initrd_end = 0;
grub_free (linux_args);
if (kernel_addr)
- grub_efi_free_pages ((grub_efi_physical_address_t) kernel_addr,
+ grub_efi_free_pages ((grub_addr_t) kernel_addr,
GRUB_EFI_BYTES_TO_PAGES (kernel_size));
grub_fdt_unload ();
return GRUB_ERR_NONE;
@@ -242,8 +240,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
fail:
grub_initrd_close (&initrd_ctx);
if (initrd_mem && !initrd_start)
- grub_efi_free_pages ((grub_efi_physical_address_t) initrd_mem,
- initrd_pages);
+ grub_efi_free_pages ((grub_addr_t) initrd_mem, initrd_pages);
return grub_errno;
}
@@ -253,7 +250,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
int argc, char *argv[])
{
grub_file_t file = 0;
- struct grub_arm64_linux_kernel_header lh;
+ struct grub_linux_kernel_header lh;
grub_dl_ref (my_mod);
@@ -272,7 +269,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
if (grub_file_read (file, &lh, sizeof (lh)) < (long) sizeof (lh))
return grub_errno;
- if (grub_arm64_uefi_check_image (&lh) != GRUB_ERR_NONE)
+ if (grub_efi_linux_check_image (&lh) != GRUB_ERR_NONE)
goto fail;
grub_loader_unset();
@@ -330,7 +327,7 @@ fail:
grub_free (linux_args);
if (kernel_addr && !loaded)
- grub_efi_free_pages ((grub_efi_physical_address_t) kernel_addr,
+ grub_efi_free_pages ((grub_addr_t) kernel_addr,
GRUB_EFI_BYTES_TO_PAGES (kernel_size));
return grub_errno;
@@ -67,7 +67,7 @@ typedef enum module_type module_type_t;
struct xen_hypervisor_header
{
- struct grub_arm64_linux_kernel_header efi_head;
+ struct grub_linux_kernel_header efi_head;
/* This is always PE\0\0. */
grub_uint8_t signature[GRUB_PE32_SIGNATURE_SIZE];
@@ -254,9 +254,9 @@ xen_boot (void)
if (err)
return err;
- return grub_arm64_uefi_boot_image (xen_hypervisor->start,
- xen_hypervisor->size,
- xen_hypervisor->cmdline);
+ return grub_efi_linux_boot_image (xen_hypervisor->start,
+ xen_hypervisor->size,
+ xen_hypervisor->cmdline);
}
static void
@@ -442,8 +442,8 @@ grub_cmd_xen_hypervisor (grub_command_t cmd __attribute__ ((unused)),
if (grub_file_read (file, &sh, sizeof (sh)) != (long) sizeof (sh))
goto fail;
- if (grub_arm64_uefi_check_image
- ((struct grub_arm64_linux_kernel_header *) &sh) != GRUB_ERR_NONE)
+ if (grub_efi_linux_check_image
+ ((struct grub_linux_kernel_header *) &sh) != GRUB_ERR_NONE)
goto fail;
grub_file_seek (file, 0);
@@ -19,14 +19,10 @@
#ifndef GRUB_LINUX_CPU_HEADER
#define GRUB_LINUX_CPU_HEADER 1
-#include <grub/efi/efi.h>
-
-#define GRUB_ARM64_LINUX_MAGIC 0x644d5241 /* 'ARM\x64' */
-
-#define GRUB_EFI_PE_MAGIC 0x5A4D
+#define GRUB_LINUX_MAGIC_SIGNATURE 0x644d5241 /* 'ARM\x64' */
/* From linux/Documentation/arm64/booting.txt */
-struct grub_arm64_linux_kernel_header
+struct grub_linux_kernel_header
{
grub_uint32_t code0; /* Executable code */
grub_uint32_t code1; /* Executable code */
@@ -40,9 +36,4 @@ struct grub_arm64_linux_kernel_header
grub_uint32_t hdr_offset; /* Offset of PE/COFF header */
};
-grub_err_t grub_arm64_uefi_check_image (struct grub_arm64_linux_kernel_header
- *lh);
-grub_err_t grub_arm64_uefi_boot_image (grub_addr_t addr, grub_size_t size,
- char *args);
-
#endif /* ! GRUB_LINUX_CPU_HEADER */
@@ -89,6 +89,10 @@ extern void (*EXPORT_VAR(grub_efi_net_config)) (grub_efi_handle_t hnd,
#if defined(__arm__) || defined(__aarch64__)
void *EXPORT_FUNC(grub_efi_get_firmware_fdt)(void);
grub_err_t EXPORT_FUNC(grub_efi_get_dram_base)(grub_addr_t *);
+#include <grub/cpu/linux.h>
+grub_err_t grub_efi_linux_check_image(struct grub_linux_kernel_header *lh);
+grub_err_t grub_efi_linux_boot_image(grub_addr_t addr, grub_size_t size,
+ char *args);
#endif
grub_addr_t grub_efi_modules_addr (void);
@@ -45,6 +45,8 @@
#define GRUB_PE32_MSDOS_STUB_SIZE 0x80
+#define GRUB_PE32_MAGIC 0x5a4d
+
/* According to the spec, the minimal alignment is 512 bytes...
But some examples (such as EFI drivers in the Intel
Sample Implementation) use 32 bytes (0x20) instead, and it seems
In order to enable reuse of the arm64 efi linux loader for arm, change a few function names and macros. Add a global definition of GRUB_PE32_MAGIC in grub/efi/pe32.h. Make the arm64 loader 32/64-bit safe. Also update the arm64 xen loader, since it depends on some of the functions in the linux loader. Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org> --- grub-core/loader/arm64/linux.c | 31 ++++++++++++++----------------- grub-core/loader/arm64/xen_boot.c | 12 ++++++------ include/grub/arm64/linux.h | 13 ++----------- include/grub/efi/efi.h | 4 ++++ include/grub/efi/pe32.h | 2 ++ 5 files changed, 28 insertions(+), 34 deletions(-) -- 2.11.0 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel