[U-Boot] [PATCH] efi_loader: move efi_init_obj_list() to a new efi_setup.c

AKASHI Takahiro takahiro.akashi at linaro.org
Tue Dec 18 05:02:15 UTC 2018


The function, efi_init_obj_list(), can be shared in different pseudo efi
applications, like bootefi/bootmgr as well as my efishell. Moreover, it
will be utilized to extend efi initialization, for example, my "removable
disk support" patch and "capsule-on-disk support" patch in the future.

So with this patch, it will be moved to a new file, efi_setup.c, under
lib/efi_loader and exported, making no changes in functionality.

Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
---
 cmd/bootefi.c              |  75 -------------------------
 include/efi_loader.h       |   2 +
 lib/efi_loader/Makefile    |   1 +
 lib/efi_loader/efi_setup.c | 112 +++++++++++++++++++++++++++++++++++++
 4 files changed, 115 insertions(+), 75 deletions(-)
 create mode 100644 lib/efi_loader/efi_setup.c

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 38679ffc56a9..7012d72ab50d 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -30,84 +30,9 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #define OBJ_LIST_NOT_INITIALIZED 1
 
-static efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED;
-
 static struct efi_device_path *bootefi_image_path;
 static struct efi_device_path *bootefi_device_path;
 
-/* Initialize and populate EFI object list */
-efi_status_t efi_init_obj_list(void)
-{
-	efi_status_t ret = EFI_SUCCESS;
-
-	/*
-	 * On the ARM architecture gd is mapped to a fixed register (r9 or x18).
-	 * As this register may be overwritten by an EFI payload we save it here
-	 * and restore it on every callback entered.
-	 */
-	efi_save_gd();
-
-	/* Initialize once only */
-	if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED)
-		return efi_obj_list_initialized;
-
-	/* Initialize system table */
-	ret = efi_initialize_system_table();
-	if (ret != EFI_SUCCESS)
-		goto out;
-
-	/* Initialize root node */
-	ret = efi_root_node_register();
-	if (ret != EFI_SUCCESS)
-		goto out;
-
-	/* Initialize EFI driver uclass */
-	ret = efi_driver_init();
-	if (ret != EFI_SUCCESS)
-		goto out;
-
-	ret = efi_console_register();
-	if (ret != EFI_SUCCESS)
-		goto out;
-#ifdef CONFIG_PARTITIONS
-	ret = efi_disk_register();
-	if (ret != EFI_SUCCESS)
-		goto out;
-#endif
-#if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO)
-	ret = efi_gop_register();
-	if (ret != EFI_SUCCESS)
-		goto out;
-#endif
-#ifdef CONFIG_NET
-	ret = efi_net_register();
-	if (ret != EFI_SUCCESS)
-		goto out;
-#endif
-#ifdef CONFIG_GENERATE_ACPI_TABLE
-	ret = efi_acpi_register();
-	if (ret != EFI_SUCCESS)
-		goto out;
-#endif
-#ifdef CONFIG_GENERATE_SMBIOS_TABLE
-	ret = efi_smbios_register();
-	if (ret != EFI_SUCCESS)
-		goto out;
-#endif
-	ret = efi_watchdog_register();
-	if (ret != EFI_SUCCESS)
-		goto out;
-
-	/* Initialize EFI runtime services */
-	ret = efi_reset_system_init();
-	if (ret != EFI_SUCCESS)
-		goto out;
-
-out:
-	efi_obj_list_initialized = ret;
-	return ret;
-}
-
 /*
  * Allow unaligned memory access.
  *
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 16633d6da0d5..dd68cfce5c65 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -252,6 +252,8 @@ extern struct list_head efi_obj_list;
 /* List of all events */
 extern struct list_head efi_events;
 
+/* Initialize efi execution environment */
+efi_status_t efi_init_obj_list(void);
 /* Called by bootefi to initialize root node */
 efi_status_t efi_root_node_register(void);
 /* Called by bootefi to initialize runtime */
diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
index 26b999bf7c51..3ba539314aee 100644
--- a/lib/efi_loader/Makefile
+++ b/lib/efi_loader/Makefile
@@ -29,6 +29,7 @@ obj-y += efi_image_loader.o
 obj-y += efi_memory.o
 obj-y += efi_root_node.o
 obj-y += efi_runtime.o
+obj-y += efi_setup.o
 obj-y += efi_unicode_collation.o
 obj-y += efi_variable.o
 obj-y += efi_watchdog.o
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
new file mode 100644
index 000000000000..215c163380ee
--- /dev/null
+++ b/lib/efi_loader/efi_setup.c
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ *  EFI setup code
+ *
+ *  Copyright (c) 2016 Alexander Graf
+ *  Copyright (c) 2018 AKASHI Takahiro, Linaro Limited
+ */
+
+#if 1 /* TODO: cleanup */
+#include <common.h>
+#include <efi_loader.h>
+#else
+#include <charset.h>
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <efi_loader.h>
+#include <efi_selftest.h>
+#include <errno.h>
+#include <linux/libfdt.h>
+#include <linux/libfdt_env.h>
+#include <mapmem.h>
+#include <memalign.h>
+#include <asm/global_data.h>
+#include <asm-generic/sections.h>
+#include <asm-generic/unaligned.h>
+#include <linux/linkage.h>
+
+#ifdef CONFIG_ARMV7_NONSEC
+#include <asm/armv7.h>
+#include <asm/secure.h>
+#endif
+#endif
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define OBJ_LIST_NOT_INITIALIZED 1
+
+static efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED;
+
+/* Initialize and populate EFI object list */
+efi_status_t efi_init_obj_list(void)
+{
+	efi_status_t ret = EFI_SUCCESS;
+
+	/*
+	 * On the ARM architecture gd is mapped to a fixed register (r9 or x18).
+	 * As this register may be overwritten by an EFI payload we save it here
+	 * and restore it on every callback entered.
+	 */
+	efi_save_gd();
+
+	/* Initialize once only */
+	if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED)
+		return efi_obj_list_initialized;
+
+	/* Initialize system table */
+	ret = efi_initialize_system_table();
+	if (ret != EFI_SUCCESS)
+		goto out;
+
+	/* Initialize root node */
+	ret = efi_root_node_register();
+	if (ret != EFI_SUCCESS)
+		goto out;
+
+	/* Initialize EFI driver uclass */
+	ret = efi_driver_init();
+	if (ret != EFI_SUCCESS)
+		goto out;
+
+	ret = efi_console_register();
+	if (ret != EFI_SUCCESS)
+		goto out;
+#ifdef CONFIG_PARTITIONS
+	ret = efi_disk_register();
+	if (ret != EFI_SUCCESS)
+		goto out;
+#endif
+#if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO)
+	ret = efi_gop_register();
+	if (ret != EFI_SUCCESS)
+		goto out;
+#endif
+#ifdef CONFIG_NET
+	ret = efi_net_register();
+	if (ret != EFI_SUCCESS)
+		goto out;
+#endif
+#ifdef CONFIG_GENERATE_ACPI_TABLE
+	ret = efi_acpi_register();
+	if (ret != EFI_SUCCESS)
+		goto out;
+#endif
+#ifdef CONFIG_GENERATE_SMBIOS_TABLE
+	ret = efi_smbios_register();
+	if (ret != EFI_SUCCESS)
+		goto out;
+#endif
+	ret = efi_watchdog_register();
+	if (ret != EFI_SUCCESS)
+		goto out;
+
+	/* Initialize EFI runtime services */
+	ret = efi_reset_system_init();
+	if (ret != EFI_SUCCESS)
+		goto out;
+
+out:
+	efi_obj_list_initialized = ret;
+	return ret;
+}
-- 
2.19.1



More information about the U-Boot mailing list