[U-Boot] [RFC v2 05/15] efi_loader: convert efi_root_node to DM

AKASHI Takahiro takahiro.akashi at linaro.org
Fri Feb 8 08:15:32 UTC 2019


All the efi-specific objects, except for existing devices, will show up
under "efi root node" device.

Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
---
 include/efi_loader.h           |  3 +++
 lib/efi_loader/efi_root_node.c | 14 +++++-----
 lib/efi_loader/efi_setup.c     | 49 +++++++++++++++++++++++++++++++++-
 3 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 86cf91a6feca..4df965455c21 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -225,6 +225,9 @@ extern struct list_head efi_obj_list;
 /* List of all events */
 extern struct list_head efi_events;
 
+/* Root device */
+extern efi_handle_t efi_root;
+
 /* Initialize efi execution environment */
 efi_status_t efi_init_obj_list(void);
 /* Called by bootefi to initialize root node */
diff --git a/lib/efi_loader/efi_root_node.c b/lib/efi_loader/efi_root_node.c
index b056ba3ee880..4b2d1457576a 100644
--- a/lib/efi_loader/efi_root_node.c
+++ b/lib/efi_loader/efi_root_node.c
@@ -16,6 +16,8 @@ struct efi_root_dp {
 	struct efi_device_path end;
 } __packed;
 
+efi_handle_t efi_root;
+
 /**
  * efi_root_node_register() - create root node
  *
@@ -26,12 +28,11 @@ struct efi_root_dp {
  */
 efi_status_t efi_root_node_register(void)
 {
-	efi_handle_t root;
 	efi_status_t ret;
 	struct efi_root_dp *dp;
 
 	/* Create handle */
-	ret = efi_create_handle(&root);
+	ret = efi_add_handle(efi_root);
 	if (ret != EFI_SUCCESS)
 		return ret;
 
@@ -52,24 +53,25 @@ efi_status_t efi_root_node_register(void)
 	dp->end.length = sizeof(struct efi_device_path);
 
 	/* Install device path protocol */
-	ret = efi_add_protocol(root, &efi_guid_device_path, dp);
+	ret = efi_add_protocol(efi_root, &efi_guid_device_path, dp);
 	if (ret != EFI_SUCCESS)
 		goto failure;
 
 	/* Install device path to text protocol */
-	ret = efi_add_protocol(root, &efi_guid_device_path_to_text_protocol,
+	ret = efi_add_protocol(efi_root, &efi_guid_device_path_to_text_protocol,
 			       (void *)&efi_device_path_to_text);
 	if (ret != EFI_SUCCESS)
 		goto failure;
 
 	/* Install device path utilities protocol */
-	ret = efi_add_protocol(root, &efi_guid_device_path_utilities_protocol,
+	ret = efi_add_protocol(efi_root,
+			       &efi_guid_device_path_utilities_protocol,
 			       (void *)&efi_device_path_utilities);
 	if (ret != EFI_SUCCESS)
 		goto failure;
 
 	/* Install Unicode collation protocol */
-	ret = efi_add_protocol(root, &efi_guid_unicode_collation_protocol,
+	ret = efi_add_protocol(efi_root, &efi_guid_unicode_collation_protocol,
 			       (void *)&efi_unicode_collation_protocol);
 	if (ret != EFI_SUCCESS)
 		goto failure;
diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c
index 38569af1f2c8..83f1b842e6be 100644
--- a/lib/efi_loader/efi_setup.c
+++ b/lib/efi_loader/efi_setup.c
@@ -7,6 +7,10 @@
  */
 
 #include <common.h>
+#include <dm.h>
+#include <dm/device-internal.h>
+#include <dm/lists.h>
+#include <dm/root.h>
 #include <efi_loader.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -16,7 +20,7 @@ DECLARE_GLOBAL_DATA_PTR;
 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)
+static efi_status_t efi_system_init(void)
 {
 	efi_status_t ret = EFI_SUCCESS;
 
@@ -87,3 +91,46 @@ out:
 	efi_obj_list_initialized = ret;
 	return ret;
 }
+
+/* For backward compatibility */
+efi_status_t efi_init_obj_list(void)
+{
+	int ret;
+	extern struct udevice *efi_root;
+
+	if (efi_root)
+		return EFI_SUCCESS;
+
+	ret = device_bind_driver(dm_root(), "efi_root", "UEFI sub system",
+				 &efi_root);
+	if (ret)
+		return EFI_OUT_OF_RESOURCES;
+
+	ret = device_probe(efi_root);
+	if (ret)
+		return EFI_OUT_OF_RESOURCES;
+
+	return EFI_SUCCESS;
+}
+
+static int efi_system_probe(struct udevice *dev)
+{
+	efi_status_t ret;
+
+	ret = efi_system_init();
+	if (ret != EFI_SUCCESS)
+		return -1;
+
+	return 0;
+}
+
+U_BOOT_DRIVER(efi_root) = {
+	.name = "efi_root",
+	.id = UCLASS_EFI,
+	.probe = efi_system_probe,
+};
+
+UCLASS_DRIVER(efi) = {
+	.name = "efi",
+	.id = UCLASS_EFI,
+};
-- 
2.19.1



More information about the U-Boot mailing list