* [PATCH v2 0/6] Restore phandles from binary representations
@ 2025-09-19 9:29 Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 1/6] Emit /plugin/ when compiling to .dts with DTSF_PLUGIN set Uwe Kleine-König
` (6 more replies)
0 siblings, 7 replies; 11+ messages in thread
From: Uwe Kleine-König @ 2025-09-19 9:29 UTC (permalink / raw)
To: devicetree-compiler; +Cc: David Gibson
Hello,
the motivation is to improve the result when compiling from dtb to dts.
By restoring the labels and phandles the noise in the output of dtdiff
is considerably reduced in many cases.
This is v2 of the series. (Implicit) v1 can be found at
https://lore.kernel.org/devicetree-compiler/cover.1755692822.git.u.kleine-koenig@baylibre.com
. The only change is an added return statement in an error case that i
missed to add. Thanks to David who spotted that.
Note that this series supersedes https://github.com/dgibson/dtc/pull/151
which can be closed once this series is in.
Best regards
Uwe
Uwe Kleine-König (6):
Emit /plugin/ when compiling to .dts with DTSF_PLUGIN set
Set DTSF_PLUGIN if needed when compiling from dtb
Improve type guessing when compiling to dts format
Restore labels from __symbols__ node
Restore phandle references from __local_fixups__ node
Restore phandle references from __fixups__ node
dtc.c | 5 ++
dtc.h | 6 ++
flattree.c | 6 +-
livetree.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++
treesource.c | 114 ++++++++++++++++++++++++---------
5 files changed, 273 insertions(+), 32 deletions(-)
base-commit: 9197f1ccd95c9475006677aa97bf39727c1e8aa5
--
2.51.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 1/6] Emit /plugin/ when compiling to .dts with DTSF_PLUGIN set
2025-09-19 9:29 [PATCH v2 0/6] Restore phandles from binary representations Uwe Kleine-König
@ 2025-09-19 9:29 ` Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 2/6] Set DTSF_PLUGIN if needed when compiling from dtb Uwe Kleine-König
` (5 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Uwe Kleine-König @ 2025-09-19 9:29 UTC (permalink / raw)
To: devicetree-compiler; +Cc: David Gibson
This fixes `dtc -I dts -O dts` to make the file a plugin if the source
file is one.
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
treesource.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/treesource.c b/treesource.c
index d25f01fc6937..72d1cb5508b5 100644
--- a/treesource.c
+++ b/treesource.c
@@ -369,7 +369,10 @@ void dt_to_source(FILE *f, struct dt_info *dti)
{
struct reserve_info *re;
- fprintf(f, "/dts-v1/;\n\n");
+ fprintf(f, "/dts-v1/;\n");
+ if (dti->dtsflags & DTSF_PLUGIN)
+ fprintf(f, "/plugin/;\n");
+ fprintf(f, "\n");
for (re = dti->reservelist; re; re = re->next) {
struct label *l;
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 2/6] Set DTSF_PLUGIN if needed when compiling from dtb
2025-09-19 9:29 [PATCH v2 0/6] Restore phandles from binary representations Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 1/6] Emit /plugin/ when compiling to .dts with DTSF_PLUGIN set Uwe Kleine-König
@ 2025-09-19 9:29 ` Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 3/6] Improve type guessing when compiling to dts format Uwe Kleine-König
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Uwe Kleine-König @ 2025-09-19 9:29 UTC (permalink / raw)
To: devicetree-compiler; +Cc: David Gibson
The need for the plugin flag is determined by the existence of __fixups__
or __local_fixups__.
This is a bit simplifying because if __fixups__ or __local_fixups__
exist but don't have properties, the plugin flag isn't needed. But in
practise the test should be good enough such that this corner case
doesn't matter.
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
flattree.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/flattree.c b/flattree.c
index 30e6de2044b2..f3b698c17e89 100644
--- a/flattree.c
+++ b/flattree.c
@@ -807,6 +807,7 @@ struct dt_info *dt_from_blob(const char *fname)
struct node *tree;
uint32_t val;
int flags = 0;
+ unsigned int dtsflags = DTSF_V1;
f = srcfile_relative_open(fname, NULL);
@@ -919,5 +920,8 @@ struct dt_info *dt_from_blob(const char *fname)
fclose(f);
- return build_dt_info(DTSF_V1, reservelist, tree, boot_cpuid_phys);
+ if (get_subnode(tree, "__fixups__") || get_subnode(tree, "__local_fixups__"))
+ dtsflags |= DTSF_PLUGIN;
+
+ return build_dt_info(dtsflags, reservelist, tree, boot_cpuid_phys);
}
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 3/6] Improve type guessing when compiling to dts format
2025-09-19 9:29 [PATCH v2 0/6] Restore phandles from binary representations Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 1/6] Emit /plugin/ when compiling to .dts with DTSF_PLUGIN set Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 2/6] Set DTSF_PLUGIN if needed when compiling from dtb Uwe Kleine-König
@ 2025-09-19 9:29 ` Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 4/6] Restore labels from __symbols__ node Uwe Kleine-König
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Uwe Kleine-König @ 2025-09-19 9:29 UTC (permalink / raw)
To: devicetree-compiler; +Cc: David Gibson
In the presence of (non-type) markers guess the type of each chunk
between markers individually instead of only once for the whole
property.
Note that this only gets relevant with the next few commits that restore
labels and phandles. Note further that this rework is necessary with
these further changes, because phandle markers are currently not
considered for type guessing and so a phandle at an offset that isn't a
multiple of 4 triggers an assertion if the property was guessed to have
type TYPE_UINT32.
Now that guess_value_type() is only called for data chunks without
markers, the function can be simplified a bit.
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
treesource.c | 70 ++++++++++++++++++++++++++++++----------------------
1 file changed, 40 insertions(+), 30 deletions(-)
diff --git a/treesource.c b/treesource.c
index 72d1cb5508b5..576495902f0d 100644
--- a/treesource.c
+++ b/treesource.c
@@ -173,23 +173,20 @@ static struct marker **add_marker(struct marker **mi,
return &nm->next;
}
-static void add_string_markers(struct property *prop)
+static void add_string_markers(struct property *prop, unsigned int offset, int len)
{
- int l, len = prop->val.len;
- const char *p = prop->val.val;
+ int l;
+ const char *p = prop->val.val + offset;
struct marker **mi = &prop->val.markers;
for (l = strlen(p) + 1; l < len; l += strlen(p + l) + 1)
- mi = add_marker(mi, TYPE_STRING, l, NULL);
+ mi = add_marker(mi, TYPE_STRING, offset + l, NULL);
}
-static enum markertype guess_value_type(struct property *prop)
+static enum markertype guess_value_type(struct property *prop, unsigned int offset, int len)
{
- int len = prop->val.len;
- const char *p = prop->val.val;
- struct marker *m = prop->val.markers;
+ const char *p = prop->val.val + offset;
int nnotstring = 0, nnul = 0;
- int nnotstringlbl = 0, nnotcelllbl = 0;
int i;
for (i = 0; i < len; i++) {
@@ -199,30 +196,49 @@ static enum markertype guess_value_type(struct property *prop)
nnul++;
}
- for_each_marker_of_type(m, LABEL) {
- if ((m->offset > 0) && (prop->val.val[m->offset - 1] != '\0'))
- nnotstringlbl++;
- if ((m->offset % sizeof(cell_t)) != 0)
- nnotcelllbl++;
- }
-
- if ((p[len-1] == '\0') && (nnotstring == 0) && (nnul <= (len-nnul))
- && (nnotstringlbl == 0)) {
+ if ((p[len-1] == '\0') && (nnotstring == 0) && (nnul <= len - nnul)) {
if (nnul > 1)
- add_string_markers(prop);
+ add_string_markers(prop, offset, len);
return TYPE_STRING;
- } else if (((len % sizeof(cell_t)) == 0) && (nnotcelllbl == 0)) {
+ } else if ((len % sizeof(cell_t)) == 0) {
return TYPE_UINT32;
}
return TYPE_UINT8;
}
+static void guess_type_markers(struct property *prop)
+{
+ struct marker **m = &prop->val.markers;
+ unsigned int offset = 0;
+
+ for (m = &prop->val.markers; *m; m = &((*m)->next)) {
+ if (is_type_marker((*m)->type))
+ /* assume the whole property is already marked */
+ return;
+
+ if ((*m)->offset > offset) {
+ m = add_marker(m, guess_value_type(prop, offset, (*m)->offset - offset),
+ offset, NULL);
+
+ offset = (*m)->offset;
+ }
+
+ if ((*m)->type == REF_PHANDLE) {
+ m = add_marker(m, TYPE_UINT32, offset, NULL);
+ offset += 4;
+ }
+ }
+
+ if (offset < prop->val.len)
+ add_marker(m, guess_value_type(prop, offset, prop->val.len - offset),
+ offset, NULL);
+}
+
static void write_propval(FILE *f, struct property *prop)
{
size_t len = prop->val.len;
- struct marker *m = prop->val.markers;
- struct marker dummy_marker;
+ struct marker *m;
enum markertype emit_type = TYPE_NONE;
char *srcstr;
@@ -241,14 +257,8 @@ static void write_propval(FILE *f, struct property *prop)
fprintf(f, " =");
- if (!next_type_marker(m)) {
- /* data type information missing, need to guess */
- dummy_marker.type = guess_value_type(prop);
- dummy_marker.next = prop->val.markers;
- dummy_marker.offset = 0;
- dummy_marker.ref = NULL;
- m = &dummy_marker;
- }
+ guess_type_markers(prop);
+ m = prop->val.markers;
for_each_marker(m) {
size_t chunk_len = (m->next ? m->next->offset : len) - m->offset;
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 4/6] Restore labels from __symbols__ node
2025-09-19 9:29 [PATCH v2 0/6] Restore phandles from binary representations Uwe Kleine-König
` (2 preceding siblings ...)
2025-09-19 9:29 ` [PATCH v2 3/6] Improve type guessing when compiling to dts format Uwe Kleine-König
@ 2025-09-19 9:29 ` Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 5/6] Restore phandle references from __local_fixups__ node Uwe Kleine-König
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Uwe Kleine-König @ 2025-09-19 9:29 UTC (permalink / raw)
To: devicetree-compiler; +Cc: David Gibson
If the input has a __symbols__ node, restore the named labels for the
respective nodes.
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
dtc.c | 2 ++
dtc.h | 1 +
livetree.c | 21 +++++++++++++++++++++
3 files changed, 24 insertions(+)
diff --git a/dtc.c b/dtc.c
index b3445b7d6473..63a6c85da5cf 100644
--- a/dtc.c
+++ b/dtc.c
@@ -338,6 +338,8 @@ int main(int argc, char *argv[])
if (auto_label_aliases)
generate_label_tree(dti, "aliases", false);
+ generate_labels_from_tree(dti, "__symbols__");
+
if (generate_symbols)
generate_label_tree(dti, "__symbols__", true);
diff --git a/dtc.h b/dtc.h
index 3a220b9afc99..f97f3c29e2d4 100644
--- a/dtc.h
+++ b/dtc.h
@@ -339,6 +339,7 @@ struct dt_info *build_dt_info(unsigned int dtsflags,
struct reserve_info *reservelist,
struct node *tree, uint32_t boot_cpuid_phys);
void sort_tree(struct dt_info *dti);
+void generate_labels_from_tree(struct dt_info *dti, const char *name);
void generate_label_tree(struct dt_info *dti, const char *name, bool allocph);
void generate_fixups_tree(struct dt_info *dti, const char *name);
void generate_local_fixups_tree(struct dt_info *dti, const char *name);
diff --git a/livetree.c b/livetree.c
index f328824c3bc6..8aafc9aa5cd6 100644
--- a/livetree.c
+++ b/livetree.c
@@ -1112,6 +1112,27 @@ static int generate_local_fixups_tree_internal(struct dt_info *dti,
return ret;
}
+void generate_labels_from_tree(struct dt_info *dti, const char *name)
+{
+ struct node *an;
+ struct property *p;
+
+ an = get_subnode(dti->dt, name);
+ if (!an)
+ return;
+
+ for_each_property(an, p) {
+ struct node *labeled_node;
+
+ labeled_node = get_node_by_path(dti->dt, p->val.val);
+ if (labeled_node)
+ add_label(&labeled_node->labels, p->name);
+ else if (quiet < 1)
+ fprintf(stderr, "Warning: Path %s referenced in property %s/%s missing",
+ p->val.val, name, p->name);
+ }
+}
+
void generate_label_tree(struct dt_info *dti, const char *name, bool allocph)
{
if (!any_label_tree(dti, dti->dt))
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 5/6] Restore phandle references from __local_fixups__ node
2025-09-19 9:29 [PATCH v2 0/6] Restore phandles from binary representations Uwe Kleine-König
` (3 preceding siblings ...)
2025-09-19 9:29 ` [PATCH v2 4/6] Restore labels from __symbols__ node Uwe Kleine-König
@ 2025-09-19 9:29 ` Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 6/6] Restore phandle references from __fixups__ node Uwe Kleine-König
2025-12-05 15:43 ` [PATCH v2 0/6] Restore phandles from binary representations Uwe Kleine-König
6 siblings, 0 replies; 11+ messages in thread
From: Uwe Kleine-König @ 2025-09-19 9:29 UTC (permalink / raw)
To: devicetree-compiler; +Cc: David Gibson
The __local_fixups__ node contains information about phandles. Parse it
to improve the result when decompiling a device tree blob.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
dtc.c | 2 ++
dtc.h | 2 ++
livetree.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++
treesource.c | 33 ++++++++++++++++++++++++++++++
4 files changed, 94 insertions(+)
diff --git a/dtc.c b/dtc.c
index 63a6c85da5cf..9f90b373967d 100644
--- a/dtc.c
+++ b/dtc.c
@@ -343,6 +343,8 @@ int main(int argc, char *argv[])
if (generate_symbols)
generate_label_tree(dti, "__symbols__", true);
+ local_fixup_phandles(dti, "__local_fixups__");
+
if (generate_fixups) {
generate_fixups_tree(dti, "__fixups__");
generate_local_fixups_tree(dti, "__local_fixups__");
diff --git a/dtc.h b/dtc.h
index f97f3c29e2d4..d07a583441f6 100644
--- a/dtc.h
+++ b/dtc.h
@@ -343,6 +343,7 @@ void generate_labels_from_tree(struct dt_info *dti, const char *name);
void generate_label_tree(struct dt_info *dti, const char *name, bool allocph);
void generate_fixups_tree(struct dt_info *dti, const char *name);
void generate_local_fixups_tree(struct dt_info *dti, const char *name);
+void local_fixup_phandles(struct dt_info *dti, const char *name);
/* Checks */
@@ -358,6 +359,7 @@ struct dt_info *dt_from_blob(const char *fname);
/* Tree source */
+void add_phandle_marker(struct dt_info *dti, struct property *prop, unsigned int offset);
void dt_to_source(FILE *f, struct dt_info *dti);
struct dt_info *dt_from_source(const char *f);
diff --git a/livetree.c b/livetree.c
index 8aafc9aa5cd6..3dbef9071017 100644
--- a/livetree.c
+++ b/livetree.c
@@ -1160,3 +1160,60 @@ void generate_local_fixups_tree(struct dt_info *dti, const char *name)
"Warning: Preexisting data in %s malformed, some content could not be added.\n",
name);
}
+
+static void local_fixup_phandles_node(struct dt_info *dti, struct node *lf, struct node *n)
+{
+ struct property *lfp;
+ struct node *lfsubnode;
+
+ for_each_property(lf, lfp) {
+ struct property *p = get_property(n, lfp->name);
+ fdt32_t *offsets = (fdt32_t *)lfp->val.val;
+ size_t i;
+
+ if (!p) {
+ if (quiet < 1)
+ fprintf(stderr, "Warning: Property %s in %s referenced in __local_fixups__ missing\n",
+ lfp->name, n->fullpath);
+ continue;
+ }
+
+ /*
+ * Each property in the __local_fixups__ tree is a concatenation
+ * of offsets, so it must be a multiple of sizeof(fdt32_t).
+ */
+ if (lfp->val.len % sizeof(fdt32_t)) {
+ if (quiet < 1)
+ fprintf(stderr, "Warning: property %s in /__local_fixups__%s malformed\n",
+ lfp->name, n->fullpath);
+ continue;
+ }
+
+ for (i = 0; i < lfp->val.len / sizeof(fdt32_t); i++)
+ add_phandle_marker(dti, p, dtb_ld32(offsets + i));
+ }
+
+ for_each_child(lf, lfsubnode) {
+ struct node *subnode = get_subnode(n, lfsubnode->name);
+
+ if (!subnode) {
+ if (quiet < 1)
+ fprintf(stderr, "Warning: node %s/%s referenced in __local_fixups__ missing\n",
+ lfsubnode->name, n->fullpath);
+ continue;
+ }
+
+ local_fixup_phandles_node(dti, lfsubnode, subnode);
+ }
+}
+
+void local_fixup_phandles(struct dt_info *dti, const char *name)
+{
+ struct node *an;
+
+ an = get_subnode(dti->dt, name);
+ if (!an)
+ return;
+
+ local_fixup_phandles_node(dti, an, dti->dt);
+}
diff --git a/treesource.c b/treesource.c
index 576495902f0d..e2eca63030a4 100644
--- a/treesource.c
+++ b/treesource.c
@@ -183,6 +183,39 @@ static void add_string_markers(struct property *prop, unsigned int offset, int l
mi = add_marker(mi, TYPE_STRING, offset + l, NULL);
}
+void add_phandle_marker(struct dt_info *dti, struct property *prop, unsigned int offset)
+{
+ cell_t phandle;
+ struct node *refn;
+ char *ref;
+
+ if (prop->val.len < offset + 4) {
+ if (quiet < 1)
+ fprintf(stderr,
+ "Warning: property %s too short to contain a phandle at offset %u\n",
+ prop->name, offset);
+ return;
+ }
+
+ phandle = dtb_ld32(prop->val.val + offset);
+ refn = get_node_by_phandle(dti->dt, phandle);
+
+ if (!refn) {
+ if (quiet < 1)
+ fprintf(stderr,
+ "Warning: node referenced by phandle 0x%x in property %s not found\n",
+ phandle, prop->name);
+ return;
+ }
+
+ if (refn->labels)
+ ref = refn->labels->label;
+ else
+ ref = refn->fullpath;
+
+ add_marker(&prop->val.markers, REF_PHANDLE, offset, ref);
+}
+
static enum markertype guess_value_type(struct property *prop, unsigned int offset, int len)
{
const char *p = prop->val.val + offset;
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 6/6] Restore phandle references from __fixups__ node
2025-09-19 9:29 [PATCH v2 0/6] Restore phandles from binary representations Uwe Kleine-König
` (4 preceding siblings ...)
2025-09-19 9:29 ` [PATCH v2 5/6] Restore phandle references from __local_fixups__ node Uwe Kleine-König
@ 2025-09-19 9:29 ` Uwe Kleine-König
2025-12-05 15:43 ` [PATCH v2 0/6] Restore phandles from binary representations Uwe Kleine-König
6 siblings, 0 replies; 11+ messages in thread
From: Uwe Kleine-König @ 2025-09-19 9:29 UTC (permalink / raw)
To: devicetree-compiler; +Cc: David Gibson
The __fixups__ node contains information about labels. Parse its
properties to create phandle markers which improve the resulting dts
when decompiling a device tree blob.
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
---
dtc.c | 1 +
dtc.h | 3 ++
livetree.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++
treesource.c | 6 ++++
4 files changed, 106 insertions(+)
diff --git a/dtc.c b/dtc.c
index 9f90b373967d..6dae60de0ea5 100644
--- a/dtc.c
+++ b/dtc.c
@@ -343,6 +343,7 @@ int main(int argc, char *argv[])
if (generate_symbols)
generate_label_tree(dti, "__symbols__", true);
+ fixup_phandles(dti, "__fixups__");
local_fixup_phandles(dti, "__local_fixups__");
if (generate_fixups) {
diff --git a/dtc.h b/dtc.h
index d07a583441f6..7231200e5d02 100644
--- a/dtc.h
+++ b/dtc.h
@@ -342,6 +342,7 @@ void sort_tree(struct dt_info *dti);
void generate_labels_from_tree(struct dt_info *dti, const char *name);
void generate_label_tree(struct dt_info *dti, const char *name, bool allocph);
void generate_fixups_tree(struct dt_info *dti, const char *name);
+void fixup_phandles(struct dt_info *dti, const char *name);
void generate_local_fixups_tree(struct dt_info *dti, const char *name);
void local_fixup_phandles(struct dt_info *dti, const char *name);
@@ -359,6 +360,8 @@ struct dt_info *dt_from_blob(const char *fname);
/* Tree source */
+void property_add_marker(struct property *prop,
+ enum markertype type, unsigned int offset, char *ref);
void add_phandle_marker(struct dt_info *dti, struct property *prop, unsigned int offset);
void dt_to_source(FILE *f, struct dt_info *dti);
struct dt_info *dt_from_source(const char *f);
diff --git a/livetree.c b/livetree.c
index 3dbef9071017..5d72abceb526 100644
--- a/livetree.c
+++ b/livetree.c
@@ -1151,6 +1151,102 @@ void generate_fixups_tree(struct dt_info *dti, const char *name)
name);
}
+void fixup_phandles(struct dt_info *dti, const char *name)
+{
+ struct node *an;
+ struct property *fp;
+
+ an = get_subnode(dti->dt, name);
+ if (!an)
+ return;
+
+ for_each_property(an, fp) {
+ char *fnext = fp->val.val;
+ char *fv;
+ unsigned int fl;
+
+ while ((fl = fp->val.len - (fnext - fp->val.val))) {
+ char *propname, *soffset;
+ struct node *n;
+ struct property *p;
+ long offset;
+
+ fv = fnext;
+ fnext = memchr(fv, 0, fl);
+
+ if (!fnext) {
+ if (quiet < 1)
+ fprintf(stderr, "Warning: Malformed fixup entry for label %s\n",
+ fp->name);
+ break;
+ }
+ fnext += 1;
+
+ propname = memchr(fv, ':', fnext - 1 - fv);
+ if (!propname) {
+ if (quiet < 1)
+ fprintf(stderr, "Warning: Malformed fixup entry for label %s\n",
+ fp->name);
+ continue;
+ }
+ propname++;
+
+ soffset = memchr(propname, ':', fnext - 1 - propname);
+ if (!soffset) {
+ if (quiet < 1)
+ fprintf(stderr, "Warning: Malformed fixup entry for label %s\n",
+ fp->name);
+ continue;
+ }
+ soffset++;
+
+ /*
+ * temporarily modify the property to not have to create
+ * a copy for the node path.
+ */
+ *(propname - 1) = '\0';
+
+ n = get_node_by_path(dti->dt, fv);
+ if (!n && quiet < 1)
+ fprintf(stderr, "Warning: Label %s references non-existing node %s\n",
+ fp->name, fv);
+
+ *(propname - 1) = ':';
+
+ if (!n)
+ continue;
+
+ /*
+ * temporarily modify the property to not have to create
+ * a copy for the property name.
+ */
+ *(soffset - 1) = '\0';
+
+ p = get_property(n, propname);
+
+ if (!p && quiet < 1)
+ fprintf(stderr, "Warning: Label %s references non-existing property %s in node %s\n",
+ fp->name, n->fullpath, propname);
+
+ *(soffset - 1) = ':';
+
+ if (!p)
+ continue;
+
+ offset = strtol(soffset, NULL, 0);
+ if (offset < 0 || offset + 4 > p->val.len) {
+ if (quiet < 1)
+ fprintf(stderr,
+ "Warning: Label %s contains invalid offset for property %s in node %s\n",
+ fp->name, p->name, n->fullpath);
+ continue;
+ }
+
+ property_add_marker(p, REF_PHANDLE, offset, fp->name);
+ }
+ }
+}
+
void generate_local_fixups_tree(struct dt_info *dti, const char *name)
{
if (!any_local_fixup_tree(dti, dti->dt))
diff --git a/treesource.c b/treesource.c
index e2eca63030a4..bf648bf6c21a 100644
--- a/treesource.c
+++ b/treesource.c
@@ -173,6 +173,12 @@ static struct marker **add_marker(struct marker **mi,
return &nm->next;
}
+void property_add_marker(struct property *prop,
+ enum markertype type, unsigned int offset, char *ref)
+{
+ add_marker(&prop->val.markers, type, offset, ref);
+}
+
static void add_string_markers(struct property *prop, unsigned int offset, int len)
{
int l;
--
2.51.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v2 0/6] Restore phandles from binary representations
2025-09-19 9:29 [PATCH v2 0/6] Restore phandles from binary representations Uwe Kleine-König
` (5 preceding siblings ...)
2025-09-19 9:29 ` [PATCH v2 6/6] Restore phandle references from __fixups__ node Uwe Kleine-König
@ 2025-12-05 15:43 ` Uwe Kleine-König
2025-12-08 6:20 ` David Gibson
6 siblings, 1 reply; 11+ messages in thread
From: Uwe Kleine-König @ 2025-12-05 15:43 UTC (permalink / raw)
To: David Gibson; +Cc: devicetree-compiler
[-- Attachment #1: Type: text/plain, Size: 638 bytes --]
Hello David,
On Fri, Sep 19, 2025 at 11:29:13AM +0200, Uwe Kleine-König wrote:
> the motivation is to improve the result when compiling from dtb to dts.
> By restoring the labels and phandles the noise in the output of dtdiff
> is considerably reduced in many cases.
>
> This is v2 of the series. (Implicit) v1 can be found at
> https://lore.kernel.org/devicetree-compiler/cover.1755692822.git.u.kleine-koenig@baylibre.com
> . The only change is an added return statement in an error case that i
> missed to add. Thanks to David who spotted that.
I wonder if you have this series still on your radar.
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 0/6] Restore phandles from binary representations
2025-12-05 15:43 ` [PATCH v2 0/6] Restore phandles from binary representations Uwe Kleine-König
@ 2025-12-08 6:20 ` David Gibson
2025-12-09 7:57 ` Uwe Kleine-König
0 siblings, 1 reply; 11+ messages in thread
From: David Gibson @ 2025-12-08 6:20 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: devicetree-compiler
[-- Attachment #1: Type: text/plain, Size: 979 bytes --]
On Fri, Dec 05, 2025 at 04:43:43PM +0100, Uwe Kleine-König wrote:
> Hello David,
>
> On Fri, Sep 19, 2025 at 11:29:13AM +0200, Uwe Kleine-König wrote:
> > the motivation is to improve the result when compiling from dtb to dts.
> > By restoring the labels and phandles the noise in the output of dtdiff
> > is considerably reduced in many cases.
> >
> > This is v2 of the series. (Implicit) v1 can be found at
> > https://lore.kernel.org/devicetree-compiler/cover.1755692822.git.u.kleine-koenig@baylibre.com
> > . The only change is an added return statement in an error case that i
> > missed to add. Thanks to David who spotted that.
>
> I wonder if you have this series still on your radar.
Theoretically, yes. Finding time to look as been.. challenging :(.
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 0/6] Restore phandles from binary representations
2025-12-08 6:20 ` David Gibson
@ 2025-12-09 7:57 ` Uwe Kleine-König
2026-01-16 2:51 ` David Gibson
0 siblings, 1 reply; 11+ messages in thread
From: Uwe Kleine-König @ 2025-12-09 7:57 UTC (permalink / raw)
To: David Gibson; +Cc: devicetree-compiler
[-- Attachment #1: Type: text/plain, Size: 1040 bytes --]
Hello David,
On Mon, Dec 08, 2025 at 05:20:09PM +1100, David Gibson wrote:
> On Fri, Dec 05, 2025 at 04:43:43PM +0100, Uwe Kleine-König wrote:
> > On Fri, Sep 19, 2025 at 11:29:13AM +0200, Uwe Kleine-König wrote:
> > > the motivation is to improve the result when compiling from dtb to dts.
> > > By restoring the labels and phandles the noise in the output of dtdiff
> > > is considerably reduced in many cases.
> > >
> > > This is v2 of the series. (Implicit) v1 can be found at
> > > https://lore.kernel.org/devicetree-compiler/cover.1755692822.git.u.kleine-koenig@baylibre.com
> > > . The only change is an added return statement in an error case that i
> > > missed to add. Thanks to David who spotted that.
> >
> > I wonder if you have this series still on your radar.
>
> Theoretically, yes. Finding time to look as been.. challenging :(.
OK, now that I know that it's not forgotten, I can be patient. I know
the time phases where it's hardly possible to care for the non-paid
duties.
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 0/6] Restore phandles from binary representations
2025-12-09 7:57 ` Uwe Kleine-König
@ 2026-01-16 2:51 ` David Gibson
0 siblings, 0 replies; 11+ messages in thread
From: David Gibson @ 2026-01-16 2:51 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: devicetree-compiler
[-- Attachment #1: Type: text/plain, Size: 1366 bytes --]
On Tue, Dec 09, 2025 at 08:57:59AM +0100, Uwe Kleine-König wrote:
> Hello David,
>
> On Mon, Dec 08, 2025 at 05:20:09PM +1100, David Gibson wrote:
> > On Fri, Dec 05, 2025 at 04:43:43PM +0100, Uwe Kleine-König wrote:
> > > On Fri, Sep 19, 2025 at 11:29:13AM +0200, Uwe Kleine-König wrote:
> > > > the motivation is to improve the result when compiling from dtb to dts.
> > > > By restoring the labels and phandles the noise in the output of dtdiff
> > > > is considerably reduced in many cases.
> > > >
> > > > This is v2 of the series. (Implicit) v1 can be found at
> > > > https://lore.kernel.org/devicetree-compiler/cover.1755692822.git.u.kleine-koenig@baylibre.com
> > > > . The only change is an added return statement in an error case that i
> > > > missed to add. Thanks to David who spotted that.
> > >
> > > I wonder if you have this series still on your radar.
> >
> > Theoretically, yes. Finding time to look as been.. challenging :(.
>
> OK, now that I know that it's not forgotten, I can be patient. I know
> the time phases where it's hardly possible to care for the non-paid
> duties.
Merged!
Sorry it's taken so long.
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2026-01-16 2:52 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-19 9:29 [PATCH v2 0/6] Restore phandles from binary representations Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 1/6] Emit /plugin/ when compiling to .dts with DTSF_PLUGIN set Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 2/6] Set DTSF_PLUGIN if needed when compiling from dtb Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 3/6] Improve type guessing when compiling to dts format Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 4/6] Restore labels from __symbols__ node Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 5/6] Restore phandle references from __local_fixups__ node Uwe Kleine-König
2025-09-19 9:29 ` [PATCH v2 6/6] Restore phandle references from __fixups__ node Uwe Kleine-König
2025-12-05 15:43 ` [PATCH v2 0/6] Restore phandles from binary representations Uwe Kleine-König
2025-12-08 6:20 ` David Gibson
2025-12-09 7:57 ` Uwe Kleine-König
2026-01-16 2:51 ` David Gibson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox