U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Charkov <alchark@flipper.net>
To: u-boot@lists.denx.de
Cc: Tom Rini <trini@konsulko.com>,
	 "Kory Maincent (TI.com)" <kory.maincent@bootlin.com>,
	 Simon Glass <sjg@chromium.org>,
	Hugo Villeneuve <hvilleneuve@dimonoff.com>,
	 Andrew Goodbody <andrew.goodbody@linaro.org>,
	 Quentin Schulz <quentin.schulz@cherry.de>,
	Anshul Dalal <anshuld@ti.com>,  Peng Fan <peng.fan@nxp.com>,
	Martin Schwan <m.schwan@phytec.de>,
	 Daniel Golle <daniel@makrotopia.org>,
	 Mattijs Korpershoek <mkorpershoek@kernel.org>,
	 Alexey Charkov <alchark@flipper.net>
Subject: [PATCH 5/7] pxe_utils: optionally ignore unknown keys in parse_label_keys()
Date: Thu, 04 Jun 2026 19:31:10 +0400	[thread overview]
Message-ID: <20260604-bls-v1-5-4ce6d1ee4711@flipper.net> (raw)
In-Reply-To: <20260604-bls-v1-0-4ce6d1ee4711@flipper.net>

The parser currently treats any keyword it does not recognise inside a
label body as the end of that label, pushing the token back so the
caller can dispatch it as menu-level input. That is correct for
extlinux/pxelinux, where the only thing legitimately following a label
body is another 'label' (or a top-level 'menu ...') line.

Other formats that share enough syntax to reuse this parser have
different rules. The Boot Loader Specification, in particular, lists a
number of entry-level keys (title, version, sort-key, machine-id,
architecture, ...) that this parser knows nothing about, and the spec
explicitly requires implementations to silently ignore unrecognised
keys rather than treat them as a structural boundary.

Add an ignore_unknown flag to parse_label_keys(): when set, the default
switch case consumes the rest of the offending line via eol_or_eof()
and continues parsing instead of returning. The existing extlinux
caller passes false and so is unaffected.

Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
 boot/pxe_utils.c    | 29 +++++++++++++++++++++++++++--
 include/pxe_utils.h |  8 +++++++-
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index 6dad3045f9d4..7ecee86a9ada 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -1266,7 +1266,8 @@ static int parse_label_kernel(char **c, struct pxe_label *label)
 	return 1;
 }
 
