pxe_utils: small fixups, implement BLS type 1 boot on top of them
v2 cover pxe_utils: small fixups, implement BLS type 1 boot on top of them
Add support for the Boot Loader Specification (BLS) type 1 boot entries, as generated by default by systemd's kernel-install when loader=bls.
Given that the format of BLS entries is pretty much the same as PXElinux, reuse the existing library for the parsing logic.
BLS type 2 entries are out of scope, as they are effectively just EFI applications and should be booted as such.
This implementation is also only allowing a single top-sorting entry to boot, as the standard boot infrastruture currently doesn't support multiple entries per partition-bootmeth tuple. I have a proposed extension to enable that and will post it separately as RFC - that enables the use of bootflow menu to select the kernel to boot without jumping through several menus with different behavior as is currently required with extlinux.conf.
CI passes all green [1]
[1] https://git.u-boot-project.org/u-boot/contributors/alchark/u-boot/-/pipelines/1089
---
Changes in v2:
- Dropped "default y" to avoid increasing image size for platforms which don't use Freedesktop-style userspace and won't benefit from BLS (thanks Tom)
- Fixed typo referring to BLS type 2 when type 1 was meant (thanks Simon)
- Added a kerneldoc for parse_label_keys() upon factoring it out, not just when it gets exported to a shared header (thanks Simon)
- Shared the pxelinux getfile helper rather than making a third copy of it in the new bootmeth (thanks Simon). It moves to a translation unit of its own, so that PXE_UTILS users without bootstd don't gain a dependency on the bootmeth uclass, and boards without PXE_UTILS don't pay for it
- Allocated the entry buffer with ARCH_DMA_MINALIGN rather than 1 (thanks Simon)
- Stopped retaining the parsed label in bflow->bootmeth_priv, which the core frees flat and would therefore leak (thanks Simon). It turned out to be worse than a leak: a bootflow is shallow-copied into the bootflow list, so the pointer was shared between the iterator's temporary and the stored copy and could be freed twice. bls_boot() now re-parses bflow->buf, as extlinux does
- Added a test for entries found under the '/boot/' prefix rather than at the root of the filesystem (thanks Simon for asking what happens there). No code change was needed
- Dropped the number prefix from the driver name (thanks Simon)
- Added sandbox tests and updated the bootmeth/bootflow expectations that binding a third bootmeth changes, plus a doc/develop/bootstd page (thanks Simon)
- Added a patch hardening the "append" parser. A bare "append" dereferenced NULL, and an "initrd=" at end-of-line computed a negative length before malloc()
- Link to v1: https://patch.msgid.link/[email protected]
To: [email protected]
Cc: Tom Rini <[email protected]>
Cc: Alexey Charkov <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Daniel Golle <[email protected]>
Cc: Johan Jonker <[email protected]>
Cc: "Lucien.Jheng" <[email protected]>
Cc: Casey Connolly <[email protected]>
Cc: Michal Simek <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Vincent Jardin <[email protected]>
Cc: Denis Mukhin <[email protected]>
Cc: Aristo Chen <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Marek Vasut <[email protected]>
---
Alexey Charkov (13):
pxe_utils: fix W=1 kernel-doc warnings
pxe_utils: accept "options" as synonym for "append"
pxe_utils: harden the "append" parser against malformed input
pxe_utils: extract per-entry key parsing into parse_label_keys()
pxe_utils: export per-entry label helpers
pxe_utils: optionally ignore unknown keys in parse_label_keys()
pxe_utils: accept "title" inside a label as a synonym for "menu label"
bootmeth: share the pxelinux getfile helper
boot: add a minimal bootmeth for the Boot Loader Specification
test: bootstd: add a BLS entry to the Fedora fixture image
sandbox: enable BLS boot method
test: bootstd: cover BLS entries below a prefix
doc: bootstd: describe the BLS bootmeth
arch/sandbox/dts/test.dts | 12 + boot/Kconfig | 24 ++ boot/Makefile | 2 + boot/bootmeth_bls.c | 370 +++++++++++++++++++++++++++++++ boot/bootmeth_extlinux.c | 20 -- boot/bootmeth_pxe.c | 22 +- boot/bootmeth_pxe_common.c | 34 +++ boot/pxe_utils.c | 146 +++++++----- configs/sandbox_defconfig | 1 + doc/develop/bootstd/bls.rst | 56 +++++ doc/develop/bootstd/index.rst | 1 + doc/develop/bootstd/overview.rst | 1 + include/extlinux.h | 23 ++ include/pxe_utils.h | 62 ++++++ test/boot/bootdev.c | 14 ++ test/boot/bootflow.c | 467 +++++++++++++++++++++++++++++++-------- test/boot/bootmeth.c | 38 +++- test/py/tests/test_ut.py | 122 ++++++++-- 18 files changed, 1200 insertions(+), 215 deletions(-)
---
base-commit: 2d379a529c257606946831a6dac1c37de6a3f8c0
change-id: 20260604-bls-db6a30b913ae
Best regards,
Signature · 1 line
Alexey Charkov <[email protected]>
PATCH v2 1/13 pxe_utils: fix W=1 kernel-doc warnings
Add the missing parameter and enum value descriptions reported by scripts/kernel-doc when building with W=1:
- get_relfile(): document @type - get_pxelinux_path(): document @pxefile_addr_r - enum lex_state: document L_NORMAL, L_KEYWORD, L_SLITERAL - get_token(): document @t and @state
No functional change.
--- boot/pxe_utils.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
boot/pxe_utils.c +12 -0
@@ -95,6 +95,7 @@ int format_mac_pxe(char *outbuf, size_t outbuf_len)* @ctx: PXE context * @file_path: File path to read (relative to the PXE file) * @file_addr: Address to load file to +* @type: Image type used to record the loaded file in the bootflow * @filesizep: If not NULL, returns the file size in bytes * Returns 1 for success, or < 0 on error */
@@ -162,6 +163,7 @@ int get_pxe_file(struct pxe_context *ctx, const char *file_path,* * @ctx: PXE context * @file: Filename to process (relative to pxelinux.cfg/) +* @pxefile_addr_r: Address to load the file to * Returns 1 for success, -ENAMETOOLONG if the resulting path is too long. * or other value < 0 on other error */
@@ -914,6 +916,13 @@ static const struct token keywords[] = {* Since pxe(linux) files don't have a token to identify the start of a * literal, we have to keep track of when we're in a state where a literal is * expected vs when we're in a state a keyword is expected. +* +* @L_NORMAL: Outside any specific lexical context; whitespace is skipped +* and the next non-blank token determines what is read +* @L_KEYWORD: A keyword is expected; the next word is matched against the +* keyword table and tagged with the matching token type +* @L_SLITERAL: A string literal is expected; characters are read up to the +* end of the line */ enum lex_state {L_NORMAL =0 ,
@@ -1018,6 +1027,9 @@ static void get_keyword(struct token *t)* * @p: Points to a pointer to the current position in the input being processed. * Updated to point at the first character after the current token +* @t: Token to populate with the type and value of what was read +* @state: Current lexer state, controlling whether a keyword or a string +* literal is expected next */ static void get_token (char **p,struct token *t,enum lex_state state) {
Signature · 1 line
2.54.0
PATCH v2 2/13 pxe_utils: accept "options" as synonym for "append"
In reply to Alexey CharkovThe Boot Loader Specification [1] type #1 entry files use the keyword "options" for the kernel command line, which corresponds to extlinux's "append". Recognising it here lets the existing pxelinux parser ingest BLS entries unchanged, paving the way for a BLS bootmeth that reuses the parser instead of duplicating it.
No effect on existing extlinux/pxelinux files: "options" is not a valid keyword in those formats, so it cannot collide with prior usage.
--- boot/pxe_utils.c | 1 + 1 file changed, 1 insertion(+)
boot/pxe_utils.c +1 -0
@@ -894,6 +894,7 @@ static const struct token keywords[] = { {"linux", T_LINUX}, {"localboot", T_LOCALBOOT}, {"append", T_APPEND}, + {"options", T_APPEND}, {"initrd", T_INITRD}, {"include", T_INCLUDE}, {"devicetree", T_FDT},
Signature · 1 line
2.54.0
PATCH v2 3/13 pxe_utils: harden the "append" parser against malformed input
In reply to Alexey CharkovThe parser can crash upon weird input to the "append" option:
- a bare "append" with no value makes parse_sliteral() fail on the T_EOL token and leave label->append untouched, so the NULL is handed straight to strstr();
- "initrd=" as the last token on the line makes strchr(s, ' ') return NULL, so the length becomes a huge negative number and the following malloc()/strncpy() pair runs wild.
Bail out on a failed parse, and use strcspn() so an unterminated value simply runs to the end of the string. strndup() then folds the allocate-copy-terminate sequence into one call.
--- boot/pxe_utils.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
boot/pxe_utils.c +6 -6
@@ -1333,16 +1333,16 @@ static int parse_label(char **c, struct pxe_menu *cfg)case T_APPEND : err =parse_sliteral (c, &label->append); -if (label->initrd) +if (err <0 || label->initrd)break ; s =strstr (label->append,"initrd=" );if (!s)break ; - s +=7 ; - len = (int )(strchr (s,' ' ) - s); - label->initrd =malloc (len +1 ); -strncpy (label->initrd, s, len); - label->initrd[len] ='\0' ; + s +=strlen ("initrd=" ); + len =strcspn (s," " ); + label->initrd =strndup (s, len); +if (!label->initrd) + err = -ENOMEM ;break ;
Signature · 1 line
2.54.0
PATCH v2 4/13 pxe_utils: extract per-entry key parsing into parse_label_keys()
In reply to Alexey CharkovSplit the body of parse_label() into a standalone parse_label_keys() helper that walks key/value lines and populates a pre-existing struct pxe_label. parse_label() becomes a thin wrapper that creates the label, reads its name, attaches it to the menu, and delegates.
This is a pure refactor: the new helper contains the original loop verbatim, with the local variable declarations moved to its scope. No call sites or behaviour change.
A subsequent change will export this helper so callers parsing formats that lack a 'label' header (notably Boot Loader Specification type #1 entries) can populate a label directly from a file body without duplicating the parser.
--- boot/pxe_utils.c | 64 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 21 deletions(-)
boot/pxe_utils.c +43 -21
@@ -1287,35 +1287,27 @@ static int parse_label_kernel(char **c, struct pxe_label *label)return 1 ; } -/* -* Parses a label and adds it to the list of labels for a menu. +/** +* parse_label_keys() - Parse the body of a label * -* A label ends when we either get to the end of a file, or -* get some input we otherwise don't have a handler defined -* for. +* 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). * +* @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 */ -static int parse_label (char **c,struct pxe_menu *cfg) +static int parse_label_keys (char **c,struct pxe_menu *cfg, +struct pxe_label *label) {struct token t; +char *s;int len; -char *s = *c; -struct pxe_label *label;int err; - label =label_create (); -if (!label) -return -ENOMEM ; - - err =parse_sliteral (c, &label->name); -if (err <0 ) { -printf ("Expected label name: %.*s\n" , (int )(*c - s), s); -label_destroy (label); -return -EINVAL ; - } - -list_add_tail (&label->list, &cfg->labels); -while (1 ) { s = *c;get_token (c, &t,L_KEYWORD );
@@ -1397,6 +1389,36 @@ static int parse_label(char **c, struct pxe_menu *cfg) } } +/* +* Parses a label and adds it to the list of labels for a menu. +* +* A label ends when we either get to the end of a file, or +* get some input we otherwise don't have a handler defined +* for. +* +*/ +static int parse_label (char **c,struct pxe_menu *cfg) +{ +char *s = *c; +struct pxe_label *label; +int err; + + label =label_create (); +if (!label) +return -ENOMEM ; + + err =parse_sliteral (c, &label->name); +if (err <0 ) { +printf ("Expected label name: %.*s\n" , (int )(*c - s), s); +label_destroy (label); +return -EINVAL ; + } + +list_add_tail (&label->list, &cfg->labels); + +return parse_label_keys (c, cfg, label); +} +/* * This 16 comes from the limit pxelinux imposes on nested includes. *
Signature · 1 line
2.54.0
PATCH v2 5/13 pxe_utils: export per-entry label helpers
In reply to Alexey CharkovDrop 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.
--- boot/pxe_utils.c | 43 ++++------------------------------------ include/pxe_utils.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 39 deletions(-)
boot/pxe_utils.c +4 -39
@@ -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,21 +1266,7 @@ static int parse_label_kernel(char **c, struct pxe_label *label)return 1 ; } -/** -* 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). -* -* @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 -*/ -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;
include/pxe_utils.h +56 -0
62 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v2 6/13 pxe_utils: optionally ignore unknown keys in parse_label_keys()
In reply to Alexey CharkovThe 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.
--- boot/pxe_utils.c | 29 +++++++++++++++++++++++++++-- include/pxe_utils.h | 8 +++++++- 2 files changed, 34 insertions(+), 3 deletions(-)
boot/pxe_utils.c +27 -2
@@ -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); }/*
include/pxe_utils.h +7 -1
@@ -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
Signature · 1 line
2.54.0
PATCH v2 7/13 pxe_utils: accept "title" inside a label as a synonym for "menu label"
In reply to Alexey CharkovThe parser already understands the "title" keyword at the menu level (via "menu title"). Boot Loader Specification [1] type #1 entry files use a bare "title" line at the entry level to give the human-readable name of the entry, the closest extlinux equivalent of which is "menu label" inside a label body.
Make parse_label_keys() honour "title" the same way it honours "menu label", populating label->menu. This lets BLS entries surface their pretty name through the existing label->menu plumbing without the BLS bootmeth (or any other caller) having to special-case it.
No effect on existing extlinux/pxelinux files: those use "menu label" inside a label, not bare "title", so this change is purely additive.
--- boot/pxe_utils.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
boot/pxe_utils.c +13 -0
@@ -1284,6 +1284,19 @@ int parse_label_keys(char **c, struct pxe_menu *cfg, struct pxe_label *label, err =parse_label_menu (c, cfg, label);break ; +case T_TITLE : +/* +* Equivalent to 'menu label' inside a label body. +* Boot Loader Specification entries use a bare +* 'title' line for the human-readable name; honour +* it here so the existing parser handles BLS files +* natively. extlinux/pxelinux files conventionally +* use 'menu label' instead, so this is additive. +*/ +if (!label->menu) + err =parse_sliteral (c, &label->menu); +break ; +case T_KERNEL :case T_LINUX : err =parse_label_kernel (c, label);
Signature · 1 line
2.54.0
PATCH v2 8/13 bootmeth: share the pxelinux getfile helper
In reply to Alexey Charkovbootmeth_extlinux.c and bootmeth_pxe.c carry byte-identical copies of the pxe_getfile_func that reads a file through the bootmeth uclass, and the Boot Loader Specification bootmeth added later needs the same thing.
Move the function into a small translation unit of its own, so that all consumers can call reuse it without introducing PXE dependency into bootstd or bootstd dependency into PXE.
Bootmeths which need it select the new hidden BOOTMETH_PXE_COMMON symbol.
--- boot/Kconfig | 8 ++++++++ boot/Makefile | 1 + boot/bootmeth_extlinux.c | 20 -------------------- boot/bootmeth_pxe.c | 22 +--------------------- boot/bootmeth_pxe_common.c | 34 ++++++++++++++++++++++++++++++++++ include/extlinux.h | 23 +++++++++++++++++++++++ 6 files changed, 67 insertions(+), 41 deletions(-)
boot/Kconfig +8 -0
@@ -622,9 +622,16 @@ config BOOTMETH_CROS Note that only x86 devices are supported at present. +config BOOTMETH_PXE_COMMON + bool + help + Helpers shared by the bootmeths that hand their config files to the + pxelinux parser. Selected by those bootmeths, not user-visible. + config BOOTMETH_EXTLINUX bool "Bootdev support for extlinux boot" select PXE_UTILS + select BOOTMETH_PXE_COMMON default y help Enables support for extlinux boot using bootdevs. This makes the
@@ -640,6 +647,7 @@ config BOOTMETH_EXTLINUX config BOOTMETH_EXTLINUX_PXE bool "Bootdev support for extlinux boot over network" depends on CMD_PXE && CMD_NET && DM_ETH + select BOOTMETH_PXE_COMMON default y help Enables support for extlinux boot using bootdevs. This makes the
boot/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_$(PHASE_)BOOTSTD) += bootstd-uclass.o obj-$(CONFIG_$(PHASE_)BOOTSTD_MENU) += bootflow_menu.o obj-$(CONFIG_$(PHASE_)BOOTSTD_PROG) += prog_boot.o +obj-$(CONFIG_$(PHASE_)BOOTMETH_PXE_COMMON) += bootmeth_pxe_common.o obj-$(CONFIG_$(PHASE_)BOOTMETH_EXTLINUX) += bootmeth_extlinux.o obj-$(CONFIG_$(PHASE_)BOOTMETH_EXTLINUX_PXE) += bootmeth_pxe.o obj-$(CONFIG_$(PHASE_)BOOTMETH_EFILOADER) += bootmeth_efi.o
boot/bootmeth_extlinux.c +0 -20
@@ -68,26 +68,6 @@ static int extlinux_get_state_desc(struct udevice *dev, char *buf, int maxsize)return 0 ; } -static int extlinux_getfile (struct pxe_context *ctx,const char *file_path, -char *file_addr,enum bootflow_img_t type, -ulong *sizep) -{ -struct extlinux_info *info = ctx->userdata; -ulong addr; -int ret; - - addr =simple_strtoul (file_addr,NULL ,16 ); - -/* Allow up to 1GB */ - *sizep =1 <<30 ; - ret =bootmeth_read_file (info->dev, info->bflow, file_path, addr, - type, sizep); -if (ret) -return log_msg_ret ("read" , ret); - -return 0 ; -} -static int extlinux_check (struct udevice *dev,struct bootflow_iter *iter) {int ret;
boot/bootmeth_pxe.c +1 -21
@@ -23,26 +23,6 @@#include <net.h> #include <pxe_utils.h> -static int extlinux_pxe_getfile (struct pxe_context *ctx,const char *file_path, -char *file_addr,enum bootflow_img_t type, -ulong *sizep) -{ -struct extlinux_info *info = ctx->userdata; -ulong addr; -int ret; - - addr =simple_strtoul (file_addr,NULL ,16 ); - -/* Allow up to 1GB */ - *sizep =1 <<30 ; - ret =bootmeth_read_file (info->dev, info->bflow, file_path, addr, - type, sizep); -if (ret) -return log_msg_ret ("read" , ret); - -return 0 ; -} -static int extlinux_pxe_check (struct udevice *dev,struct bootflow_iter *iter) {int ret;
@@ -158,7 +138,7 @@ static int extlinux_pxe_boot(struct udevice *dev, struct bootflow *bflow) info.dev = dev; info.bflow = bflow; info.cmdtp = &cmdtp; - ret =pxe_setup_ctx (ctx, &cmdtp, extlinux_pxe_getfile, &info, false, + ret =pxe_setup_ctx (ctx, &cmdtp, extlinux_getfile, &info, false, bflow->subdir, false, false);if (ret)return log_msg_ret ("ctx" , -EINVAL );
boot/bootmeth_pxe_common.c new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Helpers shared by the bootmeths that boot via the pxelinux parser +* +* Copyright 2021 Google LLC +* Written by Simon Glass <[email protected]> +*/ + +#define LOG_CATEGORY UCLASS_BOOTSTD + +#include <bootflow.h> +#include <bootmeth.h> +#include <extlinux.h> +#include <pxe_utils.h> +#include <vsprintf.h> + +int extlinux_getfile (struct pxe_context *ctx,const char *file_path, +char *file_addr,enum bootflow_img_t type,ulong *sizep) +{ +struct extlinux_info *info = ctx->userdata; +ulong addr; +int ret; + + addr =simple_strtoul (file_addr,NULL ,16 ); + +/* Allow up to 1GB */ + *sizep =1 <<30 ; + ret =bootmeth_read_file (info->dev, info->bflow, file_path, addr, + type, sizep); +if (ret) +return log_msg_ret ("read" , ret); + +return 0 ; +}
include/extlinux.h +23 -0
@@ -7,6 +7,11 @@#ifndef __extlinux_h#define __extlinux_h +#include <bootflow.h> +#include <linux/types.h> + +struct pxe_context ; +#define EXTLINUX_FNAME "extlinux/extlinux.conf"/**
@@ -14,6 +19,7 @@* * @dev: bootmethod device being used to boot * @bflow: bootflow being booted +* @cmdtp: command table entry to run the boot command with, or NULL */ struct extlinux_info {struct udevice *dev;
@@ -21,4 +27,21 @@ struct extlinux_info { struct cmd_tbl *cmdtp; }; +/** +* extlinux_getfile() - Read a file named by a pxelinux-style config +* +* This is the pxe_getfile_func used by every bootmeth that hands its files +* to the pxelinux parser. It reads the file through the bootmeth uclass, so +* @ctx->userdata must point at a struct extlinux_info. +* +* @ctx: PXE context +* @file_path: Path of the file to read +* @file_addr: Address to load the file to, as a hex string +* @type: Image type used to record the loaded file in the bootflow +* @sizep: Returns the file size in bytes +* Return: 0 if OK, -ve on error +*/ +int extlinux_getfile (struct pxe_context *ctx,const char *file_path, +char *file_addr,enum bootflow_img_t type,ulong *sizep); +#endif
Signature · 1 line
2.54.0
PATCH v2 9/13 boot: add a minimal bootmeth for the Boot Loader Specification
In reply to Alexey CharkovAdd a bootmeth that finds and boots Boot Loader Specification (BLS) type #1 entry files [1]. On each block-device partition it scans, the bootmeth looks for files matching '<prefix>loader/entries/*.conf' (where <prefix> comes from bootstd_get_prefixes(), typically '/' and '/boot/'), picks the highest-sorting filename, parses it, and exposes it as a bootflow.
Implementation reuses the existing pxelinux infrastructure.
For now the entry chosen on a partition is purely the lexicographic maximum of *.conf filenames; sort-key / version field handling (spec-mandated tiebreakers) and boot-counting (the '+TRIES_LEFT' filename suffix) are left as TODOs. Likewise, only the top-sorted entry is surfaced because the bootstd framework currently allows one bootflow per (bootmeth, partition); exposing every discovered entry will require a framework extension.
The driver takes no number prefix, unlike bootmeth_1extlinux and bootmeth_2script which carry one to pin the ordering the old distro boot scripts had. BLS has no such legacy to preserve, so leave the choice to boards via 'bootmeths' or the devicetree.
Type #2 BLS (drop-in directory of EFI binaries) is out of scope here; existing EFI bootmeths cover that use case.
--- boot/Kconfig | 16 +++ boot/Makefile | 1 + boot/bootmeth_bls.c | 370 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 387 insertions(+)
boot/Kconfig +16 -0
@@ -659,6 +659,22 @@ config BOOTMETH_EXTLINUX_PXE This provides a way to try out standard boot on an existing boot flow. +config BOOTMETH_BLS + bool "Bootdev support for Boot Loader Specification entries" + select PXE_UTILS + help + Enables support for booting via Boot Loader Specification type #1 + entry files. The bootmeth scans each filesystem it finds for files + matching 'loader/entries/*.conf' (or '/boot/loader/entries/*.conf') + and boots the highest-sorting entry. + + The specification is here: + + https://uapi-group.org/specifications/specs/boot_loader_specification/ + + Type #2 BLS (drop-in directory of EFI binaries) is not handled here; + use BOOTMETH_EFI_BOOTMGR for that. + config BOOTMETH_EFILOADER bool "Bootdev support for EFI boot" depends on EFI_BINARY_EXEC
boot/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_$(PHASE_)BOOTSTD_PROG) += prog_boot.o obj-$(CONFIG_$(PHASE_)BOOTMETH_PXE_COMMON) += bootmeth_pxe_common.o obj-$(CONFIG_$(PHASE_)BOOTMETH_EXTLINUX) += bootmeth_extlinux.o obj-$(CONFIG_$(PHASE_)BOOTMETH_EXTLINUX_PXE) += bootmeth_pxe.o +obj-$(CONFIG_$(PHASE_)BOOTMETH_BLS) += bootmeth_bls.o obj-$(CONFIG_$(PHASE_)BOOTMETH_EFILOADER) += bootmeth_efi.o obj-$(CONFIG_$(PHASE_)BOOTMETH_CROS) += bootm.o bootm_os.o bootmeth_cros.o obj-$(CONFIG_$(PHASE_)BOOTMETH_QFW) += bootmeth_qfw.o
boot/bootmeth_bls.c new file +370 -0
370 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v2 10/13 test: bootstd: add a BLS entry to the Fedora fixture image
In reply to Alexey CharkovWrite a BLS type 1 loader entry alongside the extlinux.conf already on the Fedora test image, pointing at the same kernel, initrd and devicetree.
The entry is inert until the bootmeth is bound, so no test expectations change here.
--- test/py/tests/test_ut.py | 58 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 18 deletions(-)
test/py/tests/test_ut.py +40 -18
@@ -159,10 +159,13 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r} fsh.cleanup() -def setup_extlinux_image(ubman, devnum, basename, vmlinux, initrd, dtbdir, - script): +def setup_extlinux_bls_image(ubman, devnum, basename, vmlinux, initrd, dtbdir): """Create a 20MB disk image with a single FAT partition + The image carries both an extlinux/extlinux.conf and an equivalent BLS + type 1 entry under loader/entries/, so that the two bootmeths can be + exercised against the same kernel, initrd and devicetree. + Args: ubman (ConsoleBase): Console to use devnum (int): Device number to use, e.g. 1
@@ -170,7 +173,6 @@ def setup_extlinux_image(ubman, devnum, basename, vmlinux, initrd, dtbdir, vmlinux (str): Kernel filename initrd (str): Ramdisk filename dtbdir (str or None): Devicetree filename - script (str): Script to place in the extlinux.conf file """ fsh = FsHelper(ubman.config, 'vfat', 18, prefix=basename) fsh.setup()
@@ -178,10 +180,44 @@ def setup_extlinux_image(ubman, devnum, basename, vmlinux, initrd, dtbdir, ext = os.path.join(fsh.srcdir, 'extlinux') mkdir_cond(ext) + script = '''# extlinux.conf generated by appliance-creator +ui menu.c32 +menu autoboot Welcome to Fedora-Workstation-armhfp-31-1.9. Automatic boot in # second{,s}. Press a key for options. +menu title Fedora-Workstation-armhfp-31-1.9 Boot Options. +menu hidden +timeout 20 +totaltimeout 600 + +label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) + kernel /%s + append ro root=UUID=9732b35b-4cd5-458b-9b91-80f7047e0b8a rhgb quiet LANG=en_US.UTF-8 cma=192MB cma=256MB + fdtdir /%s/ + initrd /%s''' % (vmlinux, dtbdir, initrd) + conf = os.path.join(ext, 'extlinux.conf') with open(conf, 'w', encoding='ascii') as fd: print(script, file=fd) + bls = os.path.join(fsh.srcdir, 'loader') + mkdir_cond(bls) + bls = os.path.join(bls, 'entries') + mkdir_cond(bls) + + script = '''# BLS type 1 loader entry generated by appliance-creator +title Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) +version 5.3.7-301.fc31.armv7hl +machine-id 4098b3f648d74c13b1f04ccfba7798e8 +sort-key fedora +architecture arm +linux /%s +options ro root=UUID=9732b35b-4cd5-458b-9b91-80f7047e0b8a rhgb quiet LANG=en_US.UTF-8 cma=192MB cma=256MB +devicetree /%s/sandbox.dtb +initrd /%s''' % (vmlinux, dtbdir, initrd) + + conf = os.path.join(bls, '4098b3f648d74c13b1f04ccfba7798e8-5.3.7-301.fc31.armv7hl.conf') + with open(conf, 'w', encoding='ascii') as fd: + print(script, file=fd) + inf = os.path.join(ubman.config.persistent_data_dir, 'inf') with open(inf, 'wb') as fd: fd.write(gzip.compress(b'vmlinux'))
@@ -223,21 +259,7 @@ def setup_fedora_image(ubman, devnum, basename): vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl' initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img' dtbdir = 'dtb-5.3.7-301.fc31.armv7hl' - script = '''# extlinux.conf generated by appliance-creator -ui menu.c32 -menu autoboot Welcome to Fedora-Workstation-armhfp-31-1.9. Automatic boot in # second{,s}. Press a key for options. -menu title Fedora-Workstation-armhfp-31-1.9 Boot Options. -menu hidden -timeout 20 -totaltimeout 600 - -label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) - kernel /%s - append ro root=UUID=9732b35b-4cd5-458b-9b91-80f7047e0b8a rhgb quiet LANG=en_US.UTF-8 cma=192MB cma=256MB - fdtdir /%s/ - initrd /%s''' % (vmlinux, dtbdir, initrd) - setup_extlinux_image(ubman, devnum, basename, vmlinux, initrd, dtbdir, - script) + setup_extlinux_bls_image(ubman, devnum, basename, vmlinux, initrd, dtbdir) def setup_cros_image(ubman): """Create a 20MB disk image with ChromiumOS partitions"""
Signature · 1 line
2.54.0
PATCH v2 11/13 sandbox: enable BLS boot method
In reply to Alexey CharkovEnable the Boot Loader Specification (BLS) boot method in the sandbox and its test DTS to enable runtime testing of the BLS type #1 boot entries.
Binding a third bootmeth changes the exact bootmeth and bootflow listings that the bootstd tests match against, so update those expectations. Make them conditional on CONFIG_BOOTMETH_BLS rather than absolute, so the tests keep describing the world correctly when the bootmeth is configured out.
--- arch/sandbox/dts/test.dts | 4 + configs/sandbox_defconfig | 1 + test/boot/bootdev.c | 14 ++ test/boot/bootflow.c | 377 +++++++++++++++++++++++++++++++++++----------- test/boot/bootmeth.c | 38 +++-- 5 files changed, 332 insertions(+), 102 deletions(-)
arch/sandbox/dts/test.dts +4 -0
@@ -130,6 +130,10 @@ compatible = "u-boot,distro-efi"; }; + bls { + compatible = "u-boot,bls"; + }; + theme { font-size = <30>; menu-inset = <3>;
configs/sandbox_defconfig +1 -0
@@ -26,6 +26,7 @@ CONFIG_FIT_CIPHER=y CONFIG_FIT_VERITY=y CONFIG_FIT_VERBOSE=y CONFIG_BOOTMETH_ANDROID=y +CONFIG_BOOTMETH_BLS=y CONFIG_BOOTMETH_RAUC=y CONFIG_UPL=y CONFIG_LEGACY_IMAGE_FORMAT=y
test/boot/bootdev.c +14 -0
@@ -221,6 +221,8 @@ static int bootdev_test_order(struct unit_test_state *uts)/* Use the environment variable to override it */ ut_assertok (env_set ("boot_targets" ,"mmc1 mmc2 usb" ));ut_assertok (bootflow_scan_first (NULL ,NULL , &iter,0 , &bflow)); +if (IS_ENABLED (CONFIG_BOOTMETH_BLS )) +ut_asserteq (0 ,bootflow_scan_next (&iter, &bflow));/* get the usb device which has a backing file (flash1.img) */ ut_asserteq (0 ,bootflow_scan_next (&iter, &bflow));
@@ -237,6 +239,8 @@ static int bootdev_test_order(struct unit_test_state *uts)ut_assertok (env_set ("boot_targets" ,NULL ));ut_assertok (bootflow_scan_first (NULL ,"mmc" , &iter,0 , &bflow));ut_asserteq (2 , iter.num_devs); +if (IS_ENABLED (CONFIG_BOOTMETH_BLS )) +ut_asserteq (0 ,bootflow_scan_next (&iter, &bflow));/* Now scan past mmc1 and make sure that only mmc0 shows up */ ut_asserteq (-ENODEV ,bootflow_scan_next (&iter, &bflow));
@@ -250,6 +254,8 @@ static int bootdev_test_order(struct unit_test_state *uts)ut_assertok (env_set ("boot_targets" ,"mmc" ));ut_assertok (bootflow_scan_first (NULL ,NULL , &iter,0 , &bflow));ut_asserteq (2 , iter.num_devs); +if (IS_ENABLED (CONFIG_BOOTMETH_BLS )) +ut_asserteq (0 ,bootflow_scan_next (&iter, &bflow));/* Now scan past mmc1 and make sure that only mmc0 shows up */ ut_asserteq (-ENODEV ,bootflow_scan_next (&iter, &bflow));
@@ -263,6 +269,8 @@ static int bootdev_test_order(struct unit_test_state *uts)ut_assertok (env_set ("boot_targets" ,"mmc usb" ));ut_assertok (bootflow_scan_first (NULL ,NULL , &iter,0 , &bflow));ut_asserteq (2 , iter.num_devs); +if (IS_ENABLED (CONFIG_BOOTMETH_BLS )) +ut_asserteq (0 ,bootflow_scan_next (&iter, &bflow));/* * Now scan past mmc1 and make sure that the 3 USB devices show up. The
@@ -299,6 +307,8 @@ static int bootdev_test_order_default(struct unit_test_state *uts)ut_asserteq (2 , iter.num_devs);ut_asserteq_str ("mmc2.bootdev" , iter.dev_used[0 ]->name);ut_asserteq_str ("mmc1.bootdev" , iter.dev_used[1 ]->name); +if (IS_ENABLED (CONFIG_BOOTMETH_BLS )) +ut_asserteq (0 ,bootflow_scan_next (&iter, &bflow));ut_asserteq (-ENODEV ,bootflow_scan_next (&iter, &bflow));ut_asserteq (3 , iter.num_devs);
@@ -333,6 +343,8 @@ static int bootdev_test_prio(struct unit_test_state *uts)/* get the usb device which has a backing file (flash1.img) */ ut_asserteq (0 ,bootflow_scan_next (&iter, &bflow)); +if (IS_ENABLED (CONFIG_BOOTMETH_BLS )) +ut_asserteq (0 ,bootflow_scan_next (&iter, &bflow));ut_asserteq (-ENODEV ,bootflow_scan_next (&iter, &bflow));ut_asserteq (6 , iter.num_devs);
@@ -354,6 +366,8 @@ static int bootdev_test_prio(struct unit_test_state *uts)/* get the usb device which has a backing file (flash1.img) */ ut_asserteq (0 ,bootflow_scan_next (&iter, &bflow)); +if (IS_ENABLED (CONFIG_BOOTMETH_BLS )) +ut_asserteq (0 ,bootflow_scan_next (&iter, &bflow));ut_asserteq (-ENODEV ,bootflow_scan_next (&iter, &bflow));ut_asserteq (7 , iter.num_devs);
test/boot/bootflow.c +287 -90
680 lines not on this page · raw message
test/boot/bootmeth.c +26 -12
@@ -21,11 +21,15 @@ static int bootmeth_cmd_list(struct unit_test_state *uts)ut_assert_nextlinen ("---" );ut_assert_nextline (" 0 0 extlinux Extlinux boot from a block device" );ut_assert_nextline (" 1 1 efi EFI boot from an .efi file" ); +if (IS_ENABLED (CONFIG_BOOTMETH_BLS )) +ut_assert_nextline (" 2 2 bls Boot Loader Specification" );if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL )) -ut_assert_nextline (" glob 2 firmware0 VBE simple" ); +ut_assert_nextline (" glob %d firmware0 VBE simple" , +2 +IS_ENABLED (CONFIG_BOOTMETH_BLS ));ut_assert_nextlinen ("---" ); -ut_assert_nextline (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) ? -"(3 bootmeths)" :"(2 bootmeths)" ); +ut_assert_nextline ("(%d bootmeths)" , +2 +IS_ENABLED (CONFIG_BOOTMETH_BLS ) + +IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ));ut_assert_console_end ();return 0 ;
@@ -56,11 +60,15 @@ static int bootmeth_cmd_order(struct unit_test_state *uts)ut_assert_nextlinen ("---" );ut_assert_nextline (" 0 0 extlinux Extlinux boot from a block device" );ut_assert_nextline (" - 1 efi EFI boot from an .efi file" ); +if (IS_ENABLED (CONFIG_BOOTMETH_BLS )) +ut_assert_nextline (" - 2 bls Boot Loader Specification" );if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL )) -ut_assert_nextline (" glob 2 firmware0 VBE simple" ); +ut_assert_nextline (" glob %d firmware0 VBE simple" , +2 +IS_ENABLED (CONFIG_BOOTMETH_BLS ));ut_assert_nextlinen ("---" ); -ut_assert_nextline (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) ? -"(3 bootmeths)" :"(2 bootmeths)" ); +ut_assert_nextline ("(%d bootmeths)" , +2 +IS_ENABLED (CONFIG_BOOTMETH_BLS ) + +IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ));ut_assert_console_end ();/* Check the -a flag with the reverse order */
@@ -71,11 +79,15 @@ static int bootmeth_cmd_order(struct unit_test_state *uts)ut_assert_nextlinen ("---" );ut_assert_nextline (" 1 0 extlinux Extlinux boot from a block device" );ut_assert_nextline (" 0 1 efi EFI boot from an .efi file" ); +if (IS_ENABLED (CONFIG_BOOTMETH_BLS )) +ut_assert_nextline (" - 2 bls Boot Loader Specification" );if (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL )) -ut_assert_nextline (" glob 2 firmware0 VBE simple" ); +ut_assert_nextline (" glob %d firmware0 VBE simple" , +2 +IS_ENABLED (CONFIG_BOOTMETH_BLS ));ut_assert_nextlinen ("---" ); -ut_assert_nextline (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) ? -"(3 bootmeths)" :"(2 bootmeths)" ); +ut_assert_nextline ("(%d bootmeths)" , +2 +IS_ENABLED (CONFIG_BOOTMETH_BLS ) + +IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ));ut_assert_console_end ();/* Now reset the order to empty, which should show all of them again */
@@ -83,8 +95,9 @@ static int bootmeth_cmd_order(struct unit_test_state *uts)ut_assert_console_end ();ut_assertnull (env_get ("bootmeths" ));ut_assertok (run_command ("bootmeth list" ,0 )); -ut_assert_skip_to_line (IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ) ? -"(3 bootmeths)" :"(2 bootmeths)" ); +ut_assert_skip_to_line ("(%d bootmeths)" , +2 +IS_ENABLED (CONFIG_BOOTMETH_BLS ) + +IS_ENABLED (CONFIG_BOOTMETH_GLOBAL ));/* Try reverse order */ ut_assertok (run_command ("bootmeth order \"efi extlinux\"" ,0 ));
@@ -116,7 +129,8 @@ static int bootmeth_cmd_order_glob(struct unit_test_state *uts)ut_assert_nextline ("Order Seq Name Description" );ut_assert_nextlinen ("---" );ut_assert_nextline (" 0 1 efi EFI boot from an .efi file" ); -ut_assert_nextline (" glob 2 firmware0 VBE simple" ); +ut_assert_nextline (" glob %d firmware0 VBE simple" , +2 +IS_ENABLED (CONFIG_BOOTMETH_BLS ));ut_assert_nextlinen ("---" );ut_assert_nextline ("(2 bootmeths)" );ut_assertnonnull (env_get ("bootmeths" ));
Signature · 1 line
2.54.0
PATCH v2 12/13 test: bootstd: cover BLS entries below a prefix
In reply to Alexey CharkovThe Fedora image places its BLS entry at the root of the filesystem, so the second entry in the bootstd prefix list is never what finds it. Add an image for the other layout, where $BOOT is a '/boot/' directory on a larger filesystem and only the '/boot/' prefix turns the entry up.
Its paths still name the kernel, initrd and devicetree relative to the partition root, matching what systemd's 90-loaderentry.install writes when $BOOT is not a mount point of its own, and booting it checks they are used as written rather than rebased onto the prefix. The rescan before booting covers freeing a bootflow that is still selected, which is the path a retained bootmeth_priv would double-free.
--- arch/sandbox/dts/test.dts | 8 +++++ test/boot/bootflow.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++ test/py/tests/test_ut.py | 66 +++++++++++++++++++++++++++++++++- 3 files changed, 163 insertions(+), 1 deletion(-)
arch/sandbox/dts/test.dts +8 -0
@@ -49,6 +49,7 @@ mmc8 = "/mmc8"; mmc9 = "/mmc9"; mmc10 = "/mmc10"; + mmc11 = "/mmc11"; pci0 = &pci0; pci1 = &pci1; pci2 = &pci2;
@@ -1372,6 +1373,13 @@ filename = "mmc10.img"; }; + /* This is used for BLS boot tests */ + mmc11 { + status = "disabled"; + compatible = "sandbox,mmc"; + filename = "mmc11.img"; + }; + pch { compatible = "sandbox,pch"; };
test/boot/bootflow.c +90 -0
96 lines not on this page · raw message
test/py/tests/test_ut.py +65 -1
84 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v2 13/13 doc: bootstd: describe the BLS bootmeth
In reply to Alexey CharkovEvery other bootmeth has a page under doc/develop/bootstd/; add one for BLS and list it in the index and in the overview's table of drivers.
Besides what the bootmeth does, record the two things a reader is most likely to trip over: how paths inside an entry are resolved when $BOOT is a directory rather than a partition, and which parts of the spec's entry ordering and boot counting are not implemented yet.
--- doc/develop/bootstd/bls.rst | 56 ++++++++++++++++++++++++++++++++++++++++ doc/develop/bootstd/index.rst | 1 + doc/develop/bootstd/overview.rst | 1 + 3 files changed, 58 insertions(+)
doc/develop/bootstd/bls.rst new file +56 -0
@@ -0,0 +1,56 @@ +.. SPDX-License-Identifier: GPL-2.0+: + +BLS Bootmeth +============ + +The `Boot Loader Specification +<https://uapi-group.org/specifications/specs/boot_loader_specification>`_ (BLS) +describes a drop-in directory of boot entries, so that a distribution can add +and remove kernels without rewriting a central configuration file. Type #1 +entries are plain text files, one per bootable kernel; this bootmeth implements +those. Type #2 entries are EFI binaries and are out of scope here, since the +EFI bootmeth already covers them. + +Entries live in ``<prefix>loader/entries/*.conf``, where ``<prefix>`` comes from +the bootstd list of prefixes (``{"/", "/boot/"}`` by default, settable with the +`filename-prefixes` property on the bootstd device). systemd's +``kernel-install`` writes them in this layout when ``loader=bls``. + +The format is close enough to `extlinux.conf` that U-Boot reuses the same +parser. Two extra keywords are recognised for it: ``title`` (the human-readable +entry name, equivalent to extlinux's ``menu label``) and ``options`` (the kernel +command line, equivalent to ``append``). Some spec-envisaged keys such as +``version``, ``machine-id``, ``sort-key`` and ``architecture`` are not yet +implemented and are skipped. + +Paths inside an entry are used as written: the spec has them "always relative +to the root directory of the partition they are referenced from", which is +what the bootmeth sees whichever prefix the entry itself was found under. +systemd's ``90-loaderentry.install`` agrees, since it strips the mount point +from the entry directory and so keeps the ``/boot`` component when $BOOT is +not a mount point of its own. + +Entry selection +--------------- + +Only the highest-sorting entry on a partition is returned, because the bootstd +framework currently allows one bootflow per (bootmeth, partition) pair. + +Ordering is by filename alone, which suits the common case of distros encoding +the kernel version into the filename. The spec envisages more than this, none +of which is implemented yet: + +* entries should be ordered by ``sort-key`` first and ``version`` second, + falling back to the filename only when those tie; + +* an entry may carry a boot counter as a ``+TRIES_LEFT[-TRIES_DONE]`` suffix on + its filename, to be decremented on each attempt and skipped once it reaches + zero. For now that suffix is left intact in the entry name and otherwise + ignored. + +When the bootflow is booted, the bootmeth re-parses the entry it read during +the scan and hands the resulting label to ``label_boot()``, the same code path +extlinux uses. + +The compatible string "u-boot,bls" is used for the driver. It is present if +``CONFIG_BOOTMETH_BLS`` is enabled.
doc/develop/bootstd/index.rst +1 -0
@@ -9,6 +9,7 @@ Standard Boot overview extlinux pxelinux + bls qfw android cros
doc/develop/bootstd/overview.rst +1 -0
@@ -445,6 +445,7 @@ Available bootmeth drivers Bootmeth drivers are provided for booting from various media: - :doc:`Android <android>` bootflow (boot image v4) + - :doc:`BLS <bls>`: Boot Loader Specification type #1 entries from a disk - :doc:`ChromiumOS <cros>` ChromiumOS boot from a disk - EFI boot using bootefi from disk - EFI boot using boot manager
Signature · 1 line
2.54.0
Quoted 10 lines · Alexey Charkov
Add support for the Boot Loader Specification (BLS) type 1 boot entries, as generated by default by systemd's kernel-install when loader=bls.
Given that the format of BLS entries is pretty much the same as PXElinux, reuse the existing library for the parsing logic.
BLS type 2 entries are out of scope, as they are effectively just EFI applications and should be booted as such.
[...]
Applied to u-boot/next, thanks!
[01/13] pxe_utils: fix W=1 kernel-doc warnings
commit: 42f268c89f8d5a23a0e0748693ab0cfe0e9a18f4
[02/13] pxe_utils: accept "options" as synonym for "append"
commit: 7c38bac6abf4e1b2fc3ad05e067c0090288958ab
[03/13] pxe_utils: harden the "append" parser against malformed input
commit: 5f80d8614ca2a6c71476864aee5647e66fa462e6
[04/13] pxe_utils: extract per-entry key parsing into parse_label_keys()
commit: bb7b839e71470dbfc4219e99e8fd493c4f73a6ad
[05/13] pxe_utils: export per-entry label helpers
commit: eb38123ead89f38f85e68bdefa5f5aa2bc925bfd
[06/13] pxe_utils: optionally ignore unknown keys in parse_label_keys()
commit: 98fdc9b502330eaeb60964bbf5c18024b2147b87
[07/13] pxe_utils: accept "title" inside a label as a synonym for "menu label"
commit: df3f0a81e91ed6775232291592fac232b939a75f
[08/13] bootmeth: share the pxelinux getfile helper
commit: bb3beb6c802a0d0a57bc586a9e9f14c780467820
[09/13] boot: add a minimal bootmeth for the Boot Loader Specification
commit: 17756b69064c4ccfa254becd7e52148e7d583bab
[10/13] test: bootstd: add a BLS entry to the Fedora fixture image
commit: b8b69a660231eefdbd79e04fb6940e2d13b58797
[11/13] sandbox: enable BLS boot method
commit: f1ca59e930171e6bd28ffa7e48fc29c0344c1a00
[12/13] test: bootstd: cover BLS entries below a prefix
commit: 8aa74cad35f8964287d572f77a16ba1603b143e5
[13/13] doc: bootstd: describe the BLS bootmeth
commit: 4d2d6d080620a2e5114991b8de3386ecbee0a5a3Signature · 1 line
Tom