[Concept,16/32] boot: pxe: Add FDT pointer to context for kaslrseed

Message ID 20260109231151.4056804-17-sjg@u-boot.org
State New
Headers
Series boot: pxe: Refactor into separate load/setup phases |

Commit Message

Simon Glass Jan. 9, 2026, 11:11 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

The label_boot_kaslrseed() function reads fdt_addr_r from the
environment and maps it to get the working FDT. This requires
CONFIG_CMDLINE to be enabled for the environment access.

Add a new 'fdt' field to struct pxe_context to hold the working FDT
pointer. Set this after loading the FDT file in label_process_fdt() and
use it in label_boot_kaslrseed(). This removes the environment
dependency and ensures the correct FDT is used.

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

 boot/pxe_utils.c    | 27 +++++++++++----------------
 include/pxe_utils.h |  2 ++
 2 files changed, 13 insertions(+), 16 deletions(-)
  

Patch

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index 0994e7e5196..93e00b6f97e 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -277,30 +277,23 @@  static int label_localboot(struct pxe_label *label)
 /*
  * label_boot_kaslrseed generate kaslrseed from hw rng
  */
-
-static void label_boot_kaslrseed(void)
+static void label_boot_kaslrseed(struct pxe_context *ctx)
 {
 #if CONFIG_IS_ENABLED(DM_RNG)
-	ulong fdt_addr;
-	struct fdt_header *working_fdt;
 	int err;
 
-	/* Get the main fdt and map it */
-	fdt_addr = hextoul(env_get("fdt_addr_r"), NULL);
-	working_fdt = map_sysmem(fdt_addr, 0);
-	err = fdt_check_header(working_fdt);
+	err = fdt_check_header(ctx->fdt);
 	if (err)
 		return;
 
 	/* add extra size for holding kaslr-seed */
 	/* err is new fdt size, 0 or negtive */
-	err = fdt_shrink_to_minimum(working_fdt, 512);
+	err = fdt_shrink_to_minimum(ctx->fdt, 512);
 	if (err <= 0)
 		return;
 
-	fdt_kaslrseed(working_fdt, true);
+	fdt_kaslrseed(ctx->fdt, true);
 #endif
-	return;
 }
 
 /**
@@ -577,15 +570,17 @@  static int label_process_fdt(struct pxe_context *ctx, struct pxe_label *label,
 					printf("Skipping fdtdir %s for failure retrieving dts\n",
 						label->fdtdir);
 				}
-			}
+			} else {
+				ctx->fdt = map_sysmem(addr, 0);
 
-			if (label->kaslrseed)
-				label_boot_kaslrseed();
+				if (label->kaslrseed)
+					label_boot_kaslrseed(ctx);
 
 #ifdef CONFIG_OF_LIBFDT_OVERLAY
-			if (label->fdtoverlays)
-				label_boot_fdtoverlay(ctx, label);
+				if (label->fdtoverlays)
+					label_boot_fdtoverlay(ctx, label);
 #endif
+			}
 		} else {
 			*fdt_argp = NULL;
 		}
diff --git a/include/pxe_utils.h b/include/pxe_utils.h
index 7f5b8c040d6..9bca8d7868d 100644
--- a/include/pxe_utils.h
+++ b/include/pxe_utils.h
@@ -152,6 +152,7 @@  typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path,
  * @initrd_str: initrd string to process (only used if @initrd_addr)
  * @conf_fdt_str: FDT-address string
  * @conf_fdt: FDT address
+ * @fdt: Working FDT pointer, for kaslrseed and overlay operations
  * @restart: true to use BOOTM_STATE_RESTART instead of BOOTM_STATE_START (only
  *	supported with FIT / bootm)
  * @fake_go: Do a 'fake' boot, up to the last possible point, then return
@@ -190,6 +191,7 @@  struct pxe_context {
 	char *initrd_str;
 	char *conf_fdt_str;
 	ulong conf_fdt;
+	void *fdt;		/* working FDT pointer, for kaslrseed/overlays */
 	bool restart;
 	bool fake_go;
 };