From patchwork Fri Jan 9 23:11:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1411 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=1768000402; bh=UgFbU2jSASfR19RN+rW81Ecre1s0Z0KzkmPK3fWo9nA=; 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=BfRqZfq6Xhr2sgZQD9ux/sgXTg9wnjf1kAFxZHjtYfyisl01YjyXHiX5dmjPnUJFw surDfeJ+GLT7HlhXksZe0Jw4LQrQznNqCbtrPRhD+LRusl+H5beMITE5H8XkSGZBB4 tQBlLVWyAK6Zf0g5sTMJPR5vE21FrCJMbI41SnOhrr3moq2mPKKIa/pyuRaEMnUSQP VHoBkPe8KiJKwzq1VLEzpRXZ+OnibVXHJvI9i1YMX8U0jqdDpi3f4Av8q/gsYLZBLQ GgkyGVxfUAIFtpsYH/rto5B6sgRg9CktuMU1I/WWfW2wCO4z24HG9aYoLLmJd+I/1I k1eAkdGLsfKdQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C73AE69235 for ; Fri, 9 Jan 2026 16:13:22 -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 x3JmNDklPwSy for ; Fri, 9 Jan 2026 16:13:22 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000402; bh=UgFbU2jSASfR19RN+rW81Ecre1s0Z0KzkmPK3fWo9nA=; 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=BfRqZfq6Xhr2sgZQD9ux/sgXTg9wnjf1kAFxZHjtYfyisl01YjyXHiX5dmjPnUJFw surDfeJ+GLT7HlhXksZe0Jw4LQrQznNqCbtrPRhD+LRusl+H5beMITE5H8XkSGZBB4 tQBlLVWyAK6Zf0g5sTMJPR5vE21FrCJMbI41SnOhrr3moq2mPKKIa/pyuRaEMnUSQP VHoBkPe8KiJKwzq1VLEzpRXZ+OnibVXHJvI9i1YMX8U0jqdDpi3f4Av8q/gsYLZBLQ GgkyGVxfUAIFtpsYH/rto5B6sgRg9CktuMU1I/WWfW2wCO4z24HG9aYoLLmJd+I/1I k1eAkdGLsfKdQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AC65E6923D for ; Fri, 9 Jan 2026 16:13:22 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000401; bh=IjvH2d4oLEsLL8rc17rkbbMswVHUK/ob1zVArT07jIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=klajRcaN1/iJ8nLPZYqSGIgiCF3bzVYgebwEBwBd3Me/vwoA4QVdtYQIEOcAU3a96 n6ZbeaBTKEBNn2Vsq1DNvV9bmCIGMBaMWJYmStaKz+aZhQst+u++RCleb+HeMHrK+G XScbb6YnucWAFkNfZDM3FTdlokY5AFfcXQ9HyesCFOK9KoJAX/aXoYvl77mXEz9EcH vAYF5e/kQw6zvvhUawEVjlZIJB9gVJkEspXezKQKUqG0BnIX3ctBcaniDX7ufANBaN LlNmHKWk2kztR6n11jphERawP/IPVq6kN1WLWLhdR6zxje45whcntXplvFDj+ecO/h Rkr7dGSgXX+jw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7F2D45FF82; Fri, 9 Jan 2026 16:13:21 -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 xf1J1OUFxJ01; Fri, 9 Jan 2026 16:13:21 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768000397; bh=18A2kDgNCioP15tqWcn3sKQO6BG5iEkuz56V+2/Rf/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aP1+Ke7lLR/zi4nqqNSmQ303y8fLCiSGuKD2mJkmra8PAxiaYKZ89FZKuB37ySf1k G78HMtJFdENPC42UDOJu03Dtw2+QRWXq13tJTE8vsddD15XPIbrzTXeDNDy/AezLIR tFZQgfPd1juNxcKAn71MJ0RMiAAIXt9omogtQ1OB99dduoHcjYwtPVQczhBaOwuR7X sXXYJ/FwzJ2ROYUBjxLNYAi5wCO0HcBK/bNgTdnv7mvsc4mp21yBeKnfml2QAI/lYw z4uu8jbhan1yr98a+ZdaLwPsDlQPDxcM8CBu4Bwkl5RPG2I0SZsIT/zolLTEmnjjdn 5smAvVCzcs3Sw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 0F5F669218; Fri, 9 Jan 2026 16:13:17 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Fri, 9 Jan 2026 16:11:24 -0700 Message-ID: <20260109231151.4056804-16-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: 5Q5WZXQLFMEOWYAHZA3XWPYWRAX5NCJY X-Message-ID-Hash: 5Q5WZXQLFMEOWYAHZA3XWPYWRAX5NCJY 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 15/32] boot: pxe: Split filename handling from label_process_fdt() 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 Separate the logic that determines the FDT filename into a new label_get_fdt_path() function. This handles both the label->fdt case and the label->fdtdir case where the filename is constructed from environment variables. The new function returns an allocated string that the caller must free. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- boot/pxe_utils.c | 148 +++++++++++++++++++++++++++-------------------- 1 file changed, 85 insertions(+), 63 deletions(-) diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c index 55b738e5c45..0994e7e5196 100644 --- a/boot/pxe_utils.c +++ b/boot/pxe_utils.c @@ -428,6 +428,84 @@ const char *pxe_get_fdt_fallback(struct pxe_label *label, ulong kern_addr) return conf_fdt_str; } +/** + * label_get_fdt_path() - Get the FDT path for a label + * + * Determine the FDT filename from label->fdt or by constructing it from + * label->fdtdir and environment variables. + * + * @label: Label to get FDT path for + * @fdtfilep: Returns allocated FDT path, or NULL if none. Caller must free. + * Return: 0 on success, -ENOMEM on allocation failure + */ +static int label_get_fdt_path(struct pxe_label *label, char **fdtfilep) +{ + char *fdtfile = NULL; + + if (label->fdt) { + if (IS_ENABLED(CONFIG_SUPPORT_PASSING_ATAGS)) { + if (strcmp("-", label->fdt)) + fdtfile = strdup(label->fdt); + } else { + fdtfile = strdup(label->fdt); + } + } else if (label->fdtdir) { + char *f1, *f2, *f3, *f4, *slash; + int len; + + f1 = env_get("fdtfile"); + if (f1) { + f2 = ""; + f3 = ""; + f4 = ""; + } else { + /* + * For complex cases where this code doesn't + * generate the correct filename, the board + * code should set $fdtfile during early boot, + * or the boot scripts should set $fdtfile + * before invoking "pxe" or "sysboot". + */ + f1 = env_get("soc"); + f2 = "-"; + f3 = env_get("board"); + f4 = ".dtb"; + if (!f1) { + f1 = ""; + f2 = ""; + } + if (!f3) { + f2 = ""; + f3 = ""; + } + } + + len = strlen(label->fdtdir); + if (!len) + slash = "./"; + else if (label->fdtdir[len - 1] != '/') + slash = "/"; + else + slash = ""; + + len = strlen(label->fdtdir) + strlen(slash) + + strlen(f1) + strlen(f2) + strlen(f3) + + strlen(f4) + 1; + fdtfile = malloc(len); + if (!fdtfile) { + printf("malloc fail (FDT filename)\n"); + return -ENOMEM; + } + + snprintf(fdtfile, len, "%s%s%s%s%s%s", + label->fdtdir, slash, f1, f2, f3, f4); + } + + *fdtfilep = fdtfile; + + return 0; +} + /* * label_process_fdt() - Process FDT for the label * @@ -459,6 +537,9 @@ const char *pxe_get_fdt_fallback(struct pxe_label *label, ulong kern_addr) static int label_process_fdt(struct pxe_context *ctx, struct pxe_label *label, char *kernel_addr, 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, @@ -469,68 +550,9 @@ static int label_process_fdt(struct pxe_context *ctx, struct pxe_label *label, *fdt_argp = kernel_addr; /* if fdt label is defined then get fdt from server */ } else if (*fdt_argp) { - char *fdtfile = NULL; - char *fdtfilefree = NULL; - - if (label->fdt) { - if (IS_ENABLED(CONFIG_SUPPORT_PASSING_ATAGS)) { - if (strcmp("-", label->fdt)) - fdtfile = label->fdt; - } else { - fdtfile = label->fdt; - } - } else if (label->fdtdir) { - char *f1, *f2, *f3, *f4, *slash; - int len; - - f1 = env_get("fdtfile"); - if (f1) { - f2 = ""; - f3 = ""; - f4 = ""; - } else { - /* - * For complex cases where this code doesn't - * generate the correct filename, the board - * code should set $fdtfile during early boot, - * or the boot scripts should set $fdtfile - * before invoking "pxe" or "sysboot". - */ - f1 = env_get("soc"); - f2 = "-"; - f3 = env_get("board"); - f4 = ".dtb"; - if (!f1) { - f1 = ""; - f2 = ""; - } - if (!f3) { - f2 = ""; - f3 = ""; - } - } - - len = strlen(label->fdtdir); - if (!len) - slash = "./"; - else if (label->fdtdir[len - 1] != '/') - slash = "/"; - else - slash = ""; - - len = strlen(label->fdtdir) + strlen(slash) + - strlen(f1) + strlen(f2) + strlen(f3) + - strlen(f4) + 1; - fdtfilefree = malloc(len); - if (!fdtfilefree) { - printf("malloc fail (FDT filename)\n"); - return -ENOMEM; - } - - snprintf(fdtfilefree, len, "%s%s%s%s%s%s", - label->fdtdir, slash, f1, f2, f3, f4); - fdtfile = fdtfilefree; - } + ret = label_get_fdt_path(label, &fdtfile); + if (ret) + return ret; if (fdtfile) { ulong addr; @@ -541,7 +563,7 @@ static int label_process_fdt(struct pxe_context *ctx, struct pxe_label *label, (enum bootflow_img_t)IH_TYPE_FLATDT, &addr, NULL); - free(fdtfilefree); + free(fdtfile); if (err < 0) { *fdt_argp = NULL;