[Concept,v2,16/18] efi: Move efi_load_option_dp_join() to a common file

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

Commit Message

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

This function is useful in the app so move it to the common helper.

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

(no changes since v1)

 lib/efi/helper.c            | 46 +++++++++++++++++++++++++++++++++++++
 lib/efi_loader/efi_helper.c | 44 -----------------------------------
 2 files changed, 46 insertions(+), 44 deletions(-)
  

Patch

diff --git a/lib/efi/helper.c b/lib/efi/helper.c
index 34cf3f49f95..85a2a270f20 100644
--- a/lib/efi/helper.c
+++ b/lib/efi/helper.c
@@ -5,6 +5,8 @@ 
 
 #define LOG_CATEGORY LOGC_EFI
 
+#include <efi.h>
+#include <efi_device_path.h>
 #include <string.h>
 #include <linux/types.h>
 
@@ -40,3 +42,47 @@  bool efi_varname_is_load_option(u16 *var_name16, int *index)
 
 	return false;
 }
+
+/**
+ * efi_load_option_dp_join() - join device-paths for load option
+ *
+ * @dp:		in: binary device-path, out: joined device-path
+ * @dp_size:	size of joined device-path
+ * @initrd_dp:	initrd device-path or NULL
+ * @fdt_dp:	device-tree device-path or NULL
+ * Return:	status_code
+ */
+efi_status_t efi_load_option_dp_join(struct efi_device_path **dp,
+				     size_t *dp_size,
+				     struct efi_device_path *initrd_dp,
+				     struct efi_device_path *fdt_dp)
+{
+	if (!dp)
+		return EFI_INVALID_PARAMETER;
+
+	*dp_size = efi_dp_size(*dp);
+
+	if (initrd_dp) {
+		struct efi_device_path *tmp_dp = *dp;
+
+		*dp = efi_dp_concat(tmp_dp, initrd_dp, *dp_size);
+		efi_free_pool(tmp_dp);
+		if (!*dp)
+			return EFI_OUT_OF_RESOURCES;
+		*dp_size += efi_dp_size(initrd_dp) + sizeof(EFI_DP_END);
+	}
+
+	if (fdt_dp) {
+		struct efi_device_path *tmp_dp = *dp;
+
+		*dp = efi_dp_concat(tmp_dp, fdt_dp, *dp_size);
+		efi_free_pool(tmp_dp);
+		if (!*dp)
+			return EFI_OUT_OF_RESOURCES;
+		*dp_size += efi_dp_size(fdt_dp) + sizeof(EFI_DP_END);
+	}
+
+	*dp_size += sizeof(EFI_DP_END);
+
+	return EFI_SUCCESS;
+}
diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c
index 56ea7d1c7d9..3030e6f52d4 100644
--- a/lib/efi_loader/efi_helper.c
+++ b/lib/efi_loader/efi_helper.c
@@ -99,50 +99,6 @@  err:
 	return file_path;
 }
 
-/**
- * efi_load_option_dp_join() - join device-paths for load option
- *
- * @dp:		in: binary device-path, out: joined device-path
- * @dp_size:	size of joined device-path
- * @initrd_dp:	initrd device-path or NULL
- * @fdt_dp:	device-tree device-path or NULL
- * Return:	status_code
- */
-efi_status_t efi_load_option_dp_join(struct efi_device_path **dp,
-				     size_t *dp_size,
-				     struct efi_device_path *initrd_dp,
-				     struct efi_device_path *fdt_dp)
-{
-	if (!dp)
-		return EFI_INVALID_PARAMETER;
-
-	*dp_size = efi_dp_size(*dp);
-
-	if (initrd_dp) {
-		struct efi_device_path *tmp_dp = *dp;
-
-		*dp = efi_dp_concat(tmp_dp, initrd_dp, *dp_size);
-		efi_free_pool(tmp_dp);
-		if (!*dp)
-			return EFI_OUT_OF_RESOURCES;
-		*dp_size += efi_dp_size(initrd_dp) + sizeof(EFI_DP_END);
-	}
-
-	if (fdt_dp) {
-		struct efi_device_path *tmp_dp = *dp;
-
-		*dp = efi_dp_concat(tmp_dp, fdt_dp, *dp_size);
-		efi_free_pool(tmp_dp);
-		if (!*dp)
-			return EFI_OUT_OF_RESOURCES;
-		*dp_size += efi_dp_size(fdt_dp) + sizeof(EFI_DP_END);
-	}
-
-	*dp_size += sizeof(EFI_DP_END);
-
-	return EFI_SUCCESS;
-}
-
 const struct guid_to_hash_map {
 	efi_guid_t guid;
 	const char algo[32];