From patchwork Fri Jan 9 23:11:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1413 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=1768000413; bh=25wAsNY5vbK0Hyz8zzWjfUVJxdTLfw4crWFgqfWF49o=; 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=tdmaNMQZHgDSBXh6s4jXv2iUuvDYudbD1gFZjW1lS8jG2YvXFqP8QiUO8dcnVJud1 8LawCmp/XYMYsYPLuiYyq2Zb6glr0WZrNYNr9SUw+ryXNWgJaMMOINxUfxKSRd8vyU 5RXat59WJtkFsAmkGaik2kvLNREJSTOvI8oGi0YxV/ezgh7wHgDSNW4VJdchwZ3TrH jhfAYvpbDLiNmuHYXuYcl8MjwqhsiSpoivWgv+bqk2ev4iu3AFCgld8MrIYug4Zlc0 qVbMP7W7wEHTk6hcJF3nvm97IWeo4W272ViOVHg7FeXuc0NFmqVyH0u5Ezh3XrQYWG QHgqSkv3VtMnA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A630169218 for ; Fri, 9 Jan 2026 16:13:33 -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 cPUdg86RbgvB for ; Fri, 9 Jan 2026 16:13:33 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000413; bh=25wAsNY5vbK0Hyz8zzWjfUVJxdTLfw4crWFgqfWF49o=; 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=tdmaNMQZHgDSBXh6s4jXv2iUuvDYudbD1gFZjW1lS8jG2YvXFqP8QiUO8dcnVJud1 8LawCmp/XYMYsYPLuiYyq2Zb6glr0WZrNYNr9SUw+ryXNWgJaMMOINxUfxKSRd8vyU 5RXat59WJtkFsAmkGaik2kvLNREJSTOvI8oGi0YxV/ezgh7wHgDSNW4VJdchwZ3TrH jhfAYvpbDLiNmuHYXuYcl8MjwqhsiSpoivWgv+bqk2ev4iu3AFCgld8MrIYug4Zlc0 qVbMP7W7wEHTk6hcJF3nvm97IWeo4W272ViOVHg7FeXuc0NFmqVyH0u5Ezh3XrQYWG QHgqSkv3VtMnA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8A11C5FF82 for ; Fri, 9 Jan 2026 16:13:33 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000411; bh=zCwloTE155WB4n3CUmYkyI6BdedIWu251VdeAEhEZUk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E+X8ZGD2YyFc++u7HhOWxlHZNlA21dzLGXCuUKOgllzO8uupw/2Siu22+aYhifONd CyeVgDGrEGvZ5lDCYK4Pp1LD3TLNMaAxTEsNvcIMLjI/CItvLaowIYegqBRl2G+g3h bVGY5ou69j4rkbh4dDIgTthIKLxCzpxrwIM7XA2AZnqrUWa0AOLIPmZeHzN7K1GU+S v1cyP5PxOiTCe8yvhQcT37kBXGDH5f8OjucRFV7/4PWgpoj8oDoJVQj1Nk8TIZ/8rt COStheLI11YTodtY4+eInEGzr1gebFeMavhb/W8gHiPXbEbfAs8b0sdzVTqB0PzPot 1YUoTcZ1bideA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 945D05FF82; Fri, 9 Jan 2026 16:13:31 -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 dmoxkHBcYL9W; Fri, 9 Jan 2026 16:13:31 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000407; bh=ocyyojzj5i1yo0C4rpKEiDAH0Ias3o8DMUcdV4hMcuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eO1lV/ha+3GXJRpxzAS1SpAggwzJAY2PH7mc9wJmoWRXSYrrWLNTwzy8IElABo6he hd0WTrGmb8Uywwl7UXA76WVEpMvrx3MSXThVREmAR9E7ZmxgePcmDpKRN+b2g+p2lP R93RupIR7zYMgJJB5ePx37f5nVB6qLF0ePPcK0hQrKqoWKPejpIqT1108gWLg7rzm2 9/r5mNpQEmuxHmRujD8YcAfKUD4IwZpK6WVzuQPHevqmW5jTTWr0hQxYRwsV8s3N3p TvGyADipUSRrEi0Lxlf3zAjjEwh2fXlscHTP1DG1nLMc0wZ9L83ckSCHRuhos1+QRd +Qme4ghwstGDg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id C6C7169218; Fri, 9 Jan 2026 16:13:26 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 9 Jan 2026 16:11:26 -0700 Message-ID: <20260109231151.4056804-18-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: VGUH2OWA5MLXO7ZIL4VQ2CHJBGJYVPFJ X-Message-ID-Hash: VGUH2OWA5MLXO7ZIL4VQ2CHJBGJYVPFJ 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 17/32] boot: pxe: Move FIT handling from label_process_fdt() to caller 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 The label_process_fdt() function handles both FIT images (where the FDT is embedded in the FIT) and separate FDT files. Move the FIT detection to pxe_load_label() to simplify label_process_fdt() In the FIT case, the label's fdt field matches kernel_label, indicating the FDT comes from the FIT image rather than a separate file. When this is detected, use the fit_addr string (which includes the FIT configuration) directly as conf_fdt_str This allows label_process_fdt() to focus solely on loading separate FDT files. Rename it to label_load_fdt() to reflect this. Also move the log_debug() and scenario documentation to the caller where more context is available. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- boot/pxe_utils.c | 83 ++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 38 deletions(-) diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index 93e00b6f97e..0e335cb2fdd 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -499,50 +499,31 @@ static int label_get_fdt_path(struct pxe_label *label, char **fdtfilep) return 0; } -/* - * label_process_fdt() - Process FDT for the label - * - * @ctx: PXE context - * @label: Label to process - * @kernel_addr: String containing kernel address - * @fdt_argp: bootm argument to fill in, for FDT - * Return: 0 if OK, -ENOMEM if out of memory, -ENOENT if FDT file could not be - * loaded - * - * fdt usage is optional: - * It handles the following scenarios. - * - * Scenario 1: If fdt_addr_r specified and "fdt" or "fdtdir" label is - * defined in pxe file, retrieve fdt blob from server. Pass fdt_addr_r to - * bootm, and adjust argc appropriately. - * - * If retrieve fails and no exact fdt blob is specified in pxe file with - * "fdt" label, try Scenario 2. +/** + * label_load_fdt() - Load FDT file for the label * - * Scenario 2: If there is an fdt_addr specified, pass it along to - * bootm, and adjust argc appropriately. + * If "fdt" or "fdtdir" is defined in the pxe file, retrieve the FDT blob + * from the server. This is only called when fdt_addr_r is set in the + * environment. * - * Scenario 3: If there is an fdtcontroladdr specified, pass it along to - * bootm, and adjust argc appropriately, unless the image type is fitImage. + * 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. * - * Scenario 4: fdt blob is not available. + * @ctx: PXE context + * @label: Label to process + * @fdt_argp: Updated to NULL if FDT retrieval fails + * Return: 0 if OK, -ENOMEM if out of memory, -ENOENT if FDT file specified + * by "fdt" label could not be loaded */ -static int label_process_fdt(struct pxe_context *ctx, struct pxe_label *label, - char *kernel_addr, const char **fdt_argp) +static int label_load_fdt(struct pxe_context *ctx, struct pxe_label *label, + const char **fdt_argp) { char *fdtfile; int ret; - log_debug("label '%s' kernel_addr '%s' label->fdt '%s' fdtdir '%s' " - "kernel_label '%s' fdt_argp '%s'\n", - label->name, kernel_addr, label->fdt, label->fdtdir, - label->kernel_label, *fdt_argp); - - /* For FIT, the label can be identical to kernel one */ - if (label->fdt && !strcmp(label->kernel_label, label->fdt)) { - *fdt_argp = kernel_addr; /* if fdt label is defined then get fdt from server */ - } else if (*fdt_argp) { + if (*fdt_argp) { ret = label_get_fdt_path(label, &fdtfile); if (ret) return ret; @@ -769,11 +750,37 @@ int pxe_load_label(struct pxe_context *ctx, struct pxe_label *label) return -ENOSPC; } + /* + * FDT handling has several scenarios: + * + * 1. FIT image with embedded FDT: label->fdt matches kernel_label, + * use the FIT address so bootm extracts the FDT from the FIT + * + * 2. Separate FDT file: if fdt_addr_r is set and "fdt" or "fdtdir" + * is specified, load the FDT from the server + * + * 3. Fallback to fdt_addr env var if set + * + * 4. Fallback to fdtcontroladdr for non-FIT images + * + * 5. No FDT available + */ conf_fdt_str = env_get("fdt_addr_r"); - ret = label_process_fdt(ctx, label, fit_addr, &conf_fdt_str); - if (ret) - return ret; + log_debug("label '%s' kernel_addr '%s' label->fdt '%s' fdtdir '%s' kernel_label '%s' fdt_argp '%s'\n", + label->name, fit_addr, label->fdt, label->fdtdir, + label->kernel_label, conf_fdt_str); + + /* Scenario 1: FIT with embedded FDT */ + if (label->fdt && !strcmp(label->kernel_label, label->fdt)) { + conf_fdt_str = fit_addr; + } else { + /* Scenario 2: load FDT file if fdt_addr_r is set */ + ret = label_load_fdt(ctx, label, &conf_fdt_str); + if (ret) + return ret; + } + /* Scenarios 3 and 4: fallback options */ if (!conf_fdt_str) conf_fdt_str = pxe_get_fdt_fallback(label, ctx->kern_addr); if (conf_fdt_str)