]> git.proxmox.com Git - grub2.git/commitdiff
efi: move fdt helper library
authorLeif Lindholm <leif.lindholm@linaro.org>
Thu, 3 Aug 2017 10:04:24 +0000 (11:04 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Mon, 7 Aug 2017 16:50:44 +0000 (18:50 +0200)
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 update path to
efi/fdtload.h in source code referring to it.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
grub-core/Makefile.core.def
grub-core/loader/arm64/fdt.c [deleted file]
grub-core/loader/arm64/linux.c
grub-core/loader/arm64/xen_boot.c
grub-core/loader/efi/fdt.c [new file with mode: 0644]
include/grub/arm64/fdtload.h [deleted file]
include/grub/efi/fdtload.h [new file with mode: 0644]

index 1d86bd22e04eaf39ef15269c459e8c338037cf6f..a65c27f7ff2252133998da52371d0e23b92f5984 100644 (file)
@@ -1707,7 +1707,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 (file)
index 3680016..0000000
+++ /dev/null
@@ -1,163 +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;
-
-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 = grub_efi_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_any_pages (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);
-}
index ee3fcaa86ae23632fbf2e55c6dc76961fbe99724..3e2f9b74296c9862346086a581ce58fc239e0d51 100644 (file)
@@ -26,8 +26,8 @@
 #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>
index 6c145a771eefc2861995d9bc5ef10b8b3831e75b..c95d6c5a868e37d4cbc923630d154b5422b37525 100644 (file)
@@ -27,9 +27,9 @@
 #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>
diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c
new file mode 100644 (file)
index 0000000..091e9dd
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ *  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>
+
+static void *loaded_fdt;
+static void *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 = grub_efi_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_any_pages (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/include/grub/arm64/fdtload.h b/include/grub/arm64/fdtload.h
deleted file mode 100644 (file)
index 7b9ddba..0000000
+++ /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 (file)
index 0000000..7b9ddba
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ *  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