From: Simon Glass <simon.glass@canonical.com> Update label_boot_fdtoverlay() to load each overlay to a unique address. If fdtoverlay_addr_r is defined, start at that address and increment by the overlay size after each load. If not defined, let LMB allocate a fresh address for each overlay by passing addr = 0. This ensures that multiple overlays don't overwrite each other in memory before they are applied. Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Simon Glass <simon.glass@canonical.com> --- boot/pxe_utils.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index e368b15e500..a50fa4bc333 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -307,23 +307,39 @@ static void label_boot_fdtoverlay(struct pxe_context *ctx, struct pxe_label *label) { struct fdt_header *blob; + ulong fdtoverlay_addr; char **overlayp; - ulong addr; + bool use_lmb; + char *envaddr; int err; err = fdt_check_header(ctx->fdt); if (err) return; + /* + * Get the overlay load address. If fdtoverlay_addr_r is defined, + * overlays are loaded sequentially at increasing addresses. Otherwise, + * LMB allocates a fresh address for each overlay. + */ + envaddr = env_get("fdtoverlay_addr_r"); + if (envaddr) { + fdtoverlay_addr = hextoul(envaddr, NULL); + use_lmb = false; + } else { + fdtoverlay_addr = 0; + use_lmb = true; + } + /* Apply each overlay file in order */ alist_for_each(overlayp, &label->fdtoverlays) { const char *overlayfile = *overlayp; + ulong addr = fdtoverlay_addr; + ulong size; /* Load overlay file */ - err = get_relfile_envaddr(ctx, overlayfile, "fdtoverlay_addr_r", - SZ_4K, - (enum bootflow_img_t)IH_TYPE_FLATDT, - &addr, NULL); + err = get_relfile(ctx, overlayfile, &addr, SZ_4K, + (enum bootflow_img_t)IH_TYPE_FLATDT, &size); if (err < 0) { printf("Failed loading overlay %s\n", overlayfile); continue; @@ -343,6 +359,10 @@ static void label_boot_fdtoverlay(struct pxe_context *ctx, if (err) printf("Failed to apply overlay %s, skipping\n", overlayfile); + + /* Move to next address if using fixed addresses */ + if (!use_lmb) + fdtoverlay_addr = addr + size; } } -- 2.43.0