From: Leif Lindholm <leif.lindholm@linaro.org>
To: grub-devel@gnu.org
Cc: pjones@redhat.com, agraf@suse.de
Subject: [PATCH 2/3] make arm64 linux loader more generic
Date: Mon, 22 Aug 2016 21:57:39 +0100 [thread overview]
Message-ID: <1471899460-13596-3-git-send-email-leif.lindholm@linaro.org> (raw)
In-Reply-To: <1471899460-13596-1-git-send-email-leif.lindholm@linaro.org>
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.
Also make it possible to build for 32/64-bit architectures.
Also update the arm64 xen loader, since it depends on some of the
functions in the linux loader.
---
grub-core/loader/arm64/linux.c | 31 ++++++++++++++-----------------
grub-core/loader/arm64/xen_boot.c | 12 ++++++------
include/grub/arm64/linux.h | 13 +++++--------
include/grub/efi/pe32.h | 2 ++
4 files changed, 27 insertions(+), 31 deletions(-)
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
index 02e4054..b52dbb0 100644
--- a/grub-core/loader/arm64/linux.c
+++ b/grub-core/loader/arm64/linux.c
@@ -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 @ 0x%p-0x%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;
diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c
index 341805c..fa574ae 100644
--- a/grub-core/loader/arm64/xen_boot.c
+++ b/grub-core/loader/arm64/xen_boot.c
@@ -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);
diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h
index 1ea2369..ab7696b 100644
--- a/include/grub/arm64/linux.h
+++ b/include/grub/arm64/linux.h
@@ -21,12 +21,10 @@
#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 +38,8 @@ 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);
+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_LINUX_CPU_HEADER */
diff --git a/include/grub/efi/pe32.h b/include/grub/efi/pe32.h
index f79c36c..7d44732 100644
--- a/include/grub/efi/pe32.h
+++ b/include/grub/efi/pe32.h
@@ -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
--
2.1.4
next prev parent reply other threads:[~2016-08-22 20:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-22 20:57 [PATCH 0/3] share an efi Linux loader between arm and arm64 Leif Lindholm
2016-08-22 20:57 ` [PATCH 1/3] move efi fdt helper library Leif Lindholm
2016-08-22 20:57 ` Leif Lindholm [this message]
2016-08-22 20:57 ` [PATCH 3/3] Reuse arm64 efi linux loader for arm Leif Lindholm
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=1471899460-13596-3-git-send-email-leif.lindholm@linaro.org \
--to=leif.lindholm@linaro.org \
--cc=agraf@suse.de \
--cc=grub-devel@gnu.org \
--cc=pjones@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).