From patchwork Fri Jan 9 23:11:31 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1418 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000434; bh=f1K5W67DZPnuVF/vqnsHKn84ajkuPNVtHx/0OEzLyao=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=uYguaKenCycHmibdQ8+0isa5urdzzuUfnpYVflWcFdXlNzubKUHbq/Xv6bRAbMkDm nXGVciK14eqrkibozGKkZH+e/8XCRPk9xmiO2oDtq4T+dFgDKZOcUxTz+zD6YebQ1u 7kGqlAztnztExRGkMIm/30zGAL6TIB/pSaesBrP6GkU4aTizRrfk0pLn+Jwdl7lSAl TKe3vMvQYtlll3sA6VHz3D69SLfyGBsJNJBpvTR4OOhNt4HAubGb40G9E6i2zboezn X+TggK2qb+QaQmdS3rzWHl+j+pJdDQcPV3VfqulbBWb5YRiCz18PjMcl4ebVNTdDlr 8FhqeGI01wrhA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7E8C469240 for ; Fri, 9 Jan 2026 16:13:54 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id Mgak94PXVKcj for ; Fri, 9 Jan 2026 16:13:54 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000433; bh=f1K5W67DZPnuVF/vqnsHKn84ajkuPNVtHx/0OEzLyao=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ozSMzbR9OyPf9HrjTzWtvcEL5JJfzkftkuNTeIDyQQIEck1+TyhyYXyjlMhc3SkKq Ohd7G6WG1VyYGf4H+vl8tEUqHN4pIh1SrQzN+uqoX8y5hQqrkWEW3e7kQ4iF4ns6jJ ZeYof6j/gqqfjDjUXhllE0MWOx4eyXgQSYBlq0lDq9Yo1/m7tf29e4ybKR1iGZHo/c 6dsTzSNZZtyrUFdC6nLs0f1kM8P9ugygXdV4TNm/5h+5rOUULGHBn0i8ygHUje6v5Y kSr3KhOZGITSuEB5GUijlCLciGkQGPAuBcidTYDQZGacOfgjWU9siHOpfJp6H5G59W pDIokLYjbhS4g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AE14569256 for ; Fri, 9 Jan 2026 16:13:53 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000432; bh=hJweX+nNJctpsmluFNBhGSvID7Kbn3cOkhOTnRoOV2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VVHoRhlxfZi5XAwhxa0rXWkLXfpMp6krtcxtvCFgaqeHyqx8JY1kWDfkR6EsREBhQ vx5XH1EvqaB7eMrXcBAyQ/WPAQoo6Tk/Pzkc44daELVRv2WE+fMhBesBn01gQaoba7 2c8hnenfN+M9d0Fok8QfkArWYQZzZPW/Cap3Ujh+CTjZiJ6N8nzrxjvAssLV0vL5Rj Wn+MBTSaDH0Y6QpFmKfpjXpz0MZYvKjdchpNtj3jLrhucREsP5jXJ2e3BwmMT1nYGR VXUiYqdx9837nqc9brZeBrWh9tvLsgwcAi1LVSUcXHp91oVal25/vRJReW7LLykelh yJ1qcqyr7CVDA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0C7B369252; Fri, 9 Jan 2026 16:13:52 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id SR0UIJ9_q8if; Fri, 9 Jan 2026 16:13:51 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000428; bh=adLyHAp/YC35UaTBV2+Fui/ICs/HYc8WedyT3P/aLqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WYP4eXnHl6+2NTPh3Esw9z/KlkINJQ7CNrl4q3DMl6zfabAkeud9ZvypSIUMmJ2x5 vSf6thSlR59FyRw/Hi7IADhQziVVe4pj/x96SlcG5qgsVM3+GeV0ZKYr6tepRCB0lv gIny9/xj9u0MtwDCkwl19EHHs+Z56QxpKgRKehbgVtU8D9rMjct5x2WSKTGsY16y/L o3H+3RhfjYsiboKS3zzP2i7lid/Fiva8gjGSlMXIZ603LlL6jfQDRWr7rVnnyVk/Hu aYyROJkRcD+HWxEkJnbca2RSlbjmOCeeMqPftOOHiWHtFu4Xbk2NRxS9VJX3iQzD3q pYtSBvAJuqA6Q== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id BC29769254; Fri, 9 Jan 2026 16:13:47 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 9 Jan 2026 16:11:31 -0700 Message-ID: <20260109231151.4056804-23-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260109231151.4056804-1-sjg@u-boot.org> References: <20260109231151.4056804-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: ITHOIKVE6OPGRI2KXGR4JSR6ZQMUKSHF X-Message-ID-Hash: ITHOIKVE6OPGRI2KXGR4JSR6ZQMUKSHF X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 22/32] boot: pxe: Load FDT files in pxe_load_files() List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Move the FDT file loading to pxe_load_files() so all file loading is in one place. Add fdtfile parameter to pxe_load_files() and store the loaded FDT address in ctx->fdt_addr This simplifies label_process_fdt() to just do post-processing: setting the working FDT address, handling kaslrseed, and applying overlays. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- boot/pxe_utils.c | 76 ++++++++++++++++++++------------------------- include/pxe_utils.h | 2 ++ 2 files changed, 35 insertions(+), 43 deletions(-) diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index 4cb14783c77..2b1fe45c86d 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -495,49 +495,21 @@ static int label_get_fdt_path(struct pxe_label *label, char **fdtfilep) } /** - * label_load_fdt() - Load FDT file for the label + * label_process_fdt() - Process FDT after loading * - * If "fdt" or "fdtdir" is defined in the pxe file, retrieve the FDT blob - * from the server. - * - * If retrieval fails and an exact FDT file is specified with "fdt", an - * error is returned. If "fdtdir" is used and retrieval fails, this returns - * success and allows the caller to use fallback options. + * Set the working FDT address, handle kaslrseed, and apply overlays. + * The FDT must already be loaded (ctx->fdt_addr set by pxe_load_files()). * * @ctx: PXE context * @label: Label to process - * @fdtfile: FDT file path to load (freed by this function), or NULL - * Return: 0 if OK, -ENOMEM if out of memory, -ENOENT if FDT file specified - * by "fdt" label could not be loaded + * Return: 0 if OK */ -static int label_load_fdt(struct pxe_context *ctx, struct pxe_label *label, - char *fdtfile) +static int label_process_fdt(struct pxe_context *ctx, struct pxe_label *label) { - ulong addr; - int ret; - - if (!fdtfile) + if (!ctx->fdt_addr) return 0; - ret = get_relfile_envaddr(ctx, fdtfile, "fdt_addr_r", SZ_4K, - (enum bootflow_img_t)IH_TYPE_FLATDT, - &addr, NULL); - free(fdtfile); - if (ret < 0) { - if (label->fdt) { - printf("Skipping %s for failure retrieving FDT\n", - label->name); - return -ENOENT; - } - - if (label->fdtdir) { - printf("Skipping fdtdir %s for failure retrieving dts\n", - label->fdtdir); - } - return 0; - } - - ctx->fdt = map_sysmem(addr, 0); + ctx->fdt = map_sysmem(ctx->fdt_addr, 0); if (label->kaslrseed) label_boot_kaslrseed(ctx); @@ -654,7 +626,8 @@ static int generate_localboot(struct pxe_label *label) return 0; } -static int pxe_load_files(struct pxe_context *ctx, struct pxe_label *label) +static int pxe_load_files(struct pxe_context *ctx, struct pxe_label *label, + char *fdtfile) { int ret; @@ -686,6 +659,25 @@ static int pxe_load_files(struct pxe_context *ctx, struct pxe_label *label) } } + if (fdtfile) { + ret = get_relfile_envaddr(ctx, fdtfile, "fdt_addr_r", SZ_4K, + (enum bootflow_img_t)IH_TYPE_FLATDT, + &ctx->fdt_addr, NULL); + free(fdtfile); + if (ret < 0) { + if (label->fdt) { + printf("Skipping %s for failure retrieving FDT\n", + label->name); + return -ENOENT; + } + + if (label->fdtdir) { + printf("Skipping fdtdir %s for failure retrieving dts\n", + label->fdtdir); + } + } + } + return 0; } @@ -722,11 +714,9 @@ int pxe_load_label(struct pxe_context *ctx, struct pxe_label *label) return ret; } - ret = pxe_load_files(ctx, label); - if (ret) { - free(fdtfile); + ret = pxe_load_files(ctx, label, fdtfile); + if (ret) return ret; - } /* for FIT, append the configuration identifier */ snprintf(fit_addr, sizeof(fit_addr), "%lx%s", ctx->kern_addr, @@ -764,9 +754,9 @@ int pxe_load_label(struct pxe_context *ctx, struct pxe_label *label) /* Scenario 1: FIT with embedded FDT */ if (is_fit) { conf_fdt_str = fit_addr; - } else if (fdtfile) { - /* Scenario 2: load FDT file if fdt_addr_r is set */ - ret = label_load_fdt(ctx, label, fdtfile); + } else if (ctx->fdt_addr) { + /* Scenario 2: FDT loaded by pxe_load_files(), do post-processing */ + ret = label_process_fdt(ctx, label); if (ret) return ret; conf_fdt_str = env_get("fdt_addr_r"); diff --git a/include/pxe_utils.h b/include/pxe_utils.h index 9bca8d7868d..ec7f12cd7bf 100644 --- a/include/pxe_utils.h +++ b/include/pxe_utils.h @@ -150,6 +150,7 @@ typedef int (*pxe_getfile_func)(struct pxe_context *ctx, const char *file_path, * @initrd_addr: initaddr address (0 if none) * @initrd_size: initrd size (only used if @initrd_addr) * @initrd_str: initrd string to process (only used if @initrd_addr) + * @fdt_addr: FDT address from loaded file (0 if none) * @conf_fdt_str: FDT-address string * @conf_fdt: FDT address * @fdt: Working FDT pointer, for kaslrseed and overlay operations @@ -189,6 +190,7 @@ struct pxe_context { ulong initrd_addr; ulong initrd_size; char *initrd_str; + ulong fdt_addr; char *conf_fdt_str; ulong conf_fdt; void *fdt; /* working FDT pointer, for kaslrseed/overlays */