* [PATCH 1/3] move efi fdt helper library
2016-08-22 20:57 [PATCH 0/3] share an efi Linux loader between arm and arm64 Leif Lindholm
@ 2016-08-22 20:57 ` Leif Lindholm
2016-08-22 20:57 ` [PATCH 2/3] make arm64 linux loader more generic Leif Lindholm
2016-08-22 20:57 ` [PATCH 3/3] Reuse arm64 efi linux loader for arm Leif Lindholm
2 siblings, 0 replies; 4+ messages in thread
From: Leif Lindholm @ 2016-08-22 20:57 UTC (permalink / raw)
To: grub-devel; +Cc: pjones, agraf
There is nothing ARM64 (or even ARM) specific about the efi fdt
helper library, which is used for locating or overriding a
firmware-provided devicetree in a UEFI system - so move it to
loader/efi for reuse.
Move the fdtload.h include file to grub/efi and move the (at least
theoretically) machine dependent page size definitions to
grub/machine/memory.h.
---
grub-core/Makefile.core.def | 2 +-
grub-core/loader/arm64/fdt.c | 185 -------------------------------------
grub-core/loader/arm64/linux.c | 3 +-
grub-core/loader/arm64/xen_boot.c | 3 +-
grub-core/loader/efi/fdt.c | 186 ++++++++++++++++++++++++++++++++++++++
include/grub/arm64/efi/memory.h | 3 +
include/grub/arm64/fdtload.h | 35 -------
include/grub/efi/fdtload.h | 32 +++++++
8 files changed, 226 insertions(+), 223 deletions(-)
delete mode 100644 grub-core/loader/arm64/fdt.c
create mode 100644 grub-core/loader/efi/fdt.c
delete mode 100644 include/grub/arm64/fdtload.h
create mode 100644 include/grub/efi/fdtload.h
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 58b4208..89e338d 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1674,7 +1674,7 @@ module = {
module = {
name = fdt;
- arm64 = loader/arm64/fdt.c;
+ arm64 = loader/efi/fdt.c;
common = lib/fdt.c;
enable = fdt;
};
diff --git a/grub-core/loader/arm64/fdt.c b/grub-core/loader/arm64/fdt.c
deleted file mode 100644
index 5202c14..0000000
--- a/grub-core/loader/arm64/fdt.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2013-2015 Free Software Foundation, Inc.
- *
- * GRUB is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GRUB is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <grub/fdt.h>
-#include <grub/mm.h>
-#include <grub/cpu/fdtload.h>
-#include <grub/err.h>
-#include <grub/dl.h>
-#include <grub/command.h>
-#include <grub/file.h>
-#include <grub/efi/efi.h>
-
-static void *loaded_fdt;
-static void *fdt;
-
-static void *
-get_firmware_fdt (void)
-{
- grub_efi_configuration_table_t *tables;
- grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
- void *firmware_fdt = NULL;
- unsigned int i;
-
- /* Look for FDT in UEFI config tables. */
- tables = grub_efi_system_table->configuration_table;
-
- for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
- if (grub_memcmp (&tables[i].vendor_guid, &fdt_guid, sizeof (fdt_guid)) == 0)
- {
- firmware_fdt = tables[i].vendor_table;
- grub_dprintf ("linux", "found registered FDT @ %p\n", firmware_fdt);
- break;
- }
-
- return firmware_fdt;
-}
-
-void *
-grub_fdt_load (grub_size_t additional_size)
-{
- void *raw_fdt;
- grub_size_t size;
-
- if (fdt)
- {
- size = GRUB_EFI_BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt));
- grub_efi_free_pages ((grub_efi_physical_address_t) fdt, size);
- }
-
- if (loaded_fdt)
- raw_fdt = loaded_fdt;
- else
- raw_fdt = get_firmware_fdt();
-
- size =
- raw_fdt ? grub_fdt_get_totalsize (raw_fdt) : GRUB_FDT_EMPTY_TREE_SZ;
- size += additional_size;
-
- grub_dprintf ("linux", "allocating %ld bytes for fdt\n", size);
- fdt = grub_efi_allocate_pages (0, GRUB_EFI_BYTES_TO_PAGES (size));
- if (!fdt)
- return NULL;
-
- if (raw_fdt)
- {
- grub_memmove (fdt, raw_fdt, size);
- grub_fdt_set_totalsize (fdt, size);
- }
- else
- {
- grub_fdt_create_empty_tree (fdt, size);
- }
- return fdt;
-}
-
-grub_err_t
-grub_fdt_install (void)
-{
- grub_efi_boot_services_t *b;
- grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
- grub_efi_status_t status;
-
- b = grub_efi_system_table->boot_services;
- status = b->install_configuration_table (&fdt_guid, fdt);
- if (status != GRUB_EFI_SUCCESS)
- return grub_error (GRUB_ERR_IO, "failed to install FDT");
-
- grub_dprintf ("fdt", "Installed/updated FDT configuration table @ %p\n",
- fdt);
- return GRUB_ERR_NONE;
-}
-
-void
-grub_fdt_unload (void) {
- if (!fdt) {
- return;
- }
- grub_efi_free_pages ((grub_efi_physical_address_t) fdt,
- GRUB_EFI_BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt)));
- fdt = NULL;
-}
-
-static grub_err_t
-grub_cmd_devicetree (grub_command_t cmd __attribute__ ((unused)),
- int argc, char *argv[])
-{
- grub_file_t dtb;
- void *blob = NULL;
- int size;
-
- if (loaded_fdt)
- grub_free (loaded_fdt);
- loaded_fdt = NULL;
-
- /* No arguments means "use firmware FDT". */
- if (argc == 0)
- {
- return GRUB_ERR_NONE;
- }
-
- dtb = grub_file_open (argv[0]);
- if (!dtb)
- goto out;
-
- size = grub_file_size (dtb);
- blob = grub_malloc (size);
- if (!blob)
- goto out;
-
- if (grub_file_read (dtb, blob, size) < size)
- {
- if (!grub_errno)
- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]);
- goto out;
- }
-
- if (grub_fdt_check_header (blob, size) != 0)
- {
- grub_error (GRUB_ERR_BAD_OS, N_("invalid device tree"));
- goto out;
- }
-
-out:
- if (dtb)
- grub_file_close (dtb);
-
- if (blob)
- {
- if (grub_errno == GRUB_ERR_NONE)
- loaded_fdt = blob;
- else
- grub_free (blob);
- }
-
- return grub_errno;
-}
-
-static grub_command_t cmd_devicetree;
-
-GRUB_MOD_INIT (fdt)
-{
- cmd_devicetree =
- grub_register_command ("devicetree", grub_cmd_devicetree, 0,
- N_("Load DTB file."));
-}
-
-GRUB_MOD_FINI (fdt)
-{
- grub_unregister_command (cmd_devicetree);
-}
diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
index 9519d2e..02e4054 100644
--- a/grub-core/loader/arm64/linux.c
+++ b/grub-core/loader/arm64/linux.c
@@ -26,11 +26,12 @@
#include <grub/mm.h>
#include <grub/types.h>
#include <grub/cpu/linux.h>
-#include <grub/cpu/fdtload.h>
#include <grub/efi/efi.h>
+#include <grub/efi/fdtload.h>
#include <grub/efi/pe32.h>
#include <grub/i18n.h>
#include <grub/lib/cmdline.h>
+#include <grub/machine/memory.h>
GRUB_MOD_LICENSE ("GPLv3+");
diff --git a/grub-core/loader/arm64/xen_boot.c b/grub-core/loader/arm64/xen_boot.c
index a914eb8..341805c 100644
--- a/grub-core/loader/arm64/xen_boot.c
+++ b/grub-core/loader/arm64/xen_boot.c
@@ -27,12 +27,13 @@
#include <grub/misc.h>
#include <grub/mm.h>
#include <grub/types.h>
-#include <grub/cpu/fdtload.h>
#include <grub/cpu/linux.h>
#include <grub/efi/efi.h>
+#include <grub/efi/fdtload.h>
#include <grub/efi/pe32.h> /* required by struct xen_hypervisor_header */
#include <grub/i18n.h>
#include <grub/lib/cmdline.h>
+#include <grub/machine/memory.h>
GRUB_MOD_LICENSE ("GPLv3+");
diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c
new file mode 100644
index 0000000..a1e19b7
--- /dev/null
+++ b/grub-core/loader/efi/fdt.c
@@ -0,0 +1,186 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013-2015 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/fdt.h>
+#include <grub/mm.h>
+#include <grub/err.h>
+#include <grub/dl.h>
+#include <grub/command.h>
+#include <grub/file.h>
+#include <grub/efi/efi.h>
+#include <grub/efi/fdtload.h>
+#include <grub/machine/memory.h>
+
+static void *loaded_fdt;
+static void *fdt;
+
+static void *
+get_firmware_fdt (void)
+{
+ grub_efi_configuration_table_t *tables;
+ grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
+ void *firmware_fdt = NULL;
+ unsigned int i;
+
+ /* Look for FDT in UEFI config tables. */
+ tables = grub_efi_system_table->configuration_table;
+
+ for (i = 0; i < grub_efi_system_table->num_table_entries; i++)
+ if (grub_memcmp (&tables[i].vendor_guid, &fdt_guid, sizeof (fdt_guid)) == 0)
+ {
+ firmware_fdt = tables[i].vendor_table;
+ grub_dprintf ("linux", "found registered FDT @ %p\n", firmware_fdt);
+ break;
+ }
+
+ return firmware_fdt;
+}
+
+void *
+grub_fdt_load (grub_size_t additional_size)
+{
+ void *raw_fdt;
+ unsigned int size;
+
+ if (fdt)
+ {
+ size = GRUB_EFI_BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt));
+ grub_efi_free_pages ((grub_addr_t) fdt, size);
+ }
+
+ if (loaded_fdt)
+ raw_fdt = loaded_fdt;
+ else
+ raw_fdt = get_firmware_fdt();
+
+ size =
+ raw_fdt ? grub_fdt_get_totalsize (raw_fdt) : GRUB_FDT_EMPTY_TREE_SZ;
+ size += additional_size;
+
+ grub_dprintf ("linux", "allocating %d bytes for fdt\n", size);
+ fdt = grub_efi_allocate_pages (0, GRUB_EFI_BYTES_TO_PAGES (size));
+ if (!fdt)
+ return NULL;
+
+ if (raw_fdt)
+ {
+ grub_memmove (fdt, raw_fdt, size);
+ grub_fdt_set_totalsize (fdt, size);
+ }
+ else
+ {
+ grub_fdt_create_empty_tree (fdt, size);
+ }
+ return fdt;
+}
+
+grub_err_t
+grub_fdt_install (void)
+{
+ grub_efi_boot_services_t *b;
+ grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
+ grub_efi_status_t status;
+
+ b = grub_efi_system_table->boot_services;
+ status = b->install_configuration_table (&fdt_guid, fdt);
+ if (status != GRUB_EFI_SUCCESS)
+ return grub_error (GRUB_ERR_IO, "failed to install FDT");
+
+ grub_dprintf ("fdt", "Installed/updated FDT configuration table @ %p\n",
+ fdt);
+ return GRUB_ERR_NONE;
+}
+
+void
+grub_fdt_unload (void) {
+ if (!fdt) {
+ return;
+ }
+ grub_efi_free_pages ((grub_addr_t) fdt,
+ GRUB_EFI_BYTES_TO_PAGES (grub_fdt_get_totalsize (fdt)));
+ fdt = NULL;
+}
+
+static grub_err_t
+grub_cmd_devicetree (grub_command_t cmd __attribute__ ((unused)),
+ int argc, char *argv[])
+{
+ grub_file_t dtb;
+ void *blob = NULL;
+ int size;
+
+ if (loaded_fdt)
+ grub_free (loaded_fdt);
+ loaded_fdt = NULL;
+
+ /* No arguments means "use firmware FDT". */
+ if (argc == 0)
+ {
+ return GRUB_ERR_NONE;
+ }
+
+ dtb = grub_file_open (argv[0]);
+ if (!dtb)
+ goto out;
+
+ size = grub_file_size (dtb);
+ blob = grub_malloc (size);
+ if (!blob)
+ goto out;
+
+ if (grub_file_read (dtb, blob, size) < size)
+ {
+ if (!grub_errno)
+ grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]);
+ goto out;
+ }
+
+ if (grub_fdt_check_header (blob, size) != 0)
+ {
+ grub_error (GRUB_ERR_BAD_OS, N_("invalid device tree"));
+ goto out;
+ }
+
+out:
+ if (dtb)
+ grub_file_close (dtb);
+
+ if (blob)
+ {
+ if (grub_errno == GRUB_ERR_NONE)
+ loaded_fdt = blob;
+ else
+ grub_free (blob);
+ }
+
+ return grub_errno;
+}
+
+static grub_command_t cmd_devicetree;
+
+GRUB_MOD_INIT (fdt)
+{
+ cmd_devicetree =
+ grub_register_command ("devicetree", grub_cmd_devicetree, 0,
+ N_("Load DTB file."));
+}
+
+GRUB_MOD_FINI (fdt)
+{
+ grub_unregister_command (cmd_devicetree);
+}
diff --git a/include/grub/arm64/efi/memory.h b/include/grub/arm64/efi/memory.h
index c6cb324..9414b69 100644
--- a/include/grub/arm64/efi/memory.h
+++ b/include/grub/arm64/efi/memory.h
@@ -3,4 +3,7 @@
#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL
+#define GRUB_EFI_PAGE_SHIFT 12
+#define GRUB_EFI_BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SHIFT)
+
#endif /* ! GRUB_MEMORY_CPU_HEADER */
diff --git a/include/grub/arm64/fdtload.h b/include/grub/arm64/fdtload.h
deleted file mode 100644
index 7b9ddba..0000000
--- a/include/grub/arm64/fdtload.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2013-2015 Free Software Foundation, Inc.
- *
- * GRUB is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GRUB is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GRUB_FDTLOAD_CPU_HEADER
-#define GRUB_FDTLOAD_CPU_HEADER 1
-
-#include <grub/types.h>
-#include <grub/err.h>
-
-void *
-grub_fdt_load (grub_size_t additional_size);
-void
-grub_fdt_unload (void);
-grub_err_t
-grub_fdt_install (void);
-
-#define GRUB_EFI_PAGE_SHIFT 12
-#define GRUB_EFI_BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SHIFT)
-
-#endif
diff --git a/include/grub/efi/fdtload.h b/include/grub/efi/fdtload.h
new file mode 100644
index 0000000..713c942
--- /dev/null
+++ b/include/grub/efi/fdtload.h
@@ -0,0 +1,32 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013-2015 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRUB_FDTLOAD_CPU_HEADER
+#define GRUB_FDTLOAD_CPU_HEADER 1
+
+#include <grub/types.h>
+#include <grub/err.h>
+
+void *
+grub_fdt_load (grub_size_t additional_size);
+void
+grub_fdt_unload (void);
+grub_err_t
+grub_fdt_install (void);
+
+#endif
--
2.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] make arm64 linux loader more generic
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
2016-08-22 20:57 ` [PATCH 3/3] Reuse arm64 efi linux loader for arm Leif Lindholm
2 siblings, 0 replies; 4+ messages in thread
From: Leif Lindholm @ 2016-08-22 20:57 UTC (permalink / raw)
To: grub-devel; +Cc: pjones, agraf
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] Reuse arm64 efi linux loader for arm
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 ` [PATCH 2/3] make arm64 linux loader more generic Leif Lindholm
@ 2016-08-22 20:57 ` Leif Lindholm
2 siblings, 0 replies; 4+ messages in thread
From: Leif Lindholm @ 2016-08-22 20:57 UTC (permalink / raw)
To: grub-devel; +Cc: pjones, agraf
The original 32-bit arm EFI Linux loader reused the 32-bit Linux
loader for U-Boot. However, this meant it was not necessarily
acting in an entirely UEFI-compliant fashion.
Since EFI stub loader support for arm went into upstream Linux
for 4.5, we can now reuse the same loader as is used on arm64.
This results in some now-redundant code being dropped from the
U-Boot loader. This also drops the ability to boot kernels without
the efi stub support on 32-bit arm efi grub.
---
grub-core/Makefile.core.def | 5 +++--
grub-core/kern/arm/efi/misc.c | 30 ---------------------------
grub-core/loader/arm/linux.c | 48 +++++--------------------------------------
include/grub/arm/efi/loader.h | 1 -
include/grub/arm/efi/memory.h | 3 +++
include/grub/arm/linux.h | 43 +++++++++++++++++++-------------------
6 files changed, 32 insertions(+), 98 deletions(-)
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 89e338d..b8fb104 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1665,7 +1665,8 @@ module = {
powerpc_ieee1275 = loader/powerpc/ieee1275/linux.c;
sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
ia64_efi = loader/ia64/efi/linux.c;
- arm = loader/arm/linux.c;
+ arm_uboot = loader/arm/linux.c;
+ arm_efi = loader/arm64/linux.c;
arm64 = loader/arm64/linux.c;
common = loader/linux.c;
common = lib/cmdline.c;
@@ -1674,7 +1675,7 @@ module = {
module = {
name = fdt;
- arm64 = loader/efi/fdt.c;
+ efi = loader/efi/fdt.c;
common = lib/fdt.c;
enable = fdt;
};
diff --git a/grub-core/kern/arm/efi/misc.c b/grub-core/kern/arm/efi/misc.c
index 7cd4184..036f857 100644
--- a/grub-core/kern/arm/efi/misc.c
+++ b/grub-core/kern/arm/efi/misc.c
@@ -170,33 +170,3 @@ grub_efi_allocate_loader_memory (grub_uint32_t min_offset, grub_uint32_t size)
grub_free (mmap);
return NULL;
}
-
-grub_err_t
-grub_efi_prepare_platform (void)
-{
- grub_efi_uintn_t mmap_size;
- grub_efi_uintn_t map_key;
- grub_efi_uintn_t desc_size;
- grub_efi_uint32_t desc_version;
- grub_efi_memory_descriptor_t *mmap_buf;
- grub_err_t err;
-
- /*
- * Cloned from IA64
- * Must be done after grub_machine_fini because map_key is used by
- *exit_boot_services.
- */
- mmap_size = find_mmap_size ();
- if (! mmap_size)
- return GRUB_ERR_OUT_OF_MEMORY;
- mmap_buf = grub_efi_allocate_pages (0, page_align (mmap_size) >> 12);
- if (! mmap_buf)
- return GRUB_ERR_OUT_OF_MEMORY;
-
- err = grub_efi_finish_boot_services (&mmap_size, mmap_buf, &map_key,
- &desc_size, &desc_version);
- if (err != GRUB_ERR_NONE)
- return err;
-
- return GRUB_ERR_NONE;
-}
diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c
index 5b39f02..83c0e0d 100644
--- a/grub-core/loader/arm/linux.c
+++ b/grub-core/loader/arm/linux.c
@@ -46,9 +46,6 @@ static void *fdt_addr;
typedef void (*kernel_entry_t) (int, unsigned long, void *);
-#define LINUX_ZIMAGE_OFFSET 0x24
-#define LINUX_ZIMAGE_MAGIC 0x016f2818
-
#define LINUX_PHYS_OFFSET (0x00008000)
#define LINUX_INITRD_PHYS_OFFSET (LINUX_PHYS_OFFSET + 0x02000000)
#define LINUX_FDT_PHYS_OFFSET (LINUX_INITRD_PHYS_OFFSET - 0x10000)
@@ -274,15 +271,6 @@ linux_boot (void)
*/
linuxmain = (kernel_entry_t) linux_addr;
-#ifdef GRUB_MACHINE_EFI
- {
- grub_err_t err;
- err = grub_efi_prepare_platform();
- if (err != GRUB_ERR_NONE)
- return err;
- }
-#endif
-
grub_arm_disable_caches_mmu ();
linuxmain (0, machine_type, fdt_addr);
@@ -296,17 +284,12 @@ linux_boot (void)
static grub_err_t
linux_load (const char *filename, grub_file_t file)
{
+ struct grub_linux_kernel_header *lh;
int size;
size = grub_file_size (file);
-#ifdef GRUB_MACHINE_EFI
- linux_addr = (grub_addr_t) grub_efi_allocate_loader_memory (LINUX_PHYS_OFFSET, size);
- if (!linux_addr)
- return grub_errno;
-#else
linux_addr = LINUX_ADDRESS;
-#endif
grub_dprintf ("loader", "Loading Linux to 0x%08x\n",
(grub_addr_t) linux_addr);
@@ -318,9 +301,10 @@ linux_load (const char *filename, grub_file_t file)
return grub_errno;
}
- if (size > LINUX_ZIMAGE_OFFSET + 4
- && *(grub_uint32_t *) (linux_addr + LINUX_ZIMAGE_OFFSET)
- == LINUX_ZIMAGE_MAGIC)
+ lh = (void *) linux_addr;
+
+ if ((grub_size_t) size > sizeof (*lh) &&
+ lh->magic == GRUB_LINUX_MAGIC_SIGNATURE)
;
else if (size > 0x8000 && *(grub_uint32_t *) (linux_addr) == 0xea000006
&& machine_type == GRUB_ARM_MACHINE_TYPE_RASPBERRY_PI)
@@ -410,20 +394,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
size = grub_get_initrd_size (&initrd_ctx);
-#ifdef GRUB_MACHINE_EFI
- if (initrd_start)
- grub_efi_free_pages (initrd_start,
- (initrd_end - initrd_start + 0xfff) >> 12);
- initrd_start = (grub_addr_t) grub_efi_allocate_loader_memory (LINUX_INITRD_PHYS_OFFSET, size);
-
- if (!initrd_start)
- {
- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
- goto fail;
- }
-#else
initrd_start = LINUX_INITRD_ADDRESS;
-#endif
grub_dprintf ("loader", "Loading initrd to 0x%08x\n",
(grub_addr_t) initrd_start);
@@ -473,16 +444,7 @@ grub_cmd_devicetree (grub_command_t cmd __attribute__ ((unused)),
goto out;
}
-#ifdef GRUB_MACHINE_EFI
- fdt_addr = grub_efi_allocate_loader_memory (LINUX_FDT_PHYS_OFFSET, size);
- if (!fdt_addr)
- {
- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
- goto out;
- }
-#else
fdt_addr = (void *) LINUX_FDT_ADDRESS;
-#endif
grub_dprintf ("loader", "Loading device tree to 0x%08x\n",
(grub_addr_t) fdt_addr);
diff --git a/include/grub/arm/efi/loader.h b/include/grub/arm/efi/loader.h
index 4bab18e..1bcc79e 100644
--- a/include/grub/arm/efi/loader.h
+++ b/include/grub/arm/efi/loader.h
@@ -19,7 +19,6 @@
#ifndef GRUB_LOADER_MACHINE_HEADER
#define GRUB_LOADER_MACHINE_HEADER 1
-grub_err_t EXPORT_FUNC (grub_efi_prepare_platform) (void);
void * EXPORT_FUNC (grub_efi_allocate_loader_memory) (grub_uint32_t min_offset,
grub_uint32_t size);
diff --git a/include/grub/arm/efi/memory.h b/include/grub/arm/efi/memory.h
index 2c64918..986f656 100644
--- a/include/grub/arm/efi/memory.h
+++ b/include/grub/arm/efi/memory.h
@@ -3,4 +3,7 @@
#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffff
+#define GRUB_EFI_PAGE_SHIFT 12
+#define GRUB_EFI_BYTES_TO_PAGES(bytes) (((bytes) + 0xfff) >> GRUB_EFI_PAGE_SHIFT)
+
#endif /* ! GRUB_MEMORY_CPU_HEADER */
diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h
index 059dbba..078eaa5 100644
--- a/include/grub/arm/linux.h
+++ b/include/grub/arm/linux.h
@@ -20,38 +20,37 @@
#ifndef GRUB_LINUX_CPU_HEADER
#define GRUB_LINUX_CPU_HEADER 1
-#define LINUX_ZIMAGE_OFFSET 0x24
-#define LINUX_ZIMAGE_MAGIC 0x016f2818
+#define GRUB_LINUX_MAGIC_SIGNATURE 0x016f2818
-#include "system.h"
+struct grub_linux_kernel_header {
+ grub_uint32_t code0;
+ grub_uint32_t reserved1[8];
+ grub_uint32_t magic;
+ grub_uint32_t start; /* _start */
+ grub_uint32_t end; /* _edata */
+ grub_uint32_t reserved2[4];
+ grub_uint32_t hdr_offset;
+};
#if defined GRUB_MACHINE_UBOOT
+
+# include "system.h"
# include <grub/uboot/uboot.h>
# define LINUX_ADDRESS (start_of_ram + 0x8000)
# define LINUX_INITRD_ADDRESS (start_of_ram + 0x02000000)
# define LINUX_FDT_ADDRESS (LINUX_INITRD_ADDRESS - 0x10000)
# define grub_arm_firmware_get_boot_data grub_uboot_get_boot_data
# define grub_arm_firmware_get_machine_type grub_uboot_get_machine_type
+# define FDT_ADDITIONAL_ENTRIES_SIZE 0x300
+
#elif defined GRUB_MACHINE_EFI
-# include <grub/efi/efi.h>
-# include <grub/machine/loader.h>
-/* On UEFI platforms - load the images at the lowest available address not
- less than *_PHYS_OFFSET from the first available memory location. */
-# define LINUX_PHYS_OFFSET (0x00008000)
-# define LINUX_INITRD_PHYS_OFFSET (LINUX_PHYS_OFFSET + 0x02000000)
-# define LINUX_FDT_PHYS_OFFSET (LINUX_INITRD_PHYS_OFFSET - 0x10000)
-static inline grub_addr_t
-grub_arm_firmware_get_boot_data (void)
-{
- return 0;
-}
-static inline grub_uint32_t
-grub_arm_firmware_get_machine_type (void)
-{
- return GRUB_ARM_MACHINE_TYPE_FDT;
-}
-#endif
-#define FDT_ADDITIONAL_ENTRIES_SIZE 0x300
+#include <grub/efi/efi.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
#endif /* ! GRUB_LINUX_CPU_HEADER */
--
2.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread