state: generic devicetree-overlay based state node injection
Subsystems (2)
v3 cover state: generic devicetree-overlay based state node injection
From: Chali Anis <[email protected]>
Boards that want a "barebox,state" node today have exactly one option:
carry it in their own, statically compiled-in devicetree source. That's fine as long as barebox is built per-board with a maintained dts, but it is a harder fit for targets that don't have one to begin with: the EFI payload, deliberately meant to run unmodified across arbitrary x86/arm64 EFI platforms barebox itself knows nothing about at build time, and the generic BOARD_ARM_GENERIC_DT ("barebox-dt-2nd") image, which picks up whatever devicetree a first-stage bootloader or QEMU hands it in r2 at runtime the same way a Kernel would, rather than being built against a particular board's dts. Either way there is no single "board dts" being compiled for a state node to live in.
CONFIG_EXTERNAL_DTS_FRAGMENTS already covers a related need rather well:
an external build system can append dts fragment files to a board's dts source at build time, scoped to specific boards via a per-dts preprocessor macro. That remains the more direct choice whenever a board's own dts is actually part of the build, and this series doesn't propose changing that. It runs into the same limit as static dts inclusion for the EFI payload and barebox-dt-2nd cases specifically, though, since it operates at dts-source/build time on a particular "main dts" - which neither target, by design, has one of.
This series instead proposes a devicetree *overlay* (.dtso, applied at runtime via CONFIG_STATE_OVERLAY) for that gap. Applied to whichever devicetree barebox already ends up live with by boot time - statically compiled in, EFI-firmware-derived, passed in from a first-stage bootloader, or the EFI payload's own minimal stub root - it only ever adds one small node, so it doesn't need a "main dts" to attach to at build time, and it doesn't need to know a board's memory map or other devicetree content beyond one stable label (or, for EFI, just a partition UUID, patch 1) to hook its backend into. In turn, that also means it never competes with an existing devicetree for ownership, which the one realistic alternative we considered - loading a full, standalone state.dtb at runtime - does run into: barebox_register_of() only accepts a new root if none is registered yet or the incoming tree is empty, so a real state.dtb collides with whatever root the EFI payload already registered at boot and is rejected with -EBUSY, and a rejected tree's /aliases entries never reach the global alias cache of_alias_get() relies on either.
Happy to discuss trade-offs here, in particular whether it's worth teaching CONFIG_EXTERNAL_DTS_FRAGMENTS (or a variant of it) to handle the no-base-dts case instead of adding a separate mechanism - this series is meant as a concrete starting point for that conversation, not a claim that overlays are the only reasonable answer.
Patch 1 makes of_state_fixup() able to resolve a partuuid-referenced, non-hardware-backed backend node, and exports it so it can be called directly. Patch 2 adds CONFIG_STATE_OVERLAY itself, compiling an external .dtso into the barebox binary and applying it to the live devicetree at postcore_initcall time - guarding against there being no live devicetree yet, and refreshing the alias cache once applied. Patch 3 builds on both to publish the resolved state description as a UEFI variable once such a node exists. Patch 4 makes both of those actually reachable on x86: no code path there ever registered a live devicetree root pre-boot to begin with, since that registration only existed for the EFI_STUB entry point barebox uses on other architectures, not the EFI_PAYLOAD one x86 uses.
Changes since v1:
- patch 1: fixed the compatible string on the synthesized fixed-partitions node ("fixed-partitions", not the barebox-internal "barebox,fixed-partitions" alias, which external consumers don't recognize), fixed a phandle collision where the synthesized node kept the phandle it had in barebox's own live devicetree instead of one scoped to the target tree, and resolved non-partuuid backends via the reproducible name cached at probe time again instead of recomputing it against whatever tree is being fixed up.
- patch 2: state_overlay_apply() now guards against there being no live devicetree yet and skips cleanly instead of calling into the overlay code with a NULL root, and calls of_alias_scan() afterward so the overlay's /aliases entry becomes visible the same way a live overlay applied via the interactive of_overlay command already does. Also selects CONFIG_OFDEVICE, needed for a live devicetree root to exist at all on some targets.
- patch 3: publish "BareboxState" under efi_barebox_vendor_guid instead of efi_systemd_vendor_guid - it's a barebox-defined variable, not part of the systemd-boot loader protocol. state_to_efivars_export() and efi_late_init() are both late_efi_initcall, and within one initcall level execution follows definition order in the object file, so state_to_efivars_export() is now defined after efi_late_init():
on boards with no state node in their own static devicetree, efi_late_init() is what loads and registers the standalone state.dtb, and only once that has had a chance to run does state_by_alias() (used here instead of open-coding the equivalent of_find_node_by_alias() + state_by_node()) have anything to find.
- patch 4 is new: without it, CONFIG_STATE_OVERLAY silently never had a devicetree to apply to on x86, and this series' EFI-payload rationale didn't hold up for that architecture in practice.
- cover letter: called out BOARD_ARM_GENERIC_DT ("barebox-dt-2nd") as a second target that benefits from this alongside the EFI payload, since it's in the same "no main dts at build time" situation.
Tested on a Raspberry Pi CM4 natively, and as the EFI payload on a Jetson Orin NX and under QEMU (x86, with a partuuid-referenced backend).
Chali Anis (4):
state: make of_state_fixup() usable outside common/state/
state: add CONFIG_STATE_OVERLAY to inject a state node via devicetree
overlay
efi: payload: export resolved state as a BareboxState UEFI variable
efi: payload: make CONFIG_STATE_OVERLAY (and BareboxState export) work
on x86
.../bindings/barebox/barebox,state.rst | 9 +++ Documentation/user/state.rst | 32 +++++++++ common/Kconfig | 41 +++++++++++ common/state/Makefile | 20 ++++++ common/state/state.c | 72 +++++++++++++++---- common/state/state_overlay.c | 29 ++++++++ efi/payload/Makefile | 1 + efi/payload/init.c | 69 +++++++++++++++++- include/state.h | 5 ++ 9 files changed, 263 insertions(+), 15 deletions(-) create mode 100644 common/state/state_overlay.c
PATCH v3 1/4 state: make of_state_fixup() usable outside common/state/
From: Chali Anis <[email protected]>
of_state_fixup() was static, callable only via of_register_fixup(). Export it so other subsystems can invoke it directly to render a state instance's devicetree representation on demand, without going through the global fixup-registration/of_fix_tree() machinery.
While exporting it, teach it to resolve backend nodes that are top-level "barebox,fixed-partitions" subnodes carrying a partuuid property instead of being tied to a real, already-probed storage device node in the tree - the same globally-resolvable-by-UUID binding drivers/of/of_path.c's of_cdev_find() already supports for EFI, where devices aren't instantiated from devicetree. Without this, of_state_fixup() could only find a backend reachable by walking real hardware nodes already present in root, which such a partuuid-only declaration never is.
--- common/state/state.c | 72 ++++++++++++++++++++++++++++++++++++-------- include/state.h | 5 +++ 2 files changed, 64 insertions(+), 13 deletions(-)
common/state/state.c +59 -13
@@ -433,14 +433,69 @@ int state_from_node(struct state *state, struct device_node *node, bool create)return ret; } -static int of_state_fixup (struct device_node *root,void *ctx) +static int state_get_backend (struct state *state,struct device_node *root,struct device_node *n) +{ +struct device_node *backend_node, *part, *state_root, *np; +const char *compatible ="fixed-partitions" ; +struct property *prop; +phandle phandle; +int ret; + + state_root =of_find_node_by_path (state->of_path); +if (!state_root) +return -ENODEV ; + + backend_node =of_parse_phandle (state_root,"backend" ,0 ); +if (!backend_node) +return -ENODEV ; + +if (of_node_is_fixed_partitions (of_get_parent (backend_node)) && +of_property_present (backend_node,"partuuid" )) { + part =of_create_node (root,"/partitions" ); +if (!part) +return -ENOMEM ; + + prop =of_new_property (part,"compatible" , compatible, +strlen (compatible) +1 ); +if (!prop) +return -ENOMEM ; + + np =of_copy_node (part, backend_node); +if (!np) +return -ENOMEM ; + +/* +* of_copy_node() carries over backend_node's phandle as-is, +* but that phandle was allocated in barebox's own live +* devicetree, a namespace independent of @root's. Assign a +* fresh one scoped to @root instead, so it can't collide +* with an unrelated node already using that value there. +*/ + phandle =of_get_tree_max_phandle (root) +1 ; + np->phandle = phandle; + ret =of_property_write_u32 (np,"phandle" , phandle); +if (ret) +return ret; + +return of_property_write_u32 (n,"backend" , phandle); + } + + backend_node =of_find_node_by_reproducible_name (root, state->backend_reproducible_name); +if (!backend_node) +return -ENODEV ; + + phandle =of_node_create_phandle (backend_node); + +return of_property_write_u32 (n,"backend" , phandle); +} + +int of_state_fixup (struct device_node *root,void *ctx) {struct state *state = ctx;const char *compatible ="barebox,state" ; -struct device_node *new_node, *node, *parent, *backend_node, *aliases; +struct device_node *new_node, *node, *parent, *aliases;struct property *p;int ret; -phandle phandle; node =of_find_node_by_path_from (root, state->of_path);if (node) {
@@ -498,16 +553,7 @@ static int of_state_fixup(struct device_node *root, void *ctx) goto out; } -/* backend phandle */ - backend_node =of_find_node_by_reproducible_name (root, - state->backend_reproducible_name); -if (!backend_node) { - ret = -ENODEV ; - goto out; - } - - phandle =of_node_create_phandle (backend_node); - ret =of_property_write_u32 (new_node,"backend" , phandle); + ret =state_get_backend (state, root, new_node);if (ret) goto out;
include/state.h +5 -0
@@ -22,6 +22,7 @@ void state_info(void);int state_read_mac (struct state *state,const char *name,u8 *buf); +int of_state_fixup (struct device_node *root,void *ctx);#else /* #if IS_ENABLED(CONFIG_STATE) */ static inline struct state *state_new_from_node(struct device_node *node,
@@ -60,6 +61,10 @@ static inline int state_read_mac(struct state *state, const char *name, u8 *buf) return -ENOSYS; } +static inline int of_state_fixup (struct device_node *root,void *ctx) +{ +return -ENOSYS ; +}#endif /* #if IS_ENABLED(CONFIG_STATE) / #else */ #define BAREBOX_STATE_PARTITION_GUID \
Re: [PATCH v3 1/4] state: make of_state_fixup() usable outside common/state/
Hi,
Quoted 6 lines · On 8/25/26 5:05 AM, [email protected] wrote:
From: Chali Anis <[email protected]>
of_state_fixup()was static, callable only viaof_register_fixup(). Export it so other subsystems can invoke it directly to render a state instance's devicetree representation on demand, without going through the global fixup-registration/of_fix_tree() machinery.
I guess I will see later what this is needed for.
Quoted 10 lines
While exporting it, teach it to resolve backend nodes that are top-level "barebox,fixed-partitions" subnodes carrying a partuuid property instead of being tied to a real, already-probed storage device node in the tree - the same globally-resolvable-by-UUID binding drivers/of/of_path.c's
of_cdev_find()already supports for EFI, where devices aren't instantiated from devicetree. Without this,of_state_fixup()could only find a backend reachable by walking real hardware nodes already present in root, which such a partuuid-only declaration never is.
of_fixup_partitions() already takes care of fixing up partitions into the kernel DT. If it doesn't work for your use case here, it should perhaps be adapted instead.
I haven't reviewed the code, because I am unsure why this is needed and the commit message didn't really explain.
Cheers,
Ahmad
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH v3 1/4] state: make of_state_fixup() usable outside common/state/
Hi,
Quoted 24 lines · Ahmad Fatoum
Hi,
Quoted 6 lines · On 8/25/26 5:05 AM, [email protected] wrote:
From: Chali Anis <[email protected]>
of_state_fixup()was static, callable only viaof_register_fixup(). Export it so other subsystems can invoke it directly to render a state instance's devicetree representation on demand, without going through the global fixup-registration/of_fix_tree() machinery.I guess I will see later what this is needed for.
Quoted 10 lines
While exporting it, teach it to resolve backend nodes that are top-level "barebox,fixed-partitions" subnodes carrying a partuuid property instead of being tied to a real, already-probed storage device node in the tree - the same globally-resolvable-by-UUID binding drivers/of/of_path.c's
of_cdev_find()already supports for EFI, where devices aren't instantiated from devicetree. Without this,of_state_fixup()could only find a backend reachable by walking real hardware nodes already present in root, which such a partuuid-only declaration never is.
Quoted 4 lines
of_fixup_partitions()already takes care of fixing up partitions into the kernel DT. If it doesn't work for your use case here, it should perhaps be adapted instead.
I'm not sure, I the of_fixup_partitions does not take care of partitions defined by their partuuid, the reproductible name does not find the partition in the kernel
device tree as for a real mmc or spi memory where there reg and ranges to build that string.
Quoted 4 lines
I haven't reviewed the code, because I am unsure why this is needed and the commit message didn't really explain.
Maybe give it a try and see!
Quoted 2 lines
Cheers,
Ahmad
best regards.
Anis.
Quoted 7 lines
--
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH v3 2/4 state: add CONFIG_STATE_OVERLAY to inject a state node via devicetree overlay
In reply to [email protected]From: Chali Anis <[email protected]>
Until now, a "barebox,state" node had to be part of a board's own, statically compiled-in devicetree source. That's a hard requirement for external build systems (Yocto, buildroot, ...) that want to add a state layout without carrying a board-specific dts patch.
Add CONFIG_STATE_OVERLAY, which compiles an externally supplied devicetree overlay (.dtso, pointed to by CONFIG_STATE_OVERLAY_DTS) into the barebox binary and applies it to barebox's own live devicetree at postcore_initcall time, mirroring how CONFIG_EXTERNAL_DTS_FRAGMENTS already lets an external build system inject plain dts fragments. Once applied, the resulting node is picked up by the regular state probing like any statically defined one. This selects CONFIG_OF_OVERLAY_LIVE, required so &label references in the overlay (e.g. to an existing backend partition) resolve against the base devicetree's __symbols__ node.
Not every target has a live devicetree by postcore_initcall time, though, so guard against that explicitly and skip cleanly rather than calling into the overlay code with a NULL root. Once applied, call of_alias_scan() so the overlay's /aliases entry becomes visible the same way a live overlay applied via the interactive of_overlay command already does. Also select CONFIG_OFDEVICE: registering a live devicetree root at all, on targets with no firmware-supplied one of their own, depends on it.
--- .../bindings/barebox/barebox,state.rst | 9 ++++ Documentation/user/state.rst | 32 +++++++++++++++ common/Kconfig | 41 +++++++++++++++++++ common/state/Makefile | 20 +++++++++ common/state/state_overlay.c | 29 +++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 common/state/state_overlay.c
Documentation/devicetree/bindings/barebox/barebox,state.rst +9 -0
@@ -23,6 +23,15 @@ Required Properties * additionally a *state* node must have an alias in the ``/aliases`` node pointing to it. +.. note:: A *state* node does not have to be part of the board's static + devicetree source. It can instead be added at runtime via a devicetree + overlay, see :ref:`CONFIG_STATE_OVERLAY <state_overlay>`. In that case, + the node referenced by ``backend`` must still exist in the board's own + devicetree source under a stable, well-known *label* (not merely an + ``/aliases`` entry), because overlay phandle resolution works by + resolving ``&label`` references against the base devicetree's + ``__symbols__`` node, which requires ``CONFIG_OF_OVERLAY_LIVE``. + .. _barebox,state_magic: The ``magic`` property is a unique number which identifies the *state* variable
Documentation/user/state.rst +32 -0
@@ -759,6 +759,38 @@ content, its backend-type and *state* variable layout. }; }; +.. _state_overlay: + +Devicetree Overlay based State Node +------------------------------------ + +Normally the *state* node is part of the board's own, statically compiled-in +devicetree source. ``CONFIG_STATE_OVERLAY`` allows a *state* node to instead +be added at runtime, via a devicetree overlay that is compiled into the +barebox binary and applied to barebox's own live devicetree during boot. +Once applied, the resulting node is picked up by the regular *state* probing +just like a statically defined one, and is fixed up into whatever devicetree +barebox eventually boots (internal or external), without requiring any +board-specific code. + +This is primarily meant for use by an external build system (Yocto, +buildroot, ...) that wants to inject a state layout without patching the +board's dts: set ``CONFIG_STATE_OVERLAY=y`` and point +``CONFIG_STATE_OVERLAY_DTS`` at the ``.dtso`` overlay file's path, similar to +how ``CONFIG_EXTERNAL_DTS_FRAGMENTS`` works for regular dts fragments. As +with that option, it's not intended to be set in barebox's own defconfig +files. + +Because the overlay is applied to barebox's *live* devicetree, its +``backend`` phandle can only resolve references to nodes that already exist +in the board's own devicetree source, and only if that devicetree carries a +``__symbols__`` node - i.e. ``CONFIG_OF_OVERLAY_LIVE`` must be enabled +(``CONFIG_STATE_OVERLAY`` selects it automatically). This means the +referenced backend node needs a stable, well-known *label* defined in the +board's own devicetree source, not merely an ``/aliases`` entry - the +overlay itself then only needs to add the *state* node and its alias, +referencing that existing label. + Frontend --------
common/Kconfig +41 -0
47 lines not on this page · raw message
common/state/Makefile +20 -0
@@ -7,3 +7,23 @@ obj-y += backend_format_raw.o obj-y += backend_storage.o obj-y += backend_bucket_direct.o obj-$(CONFIG_MTD) += backend_bucket_circular.o + +# External state devicetree overlay +# --------------------------------------------------------------------------- +state-overlay-dts := $(call remove_quotes,$(CONFIG_STATE_OVERLAY_DTS)) + +ifdef CONFIG_STATE_OVERLAY +ifeq ($(state-overlay-dts),) +$(error CONFIG_STATE_OVERLAY is enabled but CONFIG_STATE_OVERLAY_DTS is empty) +endif +ifeq ($(wildcard $(state-overlay-dts)),) +$(error CONFIG_STATE_OVERLAY_DTS="$(state-overlay-dts)" does not exist) +endif + +obj-y += state_overlay.o state-overlay.dtbo.o + +$(obj)/state-overlay.dtbo: $(state-overlay-dts) $(DTC) FORCE + $(call if_changed_dep,dtc) +endif + +clean-files += *.dtbo *.dtbo.S .*.dtso
common/state/state_overlay.c new file +29 -0
@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include <common.h> +#include <init.h> +#include <of.h> +#include <linux/err.h> + +extern char __dtbo_state_overlay_start[]; + +static int state_overlay_apply (void ) +{ +struct device_node *root =of_get_root_node (); +int ret; + +if (!root) { +pr_err ("no live devicetree yet, skipping state overlay\n" ); +return 0 ; + } + + ret =of_overlay_apply_dtbo (root, __dtbo_state_overlay_start); +if (ret) { +pr_err ("failed to apply state overlay: %pe\n" ,ERR_PTR (ret)); +return ret; + } + +of_alias_scan (); + +return 0 ; +} +postcore_initcall (state_overlay_apply);
Re: [PATCH v3 2/4] state: add CONFIG_STATE_OVERLAY to inject a state node via devicetree overlay
Hi,
Quoted 6 lines · On 8/25/26 5:05 AM, [email protected] wrote:
From: Chali Anis <[email protected]>
Until now, a "barebox,state" node had to be part of a board's own, statically compiled-in devicetree source. That's a hard requirement for external build systems (Yocto, buildroot, ...) that want to add a state layout without carrying a board-specific dts patch.
or externally in the ESP.
Quoted 2 lines
Add
CONFIG_STATE_OVERLAY, which compiles an externally supplied devicetree overlay (.dtso, pointed to byCONFIG_STATE_OVERLAY_DTS)
Why two options?
Quoted 8 lines
into the barebox binary and applies it to barebox's own live devicetree at
postcore_initcalltime, mirroring howCONFIG_EXTERNAL_DTS_FRAGMENTSalready lets an external build system inject plain dts fragments. Once applied, the resulting node is picked up by the regular state probing like any statically defined one. This selectsCONFIG_OF_OVERLAY_LIVE, required so &label references in the overlay (e.g. to an existing backend partition) resolve against the base devicetree's__symbols__node.
The cover letter mentions QEMU and board-dt-2nd as benefiting from this, but OF_OVERLAY_LIVE helps neither of them as the DT comes from outside barebox.
Quoted 8 lines
Not every target has a live devicetree by
postcore_initcalltime, though, so guard against that explicitly and skip cleanly rather than calling into the overlay code with a NULL root. Once applied, callof_alias_scan()so the overlay's /aliases entry becomes visible the same way a live overlay applied via the interactiveof_overlaycommand already does. Also selectCONFIG_OFDEVICE: registering a live devicetree root at all, on targets with no firmware-supplied one of their own, depends on it.
OFDEVICE is not really meant to be selected by generic features, rather generic features should depend on it if they need it. Architectures / Platforms are wgi should select OFDEVICE if they want to probe OF devices.
Quoted 18 lines
Assisted-by Claude Sonnet 5Signed-off-by Chali Anis <[email protected]>--- .../bindings/barebox/barebox,state.rst | 9 ++++ Documentation/user/state.rst | 32 +++++++++++++++ common/Kconfig | 41 +++++++++++++++++++ common/state/Makefile | 20 +++++++++ common/state/state_overlay.c | 29 +++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 common/state/state_overlay.cDocumentation/devicetree/bindings/barebox/barebox,state.rst +0
-0@@ -23,6 +23,15 @@ Required Properties * additionally a *state* node must have an alias in the ``/aliases`` node pointing
Documentation/devicetree/bindings/barebox/barebox,state.rst Required Properties · line 33
Quoted 10 lines
Documentation/devicetree/bindings/barebox/barebox,state.rst +8
-0to it. +.. note:: A *state* node does not have to be part of the board's static + devicetree source. It can instead be added at runtime via a devicetree + overlay, see :ref:`CONFIG_STATE_OVERLAY <state_overlay>`. In that case, + the node referenced by ``backend`` must still exist in the board's own + devicetree source under a stable, well-known *label* (not merely an + ``/aliases`` entry), because overlay phandle resolution works by + resolving ``&label`` references against the base devicetree's + ``__symbols__`` node, which requires ``CONFIG_OF_OVERLAY_LIVE``.
As mentioned above, this is not enough. If it's an external DT, CONFIG_OF_OVERLAY_LIVE won't help.
Quoted 33 lines
Documentation/devicetree/bindings/barebox/barebox,state.rst +1
-0+ .. _barebox,state_magic: The ``magic`` property is a unique number which identifies the *state* variableDocumentation/user/state.rst +21
-0@@ -759,6 +759,38 @@ content, its backend-type and *state* variable layout. }; }; +.. _state_overlay: + +Devicetree Overlay based State Node +------------------------------------ + +Normally the *state* node is part of the board's own, statically compiled-in +devicetree source. ``CONFIG_STATE_OVERLAY`` allows a *state* node to instead +be added at runtime, via a devicetree overlay that is compiled into the +barebox binary and applied to barebox's own live devicetree during boot. +Once applied, the resulting node is picked up by the regular *state* probing +just like a statically defined one, and is fixed up into whatever devicetree +barebox eventually boots (internal or external), without requiring any +board-specific code. + +This is primarily meant for use by an external build system (Yocto, +buildroot, ...) that wants to inject a state layout without patching the +board's dts: set ``CONFIG_STATE_OVERLAY=y`` and point +``CONFIG_STATE_OVERLAY_DTS`` at the ``.dtso`` overlay file's path, similar to +how ``CONFIG_EXTERNAL_DTS_FRAGMENTS`` works for regular dts fragments. As +with that option, it's not intended to be set in barebox's own defconfig +files.
Documentation/user/state.rst content, its backend-type and *state* variable layout. · line 792
Quoted 10 lines
Documentation/user/state.rst +10
-0+ +Because the overlay is applied to barebox's *live* devicetree, its +``backend`` phandle can only resolve references to nodes that already exist +in the board's own devicetree source, and only if that devicetree carries a +``__symbols__`` node - i.e. ``CONFIG_OF_OVERLAY_LIVE`` must be enabled +(``CONFIG_STATE_OVERLAY`` selects it automatically). This means the +referenced backend node needs a stable, well-known *label* defined in the +board's own devicetree source, not merely an ``/aliases`` entry - the +overlay itself then only needs to add the *state* node and its alias, +referencing that existing label.
Thanks for including docs.
Quoted 25 lines
Documentation/user/state.rst +1
-0+ Frontend --------common/Kconfig +13
-0@@ -1351,6 +1351,47 @@ config STATE_BACKWARD_COMPATIBLE compatibility with the state framework of barebox <= v2016.08.0. Newer revisions expect an additional 'meta header' and fail otherwise. +config STATE_OVERLAY + bool "apply an external devicetree overlay to add a state node" + depends on STATE + select OF_OVERLAY + select OF_OVERLAY_LIVE + select OFDEVICE + help + Compile an externally supplied devicetree overlay (.dtso) into the + barebox binary and apply it to barebox's own live devicetree at + boot, in order to add a "barebox,state" node (and its /aliases + entry) that isn't part of the board's own compiled-in devicetree. + + This selects CONFIG_OF_OVERLAY_LIVE, required so the board's own
common/Kconfig config STATE_BACKWARD_COMPATIBLE · line 1376
Quoted 10 lines
common/Kconfig +10
-0+ built-in devicetree carries a __symbols__ node, needed to resolve + &label references from the overlay back into the base devicetree + (e.g. a reference to a backend partition already defined in the + board's static dts). + + This also selects CONFIG_OFDEVICE: registering a live devicetree + root at all, on targets with no firmware-supplied one of their + own, depends on it. + + See CONFIG_STATE_OVERLAY_DTS to specify the overlay source file.
As mentioned above, unclear to me why we need two options.
Quoted 77 lines
common/Kconfig +18
-0+ +config STATE_OVERLAY_DTS + string "external state overlay .dtso file" + depends on STATE_OVERLAY + help + Path to a devicetree overlay source file (.dtso) that will be + compiled and linked into the barebox image and applied to the + live devicetree at boot to add a "barebox,state" node. + + As with CONFIG_EXTERNAL_DTS_FRAGMENTS, this is not intended to be + put into Barebox's defconfig files. It's an external build + system's job, like Yocto or buildroot, to inject a state overlay + file from outside the Barebox source tree. + + Any backend node referenced from the overlay via &label must + already exist in the board's own devicetree source, under a + stable, well-known label (not merely an /aliases entry). +config BOOTCHOOSER
common/Kconfig +0
-0bool "bootchooser infrastructure" select BOOTcommon/state/Makefile +20
-0@@ -7,3 +7,23 @@ obj-y += backend_format_raw.o obj-y += backend_storage.o obj-y += backend_bucket_direct.o obj-$(CONFIG_MTD) += backend_bucket_circular.o + +# External state devicetree overlay +# --------------------------------------------------------------------------- +state-overlay-dts := $(call remove_quotes,$(CONFIG_STATE_OVERLAY_DTS)) + +ifdef CONFIG_STATE_OVERLAY +ifeq ($(state-overlay-dts),) +$(error CONFIG_STATE_OVERLAY is enabled but CONFIG_STATE_OVERLAY_DTS is empty) +endif +ifeq ($(wildcard $(state-overlay-dts)),) +$(error CONFIG_STATE_OVERLAY_DTS="$(state-overlay-dts)" does not exist) +endif + +obj-y += state_overlay.o state-overlay.dtbo.o + +$(obj)/state-overlay.dtbo: $(state-overlay-dts) $(DTC) FORCE + $(call if_changed_dep,dtc) +endif + +clean-files += *.dtbo *.dtbo.S .*.dtsocommon/state/state_overlay.c new file +19
-0@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include <common.h> +#include <init.h> +#include <of.h> +#include <linux/err.h> + +extern char __dtbo_state_overlay_start[]; + +static int state_overlay_apply (void ) +{ +struct device_node *root =of_get_root_node (); +int ret; + +if (!root) { +pr_err ("no live devicetree yet, skipping state overlay\n" ); +return 0 ; + } + + ret =of_overlay_apply_dtbo (root, __dtbo_state_overlay_start);
common/state/state_overlay.c line 29
Quoted 10 lines
common/state/state_overlay.c new file +10
-0+if (ret) { +pr_err ("failed to apply state overlay: %pe\n" ,ERR_PTR (ret)); +return ret; + } + +of_alias_scan (); + +return 0 ; +} +postcore_initcall (state_overlay_apply);
This can be used to apply arbitrary overlay content, so the option name should probably not be state specific.
Cheers,
Ahmad
Quoted 1 line
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH v3 2/4] state: add CONFIG_STATE_OVERLAY to inject a state node via devicetree overlay
Hi,
Quoted 11 lines · Ahmad Fatoum
Hi,
Quoted 6 lines · On 8/25/26 5:05 AM, [email protected] wrote:
From: Chali Anis <[email protected]>
Until now, a "barebox,state" node had to be part of a board's own, statically compiled-in devicetree source. That's a hard requirement for external build systems (Yocto, buildroot, ...) that want to add a state layout without carrying a board-specific dts patch.
Quoted 6 lines
or externally in the ESP.
Quoted 2 lines
Add
CONFIG_STATE_OVERLAY, which compiles an externally supplied devicetree overlay (.dtso, pointed to byCONFIG_STATE_OVERLAY_DTS)Why two options?
it could be one option.
Quoted 238 lines
Quoted 8 lines
into the barebox binary and applies it to barebox's own live devicetree at
postcore_initcalltime, mirroring howCONFIG_EXTERNAL_DTS_FRAGMENTSalready lets an external build system inject plain dts fragments. Once applied, the resulting node is picked up by the regular state probing like any statically defined one. This selectsCONFIG_OF_OVERLAY_LIVE, required so &label references in the overlay (e.g. to an existing backend partition) resolve against the base devicetree's__symbols__node.The cover letter mentions QEMU and board-dt-2nd as benefiting from this, but
OF_OVERLAY_LIVEhelps neither of them as the DT comes from outside barebox.Quoted 8 lines
Not every target has a live devicetree by
postcore_initcalltime, though, so guard against that explicitly and skip cleanly rather than calling into the overlay code with a NULL root. Once applied, callof_alias_scan()so the overlay's /aliases entry becomes visible the same way a live overlay applied via the interactiveof_overlaycommand already does. Also selectCONFIG_OFDEVICE: registering a live devicetree root at all, on targets with no firmware-supplied one of their own, depends on it.OFDEVICE is not really meant to be selected by generic features, rather generic features should depend on it if they need it. Architectures / Platforms are wgi should select OFDEVICE if they want to probe OF devices.
Quoted 18 lines
Assisted-by Claude Sonnet 5Signed-off-by Chali Anis <[email protected]>--- .../bindings/barebox/barebox,state.rst | 9 ++++ Documentation/user/state.rst | 32 +++++++++++++++ common/Kconfig | 41 +++++++++++++++++++ common/state/Makefile | 20 +++++++++ common/state/state_overlay.c | 29 +++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 common/state/state_overlay.cDocumentation/devicetree/bindings/barebox/barebox,state.rst +0
-0@@ -23,6 +23,15 @@ Required Properties * additionally a *state* node must have an alias in the ``/aliases`` node pointingDocumentation/devicetree/bindings/barebox/barebox,state.rst Required Properties · line 33
Quoted 10 lines
Documentation/devicetree/bindings/barebox/barebox,state.rst +8
-0to it. +.. note:: A *state* node does not have to be part of the board's static + devicetree source. It can instead be added at runtime via a devicetree + overlay, see :ref:`CONFIG_STATE_OVERLAY <state_overlay>`. In that case, + the node referenced by ``backend`` must still exist in the board's own + devicetree source under a stable, well-known *label* (not merely an + ``/aliases`` entry), because overlay phandle resolution works by + resolving ``&label`` references against the base devicetree's + ``__symbols__`` node, which requires ``CONFIG_OF_OVERLAY_LIVE``.As mentioned above, this is not enough. If it's an external DT,
CONFIG_OF_OVERLAY_LIVEwon't help.Quoted 33 lines
Documentation/devicetree/bindings/barebox/barebox,state.rst +1
-0+ .. _barebox,state_magic: The ``magic`` property is a unique number which identifies the *state* variableDocumentation/user/state.rst +21
-0@@ -759,6 +759,38 @@ content, its backend-type and *state* variable layout. }; }; +.. _state_overlay: + +Devicetree Overlay based State Node +------------------------------------ + +Normally the *state* node is part of the board's own, statically compiled-in +devicetree source. ``CONFIG_STATE_OVERLAY`` allows a *state* node to instead +be added at runtime, via a devicetree overlay that is compiled into the +barebox binary and applied to barebox's own live devicetree during boot. +Once applied, the resulting node is picked up by the regular *state* probing +just like a statically defined one, and is fixed up into whatever devicetree +barebox eventually boots (internal or external), without requiring any +board-specific code. + +This is primarily meant for use by an external build system (Yocto, +buildroot, ...) that wants to inject a state layout without patching the +board's dts: set ``CONFIG_STATE_OVERLAY=y`` and point +``CONFIG_STATE_OVERLAY_DTS`` at the ``.dtso`` overlay file's path, similar to +how ``CONFIG_EXTERNAL_DTS_FRAGMENTS`` works for regular dts fragments. As +with that option, it's not intended to be set in barebox's own defconfig +files.Documentation/user/state.rst content, its backend-type and *state* variable layout. · line 792
Quoted 10 lines
Documentation/user/state.rst +10
-0+ +Because the overlay is applied to barebox's *live* devicetree, its +``backend`` phandle can only resolve references to nodes that already exist +in the board's own devicetree source, and only if that devicetree carries a +``__symbols__`` node - i.e. ``CONFIG_OF_OVERLAY_LIVE`` must be enabled +(``CONFIG_STATE_OVERLAY`` selects it automatically). This means the +referenced backend node needs a stable, well-known *label* defined in the +board's own devicetree source, not merely an ``/aliases`` entry - the +overlay itself then only needs to add the *state* node and its alias, +referencing that existing label.Thanks for including docs.
Quoted 25 lines
Documentation/user/state.rst +1
-0+ Frontend --------common/Kconfig +13
-0@@ -1351,6 +1351,47 @@ config STATE_BACKWARD_COMPATIBLE compatibility with the state framework of barebox <= v2016.08.0. Newer revisions expect an additional 'meta header' and fail otherwise. +config STATE_OVERLAY + bool "apply an external devicetree overlay to add a state node" + depends on STATE + select OF_OVERLAY + select OF_OVERLAY_LIVE + select OFDEVICE + help + Compile an externally supplied devicetree overlay (.dtso) into the + barebox binary and apply it to barebox's own live devicetree at + boot, in order to add a "barebox,state" node (and its /aliases + entry) that isn't part of the board's own compiled-in devicetree. + + This selects CONFIG_OF_OVERLAY_LIVE, required so the board's owncommon/Kconfig config STATE_BACKWARD_COMPATIBLE · line 1376
Quoted 10 lines
common/Kconfig +10
-0+ built-in devicetree carries a __symbols__ node, needed to resolve + &label references from the overlay back into the base devicetree + (e.g. a reference to a backend partition already defined in the + board's static dts). + + This also selects CONFIG_OFDEVICE: registering a live devicetree + root at all, on targets with no firmware-supplied one of their + own, depends on it. + + See CONFIG_STATE_OVERLAY_DTS to specify the overlay source file.As mentioned above, unclear to me why we need two options.
Quoted 77 lines
common/Kconfig +18
-0+ +config STATE_OVERLAY_DTS + string "external state overlay .dtso file" + depends on STATE_OVERLAY + help + Path to a devicetree overlay source file (.dtso) that will be + compiled and linked into the barebox image and applied to the + live devicetree at boot to add a "barebox,state" node. + + As with CONFIG_EXTERNAL_DTS_FRAGMENTS, this is not intended to be + put into Barebox's defconfig files. It's an external build + system's job, like Yocto or buildroot, to inject a state overlay + file from outside the Barebox source tree. + + Any backend node referenced from the overlay via &label must + already exist in the board's own devicetree source, under a + stable, well-known label (not merely an /aliases entry). +config BOOTCHOOSER
bool "bootchooser infrastructure"
select BOOTcommon/state/Makefile +20
-0@@ -7,3 +7,23 @@ obj-y += backend_format_raw.o obj-y += backend_storage.o obj-y += backend_bucket_direct.o obj-$(CONFIG_MTD) += backend_bucket_circular.o + +# External state devicetree overlay +# --------------------------------------------------------------------------- +state-overlay-dts := $(call remove_quotes,$(CONFIG_STATE_OVERLAY_DTS)) + +ifdef CONFIG_STATE_OVERLAY +ifeq ($(state-overlay-dts),) +$(error CONFIG_STATE_OVERLAY is enabled but CONFIG_STATE_OVERLAY_DTS is empty) +endif +ifeq ($(wildcard $(state-overlay-dts)),) +$(error CONFIG_STATE_OVERLAY_DTS="$(state-overlay-dts)" does not exist) +endif + +obj-y += state_overlay.o state-overlay.dtbo.o + +$(obj)/state-overlay.dtbo: $(state-overlay-dts) $(DTC) FORCE + $(call if_changed_dep,dtc) +endif + +clean-files += *.dtbo *.dtbo.S .*.dtsocommon/state/state_overlay.c new file +19
-0@@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include <common.h> +#include <init.h> +#include <of.h> +#include <linux/err.h> + +extern char __dtbo_state_overlay_start[]; + +static int state_overlay_apply (void ) +{ +struct device_node *root =of_get_root_node (); +int ret; + +if (!root) { +pr_err ("no live devicetree yet, skipping state overlay\n" ); +return 0 ; + } + + ret =of_overlay_apply_dtbo (root, __dtbo_state_overlay_start);common/state/state_overlay.c line 29
Quoted 10 lines
common/state/state_overlay.c new file +10
-0+if (ret) { +pr_err ("failed to apply state overlay: %pe\n" ,ERR_PTR (ret)); +return ret; + } + +of_alias_scan (); + +return 0 ; +} +postcore_initcall (state_overlay_apply);This can be used to apply arbitrary overlay content, so the option name should probably not be state specific.
Cheers,
AhmadQuoted 1 line
Quoted 6 lines
--
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Best regards,
Anis
PATCH v3 3/4 efi: payload: export resolved state as a BareboxState UEFI variable
In reply to [email protected]From: Chali Anis <[email protected]>
When a "barebox,state" node is already reachable via barebox's live devicetree (statically compiled in, or injected by CONFIG_STATE_OVERLAY), render its fully resolved description - backend phandle included - with of_state_fixup() and publish it as a "BareboxState" UEFI variable, so an OS-side consumer can locate the state layout without needing a separate state.dtb file on the ESP.
state_to_efivars_export() and efi_late_init() are both late_efi_initcall, and within one initcall level, execution follows definition order in the object file, so state_to_efivars_export() must be defined after efi_late_init(): on boards with no state node in their own static devicetree, efi_late_init() is what loads and registers /boot/EFI/barebox/state.dtb, and only once that has had a chance to run does state_by_alias() have anything to find. Defined the other way around, state_to_efivars_export() would always run first and never see a state.dtb efi_late_init() had not loaded yet - it would only have happened to work when CONFIG_STATE_OVERLAY had already registered the node much earlier, at postcore_initcall, a narrower case than the state.dtb fallback efi_late_init() exists to support.
Look the state instance up via the state_by_alias() helper (common/state/state.c) rather than open-coding the equivalent of_find_node_by_alias() + state_by_node(). This also means state not being set up yet is just a clean no-op, rather than the -ENODEV that open-coded version returned, which would've been logged as an initcall failure for what is an entirely ordinary condition.
--- efi/payload/init.c | 51 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-)
efi/payload/init.c +50 -1
@@ -287,7 +287,6 @@ core_efi_initcall(efi_register_firmware_nodes_fixup);#define EFI_LOADER_FEATURE_SECUREBOOT_ENROLL (1LL << 11)#define EFI_LOADER_FEATURE_RETAIN_SHIM (1LL << 12) -static int efi_postcore_init (void ) {const struct efi_device_path *parent_image_dp, *loaded_image_dp;
@@ -404,6 +403,56 @@ static int efi_late_init(void) }late_efi_initcall (efi_late_init); +/* +* Must run after efi_late_init(): on boards with no state node compiled +* into their own devicetree, efi_late_init() is what loads and registers +* /boot/EFI/barebox/state.dtb (or, on CONFIG_STATE_OVERLAY targets, that +* already happened much earlier). Only once that has had a chance to run +* does state_by_alias() have anything to find here. +*/ +static int state_to_efivars_export (void ) +{ +struct device_node *np; +struct state *state; +void *fdt; +size_t size; +int ret; + +if (!IS_ENABLED (CONFIG_STATE )) +return 0 ; + + state =state_by_alias ("state" ); +if (!state) +return 0 ; + + np =of_new_node (NULL ,NULL ); +if (!np) +return -ENOMEM ; + + ret =of_state_fixup (np, state); +if (ret) + goto out; + + fdt =of_flatten_dtb (np); +if (!fdt) { + ret = -ENOMEM ; + goto out; + } + + size =fdt_totalsize (fdt); + +efi_set_variable ("BareboxState" , &efi_barebox_vendor_guid, +EFI_VARIABLE_BOOTSERVICE_ACCESS | +EFI_VARIABLE_RUNTIME_ACCESS , + fdt, size); + +free (fdt); + ret =0 ; +out: +of_delete_node (np); +return ret; +} +late_efi_initcall (state_to_efivars_export);static int do_efiexit (int argc,char *argv[]) {if (!BS )
Re: [PATCH v3 3/4] efi: payload: export resolved state as a BareboxState UEFI variable
Hi,
Quoted 8 lines · On 8/25/26 5:05 AM, [email protected] wrote:
From: Chali Anis <[email protected]>
When a "barebox,state" node is already reachable via barebox's live devicetree (statically compiled in, or injected by
CONFIG_STATE_OVERLAY), render its fully resolved description - backend phandle included - withof_state_fixup()and publish it as a "BareboxState" UEFI variable, so an OS-side consumer can locate the state layout without needing a separate state.dtb file on the ESP.
Why not pass along the whole barebox DT? For EFI payloads, that's effectively the state and the backend already and in case we gain more content in future, it will just be passed along as well.
Quoted 97 lines
state_to_efivars_export()andefi_late_init()are bothlate_efi_initcall, and within one initcall level, execution follows definition order in the object file, sostate_to_efivars_export()must be defined afterefi_late_init(): on boards with no state node in their own static devicetree,efi_late_init()is what loads and registers/boot/EFI/barebox/state.dtb, and only once that has had a chance to run doesstate_by_alias()have anything to find. Defined the other way around,state_to_efivars_export()would always run first and never see a state.dtbefi_late_init()had not loaded yet - it would only have happened to work whenCONFIG_STATE_OVERLAYhad already registered the node much earlier, atpostcore_initcall, a narrower case than the state.dtb fallbackefi_late_init()exists to support.Look the state instance up via the
state_by_alias()helper (common/state/state.c) rather than open-coding the equivalentof_find_node_by_alias()+state_by_node(). This also means state not being set up yet is just a clean no-op, rather than the-ENODEVthat open-coded version returned, which would've been logged as an initcall failure for what is an entirely ordinary condition.Assisted-by Claude Sonnet 5Signed-off-by Chali Anis <[email protected]>--- efi/payload/init.c | 51 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-)efi/payload/init.c +50
-1@@ -287,7 +287,6 @@ core_efi_initcall(efi_register_firmware_nodes_fixup);#define EFI_LOADER_FEATURE_SECUREBOOT_ENROLL (1LL << 11)#define EFI_LOADER_FEATURE_RETAIN_SHIM (1LL << 12) -static int efi_postcore_init (void ) {const struct efi_device_path *parent_image_dp, *loaded_image_dp;@@ -404,6 +403,56 @@ static int efi_late_init(void) }late_efi_initcall (efi_late_init); +/* +* Must run after efi_late_init(): on boards with no state node compiled +* into their own devicetree, efi_late_init() is what loads and registers +* /boot/EFI/barebox/state.dtb (or, on CONFIG_STATE_OVERLAY targets, that +* already happened much earlier). Only once that has had a chance to run +* does state_by_alias() have anything to find here. +*/ +static int state_to_efivars_export (void ) +{ +struct device_node *np; +struct state *state; +void *fdt; +size_t size; +int ret; + +if (!IS_ENABLED (CONFIG_STATE )) +return 0 ; + + state =state_by_alias ("state" ); +if (!state) +return 0 ; + + np =of_new_node (NULL ,NULL ); +if (!np) +return -ENOMEM ; + + ret =of_state_fixup (np, state); +if (ret) + goto out; + + fdt =of_flatten_dtb (np); +if (!fdt) { + ret = -ENOMEM ; + goto out; + } + + size =fdt_totalsize (fdt); + +efi_set_variable ("BareboxState" , &efi_barebox_vendor_guid, +EFI_VARIABLE_BOOTSERVICE_ACCESS | +EFI_VARIABLE_RUNTIME_ACCESS , + fdt, size); + +free (fdt); + ret =0 ; +out: +of_delete_node (np); +return ret; +} +late_efi_initcall (state_to_efivars_export);static int do_efiexit (int argc,char *argv[]) {if (!BS )
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [PATCH v3 3/4] efi: payload: export resolved state as a BareboxState UEFI variable
Hi,
Quoted 13 lines · Ahmad Fatoum
Hi,
Quoted 8 lines · On 8/25/26 5:05 AM, [email protected] wrote:
From: Chali Anis <[email protected]>
When a "barebox,state" node is already reachable via barebox's live devicetree (statically compiled in, or injected by
CONFIG_STATE_OVERLAY), render its fully resolved description - backend phandle included - withof_state_fixup()and publish it as a "BareboxState" UEFI variable, so an OS-side consumer can locate the state layout without needing a separate state.dtb file on the ESP.
Quoted 3 lines
Why not pass along the whole barebox DT? For EFI payloads, that's effectively the state and the backend already and in case we gain more content in future, it will just be passed along as well.
I understand, so we should call the efivar BareboxDT-XXXXX ??
or If we keep the variable name BareboxState and pass the entire device tree, going forward we would only support state definitions within the barebox DT in efi payloads???
Quoted 99 lines
Quoted 87 lines
state_to_efivars_export()andefi_late_init()are bothlate_efi_initcall, and within one initcall level, execution follows definition order in the object file, sostate_to_efivars_export()must be defined afterefi_late_init(): on boards with no state node in their own static devicetree,efi_late_init()is what loads and registers/boot/EFI/barebox/state.dtb, and only once that has had a chance to run doesstate_by_alias()have anything to find. Defined the other way around,state_to_efivars_export()would always run first and never see a state.dtbefi_late_init()had not loaded yet - it would only have happened to work whenCONFIG_STATE_OVERLAYhad already registered the node much earlier, atpostcore_initcall, a narrower case than the state.dtb fallbackefi_late_init()exists to support.Look the state instance up via the
state_by_alias()helper (common/state/state.c) rather than open-coding the equivalentof_find_node_by_alias()+state_by_node(). This also means state not being set up yet is just a clean no-op, rather than the-ENODEVthat open-coded version returned, which would've been logged as an initcall failure for what is an entirely ordinary condition.Assisted-by Claude Sonnet 5Signed-off-by Chali Anis <[email protected]>--- efi/payload/init.c | 51 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-)efi/payload/init.c +43
-1@@ -287,7 +287,6 @@ core_efi_initcall(efi_register_firmware_nodes_fixup);#define EFI_LOADER_FEATURE_SECUREBOOT_ENROLL (1LL << 11)#define EFI_LOADER_FEATURE_RETAIN_SHIM (1LL << 12) -static int efi_postcore_init (void ) {const struct efi_device_path *parent_image_dp, *loaded_image_dp;@@ -404,6 +403,56 @@ static int efi_late_init(void) }late_efi_initcall (efi_late_init); +/* +* Must run after efi_late_init(): on boards with no state node compiled +* into their own devicetree, efi_late_init() is what loads and registers +* /boot/EFI/barebox/state.dtb (or, on CONFIG_STATE_OVERLAY targets, that +* already happened much earlier). Only once that has had a chance to run +* does state_by_alias() have anything to find here. +*/ +static int state_to_efivars_export (void ) +{ +struct device_node *np; +struct state *state; +void *fdt; +size_t size; +int ret; + +if (!IS_ENABLED (CONFIG_STATE )) +return 0 ; + + state =state_by_alias ("state" ); +if (!state) +return 0 ; + + np =of_new_node (NULL ,NULL ); +if (!np) +return -ENOMEM ; + + ret =of_state_fixup (np, state); +if (ret) + goto out; + + fdt =of_flatten_dtb (np); +if (!fdt) { + ret = -ENOMEM ; + goto out; + } + + size =fdt_totalsize (fdt); + +efi_set_variable ("BareboxState" , &efi_barebox_vendor_guid, +EFI_VARIABLE_BOOTSERVICE_ACCESS | +EFI_VARIABLE_RUNTIME_ACCESS , + fdt, size); +efi/payload/init.c static int efi_late_init(void) · line 458
Quoted 10 lines
efi/payload/init.c +7
-0+free (fdt); + ret =0 ; +out: +of_delete_node (np); +return ret; +} +late_efi_initcall (state_to_efivars_export);static int do_efiexit (int argc,char *argv[]) {if (!BS )--
Quoted 5 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
best regards.
Anis
PATCH v3 4/4 efi: payload: make CONFIG_STATE_OVERLAY (and BareboxState export) work on x86
In reply to [email protected]From: Chali Anis <[email protected]>
barebox_register_of() - the only thing that ever registers a live devicetree root pre-boot on x86 EFI - lived in boarddata.c, which was compiled solely for CONFIG_EFI_STUB (the chain-loaded/ARM handoff-data entry point). x86 uses CONFIG_EFI_PAYLOAD (entry-single.c's standalone efi_main()), so no code ever called it there: of_get_root_node() stayed NULL for the entire pre-boot sequence. That's what state_overlay_apply() (CONFIG_STATE_OVERLAY's postcore_initcall) and state_to_efivars_export() (the BareboxState UEFI variable export) both rely on, so neither ever had anything to work with on x86. Compile boarddata.o for CONFIG_EFI_PAYLOAD too - efi_register_of() only needs BS, which entry-single.c's efi_main() already sets before any initcall runs, and handle_efi_boarddata() already no-ops cleanly when there is no PBL handoff data, the normal case for this entry point.
On x86, actually binding a struct state to the node CONFIG_STATE_OVERLAY adds still needs a fresh of_probe() pass: barebox_register_of() already ran one, before the overlay added anything, and the next one needs to happen later still than state_overlay_apply()'s own postcore_initcall, too - PCI/SATA enumeration (and thus the disk cdevs a partuuid-based state backend resolves against) only completes well after that point. Add efi_devices_probe() at device_efi_initcall to cover it.
Finally, now that a state node reachable via CONFIG_STATE_OVERLAY is something x86 can actually end up with pre-boot, add efi_late_init()'s "skip loading the standalone state.dtb whenever a 'state' alias is already present" check - it's only meaningful once that can happen.
Tested on QEMU as the EFI payload with a partuuid-referenced backend.
--- efi/payload/Makefile | 1 + efi/payload/init.c | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-)
efi/payload/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-pbl-$(CONFIG_EFI_PAYLOAD) += early-mem.o obj-$(CONFIG_EFI_PAYLOAD) += entry-single.o pbl-$(CONFIG_EFI_STUB) += entry-multi.o obj-$(CONFIG_EFI_STUB) += boarddata.o +obj-$(CONFIG_EFI_PAYLOAD) += boarddata.o
efi/payload/init.c +17 -1
@@ -355,7 +355,7 @@ static int efi_late_init(void)void *fdt;int ret; -if (!IS_ENABLED (CONFIG_STATE )) +if (!IS_ENABLED (CONFIG_STATE ) ||of_find_node_by_alias (NULL ,"state" ))return 0 ;if (!get_mounted_path ("/boot" )) {
@@ -453,6 +453,22 @@ static int state_to_efivars_export(void)return ret; }late_efi_initcall (state_to_efivars_export); + +/* +* On x86, PCI/SATA enumeration (and thus the disk cdevs a partuuid-based +* state backend resolves against) only completes well after the one +* of_probe() pass barebox_register_of() already did, before the state +* overlay even added its node. Re-probe once devices have actually shown +* up, so such a backend can still bind. +*/ +static int __maybe_unused efi_devices_probe (void ) +{ +return of_probe (); +} +#if IS_ENABLED (CONFIG_X86 ) +device_efi_initcall (efi_devices_probe); +#endif +static int do_efiexit (int argc,char *argv[]) {if (!BS )
Re: [PATCH v3 4/4] efi: payload: make CONFIG_STATE_OVERLAY (and BareboxState export) work on x86
Quoted 62 lines · On 8/25/26 5:05 AM, [email protected] wrote:
From: Chali Anis <[email protected]>
barebox_register_of()- the only thing that ever registers a live devicetree root pre-boot on x86 EFI - lived inboarddata.c, which was compiled solely forCONFIG_EFI_STUB(the chain-loaded/ARM handoff-data entry point). x86 usesCONFIG_EFI_PAYLOAD(entry-single.c's standaloneefi_main()), so no code ever called it there:of_get_root_node()stayed NULL for the entire pre-boot sequence. That's whatstate_overlay_apply()(CONFIG_STATE_OVERLAY'spostcore_initcall) andstate_to_efivars_export()(the BareboxState UEFI variable export) both rely on, so neither ever had anything to work with on x86. Compile boarddata.o forCONFIG_EFI_PAYLOADtoo -efi_register_of()only needs BS, which entry-single.c'sefi_main()already sets before any initcall runs, andhandle_efi_boarddata()already no-ops cleanly when there is no PBL handoff data, the normal case for this entry point.On x86, actually binding a struct state to the node
CONFIG_STATE_OVERLAYadds still needs a freshof_probe()pass:barebox_register_of()already ran one, before the overlay added anything, and the next one needs to happen later still than state_overlay_apply()'s ownpostcore_initcall, too - PCI/SATA enumeration (and thus the disk cdevs a partuuid-based state backend resolves against) only completes well after that point. Addefi_devices_probe()atdevice_efi_initcallto cover it.Finally, now that a state node reachable via
CONFIG_STATE_OVERLAYis something x86 can actually end up with pre-boot, add efi_late_init()'s "skip loading the standalone state.dtb whenever a 'state' alias is already present" check - it's only meaningful once that can happen.Tested on QEMU as the EFI payload with a partuuid-referenced backend.
Assisted-by Claude Sonnet 5Signed-off-by Chali Anis <[email protected]>--- efi/payload/Makefile | 1 + efi/payload/init.c | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-)efi/payload/Makefile +1
-0@@ -11,3 +11,4 @@ obj-pbl-$(CONFIG_EFI_PAYLOAD) += early-mem.o obj-$(CONFIG_EFI_PAYLOAD) += entry-single.o pbl-$(CONFIG_EFI_STUB) += entry-multi.o obj-$(CONFIG_EFI_STUB) += boarddata.o +obj-$(CONFIG_EFI_PAYLOAD) += boarddata.oefi/payload/init.c +1
-1@@ -355,7 +355,7 @@ static int efi_late_init(void)void *fdt;int ret; -if (!IS_ENABLED (CONFIG_STATE )) +if (!IS_ENABLED (CONFIG_STATE ) ||of_find_node_by_alias (NULL ,"state" ))return 0 ;if (!get_mounted_path ("/boot" )) {@@ -453,6 +453,22 @@ static int state_to_efivars_export(void)return ret;
efi/payload/init.c static int state_to_efivars_export(void) · line 463
Quoted 10 lines
efi/payload/init.c +8
-0}late_efi_initcall (state_to_efivars_export); + +/* +* On x86, PCI/SATA enumeration (and thus the disk cdevs a partuuid-based +* state backend resolves against) only completes well after the one +* of_probe() pass barebox_register_of() already did, before the state +* overlay even added its node. Re-probe once devices have actually shown +* up, so such a backend can still bind. +*/
This comment makes no sense. Block devices we boot from under EFI are usually EFI block devices. We don't have PCI/SATA drivers even in barebox.
Quoted 12 lines
efi/payload/init.c +8
-0+static int __maybe_unused efi_devices_probe (void ) +{ +return of_probe (); +} +#if IS_ENABLED (CONFIG_X86 ) +device_efi_initcall (efi_devices_probe); +#endif +static int do_efiexit (int argc,char *argv[]) {if (!BS )
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hi,
Quoted 13 lines · On 8/25/26 5:05 AM, [email protected] wrote:
From: Chali Anis <[email protected]>
Boards that want a "barebox,state" node today have exactly one option:
carry it in their own, statically compiled-in devicetree source. That's fine as long as barebox is built per-board with a maintained dts, but it is a harder fit for targets that don't have one to begin with: the EFI payload, deliberately meant to run unmodified across arbitrary x86/arm64 EFI platforms barebox itself knows nothing about at build time, and the genericBOARD_ARM_GENERIC_DT("barebox-dt-2nd") image, which picks up whatever devicetree a first-stage bootloader or QEMU hands it in r2 at runtime the same way a Kernel would, rather than being built against a particular board's dts. Either way there is no single "board dts" being compiled for a state node to live in.
We indeed have nothing for the barebox-dt-2nd.img case, but this image is meant to be used with a *barebox* device tree, not some random DT that may use bindings barebox isn't compatible with.
This is intentionally narrower than what the kernel supports: The kernel will keep supporting old bindings, but barebox will only support the bindings it ships with.
With that background, barebox-dt-2nd.img should never be called with some random DT that's not matched to what barebox expects and thus we can expect that if someone wants a barebox state node they would add it.
As for QEMU, barebox already ships state overlays for it, but these are built-in and applied early-on.
Quoted 8 lines
CONFIG_EXTERNAL_DTS_FRAGMENTSalready covers a related need rather well:
an external build system can append dts fragment files to a board's dts source at build time, scoped to specific boards via a per-dts preprocessor macro. That remains the more direct choice whenever a board's own dts is actually part of the build, and this series doesn't propose changing that. It runs into the same limit as static dts inclusion for the EFI payload
As mentioned on IRC, this is a limitation that can be fixed and not some deliberate choice.
Quoted 1 line
and barebox-dt-2nd cases specifically,
As elaborated above, I have my reservations about starting barebox with arbitrary DTs.
Quoted 2 lines
though, since it operates at dts-source/build time on a particular "main dts" - which neither target, by design, has one of.
As the EFI payload needs the DT for nothing apart of state, we could also ship an empty DT and make that extensible via fragments.
FYI, there was discussion when fragments were first added if they should be overlays instead:
https://lore.barebox.org/barebox/CAMHeXxPZ9on3rZu92H1EeNQj79rUFBRbs5Qre=AS3U7_y=UueQ@mail.gmail.com/
Quoted 9 lines
This series instead proposes a devicetree *overlay* (.dtso, applied at runtime via
CONFIG_STATE_OVERLAY) for that gap. Applied to whichever devicetree barebox already ends up live with by boot time - statically compiled in, EFI-firmware-derived, passed in from a first-stage bootloader, or the EFI payload's own minimal stub root - it only ever adds one small node, so it doesn't need a "main dts" to attach to at build time, and it doesn't need to know a board's memory map or other devicetree content beyond one stable label (or, for EFI, just a partition UUID, patch 1) to hook its backend into.
If we were to allow supplying external overlays at build time that are applied at runtime, why make it specific to only state?
Also to be a truly generic solution, we need some accounting for multi-image (what if your build produces both a rpi3 and a rpi4 image and you want different overlays for each?).
Quoted 6 lines
In turn, that also
means it never competes with an existing devicetree for ownership, which the one realistic alternative we considered - loading a full, standalone state.dtb at runtime - does run into:barebox_register_of()only accepts a new root if none is registered yet or the incoming tree is empty,
It only accepting empty state.dtbs is a bug! It's fixed on master now though (and in the latest release).
Quoted 4 lines
so a real state.dtb collides with whatever root the EFI payload already registered at boot and is rejected with
-EBUSY, and a rejected tree's /aliases entries never reach the global alias cacheof_alias_get()relies on either.
This argumentation follows from a bug, so it doesn't say anything to the merit of this new feature.
Quoted 5 lines
Happy to discuss trade-offs here, in particular whether it's worth teaching
CONFIG_EXTERNAL_DTS_FRAGMENTS(or a variant of it) to handle the no-base-dts case instead of adding a separate mechanism - this series is meant as a concrete starting point for that conversation, not a claim that overlays are the only reasonable answer.
I appreciate you putting in the effort. As mentioned on IRC, I am in favor of extending fragments as it meshes with what we already have, but I agree overlays can cover use cases that fragments don't (while overlays as implemented here can't cover all users that fragments provide).
Quoted 4 lines
Patch 1 makes
of_state_fixup()able to resolve a partuuid-referenced, non-hardware-backed backend node, and exports it so it can be called directly. Patch 2 addsCONFIG_STATE_OVERLAYitself, compiling an external .dtso into the barebox binary and applying it to the live
Quoted 8 lines
devicetree at
postcore_initcalltime - guarding against there being no live devicetree yet, and refreshing the alias cache once applied. Patch 3 builds on both to publish the resolved state description as a UEFI variable once such a node exists. Patch 4 makes both of those actually reachable on x86: no code path there ever registered a live devicetree root pre-boot to begin with, since that registration only existed for theEFI_STUBentry point barebox uses on other architectures, not theEFI_PAYLOADone x86 uses.
No need to recount the patch commit messages here. If at all, just include a general description in the cover letter. This mail is already very verbose, which makes following it a bit hard for me.
Quoted 26 lines
Changes since v1:
- patch 1: fixed the compatible string on the synthesized fixed-partitions node ("fixed-partitions", not the barebox-internal "barebox,fixed-partitions" alias, which external consumers don't recognize), fixed a phandle collision where the synthesized node kept the phandle it had in barebox's own live devicetree instead of one scoped to the target tree, and resolved non-partuuid backends via the reproducible name cached at probe time again instead of recomputing it against whatever tree is being fixed up.
- patch 2:state_overlay_apply()now guards against there being no live devicetree yet and skips cleanly instead of calling into the overlay code with a NULL root, and callsof_alias_scan()afterward so the overlay's /aliases entry becomes visible the same way a live overlay applied via the interactiveof_overlaycommand already does. Also selectsCONFIG_OFDEVICE, needed for a live devicetree root to exist at all on some targets.
- patch 3: publish "BareboxState" underefi_barebox_vendor_guidinstead ofefi_systemd_vendor_guid- it's a barebox-defined variable, not part of the systemd-boot loader protocol.state_to_efivars_export()andefi_late_init()are bothlate_efi_initcall, and within one initcall level execution follows definition order in the object file, sostate_to_efivars_export()is now defined afterefi_late_init():
on boards with no state node in their own static devicetree,efi_late_init()is what loads and registers the standalone state.dtb, and only once that has had a chance to run doesstate_by_alias()(used
Quoted 8 lines
here instead of open-coding the equivalent
of_find_node_by_alias()+state_by_node()) have anything to find.
- patch 4 is new: without it,CONFIG_STATE_OVERLAYsilently never had a devicetree to apply to on x86, and this series' EFI-payload rationale didn't hold up for that architecture in practice.
- cover letter: called outBOARD_ARM_GENERIC_DT("barebox-dt-2nd") as a second target that benefits from this alongside the EFI payload, since it's in the same "no main dts at build time" situation.
I haven't checked out the earlier versions, so I will just gloss over this.
Quoted 2 lines
Tested on a Raspberry Pi CM4 natively, and as the EFI payload on a Jetson Orin NX and under QEMU (x86, with a partuuid-referenced backend).
Thanks. This is useful info.
Quoted 9 lines
Chali Anis (4):
state: makeof_state_fixup()usable outside common/state/
state: addCONFIG_STATE_OVERLAYto inject a state node via devicetree
overlay
efi: payload: export resolved state as a BareboxState UEFI variable
efi: payload: makeCONFIG_STATE_OVERLAY(and BareboxState export) workon x86
Quoted 13 lines
.../bindings/barebox/barebox,state.rst | 9 +++ Documentation/user/state.rst | 32 +++++++++ common/Kconfig | 41 +++++++++++ common/state/Makefile | 20 ++++++ common/state/state.c | 72 +++++++++++++++---- common/state/state_overlay.c | 29 ++++++++ efi/payload/Makefile | 1 + efi/payload/init.c | 69 +++++++++++++++++- include/state.h | 5 ++ 9 files changed, 263 insertions(+), 15 deletions(-) create mode 100644 common/state/state_overlay.c
Cheers,
Ahmad
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hi,
Quoted 8 lines · Ahmad Fatoum
Quoted 4 lines · On 8/25/26 5:05 AM, [email protected] wrote:
so a real state.dtb collides with whatever root the EFI payload already registered at boot and is rejected with
-EBUSY, and a rejected tree's /aliases entries never reach the global alias cacheof_alias_get()relies on either.This argumentation follows from a bug, so it doesn't say anything to the merit of this new feature.
I have now read through the series and my thoughts are that applying overlays to the barebox live tree from outside can be useful (I wouldn't limit it to state), but:
- it needs better argumentation what it allows that is not feasible with fragments
- it needs some way to account for multi-image
I am going to send out my EFI-payload-state-via-fragment series soon and I am interested to hear your thoughts on it.
Thanks,
Ahmad
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hi
Quoted 10 lines · Ahmad Fatoum
Hi,
Quoted 6 lines · Ahmad Fatoum
Quoted 4 lines · On 8/25/26 5:05 AM, [email protected] wrote:
so a real state.dtb collides with whatever root the EFI payload already registered at boot and is rejected with
-EBUSY, and a rejected tree's /aliases entries never reach the global alias cacheof_alias_get()relies on either.
Quoted 6 lines
Quoted 2 lines
This argumentation follows from a bug, so it doesn't say anything to the merit of this new feature.
I have now read through the series and my thoughts are that applying overlays to the barebox live tree from outside can be useful (I wouldn't limit it to state), but:
Ack, and if we have overlays we can apply whatever we want (state, other things) it more useful than the state, because it permits to add more stuff and permits to
address state and more.
Quoted 3 lines
- it needs better argumentation what it allows that is not feasible with fragments
- it needs some way to account for multi-image
Yes, agreed. One approach could be to use a global label, or alternatively scan all
barebox state partitions and check for a tag that matches the corresponding state
fragment or overlay. The matching backend partition would then be used.
Quoted 12 lines
I am going to send out my EFI-payload-state-via-fragment series soon and I am interested to hear your thoughts on it.
Thanks,
Ahmad--
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
On Tue, Aug 25, 2026 at 05:02:40PM +0200, Ahmad Fatoum wrote:
Hi,
Quoted 21 lines
Hi,
Quoted 13 lines · On 8/25/26 5:05 AM, [email protected] wrote:
From: Chali Anis <[email protected]>
Boards that want a "barebox,state" node today have exactly one option:
carry it in their own, statically compiled-in devicetree source. That's fine as long as barebox is built per-board with a maintained dts, but it is a harder fit for targets that don't have one to begin with: the EFI payload, deliberately meant to run unmodified across arbitrary x86/arm64 EFI platforms barebox itself knows nothing about at build time, and the genericBOARD_ARM_GENERIC_DT("barebox-dt-2nd") image, which picks up whatever devicetree a first-stage bootloader or QEMU hands it in r2 at runtime the same way a Kernel would, rather than being built against a particular board's dts. Either way there is no single "board dts" being compiled for a state node to live in.We indeed have nothing for the barebox-dt-2nd.img case, but this image is meant to be used with a *barebox* device tree, not some random DT that may use bindings barebox isn't compatible with.
Quoted 7 lines
This is intentionally narrower than what the kernel supports: The kernel will keep supporting old bindings, but barebox will only support the bindings it ships with.
With that background, barebox-dt-2nd.img should never be called with some random DT that's not matched to what barebox expects and thus we can expect that if someone wants a barebox state node they would add it.
The state overlay doesn't resolve against "a random DT" — it's applied via a fixup that doesn't need to know which exact DT or platform actually booted, works against whatever supported board's DT, just one that isn't available at build time to compile against.
Quoted 12 lines
As for QEMU, barebox already ships state overlays for it, but these are built-in and applied early-on.
Quoted 8 lines
CONFIG_EXTERNAL_DTS_FRAGMENTSalready covers a related need rather well:
an external build system can append dts fragment files to a board's dts source at build time, scoped to specific boards via a per-dts preprocessor macro. That remains the more direct choice whenever a board's own dts is actually part of the build, and this series doesn't propose changing that. It runs into the same limit as static dts inclusion for the EFI payload
Quoted 7 lines
As mentioned on IRC, this is a limitation that can be fixed and not some deliberate choice.
Quoted 1 line
and barebox-dt-2nd cases specifically,
As elaborated above, I have my reservations about starting barebox with arbitrary DTs.
Arbitrary DTs will not work anyway if the SOC at least not supported.
Quoted 5 lines
Quoted 2 lines
though, since it operates at dts-source/build time on a particular "main dts" - which neither target, by design, has one of.
As the EFI payload needs the DT for nothing apart of state, we could also ship an empty DT and make that extensible via fragments.
Yes in the case of EFI, both fragments and overlays has the same result since we use a partuuid to declare the state partition
Quoted 15 lines
FYI, there was discussion when fragments were first added if they should be overlays instead:
https://lore.barebox.org/barebox/CAMHeXxPZ9on3rZu92H1EeNQj79rUFBRbs5Qre=AS3U7_y=UueQ@mail.gmail.com/
Quoted 9 lines
This series instead proposes a devicetree *overlay* (.dtso, applied at runtime via
CONFIG_STATE_OVERLAY) for that gap. Applied to whichever devicetree barebox already ends up live with by boot time - statically compiled in, EFI-firmware-derived, passed in from a first-stage bootloader, or the EFI payload's own minimal stub root - it only ever adds one small node, so it doesn't need a "main dts" to attach to at build time, and it doesn't need to know a board's memory map or other devicetree content beyond one stable label (or, for EFI, just a partition UUID, patch 1) to hook its backend into.
Quoted 2 lines
If we were to allow supplying external overlays at build time that are applied at runtime, why make it specific to only state?
making it specific to state overlay is cleaner in my opinion. we can support other overlays, this patches does not prevent them
Quoted 3 lines
Also to be a truly generic solution, we need some accounting for multi-image (what if your build produces both a rpi3 and a rpi4 image and you want different overlays for each?).
a multi image will apply the same overlay which seems to be a limitation some people, for my case I run 5 products on the exact same stack which reduces support for me once something is fixed in one platform automaticly the others will benefet from it.
Quoted 9 lines
Quoted 6 lines
In turn, that also
means it never competes with an existing devicetree for ownership, which the one realistic alternative we considered - loading a full, standalone state.dtb at runtime - does run into:barebox_register_of()only accepts a new root if none is registered yet or the incoming tree is empty,It only accepting empty state.dtbs is a bug! It's fixed on master now though (and in the latest release).
okay.
Quoted 7 lines
Quoted 4 lines
so a real state.dtb collides with whatever root the EFI payload already registered at boot and is rejected with
-EBUSY, and a rejected tree's /aliases entries never reach the global alias cacheof_alias_get()relies on either.This argumentation follows from a bug, so it doesn't say anything to the merit of this new feature.
The solutions or feature might come from bugs otherwise why changing things if they are already perfect.
Quoted 10 lines
Quoted 5 lines
Happy to discuss trade-offs here, in particular whether it's worth teaching
CONFIG_EXTERNAL_DTS_FRAGMENTS(or a variant of it) to handle the no-base-dts case instead of adding a separate mechanism - this series is meant as a concrete starting point for that conversation, not a claim that overlays are the only reasonable answer.I appreciate you putting in the effort. As mentioned on IRC, I am in favor of extending fragments as it meshes with what we already have, but I agree overlays can cover use cases that fragments don't (while overlays as implemented here can't cover all users that fragments provide).
as I said one feature not prevent the other, but anyway If fragments solve most cases and permits to embbed the state to barebox without having a separate file or patching a given internal dts file or maintaining whole dts separatly, in
side it will be fine.
Quoted 14 lines
Quoted 4 lines
Patch 1 makes
of_state_fixup()able to resolve a partuuid-referenced, non-hardware-backed backend node, and exports it so it can be called directly. Patch 2 addsCONFIG_STATE_OVERLAYitself, compiling an external .dtso into the barebox binary and applying it to the liveQuoted 8 lines
devicetree at
postcore_initcalltime - guarding against there being no live devicetree yet, and refreshing the alias cache once applied. Patch 3 builds on both to publish the resolved state description as a UEFI variable once such a node exists. Patch 4 makes both of those actually reachable on x86: no code path there ever registered a live devicetree root pre-boot to begin with, since that registration only existed for theEFI_STUBentry point barebox uses on other architectures, not theEFI_PAYLOADone x86 uses.
Quoted 3 lines
No need to recount the patch commit messages here. If at all, just include a general description in the cover letter. This mail is already very verbose, which makes following it a bit hard for me.
Sorry claude authoring.
Quoted 71 lines
Quoted 26 lines
Changes since v1:
- patch 1: fixed the compatible string on the synthesized fixed-partitions node ("fixed-partitions", not the barebox-internal "barebox,fixed-partitions" alias, which external consumers don't recognize), fixed a phandle collision where the synthesized node kept the phandle it had in barebox's own live devicetree instead of one scoped to the target tree, and resolved non-partuuid backends via the reproducible name cached at probe time again instead of recomputing it against whatever tree is being fixed up.
- patch 2:state_overlay_apply()now guards against there being no live devicetree yet and skips cleanly instead of calling into the overlay code with a NULL root, and callsof_alias_scan()afterward so the overlay's /aliases entry becomes visible the same way a live overlay applied via the interactiveof_overlaycommand already does. Also selectsCONFIG_OFDEVICE, needed for a live devicetree root to exist at all on some targets.
- patch 3: publish "BareboxState" underefi_barebox_vendor_guidinstead ofefi_systemd_vendor_guid- it's a barebox-defined variable, not part of the systemd-boot loader protocol.state_to_efivars_export()andefi_late_init()are bothlate_efi_initcall, and within one initcall level execution follows definition order in the object file, sostate_to_efivars_export()is now defined afterefi_late_init():
on boards with no state node in their own static devicetree,efi_late_init()is what loads and registers the standalone state.dtb, and only once that has had a chance to run doesstate_by_alias()(usedQuoted 8 lines
here instead of open-coding the equivalent
of_find_node_by_alias()+state_by_node()) have anything to find.
- patch 4 is new: without it,CONFIG_STATE_OVERLAYsilently never had a devicetree to apply to on x86, and this series' EFI-payload rationale didn't hold up for that architecture in practice.
- cover letter: called outBOARD_ARM_GENERIC_DT("barebox-dt-2nd") as a second target that benefits from this alongside the EFI payload, since it's in the same "no main dts at build time" situation.I haven't checked out the earlier versions, so I will just gloss over this.
Quoted 2 lines
Tested on a Raspberry Pi CM4 natively, and as the EFI payload on a Jetson Orin NX and under QEMU (x86, with a partuuid-referenced backend).
Thanks. This is useful info.
Quoted 9 lines
Chali Anis (4):
state: makeof_state_fixup()usable outside common/state/
state: addCONFIG_STATE_OVERLAYto inject a state node via devicetree
overlay
efi: payload: export resolved state as a BareboxState UEFI variable
efi: payload: makeCONFIG_STATE_OVERLAY(and BareboxState export) workon x86Quoted 13 lines
.../bindings/barebox/barebox,state.rst | 9 +++ Documentation/user/state.rst | 32 +++++++++ common/Kconfig | 41 +++++++++++ common/state/Makefile | 20 ++++++ common/state/state.c | 72 +++++++++++++++---- common/state/state_overlay.c | 29 ++++++++ efi/payload/Makefile | 1 + efi/payload/init.c | 69 +++++++++++++++++- include/state.h | 5 ++ 9 files changed, 263 insertions(+), 15 deletions(-) create mode 100644 common/state/state_overlay.cCheers,
Ahmad
Quoted 8 lines
--
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Best regards.
Anis