From: Primoz Fiser <primoz.fiser@norik.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/1] commands: of_property: resolve phandles of fixups in the booted tree
Date: Fri, 13 Nov 2026 12:55:48 +0100 [thread overview]
Message-ID: <20261113115548.2224914-2-primoz.fiser@norik.com> (raw)
In-Reply-To: <20261113115548.2224914-1-primoz.fiser@norik.com>
Node paths in a cell value are converted to phandles when the command
runs: in the barebox live tree, or in the tree read with -e. For a fixup
(-f), the phandle is then written to the tree the kernel is booted with.
Phandles are assigned by dtc and differ between the barebox and the
kernel tree, so without -e the fixup points to a wrong node.
With -e, the kernel dtb must be available as a separate file, and its
phandles must match the tree that is actually booted. This is not the
case when the device tree comes from a FIT image: the command fails
because the file does not exist, and the fixup is never registered.
Only check the syntax of the value when the command runs, and parse it
when the fixup is applied, so node paths are resolved in the tree that
is booted. The -e option is not needed for fixups anymore and is
ignored with -f, so existing scripts keep working.
Signed-off-by: Primoz Fiser <primoz.fiser@norik.com>
---
commands/of_property.c | 75 ++++++++++++++++++++++++++++--------------
1 file changed, 51 insertions(+), 24 deletions(-)
diff --git a/commands/of_property.c b/commands/of_property.c
index c1c2b343bccc..24d812069b70 100644
--- a/commands/of_property.c
+++ b/commands/of_property.c
@@ -19,7 +19,12 @@
#include <init.h>
#include <xfuncs.h>
-static int of_parse_prop_cells(struct device_node *root, char * const *newval, int count, char *data, int *len)
+/*
+ * With @resolve false, node paths are only checked for syntax and
+ * converted to 0 instead of a phandle.
+ */
+static int of_parse_prop_cells(struct device_node *root, bool resolve,
+ char * const *newval, int count, char *data, int *len)
{
char *cp;
unsigned long tmp; /* holds converted values */
@@ -58,6 +63,12 @@ static int of_parse_prop_cells(struct device_node *root, char * const *newval, i
len++;
}
+ if (!resolve) {
+ tmp = 0;
+ newp += len;
+ goto next;
+ }
+
str = xzalloc(len + 1);
strncpy(str, cp, len);
@@ -73,7 +84,7 @@ static int of_parse_prop_cells(struct device_node *root, char * const *newval, i
tmp = of_node_create_phandle(n);
newp += len;
}
-
+next:
*(__be32 *)data = __cpu_to_be32(tmp);
data += 4;
*len += 4;
@@ -165,7 +176,8 @@ static int of_parse_prop_string(char * const *newval, int count, char *data, int
* data: A bytestream to be placed in the property
* len: The length of the resulting bytestream
*/
-static int of_parse_prop(struct device_node *root, char * const *newval, int count, char *data, int *len)
+static int of_parse_prop(struct device_node *root, bool resolve,
+ char * const *newval, int count, char *data, int *len)
{
char *newp; /* temporary newval char pointer */
@@ -178,7 +190,7 @@ static int of_parse_prop(struct device_node *root, char * const *newval, int cou
switch (*newp) {
case '<':
- return of_parse_prop_cells(root, newval, count, data, len);
+ return of_parse_prop_cells(root, resolve, newval, count, data, len);
case '[':
return of_parse_prop_stream(newval, count, data, len);
default:
@@ -189,8 +201,8 @@ static int of_parse_prop(struct device_node *root, char * const *newval, int cou
struct of_fixup_property_data {
const char *path;
const char *propname;
- void *data;
- int len;
+ char **values;
+ int count;
};
static int do_of_property_delete_now(struct device_node *root, const char *path,
@@ -201,9 +213,20 @@ static int do_of_property_set_now(struct device_node *root, const char *path,
static int of_fixup_property_set(struct device_node *root, void *context)
{
struct of_fixup_property_data *fixup = context;
+ void *data;
+ int len, ret;
+
+ /* parse now, so node paths resolve against the tree being booted */
+ data = xmalloc(1024);
+
+ ret = of_parse_prop(root, true, fixup->values, fixup->count, data, &len);
+ if (!ret)
+ ret = do_of_property_set_now(root, fixup->path, fixup->propname,
+ data, len);
- return do_of_property_set_now(root, fixup->path, fixup->propname,
- fixup->data, fixup->len);
+ free(data);
+
+ return ret;
}
static int of_fixup_property_delete(struct device_node *root, void *context)
@@ -214,15 +237,19 @@ static int of_fixup_property_delete(struct device_node *root, void *context)
}
static int do_of_property_set_fixup(const char *path, const char *propname,
- void *data, int len)
+ char * const *values, int count)
{
struct of_fixup_property_data *fixup;
+ int i;
fixup = xzalloc(sizeof(*fixup));
fixup->path = xstrdup_const(path);
fixup->propname = xstrdup_const(propname);
- fixup->data = data;
- fixup->len = len;
+ fixup->values = xzalloc(count * sizeof(*fixup->values));
+ fixup->count = count;
+
+ for (i = 0; i < count; i++)
+ fixup->values[i] = xstrdup(values[i]);
return of_register_fixup(of_fixup_property_set, (void *)fixup);
}
@@ -234,8 +261,6 @@ static int do_of_property_delete_fixup(const char *path, const char *propname)
fixup = xzalloc(sizeof(*fixup));
fixup->path = xstrdup_const(path);
fixup->propname = xstrdup_const(propname);
- fixup->data = NULL;
- fixup->len = 0;
return of_register_fixup(of_fixup_property_delete, (void *)fixup);
}
@@ -338,7 +363,8 @@ static int do_of_property(int argc, char *argv[])
if ( !(set || delete))
return COMMAND_ERROR_USAGE;
- if (dtbfile) {
+ /* fixups apply to the booted tree; -e is accepted but ignored */
+ if (dtbfile && !fixup) {
root = of_read_file(dtbfile);
if (IS_ERR(root))
return PTR_ERR(root);
@@ -356,20 +382,20 @@ static int do_of_property(int argc, char *argv[])
if (!data)
return -ENOMEM;
- ret = of_parse_prop(root, &argv[optind + 2], argc - optind - 2, data, &len);
+ ret = of_parse_prop(root, !fixup, &argv[optind + 2],
+ argc - optind - 2, data, &len);
if (ret) {
free(data);
goto out;
}
- if (fixup) {
- ret = do_of_property_set_fixup(path, propname, data, len);
- if (ret)
- free(data);
- } else {
+ if (fixup)
+ ret = do_of_property_set_fixup(path, propname,
+ &argv[optind + 2], argc - optind - 2);
+ else
ret = do_of_property_set_now(root, path, propname, data, len);
- free(data);
- }
+
+ free(data);
if (ret)
goto out;
@@ -404,11 +430,12 @@ BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT ("-s", "set property to value")
BAREBOX_CMD_HELP_OPT ("-d", "delete property")
BAREBOX_CMD_HELP_OPT ("-f", "set/delete as a fixup (defer the action until booting)")
-BAREBOX_CMD_HELP_OPT ("-e dtb", "set/delete/fixup from external dtb")
+BAREBOX_CMD_HELP_OPT ("-e dtb", "set/delete in external dtb (ignored with -f)")
BAREBOX_CMD_HELP_TEXT("")
BAREBOX_CMD_HELP_TEXT("Valid formats for values:")
BAREBOX_CMD_HELP_TEXT("<0x00112233 4 05> - an array of cells. cells not beginning with a digit are")
-BAREBOX_CMD_HELP_TEXT(" interpreted as node paths and converted to phandles")
+BAREBOX_CMD_HELP_TEXT(" interpreted as node paths and converted to phandles.")
+BAREBOX_CMD_HELP_TEXT(" With -f, the paths are looked up in the booted tree")
BAREBOX_CMD_HELP_TEXT("[00 11 22 .. nn] - byte stream")
BAREBOX_CMD_HELP_TEXT("If the value does not start with '<' or '[' it is interpreted as string")
BAREBOX_CMD_HELP_END
--
2.34.1
next prev parent reply other threads:[~2026-11-13 12:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 11:55 [PATCH 0/1] of_property: resolve phandles against the booted device tree Primoz Fiser
2026-11-13 11:55 ` Primoz Fiser [this message]
2026-11-17 8:23 ` [PATCH 1/1] commands: of_property: resolve phandles of fixups in the booted tree Sascha Hauer
2026-11-17 8:44 ` [PATCH 0/1] of_property: resolve phandles against the booted device tree Sascha Hauer
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=20261113115548.2224914-2-primoz.fiser@norik.com \
--to=primoz.fiser@norik.com \
--cc=barebox@lists.infradead.org \
/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