[Concept,12/18] efi: app: Find the device-path-to-text protocol on startup

Message ID 20250820004039.3920254-13-sjg@u-boot.org
State New
Headers
Series efi: Move towards the EFI app booting EFI applications |

Commit Message

Simon Glass Aug. 20, 2025, 12:40 a.m. UTC
  From: Simon Glass <sjg@chromium.org>

Some protocols are generally useful for the app and it makes sense to
store these in the priv struct rather than requesting them each time
they are needed.

Add a new function which locates the device-path-to-text protocol and
stores it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 include/efi.h            | 2 ++
 lib/efi_client/efi_app.c | 9 +++++++++
 2 files changed, 11 insertions(+)
  

Patch

diff --git a/include/efi.h b/include/efi.h
index ed22ff9a5a4..28c297d87db 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -471,6 +471,7 @@  static inline struct efi_mem_desc *efi_get_next_mem_desc(
  *	allocate_pages() and free_pages()
  * @ram_base: Base address of RAM (size CONFIG_EFI_RAM_SIZE)
  * @image_data_type: Type of the loaded image (e.g. EFI_LOADER_CODE)
+ * @efi_dp_to_text: Pointer to the EFI_DEVICE_PATH protocol, or NULL if none
  *
  * @info: Header of the info list, holding info collected by the stub and passed
  *	to U-Boot
@@ -496,6 +497,7 @@  struct efi_priv {
 	bool use_pool_for_malloc;
 	unsigned long ram_base;
 	unsigned int image_data_type;
+	struct efi_device_path_to_text_protocol *efi_dp_to_text;
 
 	/* stub: */
 	struct efi_info_hdr *info;
diff --git a/lib/efi_client/efi_app.c b/lib/efi_client/efi_app.c
index df51c5a4de9..7c9c156e006 100644
--- a/lib/efi_client/efi_app.c
+++ b/lib/efi_client/efi_app.c
@@ -176,6 +176,14 @@  static void scan_tables(struct efi_system_table *sys_table)
 	}
 }
 
+static void find_protocols(struct efi_priv *priv)
+{
+	efi_guid_t guid = EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID;
+	struct efi_boot_services *boot = priv->boot;
+
+	boot->locate_protocol(&guid, NULL, (void **)&priv->efi_dp_to_text);
+}
+
 /**
  * efi_main() - Start an EFI image
  *
@@ -211,6 +219,7 @@  efi_status_t EFIAPI efi_main(efi_handle_t image,
 	}
 
 	scan_tables(priv->sys_table);
+	find_protocols(priv);
 
 	/*
 	 * We could store the EFI memory map here, but it changes all the time,