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 4/7] pxe_utils: export per-entry label helpers
Date: Thu, 04 Jun 2026 19:31:09 +0400	[thread overview]
Message-ID: <20260604-bls-v1-4-4ce6d1ee4711@flipper.net> (raw)
In-Reply-To: <20260604-bls-v1-0-4ce6d1ee4711@flipper.net>

Drop the static qualifier from label_create(), label_destroy(),
parse_label_keys() and label_boot(), and declare them in
<pxe_utils.h> to make them reusable.

The intended consumer is a Boot Loader Specification bootmeth, where
each on-disk file under loader/entries/ is a single entry with no
'label' header and no menu to traverse: the bootmeth derives the
label name from the filename, hands the file body to
parse_label_keys(), and invokes label_boot() directly.

No behaviour change: the implementations are unchanged and existing
in-tree callers in pxe_utils.c continue to use them as before.

Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
 boot/pxe_utils.c    | 37 ++++-------------------------------
 include/pxe_utils.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 33 deletions(-)

diff --git a/boot/pxe_utils.c b/boot/pxe_utils.c
index 420cee307baf..6dad3045f9d4 100644
--- a/boot/pxe_utils.c
+++ b/boot/pxe_utils.c
@@ -218,15 +218,7 @@ static int get_relfile_envaddr(struct pxe_context *ctx, const char *file_path,
 	return get_relfile(ctx, file_path, file_addr, type, filesizep);
 }
 
-/**
- * label_create() - crate a new PXE label
- *
- * Allocates memory for and initializes a pxe_label. This uses malloc, so the
- * result must be free()'d to reclaim the memory.
- *
- * Returns a pointer to the label, or NULL if out of memory
- */
-static struct pxe_label *label_create(void)
+struct pxe_label *label_create(void)
 {
 	struct pxe_label *label;
 
@@ -239,20 +231,7 @@ static struct pxe_label *label_create(void)
 	return label;
 }
 
-/**
- * label_destroy() - free the memory used by a pxe_label
- *
- * This frees @label itself as well as memory used by its name,
- * kernel, config, append, initrd, fdt, fdtdir and fdtoverlay members, if
- * they're non-NULL.
- *
- * So - be sure to only use dynamically allocated memory for the members of
- * the pxe_label struct, unless you want to clean it up first. These are
- * currently only created by the pxe file parsing code.
- *
- * @label: Label to free
- */
-static void label_destroy(struct pxe_label *label)
+void label_destroy(struct pxe_label *label)
 {
 	free(label->name);
 	free(label->kernel_label);
@@ -542,7 +521,7 @@ cleanup:
  * Returns does not return on success, otherwise returns 0 if a localboot
  *	label was processed, or 1 on error
  */
-static int label_boot(struct pxe_context *ctx, struct pxe_label *label)
+int label_boot(struct pxe_context *ctx, struct pxe_label *label)
 {
 	char *bootm_argv[] = { "bootm", NULL, NULL, NULL, NULL };
 	char *zboot_argv[] = { "zboot", NULL, "0", NULL, NULL };
@@ -1287,15 +1266,7 @@ static int parse_label_kernel(char **c, struct pxe_label *label)
 	return 1;
 }
 
-/*
- * Parse the body of a label: the sequence of key/value lines that follow
- * the 'label NAME' header. Stops at end-of-file or at a token that doesn't
- * belong inside a label (which is pushed back so the caller can handle it).
- *
- * Returns 1 on success, < 0 on error.
- */
-static 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)
 {
 	struct token t;
 	char *s;
diff --git a/include/pxe_utils.h b/include/pxe_utils.h
index 0378f2889f7b..e639e59e5dc8 100644
--- a/include/pxe_utils.h
+++ b/include/pxe_utils.h
@@ -202,6 +202,62 @@ void handle_pxe_menu(struct pxe_context *ctx, struct pxe_menu *cfg);
  */
 struct pxe_menu *parse_pxefile(struct pxe_context *ctx, ulong menucfg);
 
+/**
+ * label_create() - Allocate and zero-initialise a struct pxe_label
+ *
+ * The result must be freed with label_destroy().
+ *
+ * Return: pointer to the new label, or NULL if out of memory
+ */
+struct pxe_label *label_create(void);
+
+/**
+ * label_destroy() - Free a struct pxe_label and its string members
+ *
+ * Frees @label as well as memory used by its name, kernel, config, append,
+ * initrd, fdt, fdtdir and fdtoverlays members, if they are non-NULL. All
+ * such members must therefore reference malloc()'d memory.
+ *
+ * @label: Label to free
+ */
+void label_destroy(struct pxe_label *label);
+
+/**
+ * parse_label_keys() - Parse the body of a label
+ *
+ * Walks the sequence of key/value lines that follow a 'label NAME' header,
+ * populating @label. Stops at end-of-file or at a token that does not
+ * belong inside a label (which is pushed back so the caller can handle it).
+ *
+ * This is exported so that callers handling formats which lack a 'label'
+ * header (e.g. Boot Loader Specification type #2 entry files) can populate
+ * a pre-created label directly from a file body.
+ *
+ * @c: Pointer to the cursor into the file being parsed; updated on return
+ * @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
+ * Return: 1 on success, < 0 on error
+ */
+int parse_label_keys(char **c, struct pxe_menu *cfg, struct pxe_label *label);
+
+/**
+ * label_boot() - Boot according to the contents of a single pxe_label
+ *
+ * On success this function does not return; on failure it returns to
+ * let the caller try a different label or surface an error.
+ *
+ * The kernel is staged at $kernel_addr_r, an optional initrd at
+ * $ramdisk_addr_r, and an optional FDT at $fdt_addr_r. If the label
+ * has an 'append' string it overwrites $bootargs.
+ *
+ * @ctx: PXE context
+ * @label: Label to boot
+ * Return: does not return on success; 0 if a 'localboot' label was
+ *	processed; 1 on error
+ */
+int label_boot(struct pxe_context *ctx, struct pxe_label *label);
+
 /**
  * format_mac_pxe() - Convert a MAC address to PXE format
  *

-- 
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 ` Alexey Charkov [this message]
2026-06-04 15:31 ` [PATCH 5/7] pxe_utils: optionally ignore unknown keys in parse_label_keys() Alexey Charkov
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-4-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