From: chalianis1@gmail.com
To: s.hauer@pengutronix.de
Cc: barebox@lists.infradead.org, Chali Anis <chalianis1@gmail.com>
Subject: [PATCH v2 1/3] state: make of_state_fixup() usable outside common/state/
Date: Tue, 25 Aug 2026 02:06:43 +0200 [thread overview]
Message-ID: <20260825000645.122086-2-chalianis1@gmail.com> (raw)
In-Reply-To: <20260825000645.122086-1-chalianis1@gmail.com>
From: Chali Anis <chalianis1@gmail.com>
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.
Assisted-by: Claude Sonnet 5
Signed-off-by: Chali Anis <chalianis1@gmail.com>
---
common/state/state.c | 72 ++++++++++++++++++++++++++++++++++++--------
include/state.h | 5 +++
2 files changed, 64 insertions(+), 13 deletions(-)
diff --git a/common/state/state.c b/common/state/state.c
index b421b43da539..5de806b954e9 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -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;
diff --git a/include/state.h b/include/state.h
index 3daf82c0735f..d0034506f6e3 100644
--- a/include/state.h
+++ b/include/state.h
@@ -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 \
next prev parent reply other threads:[~2026-08-25 0:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 0:06 [PATCH v2 0/3] state: generic devicetree-overlay based state node injection chalianis1
2026-08-25 0:06 ` chalianis1 [this message]
2026-08-25 0:06 ` [PATCH v2 2/3] state: add CONFIG_STATE_OVERLAY to inject a state node via devicetree overlay chalianis1
2026-08-25 0:06 ` [PATCH v2 3/3] efi: payload: export resolved state as a BareboxState UEFI variable chalianis1
-- strict thread matches above, loose matches on Subject: below --
2026-08-24 23:52 [PATCH v2 0/3] state: generic devicetree-overlay based state node injection chalianis1
2026-08-24 23:52 ` [PATCH v2 1/3] state: make of_state_fixup() usable outside common/state/ chalianis1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260825000645.122086-2-chalianis1@gmail.com \
--to=chalianis1@gmail.com \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox