[Concept,09/26] boot: pxe: Replace pxe_fdtoverlay with pxe_file

Message ID 20260110202906.187370-10-sjg@u-boot.org
State New
Headers
Series boot: pxe: Add three-phase API and fix memory leaks |

Commit Message

Simon Glass Jan. 10, 2026, 8:28 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

The new struct pxe_file provides a more general way to describe files
that need to be loaded. Replace the FDT-overlay-specific struct with the
new general-purpose one, setting the type field to PFT_FDTOVERLAY.

This change prepares for moving away from callback-based file loading to
a model where PXE returns a list of files to load and the caller handles
the actual loading.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 boot/pxe_parse.c    |  8 +++++---
 boot/pxe_utils.c    |  4 ++--
 include/pxe_utils.h | 13 +------------
 test/boot/pxe.c     | 12 ++++++------
 4 files changed, 14 insertions(+), 23 deletions(-)
  

Patch

diff --git a/boot/pxe_parse.c b/boot/pxe_parse.c
index f6b7887f603..29bee4d908c 100644
--- a/boot/pxe_parse.c
+++ b/boot/pxe_parse.c
@@ -106,14 +106,14 @@  static struct pxe_label *label_create(void)
 	if (!label)
 		return NULL;
 	memset(label, 0, sizeof(struct pxe_label));
-	alist_init_struct(&label->fdtoverlays, struct pxe_fdtoverlay);
+	alist_init_struct(&label->fdtoverlays, struct pxe_file);
 
 	return label;
 }
 
 void label_destroy(struct pxe_label *label)
 {
-	struct pxe_fdtoverlay *overlay;
+	struct pxe_file *overlay;
 
 	free(label->name);
 	free(label->menu);
@@ -326,7 +326,7 @@  static int parse_fdtoverlays(char **c, struct alist *overlays)
 	start = val;
 
 	while (*val) {
-		struct pxe_fdtoverlay item;
+		struct pxe_file item;
 		char *end;
 
 		/* Skip leading spaces */
@@ -345,7 +345,9 @@  static int parse_fdtoverlays(char **c, struct alist *overlays)
 			item.path = strdup(val);
 			val += strlen(val);
 		}
+		item.type = PFT_FDTOVERLAY;
 		item.addr = 0;
+		item.size = 0;
 
 		if (!item.path || !alist_add(overlays, item)) {
 			free(item.path);
diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index 384a4e4f8ab..b4bcba422b8 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -308,7 +308,7 @@  static void label_boot_kaslrseed(struct pxe_context *ctx)
 static void label_load_fdtoverlays(struct pxe_context *ctx,
 				   struct pxe_label *label)
 {
-	struct pxe_fdtoverlay *overlay;
+	struct pxe_file *overlay;
 	ulong fdtoverlay_addr;
 	bool use_lmb;
 	char *envaddr;
@@ -357,7 +357,7 @@  static void label_load_fdtoverlays(struct pxe_context *ctx,
 static void label_apply_fdtoverlays(struct pxe_context *ctx,
 				    struct pxe_label *label)
 {
-	struct pxe_fdtoverlay *overlay;
+	struct pxe_file *overlay;
 	struct fdt_header *blob;
 	int err;
 
diff --git a/include/pxe_utils.h b/include/pxe_utils.h
index 2f194b91683..75437885dd3 100644
--- a/include/pxe_utils.h
+++ b/include/pxe_utils.h
@@ -24,17 +24,6 @@ 
  * take a 'include file getter' function.
  */
 
-/**
- * struct pxe_fdtoverlay - info about an FDT overlay
- *
- * @path: Path to the overlay file
- * @addr: Address where the overlay was loaded (0 if not yet loaded)
- */
-struct pxe_fdtoverlay {
-	char *path;
-	ulong addr;
-};
-
 /**
  * struct pxe_label - describes a single label in a pxe file
  *
@@ -50,7 +39,7 @@  struct pxe_fdtoverlay {
  * @initrd: path to the initrd to use for this label.
  * @fdt: path to FDT to use
  * @fdtdir: path to FDT directory to use
- * @fdtoverlays: list of FDT overlays to apply (alist of struct pxe_fdtoverlay)
+ * @fdtoverlays: list of FDT overlays to apply (alist of struct pxe_file)
  * @files: list of files to load (alist of struct pxe_file)
  * @say: message to print when this label is selected for booting
  * @ipappend: flags for appending IP address (0x1) and MAC address (0x3)
diff --git a/test/boot/pxe.c b/test/boot/pxe.c
index 97049e27ab6..260fc918592 100644
--- a/test/boot/pxe.c
+++ b/test/boot/pxe.c
@@ -192,9 +192,9 @@  static int pxe_test_parse_norun(struct unit_test_state *uts)
 	ut_assertnull(label->fdtdir);
 	ut_asserteq(2, label->fdtoverlays.count);
 	ut_asserteq_str("/dtb/overlay1.dtbo",
-			alist_get(&label->fdtoverlays, 0, struct pxe_fdtoverlay)->path);
+			alist_get(&label->fdtoverlays, 0, struct pxe_file)->path);
 	ut_asserteq_str("/dtb/overlay2.dtbo",
-			alist_get(&label->fdtoverlays, 1, struct pxe_fdtoverlay)->path);
+			alist_get(&label->fdtoverlays, 1, struct pxe_file)->path);
 	ut_asserteq_str("Booting default Linux kernel", label->say);
 	ut_asserteq(0, label->ipappend);
 	ut_asserteq(0, label->attempted);
@@ -317,13 +317,13 @@  static int pxe_test_parse_norun(struct unit_test_state *uts)
 
 	/* Verify overlays were loaded to valid addresses */
 	ut_assert(alist_get(&label->fdtoverlays, 0,
-			    struct pxe_fdtoverlay)->addr >= PXE_OVERLAY_ADDR);
+			    struct pxe_file)->addr >= PXE_OVERLAY_ADDR);
 	ut_assert(alist_get(&label->fdtoverlays, 1,
-			    struct pxe_fdtoverlay)->addr >= PXE_OVERLAY_ADDR);
+			    struct pxe_file)->addr >= PXE_OVERLAY_ADDR);
 
 	/* Second overlay should be at a higher address than the first */
-	ut_assert(alist_get(&label->fdtoverlays, 1, struct pxe_fdtoverlay)->addr >
-		  alist_get(&label->fdtoverlays, 0, struct pxe_fdtoverlay)->addr);
+	ut_assert(alist_get(&label->fdtoverlays, 1, struct pxe_file)->addr >
+		  alist_get(&label->fdtoverlays, 0, struct pxe_file)->addr);
 
 	/* Verify no more console output */
 	ut_assert_console_end();