-int parse_label_keys(char **c, struct pxe_menu *cfg, struct pxe_label *label)
+int parse_label_keys(char **c, struct pxe_menu *cfg, struct pxe_label *label,
+		     bool ignore_unknown)
 {
 	struct token t;
 	char *s;
@@ -1339,7 +1340,31 @@ int parse_label_keys(char **c, struct pxe_menu *cfg, struct pxe_label *label)
 		case T_EOL:
 			break;
 
+		case T_EOF:
+			if (ignore_unknown) {
+				/*
+				 * BLS-style callers parse a standalone label
+				 * body, so there is no outer context to push
+				 * T_EOF back into — stop cleanly here.
+				 */
+				return 1;
+			}
+			/*
+			 * For pxelinux/extlinux, fall through so the default
+			 * case pushes T_EOF back for the top-level parser.
+			 */
+			fallthrough;
 		default:
+			if (ignore_unknown) {
+				/*
+				 * Skip the rest of the line and keep going.
+				 * Used for formats like the Boot Loader
+				 * Specification, where the spec mandates that
+				 * unknown keys must be silently ignored.
+				 */
+				eol_or_eof(c);
+				break;
+			}
 			/*
 			 * put the token back! we don't want it - it's the end
 			 * of a label and whatever token this is, it's
@@ -1381,7 +1406,7 @@ static int parse_label(char **c, struct pxe_menu *cfg)
 
 	list_add_tail(&label->list, &cfg->labels);
 
-	return parse_label_keys(c, cfg, label);
+	return parse_label_keys(c, cfg, label, false);
 }
 
 /*
diff --git a/include/pxe_utils.h b/include/pxe_utils.h
index e639e59e5dc8..653e1a7d866e 100644
--- a/include/pxe_utils.h
+++ b/include/pxe_utils.h
@@ -237,9 +237,15 @@ void label_destroy(struct pxe_label *label);
  * @cfg: Menu the label belongs to (used for 'menu default' bookkeeping)
  * @label: Label to populate; must already be allocated and (when called for
  *	a file that has a 'label' header) attached to @cfg->labels
+ * @ignore_unknown: If true, silently skip unknown keys (and consume the
+ *	rest of their lines) instead of stopping. This matches the Boot
+ *	Loader Specification's requirement that unknown keys be ignored.
+ *	If false (extlinux/pxelinux behaviour), an unknown token is pushed
+ *	back so the caller can treat it as the start of the next label.
  * Return: 1 on success, < 0 on error
  */
-int parse_label_keys(char **c, struct pxe_menu *cfg, struct pxe_label *label);
+int parse_label_keys(char **c, struct pxe_menu *cfg, struct pxe_label *label,
+		     bool ignore_unknown);
 
 /**
  * label_boot() - Boot according to the contents of a single pxe_label

-- 
2.53.0


  parent reply	other threads:[~2026-06-04 15:31 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04 15:31 [PATCH 0/7] pxe_utils: small fixups, implement BLS type 1 boot on top of them Alexey Charkov
2026-06-04 15:31 ` [PATCH 1/7] pxe_utils: fix W=1 kernel-doc warnings Alexey Charkov
2026-06-04 16:05   ` Tom Rini
2026-06-25 15:25   ` Simon Glass
2026-06-25 15:28   ` Simon Glass
2026-06-04 15:31 ` [PATCH 2/7] pxe_utils: accept "options" as synonym for "append" Alexey Charkov
2026-06-04 16:06   ` Tom Rini
2026-06-04 15:31 ` [PATCH 3/7] pxe_utils: extract per-entry key parsing into parse_label_keys() Alexey Charkov
2026-06-04 16:06   ` Tom Rini
2026-06-18 15:12   ` Simon Glass
2026-06-25 15:28   ` Simon Glass
2026-06-25 15:55     ` Alexey Charkov
2026-06-04 15:31 ` [PATCH 4/7] pxe_utils: export per-entry label helpers Alexey Charkov
2026-06-04 15:31 ` Alexey Charkov [this message]
2026-06-04 15:31 ` [PATCH 6/7] pxe_utils: accept "title" inside a label as a synonym for "menu label" Alexey Charkov
2026-06-04 15:31 ` [PATCH 7/7] boot: add a minimal bootmeth for the Boot Loader Specification Alexey Charkov
2026-06-12 18:24   ` Simon Glass
2026-06-25 15:28   ` Simon Glass
2026-06-25 15:51     ` Alexey Charkov
2026-06-25 16:24       ` Simon Glass
2026-06-25 16:57         ` Alexey Charkov
2026-06-25 17:24           ` Tom Rini
2026-06-25 17:29             ` Simon Glass
2026-06-25 17:32               ` Tom Rini
2026-06-26 10:45                 ` Simon Glass
2026-06-26 13:47                   ` Tom Rini
2026-06-29  5:45                     ` Simon Glass
2026-06-29 14:24                       ` Tom Rini
2026-06-25 17:25           ` Simon Glass
2026-06-04 16:05 ` [PATCH 0/7] pxe_utils: small fixups, implement BLS type 1 boot on top of them Tom Rini
2026-06-04 17:16   ` Alexey Charkov
2026-06-04 17:21     ` Tom Rini
2026-06-04 17:35       ` Alexey Charkov
2026-06-12 18:23         ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260604-bls-v1-5-4ce6d1ee4711@flipper.net \
    --to=alchark@flipper.net \
    --cc=andrew.goodbody@linaro.org \
    --cc=anshuld@ti.com \
    --cc=daniel@makrotopia.org \
    --cc=hvilleneuve@dimonoff.com \
    --cc=kory.maincent@bootlin.com \
    --cc=m.schwan@phytec.de \
    --cc=mkorpershoek@kernel.org \
    --cc=peng.fan@nxp.com \
    --cc=quentin.schulz@cherry.de \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox