From: Simon Glass <simon.glass@canonical.com> Split pxe_load_label() into two functions to allow more flexible use: - pxe_load_label(): Handles localboot setup, FIT detection, and calls pxe_load_files() to load all files (kernel, initrd, FDT, overlays) - pxe_setup_label(): Processes the FDT (applying overlays), determines the FDT address, and saves boot parameters to the context This separation allows callers to load files without immediately setting up boot parameters, which is useful for inspection or validation before booting. Update label_boot() to call both functions in sequence. Copy fdt_addr to conf_fdt at the end of pxe_load_label() to maintain backward compatibility for callers that only call pxe_load_label() without pxe_setup_label(). Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- boot/pxe_utils.c | 28 +++++++++++++++++++++++----- include/pxe_utils.h | 19 ++++++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index 8609d832aa6..49934d626ee 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -687,10 +687,6 @@ int pxe_load_files(struct pxe_context *ctx, struct pxe_label *label, int pxe_load_label(struct pxe_context *ctx, struct pxe_label *label) { - char fit_addr[200]; - const char *conf_fdt_str; - ulong conf_fdt = 0; - char initrd_str[28] = ""; char *fdtfile = NULL; bool is_fit; int ret; @@ -722,6 +718,25 @@ int pxe_load_label(struct pxe_context *ctx, struct pxe_label *label) if (ret) return ret; + /* Copy fdt_addr to conf_fdt for callers that don't use pxe_setup_label */ + ctx->conf_fdt = ctx->fdt_addr; + + return 0; +} + +int pxe_setup_label(struct pxe_context *ctx, struct pxe_label *label) +{ + char fit_addr[200]; + const char *conf_fdt_str; + ulong conf_fdt = 0; + char initrd_str[28] = ""; + bool is_fit; + int ret; + + /* Check for FIT case: FDT comes from FIT image, not a separate file */ + is_fit = label->fdt && label->kernel_label && + !strcmp(label->kernel_label, label->fdt); + /* for FIT, append the configuration identifier */ snprintf(fit_addr, sizeof(fit_addr), "%lx%s", ctx->kern_addr, label->config ? label->config : ""); @@ -850,11 +865,14 @@ static int label_boot(struct pxe_context *ctx, struct pxe_label *label) } } - /* Load files if not already loaded */ + /* Load files and set up boot params if not already done */ if (!ctx->label) { ret = pxe_load_label(ctx, label); if (ret) return 1; + ret = pxe_setup_label(ctx, label); + if (ret) + return 1; } if (label->ipappend & 0x1) { diff --git a/include/pxe_utils.h b/include/pxe_utils.h index aa73f5ff7f0..a03e00e2a4a 100644 --- a/include/pxe_utils.h +++ b/include/pxe_utils.h @@ -464,9 +464,9 @@ int pxe_load_files(struct pxe_context *ctx, struct pxe_label *label, /** * pxe_load_label() - Load kernel/initrd/FDT for a label * - * Loads the files specified in the label into memory and saves the - * addresses and sizes in @ctx. Call this only when ready to boot or - * inspect loaded files. + * Loads the files specified in the label into memory. Call + * pxe_setup_label() after this to process the FDT and set up + * boot parameters. * * @ctx: PXE context with getfile callback * @label: Label whose files to load @@ -475,6 +475,19 @@ int pxe_load_files(struct pxe_context *ctx, struct pxe_label *label, */ int pxe_load_label(struct pxe_context *ctx, struct pxe_label *label); +/** + * pxe_setup_label() - Set up boot parameters for a loaded label + * + * Processes the FDT (applying overlays if needed) and saves the boot + * parameters in @ctx. Call this after pxe_load_label(). + * + * @ctx: PXE context with loaded files + * @label: Label to set up + * Return: 0 on success, -ENOSPC if initrd string too long, -ENOMEM if + * out of memory + */ +int pxe_setup_label(struct pxe_context *ctx, struct pxe_label *label); + /* * Entry point for parsing a menu file. nest_level indicates how many times * we've nested in includes. It will be 1 for the top level menu file. -- 2.43.0