From patchwork Tue Mar 24 22:18:55 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2047 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=1774390779; bh=bJQDGSaEZqtICMwGKDEtBwy3VxaqixqgQz6v7o2PsaM=; 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=E/U+iA49cPujF1090ho3M3Ybl7VE6KDpur9hqLBjPcz9Vxd3tez8Nah8t4N8u1Koo eDAo93wiyCPUHcpSvPZuna0et6N3xMIPrdlQC8WEDaQv4CZT8tAY3qHGfa9p8uJkha wALS5L4EfRI4JsSMKyjBidAyw9pb1MKl4lMS9W0KxjcvkKSZXc18nfpK+yGCfYsHiJ EQ8OZ6BLSrgwtetx76QSOHw+6ulhqaotkwFWoejk/6RVvdE5zsyBnpva74GqO+STP+ 1mFUsMHd5TiGiiiugUIKXgd4xaOOJccg32G+LJspVTctqZCYk/81TVmEESUROSqazW o0Gpr60jSD5Rw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id F40726A243 for ; Tue, 24 Mar 2026 16:19:38 -0600 (MDT) 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 CrKPHAX6dQHM for ; Tue, 24 Mar 2026 16:19:38 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1774390777; bh=bJQDGSaEZqtICMwGKDEtBwy3VxaqixqgQz6v7o2PsaM=; 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=JCN4zNK4DJrV9HARbs+z2KSWVS2lR9YBw/IHq3moV/fh5Gn23/WWF0mR9vnFiNEin FBci6DAOQ30RAnuD5Ke0lXcnVPe8Dxk52/bU642ZDc1I75OlIuxXvvIAVltL72tCR3 YOLQ4Pfhk89Ty5XFmnjfTUAVF5XJMY+AQjeZRtP80udwZjPRdUzsxLDm/0JIW2McDV iN3geLkYwdBYKzj3B7KNBM0IXWy0V9fqHfOWyGDlABXDAL8mIsb/dyr1ND7N3/qd8g DR/ZBbeX9NDVhd1dzCmjyMS06pcomBYQrTAwJfdeMd0lUGktcySnBkHkLLbu6ubDRu zNVCJcsBnb6dw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D01EF6A23D for ; Tue, 24 Mar 2026 16:19:37 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1774390776; bh=ojTC8CkK9giogzMqwYa29fzWRprl9KPw2ciBw0376x8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y5IR24LXX4RMyPMGM3t+XnVNM3c63spa0F/fmSNrcvhBLYpsKPnNiqTzxz7gcTenM N77s2kV8JCYrl/fbaFOHdcr+3ID3EeIJrZCilbkSny6pM4OxhhYpxv7DnZw1quZVb9 PpzZMaKdrfIs8x+wNDNYlGNk+k7N63umYJ6AgDdmPzS5P3UN67UVPQeNstzuHp3r8e 3OHaqt5HFHy/0sKLsnt2wgMjQcnKuzi6igoAEZl4BZnwbJJHHGk+nrkOMJK4Pa94Q0 gEJ9E19z9m7F0I1f1egFXB20mKeGyUmoKdNm4MxNIZIxSOHHFiZHbg683+zqziW8U5 PfI2hhGKoLZbw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 64DC46A23F; Tue, 24 Mar 2026 16:19:36 -0600 (MDT) 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 F72QaeRuxH-F; Tue, 24 Mar 2026 16:19:36 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1774390776; bh=XZrMuvdHCmUKEOLNNs8B3iIwPSYWWVCADStjWN9byAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZNifygfOqkTEV+aL43trdeWurh/LM2qir+yV7lcKkAfcC7YsSwSKi5Z78OyXGkZOj w0R5he8JyxcrdlKfXits6QHmYbbSF8mL2zBfVM/fJ+qOeP4xAor/P/Uxk6Z0i+XIyG vRNrbtpfZ5NpL+Xxre8jW8wGn8DBt2D7FaVe/aK2WJoEZXdjsYMouyJXxMu42JxLU7 9laIs4Bya4mrIfz4z3xfrGAHwJN3gX960lcfp4MQcR4oyxeI83zyZNex6VCtuLFJNH mtMorAzUIETroSda83I3/QA5cR9rh1ll+8+s2p6Fbe5SPpKb7ohTWD/V+KczEdhkth YCKL3cmi4TAAg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id D215C6A1DD; Tue, 24 Mar 2026 16:19:35 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 24 Mar 2026 16:18:55 -0600 Message-ID: <20260324221911.3678307-2-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260324221911.3678307-1-sjg@u-boot.org> References: <20260324221911.3678307-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: OA7WXBFRDQ6POH3HZPSU4A36GHG4NLUD X-Message-ID-Hash: OA7WXBFRDQ6POH3HZPSU4A36GHG4NLUD 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: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 01/12] extlinux: Use pxe_parse() to extract bootflow info 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 Replace the hand-rolled line-by-line parser in extlinux_fill_info() with the pxe_parse() API. This gives a fully parsed menu structure instead of ad-hoc string matching, and is a first step towards supporting multiple bootflows per partition (e.g. when an extlinux config defines several labels). The first label's menu name is used if available, falling back to the label name, matching the previous behaviour. Signed-off-by: Simon Glass --- boot/bootmeth_extlinux.c | 60 ++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/boot/bootmeth_extlinux.c b/boot/bootmeth_extlinux.c index 286d176ae20..3ffe21d96a3 100644 --- a/boot/bootmeth_extlinux.c +++ b/boot/bootmeth_extlinux.c @@ -117,48 +117,42 @@ static int extlinux_check_luks(struct bootflow *bflow) /** * extlinux_fill_info() - Decode the extlinux file to find out its info * + * Uses pxe_parse() to parse the configuration file and extract the first + * label's name to use as the bootflow OS name. + * * @bflow: Bootflow to process - * @return 0 if OK, -ve on error + * Return: 0 if OK, -ve on error */ static int extlinux_fill_info(struct bootflow *bflow) { - struct membuf mb; - char line[200]; - char *data; - int len; + struct pxe_context *ctx; + struct pxe_label *label; + const char *name; + ulong addr; log_debug("parsing bflow file size %x\n", bflow->size); - membuf_init(&mb, bflow->buf, bflow->size); - membuf_putraw(&mb, bflow->size, true, &data); - while (len = membuf_readline(&mb, line, sizeof(line) - 1, 0, true), len) { - char *tok, *p = line; - const char *name = NULL; - - if (*p == '#') - continue; - while (*p == ' ' || *p == '\t') - p++; - tok = strsep(&p, " "); - if (p) { - if (!strcmp("label", tok)) { - name = p; - if (bflow->os_name) - break; /* just find the first */ - } else if (!strcmp("menu", tok)) { - tok = strsep(&p, " "); - if (!strcmp("label", tok)) { - name = p; - } - } - if (name) { - free(bflow->os_name); - bflow->os_name = strdup(name); - if (!bflow->os_name) - return log_msg_ret("os", -ENOMEM); - } + addr = map_to_sysmem(bflow->buf); + ctx = pxe_parse(addr, bflow->size, bflow->fname); + if (!ctx) + return log_msg_ret("prs", -EINVAL); + + if (list_empty(&ctx->cfg->labels)) { + pxe_cleanup(ctx); + return log_msg_ret("lab", -ENOENT); + } + + label = list_first_entry(&ctx->cfg->labels, struct pxe_label, list); + name = label->menu ? label->menu : label->name; + if (name) { + bflow->os_name = strdup(name); + if (!bflow->os_name) { + pxe_cleanup(ctx); + return log_msg_ret("os", -ENOMEM); } } + pxe_cleanup(ctx); + return 0; }