Skip to contentSkip to conversation

Add support for dtb metadata and addon device-trees

RFC PATCH Superseded Herve Codina 4 participants 160 messages Jan 12 – Jan 29 Page 1 of 2

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add support for dtb metadata and addon device-trees

This big picture series adds support for dtb metadata and addon device-trees.

Before giving details about the series content, let me give a little bit of context.

The use-case is to support additional boards that can be hot-plugged to a connector available in a base board. This connector is standardized in terms of resources available on each pin. Any additional boards compatible with the connector should be able to be connected to base board and all base boards where this connector is implemented should support any additional boards.

TLDR: The last patch, patch 77, gives an example of dts and dtsa (new
addon device-tree) handling this use-case. It provides an example of a realistic base board description (dts) and an realistic additional board description (dtsa).

Each base board is described by its own device-tree and the real resource connected to the connector depends on each board. For instance an i2c bus on the connector can come from the i2c1 controller from base board A and i2c5 controller from base board B. This is obviously the case for all resources wired to the connector.

On the other hand, the device-tree describing the additional board has no reason to be changed based on the base board the additional board is going to be connected. Indeed this device-tree describes the additional board hardware and this hardware doesn't change if the additional board is connected to the base board A or the base board B.

In order to extend a device-tree at runtime, a device-tree overlay can be used. The drawback of current overlay implementation is that an overlay is tightly coupled with the base device-tree it is applied to.

If a symbol of the base device-tree has to be used by the overlay, all symbols available in the base device-tree need to be visible by the overlay and the overlay can use only those symbol without any kind of name translation.

With current overlay implementation, a overlay depends on the base board. Indeed, if an overlay wants to add an I2C device on the I2C bus available on the base board A connector, it needs to reference the i2c1 bus whereas it needs to reference the i2c5 bus if it used with the base board B.

In order to fix the issue, the 'export symbol' concept has been proposed. This concept allows some specific node to 'export' symbols in order to be seen by an overlay applied to this node.

The use-case and the export symbol proposal have been detailed during a talk at ELCE 2025. Have a look at the slides [1] and/or the video [2] to have a clear view of the topic

[1] https://bootlin.com/pub/conferences/2025/elce/ceresoli-hotplug-status.pdf
[2] https://www.youtube.com/watch?v=C8dEQ4OzMnc

The export symbol proposal based on an export-symbol node in the device-tree have been rejected by device-tree and dtc maintainers.

A discussion about the topic has been started on the mailing-list [3]. This discussions led to:

- The addition of meta-data in dtb instead of having __fixup__, __local__fixup__, an similar nodes in the device-tree used by overlays

- A new kind of device-tree, an addon device-tree, in order to replace the usage of the overlay device-tree in this 'hot-plugging additional board' use-case.

[3] https://lore.kernel.org/all/20250902105710.00512c6d@booty/

This current RFC is the implementation of features discussed on the mailing-list. A lot of things are new in dtb format (new tags) and dts format (new keyword, new kind of references) and not yet mentioned in the standard.

The purpose of this big picture RFC is to move forward on this topic based on code and some concrete dts / dtb example. Indeed, this RFC also adds tests for each feature introduced. Those tests are performed using dts files and the content of those dts files can also help in the discussion.

The first patch is just a simple fix and can probably be merged out of this meta-data and addon discussion.

- Patches 2..12: Introduce new meta-data dtb tags based on markers

Those new tags are FDT_REF_LOCAL and FDT_REF_PHANDLE.

FDT_REF_LOCAL (details in patch 6) is used to tag property using a phandle and this phandle points to a local node (i.e. a node existing in the dtb).

FDT_REF_PHANDLE (details in patch 11) is used to tag a property using a phandle but this phandle points to a non local node (i.e. the node doesn't exist in the dtb). The reference to the node is present with the tag and the phandle value has to be fixed when the dtb is applied. This tag can only be present in plugins (overlays) and addons dtb.

- Patches 13..17: Introduce addons device-tree

This part introduce the new /addon/ dts keyword

- Patches 18..30: Introduce /export/ keyword and related dtb tags

This part introduces the new /export/ dts keyword (details in patch
20) and the related FDT_EXPORT_SYM and FDT_EXPORT_SYM_REF dtb tags.

FDT_EXPORT_SYM (details in patch 25) is used when the exported symbol involved is a local node and FDT_EXPORT_SYM_REF (details in patch 29) is used when the node involved is a non local node.

- Patches 31..38: Introduce /import/ keyword and related dtb tags

This part introduces the new /import/ dts keyword (details in patch
33) and the related FDT_IMPORT_SYM dtb tag (details in patch 35).

- Patches 39..63: Introduce orphan nodes

Even if the orphan nodes concept was already present in overlays, the final encoding of those nodes in addon dtbs is different compared to overlays dtbs.

In overlays, orphan nodes are transformed to a /fragment@n/__overlay__ node. This is not the way used in addons.

Indeed, in addons, orphan nodes are not transformed to fit in something like /fragment@n/__overlay__. They are encoded in the dtb using a specific tag.

This part, after some preparation, introduces orphan nodes (details in patch 48) and the related FDT_BEGIN_NODE_REF_SYM dtb tag (details in patch 56).

It also adds support for addons dts/dtb without a 'root' (details in patch 58).

This part ended with the support for merging orphan node described in dts when relevant (details patch 60).

- Patches 64..65: Reference orphan nodes and its sub-nodes by path

A new syntax is needed to be able to reference a an orphan node and its sub-nodes by path.

This new syntax is '${$<orphan_name>/<path>}' (details in patch #60)

- Patches 66..67: Namespace labels references

Add Namespace labels references with the new syntax '&foo.bar.baz'.

This new syntax, only allowed in addons, allows to 'jump' from node to node based on exported symbols defined at each node (details in patch 66).

- Patches 68..71: Support for applying an addon

First, add fdt_addon_apply() in libfdt (details in patch 70) and then the fdtaddon command line tool (details in patch 71).

- Patches 72..76: fdtaddon test

Several tests related to addon application

- Patch 77: A more Realistic test

A last test based on use-case we want to handle.

This last patch (and its dts and dtsa files) shows the kind of usage is expected for addons.

Also it proves that metadata and addons features handles our use-case.

I know this series is a huge series but I would like to give the big picture in this RFC (I hope this was a good idea). Of course, this series can be split for the upstreaming step and handled by parts by parts. Let me know.

Tests are provided for each feature. In addition to be used for testing, tests input source files and expected output files can be used to see the expected behavior related to each feature.

I hope also that this first RFC will help in moving forward regarding this 'handling an additional board described by a device-tree' topic.

Best regards,
Hervé

Herve Codina (77):
checks: Use consistent type for strspn() returned value Introduce v18 dtb version
libfdt: Introduce fdt_next_tag_full() and use it in fdt_next_tag()
dtc: Allow to use data_append_markers() out of data.c
fdtdump: Change FDT_PROP prob handling to ease future addition Add support for FDT_REF_LOCAL dtb tag
livetree: Improve get_node_by_phandle()
dtc: Introduce update_phandles_ref()
dtc: Introduce mark_local_phandles()
tests: Add basic metadata tests
Add support for FDT_REF_PHANDLE dtb tag
tests: metadata: Add external phandle reference tests Introduce dt_flags field in dtb header
tests: metadata: Add a first test related to the dt_flags header field Add support for /addon/ keyword
tests: metadata: Add a test related to addon dt_flags header value
tests: metadata: Add a basic addon test
dtc-parser.y: Avoid an empty proplist
dtc: Introduce export symbols
dtc: Add support for /export/ dts keyword parsing
checks: Handle export symbols in fixup_phandle_references()
dtc: Add export symbols (/export/ keyword) in generated dts file
dtc: Introduce mark_local_exports()
dtc: Introduce update_exports_ref()
Add support for FDT_EXPORT_SYM dtb tag
tests: metadata: Add export symbols with local references tests
dtc: Add support for export symbols sorting
tests: metadata: Add a test for export symbols sorting
Add support for FDT_EXPORT_SYM_REF dtb tag
tests: metadata: Add export symbols with external references tests
dtc: Introduce import symbols
dtc-parser: Introduce last_header_flags
dtc: Add support for /import/ dts keyword parsing
dtc: Add import symbols (/import/ keyword) in generated dts file Add support for FDT_IMPORT_SYM dtb tag
tests: metadata: Add import symbols tests
dtc: Add support for import symbols sorting
tests: metadata: Improve sort test to check for import symbols sorting
check: Get 'chosen' node using get_subnode()
dtc: Introduce dti_get_node_by_path()
dtc: Introduce dti_get_node_by_label()
dtc: Introduce dti_get_node_by_phandle()
dtc: Introduce dti_get_node_by_ref()
dtc: Introduce dti_get_node_phandle()
dtc: Introduce dti_get_property_by_label()
dtc: Introduce dti_get_marker_label()
dtc: Introduce dti_fill_fullpaths()
dtc: Introduce orphan nodes
dtc: Handle orphan nodes in dti_get_xxx_by_yyy()
dtc: Handle orphan nodes in mark_local_xxx() and update_xxx_ref()
dtc: Avoid NULL fullpath for nodes in orphan trees
checks: Perform checks for orphan nodes
dtc: Rename add_orphan_node() to plugin_add_orphan_node()
dtc: Add basic support for addon orphan nodes dts parsing
dtc: Add orphan nodes in generated dts file
Add support for FDT_BEGIN_NODE_REF_SYM dtb tag
tests: metadata: Add basic test for addon orphan nodes
dtc: Add support for missing root node in addon device-tree
tests: metadata: Add a test for addon without root node
dtc: Allow parser_get_node_by_ref() to return an orphan node for
merging purpose
tests: metadata: Add a test related to orphan node merging
dtc: Add support for orphan nodes sorting
tests: metadata: Improve sort test to check for orphan nodes sorting
dtc: Add support for references by path involving orphan nodes
tests: metadata: Add a test for references by path involving orphan
nodes
dtc: Add support for namespace labels references
tests: metadata: Add a test for namespace labels references
libfdt: Introduce fdt_getprop_by_offset_w()
libfdt: Introduce fdt_getprop_offset()
libfdt: Add support for applying an addon on a base device-tree blob Add fdtaddon tool to apply an addon
tests: Add a first basic test for fdtaddon
tests: fdtaddon: Add a basic test for addons using an orphan nodes
tests: fdtaddon: Add a basic test for addons with unresolved phandle
references
tests: fdtaddon: Add a test for addons using namespace label
references
tests: fdtaddon: Add a test for using 'stacked' addons
tests: fdtaddon: Add a test using more realistic dts and dtsa

 Makefile                                      |    5 +
 checks.c                                      |  135 +-
 data.c                                        |    3 +-
 dtc-lexer.l                                   |   37 +
 dtc-parser.y                                  |  307 +++-
 dtc.c                                         |   64 +-
 dtc.h                                         |   72 +-
 fdtaddon.c                                    |  197 ++
 fdtdump.c                                     |  114 +-
 flattree.c                                    |  396 +++-
 fstree.c                                      |    5 +-
 libfdt/Makefile.libfdt                        |    2 +-
 libfdt/fdt.c                                  |  152 +-
 libfdt/fdt.h                                  |   15 +
 libfdt/fdt_addon.c                            | 1636 +++++++++++++++++
 libfdt/fdt_ro.c                               |   12 +
 libfdt/fdt_rw.c                               |  102 +-
 libfdt/libfdt.h                               |   60 +-
 libfdt/libfdt_internal.h                      |    7 +
 libfdt/meson.build                            |    1 +
 libfdt/version.lds                            |    2 +
 livetree.c                                    |  563 +++++-
 meson.build                                   |    2 +-
 ...ddon_addon_namespace-merged.dtb.dts.expect |   57 +
 ...fdtaddon_addon_namespace-merged.dtb.expect |   49 +
 tests/fdtaddon_addon_namespace.dtba.expect    |   31 +
 tests/fdtaddon_addon_namespace.dtsa           |   34 +
 tests/fdtaddon_base.dtb.expect                |   24 +
 tests/fdtaddon_base.dts                       |   27 +
 tests/fdtaddon_base_namespace.dtb.expect      |   29 +
 tests/fdtaddon_base_namespace.dts             |   33 +
 tests/fdtaddon_basics1-merged1.dtb.dts.expect |   35 +
 tests/fdtaddon_basics1-merged1.dtb.expect     |   27 +
 tests/fdtaddon_basics1-merged2.dtb.dts.expect |   35 +
 tests/fdtaddon_basics1-merged2.dtb.expect     |   27 +
 tests/fdtaddon_basics1.dtba.expect            |    8 +
 tests/fdtaddon_basics1.dtsa                   |   13 +
 tests/fdtaddon_basics2-merged1.dtb.dts.expect |   35 +
 tests/fdtaddon_basics2-merged1.dtb.expect     |   27 +
 tests/fdtaddon_basics2-merged2.dtb.dts.expect |   35 +
 tests/fdtaddon_basics2-merged2.dtb.expect     |   27 +
 tests/fdtaddon_basics2.dtba.expect            |    9 +
 tests/fdtaddon_basics2.dtsa                   |   15 +
 tests/fdtaddon_basics3-merged1.dtb.dts.expect |   36 +
 tests/fdtaddon_basics3-merged1.dtb.expect     |   29 +
 tests/fdtaddon_basics3-merged2.dtb.dts.expect |   36 +
 tests/fdtaddon_basics3-merged2.dtb.expect     |   29 +
 tests/fdtaddon_basics3.dtba.expect            |   12 +
 tests/fdtaddon_basics3.dtsa                   |   17 +
 ...ddon_realistic_addon-merged.dtb.dts.expect |   91 +
 ...fdtaddon_realistic_addon-merged.dtb.expect |   93 +
 tests/fdtaddon_realistic_addon.dtba.expect    |   32 +
 tests/fdtaddon_realistic_addon.dtsa           |   50 +
 tests/fdtaddon_realistic_base.dtb.expect      |   72 +
 tests/fdtaddon_realistic_base.dts             |   74 +
 .../fdtaddon_stack_1st-merged.dtb.dts.expect  |   51 +
 tests/fdtaddon_stack_1st-merged.dtb.expect    |   41 +
 tests/fdtaddon_stack_1st.dtba.expect          |   24 +
 tests/fdtaddon_stack_1st.dtsa                 |   27 +
 .../fdtaddon_stack_2nd-merged.dtb.dts.expect  |   70 +
 tests/fdtaddon_stack_2nd-merged.dtb.expect    |   59 +
 tests/fdtaddon_stack_2nd.dtba.expect          |   30 +
 tests/fdtaddon_stack_2nd.dtsa                 |   35 +
 tests/meson.build                             |    4 +-
 tests/metadata_addon_base.dtb.dts.expect      |   10 +
 tests/metadata_addon_base.dtb.expect          |   10 +
 tests/metadata_addon_base.dts                 |   14 +
 tests/metadata_addon_base.dts.dts.expect      |   10 +
 tests/metadata_addon_orphan1.dtb.dts.expect   |   16 +
 tests/metadata_addon_orphan1.dtb.expect       |   13 +
 tests/metadata_addon_orphan1.dts              |   19 +
 tests/metadata_addon_orphan1.dts.dts.expect   |   16 +
 tests/metadata_addon_orphan2.dtb.dts.expect   |   10 +
 tests/metadata_addon_orphan2.dtb.expect       |    8 +
 tests/metadata_addon_orphan2.dts              |   13 +
 tests/metadata_addon_orphan2.dts.dts.expect   |   10 +
 tests/metadata_addon_orphan3.dtb.dts.expect   |   22 +
 tests/metadata_addon_orphan3.dtb.expect       |   17 +
 tests/metadata_addon_orphan3.dts              |   28 +
 tests/metadata_addon_orphan3.dts.dts.expect   |   22 +
 .../metadata_addon_references.dtb.dts.expect  |   48 +
 tests/metadata_addon_references.dtb.expect    |   48 +
 tests/metadata_addon_references.dts           |   43 +
 .../metadata_addon_references.dts.dts.expect  |   48 +
 ...metadata_addon_refnamespace.dtb.dts.expect |   32 +
 tests/metadata_addon_refnamespace.dtb.expect  |   29 +
 tests/metadata_addon_refnamespace.dts         |   38 +
 ...metadata_addon_refnamespace.dts.dts.expect |   32 +
 tests/metadata_dtflags0.dtb.expect            |    1 +
 tests/metadata_dtflags0.dts                   |   10 +
 tests/metadata_dtflags1.dtb.expect            |    1 +
 tests/metadata_dtflags1.dts                   |   11 +
 .../metadata_exportsyms_local.dtb.dts.expect  |   26 +
 tests/metadata_exportsyms_local.dtb.expect    |   20 +
 tests/metadata_exportsyms_local.dts           |   28 +
 .../metadata_exportsyms_local.dts.dts.expect  |   26 +
 tests/metadata_exportsyms_ref.dtb.dts.expect  |   25 +
 tests/metadata_exportsyms_ref.dtb.expect      |   18 +
 tests/metadata_exportsyms_ref.dts             |   26 +
 tests/metadata_exportsyms_ref.dts.dts.expect  |   25 +
 tests/metadata_importsyms.dtb.dts.expect      |    9 +
 tests/metadata_importsyms.dtb.expect          |    8 +
 tests/metadata_importsyms.dts                 |   14 +
 tests/metadata_importsyms.dts.dts.expect      |    9 +
 tests/metadata_reflocal.dtb.dts.expect        |   23 +
 tests/metadata_reflocal.dtb.expect            |   20 +
 tests/metadata_reflocal.dts                   |   27 +
 tests/metadata_reflocal.dts.dts.expect        |   23 +
 tests/metadata_refphandle.dtb.dts.expect      |   17 +
 tests/metadata_refphandle.dtb.expect          |   16 +
 tests/metadata_refphandle.dts                 |   11 +
 tests/metadata_refphandle.dts.dts.expect      |   17 +
 tests/metadata_sort.dtb.dts.expect            |   61 +
 tests/metadata_sort.dtb.expect                |   48 +
 tests/metadata_sort.dts                       |   58 +
 tests/pylibfdt_tests.py                       |    8 +-
 tests/run_tests.sh                            |  176 +-
 tests/testutils.c                             |    2 +-
 tests/testutils.sh                            |    1 +
 tests/trees.S                                 |    3 +-
 treesource.c                                  |   42 +-
 121 files changed, 6552 insertions(+), 192 deletions(-)
 create mode 100644 fdtaddon.c
 create mode 100644 libfdt/fdt_addon.c
 create mode 100644 tests/fdtaddon_addon_namespace-merged.dtb.dts.expect
 create mode 100644 tests/fdtaddon_addon_namespace-merged.dtb.expect
 create mode 100644 tests/fdtaddon_addon_namespace.dtba.expect
 create mode 100644 tests/fdtaddon_addon_namespace.dtsa
 create mode 100644 tests/fdtaddon_base.dtb.expect
 create mode 100644 tests/fdtaddon_base.dts
 create mode 100644 tests/fdtaddon_base_namespace.dtb.expect
 create mode 100644 tests/fdtaddon_base_namespace.dts
 create mode 100644 tests/fdtaddon_basics1-merged1.dtb.dts.expect
 create mode 100644 tests/fdtaddon_basics1-merged1.dtb.expect
 create mode 100644 tests/fdtaddon_basics1-merged2.dtb.dts.expect
 create mode 100644 tests/fdtaddon_basics1-merged2.dtb.expect
 create mode 100644 tests/fdtaddon_basics1.dtba.expect
 create mode 100644 tests/fdtaddon_basics1.dtsa
 create mode 100644 tests/fdtaddon_basics2-merged1.dtb.dts.expect
 create mode 100644 tests/fdtaddon_basics2-merged1.dtb.expect
 create mode 100644 tests/fdtaddon_basics2-merged2.dtb.dts.expect
 create mode 100644 tests/fdtaddon_basics2-merged2.dtb.expect
 create mode 100644 tests/fdtaddon_basics2.dtba.expect
 create mode 100644 tests/fdtaddon_basics2.dtsa
 create mode 100644 tests/fdtaddon_basics3-merged1.dtb.dts.expect
 create mode 100644 tests/fdtaddon_basics3-merged1.dtb.expect
 create mode 100644 tests/fdtaddon_basics3-merged2.dtb.dts.expect
 create mode 100644 tests/fdtaddon_basics3-merged2.dtb.expect
 create mode 100644 tests/fdtaddon_basics3.dtba.expect
 create mode 100644 tests/fdtaddon_basics3.dtsa
 create mode 100644 tests/fdtaddon_realistic_addon-merged.dtb.dts.expect
 create mode 100644 tests/fdtaddon_realistic_addon-merged.dtb.expect
 create mode 100644 tests/fdtaddon_realistic_addon.dtba.expect
 create mode 100644 tests/fdtaddon_realistic_addon.dtsa
 create mode 100644 tests/fdtaddon_realistic_base.dtb.expect
 create mode 100644 tests/fdtaddon_realistic_base.dts
 create mode 100644 tests/fdtaddon_stack_1st-merged.dtb.dts.expect
 create mode 100644 tests/fdtaddon_stack_1st-merged.dtb.expect
 create mode 100644 tests/fdtaddon_stack_1st.dtba.expect
 create mode 100644 tests/fdtaddon_stack_1st.dtsa
 create mode 100644 tests/fdtaddon_stack_2nd-merged.dtb.dts.expect
 create mode 100644 tests/fdtaddon_stack_2nd-merged.dtb.expect
 create mode 100644 tests/fdtaddon_stack_2nd.dtba.expect
 create mode 100644 tests/fdtaddon_stack_2nd.dtsa
 create mode 100644 tests/metadata_addon_base.dtb.dts.expect
 create mode 100644 tests/metadata_addon_base.dtb.expect
 create mode 100644 tests/metadata_addon_base.dts
 create mode 100644 tests/metadata_addon_base.dts.dts.expect
 create mode 100644 tests/metadata_addon_orphan1.dtb.dts.expect
 create mode 100644 tests/metadata_addon_orphan1.dtb.expect
 create mode 100644 tests/metadata_addon_orphan1.dts
 create mode 100644 tests/metadata_addon_orphan1.dts.dts.expect
 create mode 100644 tests/metadata_addon_orphan2.dtb.dts.expect
 create mode 100644 tests/metadata_addon_orphan2.dtb.expect
 create mode 100644 tests/metadata_addon_orphan2.dts
 create mode 100644 tests/metadata_addon_orphan2.dts.dts.expect
 create mode 100644 tests/metadata_addon_orphan3.dtb.dts.expect
 create mode 100644 tests/metadata_addon_orphan3.dtb.expect
 create mode 100644 tests/metadata_addon_orphan3.dts
 create mode 100644 tests/metadata_addon_orphan3.dts.dts.expect
 create mode 100644 tests/metadata_addon_references.dtb.dts.expect
 create mode 100644 tests/metadata_addon_references.dtb.expect
 create mode 100644 tests/metadata_addon_references.dts
 create mode 100644 tests/metadata_addon_references.dts.dts.expect
 create mode 100644 tests/metadata_addon_refnamespace.dtb.dts.expect
 create mode 100644 tests/metadata_addon_refnamespace.dtb.expect
 create mode 100644 tests/metadata_addon_refnamespace.dts
 create mode 100644 tests/metadata_addon_refnamespace.dts.dts.expect
 create mode 100644 tests/metadata_dtflags0.dtb.expect
 create mode 100644 tests/metadata_dtflags0.dts
 create mode 100644 tests/metadata_dtflags1.dtb.expect
 create mode 100644 tests/metadata_dtflags1.dts
 create mode 100644 tests/metadata_exportsyms_local.dtb.dts.expect
 create mode 100644 tests/metadata_exportsyms_local.dtb.expect
 create mode 100644 tests/metadata_exportsyms_local.dts
 create mode 100644 tests/metadata_exportsyms_local.dts.dts.expect
 create mode 100644 tests/metadata_exportsyms_ref.dtb.dts.expect
 create mode 100644 tests/metadata_exportsyms_ref.dtb.expect
 create mode 100644 tests/metadata_exportsyms_ref.dts
 create mode 100644 tests/metadata_exportsyms_ref.dts.dts.expect
 create mode 100644 tests/metadata_importsyms.dtb.dts.expect
 create mode 100644 tests/metadata_importsyms.dtb.expect
 create mode 100644 tests/metadata_importsyms.dts
 create mode 100644 tests/metadata_importsyms.dts.dts.expect
 create mode 100644 tests/metadata_reflocal.dtb.dts.expect
 create mode 100644 tests/metadata_reflocal.dtb.expect
 create mode 100644 tests/metadata_reflocal.dts
 create mode 100644 tests/metadata_reflocal.dts.dts.expect
 create mode 100644 tests/metadata_refphandle.dtb.dts.expect
 create mode 100644 tests/metadata_refphandle.dtb.expect
 create mode 100644 tests/metadata_refphandle.dts
 create mode 100644 tests/metadata_refphandle.dts.dts.expect
 create mode 100644 tests/metadata_sort.dtb.dts.expect
 create mode 100644 tests/metadata_sort.dtb.expect
 create mode 100644 tests/metadata_sort.dts
Signature · 1 line
2.52.0
#1 lore raw

RFC PATCH 1/77 checks: Use consistent type for strspn() returned value

strspn() returns a size_t value.

The function is called in several places and in all places this value is stored in a size_t variable except in check_node_name_chars_strict().

Fix the variable type used in check_node_name_chars_strict().

---
 checks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
checks.c +1 -1
index 5d09216..041e565 100644
@@ -324,7 +324,7 @@ ERROR(node_name_chars, check_node_name_chars, NODECHARS);
 static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,
 					 struct node *node)
 {
-	int n = strspn(node->name, c->data);
+	size_t n = strspn(node->name, c->data);
 
 	if (n < node->basenamelen)
 		FAIL(c, dti, node, "Character '%c' not recommended in node name",
Signature · 1 line
2.52.0
Reviewed-by on v1 1/77
#2 lore raw

Re: [RFC PATCH 01/77] checks: Use consistent type for strspn() returned value

Quoted 17 lines · Herve Codina

strspn() returns a size_t value.

The function is called in several places and in all places this value is stored in a size_t variable except in check_node_name_chars_strict().

Fix the variable type used in check_node_name_chars_strict().

---
  checks.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
checks.c +0 -0
index 5d09216..041e565 100644

checks.c ERROR(node_name_chars, check_node_name_chars, NODECHARS); · line 330

Quoted 8 lines
checks.c +1 -1
@@ -324,7 +324,7 @@ ERROR(node_name_chars, check_node_name_chars, NODECHARS);
  static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,
  					 struct node *node)
  {
-	int n = strspn(node->name, c->data);
+	size_t n = strspn(node->name, c->data);
 
  	if (n < node->basenamelen)
  		FAIL(c, dti, node, "Character '%c' not recommended in node name",
#3 lore raw

Re: [RFC PATCH 01/77] checks: Use consistent type for strspn() returned value

In reply to Herve Codina
Quoted 8 lines · Herve Codina

strspn() returns a size_t value.

The function is called in several places and in all places this value is stored in a size_t variable except in check_node_name_chars_strict().

Fix the variable type used in check_node_name_chars_strict().

This one makes sense regardless of the rest, so, merged.

Quoted 21 lines
---
 checks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
checks.c +1 -1
index 5d09216..041e565 100644
@@ -324,7 +324,7 @@ ERROR(node_name_chars, check_node_name_chars, NODECHARS);
 static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,
 					 struct node *node)
 {
-	int n = strspn(node->name, c->data);
+	size_t n = strspn(node->name, c->data);
 
 	if (n < node->basenamelen)
 		FAIL(c, dti, node, "Character '%c' not recommended in node name",
Signature · 1 line
2.52.0
Signature · 4 lines
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
#4 lore raw

Re: [RFC PATCH 01/77] checks: Use consistent type for strspn() returned value

Quoted 11 lines · David Gibson
Quoted 8 lines · Herve Codina

strspn() returns a size_t value.

The function is called in several places and in all places this value is stored in a size_t variable except in check_node_name_chars_strict().

Fix the variable type used in check_node_name_chars_strict().

This one makes sense regardless of the rest, so, merged.

I spoke too soon. This causes a compile error:

https://github.com/dgibson/dtc/actions/runs/20944813954/job/60185662154#step:5:130

For some reason it's only showing on the make build, not meson. I guess there must be a mismatch in which warnings are enabled.

Quoted 28 lines
Quoted 22 lines
---
 checks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
checks.c +1 -1
index 5d09216..041e565 100644
@@ -324,7 +324,7 @@ ERROR(node_name_chars, check_node_name_chars, NODECHARS);
 static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,
 					 struct node *node)
 {
-	int n = strspn(node->name, c->data);
+	size_t n = strspn(node->name, c->data);
 
 	if (n < node->basenamelen)
 		FAIL(c, dti, node, "Character '%c' not recommended in node name",
Signature · 1 line
2.52.0
Signature · 4 lines
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
Signature · 4 lines
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
#5 lore raw

Re: [RFC PATCH 01/77] checks: Use consistent type for strspn() returned value

Hi David,

Quoted 11 lines · On Tue, 13 Jan 2026 15:42:31 +1100 David Gibson <[email protected]>…
Quoted 10 lines · David Gibson
Quoted 8 lines · Herve Codina

strspn() returns a size_t value.

The function is called in several places and in all places this value is stored in a size_t variable except in check_node_name_chars_strict().

Fix the variable type used in check_node_name_chars_strict().

Quoted 8 lines
Quoted 1 line

This one makes sense regardless of the rest, so, merged.

I spoke too soon. This causes a compile error:

https://github.com/dgibson/dtc/actions/runs/20944813954/job/60185662154#step:5:130

For some reason it's only showing on the make build, not meson. I guess there must be a mismatch in which warnings are enabled.

I used only meson and so I missed the signed/unsigned comparison warning.

I will remove this signed/unsigned warning in the next iteration.

Best regards,
Hervé

#6 lore raw

RFC PATCH 2/77 Introduce v18 dtb version

In reply to Herve Codina

This v18 version will add support for
- metadata in device-tree blobs in order to have a better handling of phandles and unresolved references.
- Addon device-tree blob (successor of device-tree overlay)
- Import and export symbols feature
- multiple trees in a addon device-tree blob (i.e. root device tree and orphan node tree)

---
 dtc.h                   |  2 +-
 fdtdump.c               |  2 +-
 flattree.c              |  2 ++
 libfdt/fdt.h            |  1 +
 libfdt/fdt_rw.c         | 13 +++++++------
 libfdt/libfdt.h         |  2 +-
 tests/pylibfdt_tests.py |  2 +-
 tests/trees.S           |  2 +-
 8 files changed, 15 insertions(+), 11 deletions(-)
dtc.h +1 -1
index 3a220b9..186caad 100644
@@ -29,7 +29,7 @@
 #define debug(...)
 #endif
 
-#define DEFAULT_FDT_VERSION	17
+#define DEFAULT_FDT_VERSION	18
 
 /*
  * Command line options
fdtdump.c +1 -1
index d424869..ec25edf 100644
@@ -18,7 +18,7 @@
 #include "util.h"
 
 #define FDT_MAGIC_SIZE	4
-#define MAX_VERSION 17U
+#define MAX_VERSION 18U
 
 #define ALIGN(x, a)	(((x) + ((a) - 1)) & ~((a) - 1))
 #define PALIGN(p, a)	((void *)(ALIGN((uintptr_t)(p), (a))))
flattree.c +2 -0
index 30e6de2..c3887da 100644
@@ -30,6 +30,8 @@ static struct version_info {
 	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_NOPS},
 	{17, 16, FDT_V17_SIZE,
 	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS},
+	{18, 18, FDT_V18_SIZE,
+	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS},
 };
 
 struct emitter {
libfdt/fdt.h +1 -0
index a07abfc..9372353 100644
@@ -62,5 +62,6 @@ struct fdt_property {
 #define FDT_V3_SIZE	(FDT_V2_SIZE + sizeof(fdt32_t))
 #define FDT_V16_SIZE	FDT_V3_SIZE
 #define FDT_V17_SIZE	(FDT_V16_SIZE + sizeof(fdt32_t))
+#define FDT_V18_SIZE	FDT_V17_SIZE
 
 #endif /* FDT_H */
libfdt/fdt_rw.c +7 -6
index 7475caf..00e32bb 100644
@@ -28,13 +28,13 @@ static int fdt_rw_probe_(void *fdt)
 		return 0;
 	FDT_RO_PROBE(fdt);
 
-	if (!can_assume(LATEST) && fdt_version(fdt) < 17)
+	if (!can_assume(LATEST) && fdt_version(fdt) < 18)
 		return -FDT_ERR_BADVERSION;
 	if (fdt_blocks_misordered_(fdt, sizeof(struct fdt_reserve_entry),
 				   fdt_size_dt_struct(fdt)))
 		return -FDT_ERR_BADLAYOUT;
-	if (!can_assume(LATEST) && fdt_version(fdt) > 17)
-		fdt_set_version(fdt, 17);
+	if (!can_assume(LATEST) && fdt_version(fdt) > 18)
+		fdt_set_version(fdt, 18);
 
 	return 0;
 }
@@ -455,7 +455,8 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
 		err = fdt_move(fdt, buf, bufsize);
 		if (err)
 			return err;
-		fdt_set_version(buf, 17);
+		fdt_set_version(buf, 18);
+		fdt_set_last_comp_version(buf, 18);
 		fdt_set_size_dt_struct(buf, struct_size);
 		fdt_set_totalsize(buf, bufsize);
 		return 0;
@@ -484,8 +485,8 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
 
 	fdt_set_magic(buf, FDT_MAGIC);
 	fdt_set_totalsize(buf, bufsize);
-	fdt_set_version(buf, 17);
-	fdt_set_last_comp_version(buf, 16);
+	fdt_set_version(buf, 18);
+	fdt_set_last_comp_version(buf, 18);
 	fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt));
 
 	return 0;
libfdt/libfdt.h +1 -1
index 7a10f66..c5cd35d 100644
@@ -15,7 +15,7 @@ extern "C" {
 
 #define FDT_FIRST_SUPPORTED_VERSION	0x02
 #define FDT_LAST_COMPATIBLE_VERSION	0x10
-#define FDT_LAST_SUPPORTED_VERSION	0x11
+#define FDT_LAST_SUPPORTED_VERSION	0x12
 
 /* Error codes: informative error codes */
 #define FDT_ERR_NOTFOUND	1
tests/pylibfdt_tests.py +1 -1
index a4f73ed..373e11a 100644
@@ -288,7 +288,7 @@ class PyLibfdtBasicTests(unittest.TestCase):
         self.assertEqual(self.fdt.off_dt_struct(), 88)
         self.assertEqual(self.fdt.off_dt_strings(), 652)
         self.assertEqual(self.fdt.off_mem_rsvmap(), 40)
-        self.assertEqual(self.fdt.version(), 17)
+        self.assertEqual(self.fdt.version(), 18)
         self.assertEqual(self.fdt.last_comp_version(), 16)
         self.assertEqual(self.fdt.boot_cpuid_phys(), 0)
         self.assertEqual(self.fdt.size_dt_strings(), 105)
tests/trees.S +1 -1
index d69f7f1..ecd43bc 100644
@@ -17,7 +17,7 @@
 	fdtlong	(\tree\()_struct - \tree)
 	fdtlong	(\tree\()_strings - \tree)
 	fdtlong	(\tree\()_rsvmap - \tree)
-	fdtlong	0x11
+	fdtlong	0x12
 	fdtlong	0x10
 	fdtlong	0
 	fdtlong	(\tree\()_strings_end - \tree\()_strings)
Signature · 1 line
2.52.0
#7 lore raw

Re: [RFC PATCH 02/77] Introduce v18 dtb version

Quoted 7 lines · Herve Codina

This v18 version will add support for
- metadata in device-tree blobs in order to have a better handling of phandles and unresolved references.
- Addon device-tree blob (successor of device-tree overlay)
- Import and export symbols feature
- multiple trees in a addon device-tree blob (i.e. root device tree and orphan node tree)

So, once this patch is applied, the rest of the series pretty much has to be applied "atomically" - otherwise a version built in the interim will be lying in saying that it supports v18.

I therefore suggest moving any changes that *can* be moved before this patch, should be moved before this patch. That will assist in reviewing and merging the series piecemeal, rather than as a single giant blob.

Regarding the content itself. It seems like this is a pretty major change to the dtb format - maybe that would suggest bumping the version by more than one (e.g. like we went from v3 to v16 in the past).

It would also be nice to have some docs for the new dtb extensions before or at the same time as this.

Quoted 148 lines
---
 dtc.h                   |  2 +-
 fdtdump.c               |  2 +-
 flattree.c              |  2 ++
 libfdt/fdt.h            |  1 +
 libfdt/fdt_rw.c         | 13 +++++++------
 libfdt/libfdt.h         |  2 +-
 tests/pylibfdt_tests.py |  2 +-
 tests/trees.S           |  2 +-
 8 files changed, 15 insertions(+), 11 deletions(-)
dtc.h +1 -1
index 3a220b9..186caad 100644
@@ -29,7 +29,7 @@
 #define debug(...)
 #endif
 
-#define DEFAULT_FDT_VERSION	17
+#define DEFAULT_FDT_VERSION	18
 
 /*
  * Command line options
fdtdump.c +1 -1
index d424869..ec25edf 100644
@@ -18,7 +18,7 @@
 #include "util.h"
 
 #define FDT_MAGIC_SIZE	4
-#define MAX_VERSION 17U
+#define MAX_VERSION 18U
 
 #define ALIGN(x, a)	(((x) + ((a) - 1)) & ~((a) - 1))
 #define PALIGN(p, a)	((void *)(ALIGN((uintptr_t)(p), (a))))
flattree.c +2 -0
index 30e6de2..c3887da 100644
@@ -30,6 +30,8 @@ static struct version_info {
 	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_NOPS},
 	{17, 16, FDT_V17_SIZE,
 	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS},
+	{18, 18, FDT_V18_SIZE,
+	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS},
 };
 
 struct emitter {
libfdt/fdt.h +1 -0
index a07abfc..9372353 100644
@@ -62,5 +62,6 @@ struct fdt_property {
 #define FDT_V3_SIZE	(FDT_V2_SIZE + sizeof(fdt32_t))
 #define FDT_V16_SIZE	FDT_V3_SIZE
 #define FDT_V17_SIZE	(FDT_V16_SIZE + sizeof(fdt32_t))
+#define FDT_V18_SIZE	FDT_V17_SIZE
 
 #endif /* FDT_H */
libfdt/fdt_rw.c +7 -6
index 7475caf..00e32bb 100644
@@ -28,13 +28,13 @@ static int fdt_rw_probe_(void *fdt)
 		return 0;
 	FDT_RO_PROBE(fdt);
 
-	if (!can_assume(LATEST) && fdt_version(fdt) < 17)
+	if (!can_assume(LATEST) && fdt_version(fdt) < 18)
 		return -FDT_ERR_BADVERSION;
 	if (fdt_blocks_misordered_(fdt, sizeof(struct fdt_reserve_entry),
 				   fdt_size_dt_struct(fdt)))
 		return -FDT_ERR_BADLAYOUT;
-	if (!can_assume(LATEST) && fdt_version(fdt) > 17)
-		fdt_set_version(fdt, 17);
+	if (!can_assume(LATEST) && fdt_version(fdt) > 18)
+		fdt_set_version(fdt, 18);
 
 	return 0;
 }
@@ -455,7 +455,8 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
 		err = fdt_move(fdt, buf, bufsize);
 		if (err)
 			return err;
-		fdt_set_version(buf, 17);
+		fdt_set_version(buf, 18);
+		fdt_set_last_comp_version(buf, 18);
 		fdt_set_size_dt_struct(buf, struct_size);
 		fdt_set_totalsize(buf, bufsize);
 		return 0;
@@ -484,8 +485,8 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
 
 	fdt_set_magic(buf, FDT_MAGIC);
 	fdt_set_totalsize(buf, bufsize);
-	fdt_set_version(buf, 17);
-	fdt_set_last_comp_version(buf, 16);
+	fdt_set_version(buf, 18);
+	fdt_set_last_comp_version(buf, 18);
 	fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt));
 
 	return 0;
libfdt/libfdt.h +1 -1
index 7a10f66..c5cd35d 100644
@@ -15,7 +15,7 @@ extern "C" {
 
 #define FDT_FIRST_SUPPORTED_VERSION	0x02
 #define FDT_LAST_COMPATIBLE_VERSION	0x10
-#define FDT_LAST_SUPPORTED_VERSION	0x11
+#define FDT_LAST_SUPPORTED_VERSION	0x12
 
 /* Error codes: informative error codes */
 #define FDT_ERR_NOTFOUND	1
tests/pylibfdt_tests.py +1 -1
index a4f73ed..373e11a 100644
@@ -288,7 +288,7 @@ class PyLibfdtBasicTests(unittest.TestCase):
         self.assertEqual(self.fdt.off_dt_struct(), 88)
         self.assertEqual(self.fdt.off_dt_strings(), 652)
         self.assertEqual(self.fdt.off_mem_rsvmap(), 40)
-        self.assertEqual(self.fdt.version(), 17)
+        self.assertEqual(self.fdt.version(), 18)
         self.assertEqual(self.fdt.last_comp_version(), 16)
         self.assertEqual(self.fdt.boot_cpuid_phys(), 0)
         self.assertEqual(self.fdt.size_dt_strings(), 105)
tests/trees.S +1 -1
index d69f7f1..ecd43bc 100644
@@ -17,7 +17,7 @@
 	fdtlong	(\tree\()_struct - \tree)
 	fdtlong	(\tree\()_strings - \tree)
 	fdtlong	(\tree\()_rsvmap - \tree)
-	fdtlong	0x11
+	fdtlong	0x12
 	fdtlong	0x10
 	fdtlong	0
 	fdtlong	(\tree\()_strings_end - \tree\()_strings)
Signature · 1 line
2.52.0
Signature · 4 lines
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
#8 lore raw

Re: [RFC PATCH 02/77] Introduce v18 dtb version

Hi David,

Quoted 19 lines · On Thu, 15 Jan 2026 11:12:49 +1100 David Gibson <[email protected]>…
Quoted 7 lines · Herve Codina

This v18 version will add support for
- metadata in device-tree blobs in order to have a better handling of phandles and unresolved references.
- Addon device-tree blob (successor of device-tree overlay)
- Import and export symbols feature
- multiple trees in a addon device-tree blob (i.e. root device tree and orphan node tree)

So, once this patch is applied, the rest of the series pretty much has to be applied "atomically" - otherwise a version built in the interim will be lying in saying that it supports v18.

I therefore suggest moving any changes that *can* be moved before this patch, should be moved before this patch. That will assist in reviewing and merging the series piecemeal, rather than as a single giant blob.

Quoted 4 lines

Regarding the content itself. It seems like this is a pretty major change to the dtb format - maybe that would suggest bumping the version by more than one (e.g. like we went from v3 to v16 in the past).

I see your point.

Maybe the Rob's idea related to 'unknown tag' and the suggestion I did [1] related to the generic tag value definition to support those 'unknown tag' could help here.

As a reminder here, this generic tag value definition consist in:
--- 8< ---
A tag value is on 32bits. We can define the structure of this value.
- bit 31 (msb):
- 0: This is not a new kind to tag and so it doesn't follow this definition. All existing tags are in this category
- 1: New kind of tag adopting this definition

- bits 30..28:
tag data length encoding
0b000: No data related to the tag
0b001: 1 data cell (u32) directly follows the tag
0b010: 2 data cells (2 u32) directly follow the tag
...
0b110: 6 data cells (6 u32) directly follow the tag
0b111: Tag is followed by a cell (u32) indicating the size (in bytes)
of data available just after this cell (including any padding if needed).
Because this size include some possible padding, its value is a multiple of 4 bytes.
The offset of the tag + 4 + size points to the next tag.

- bit 27..0
tag specific identifier
--- 8< ---

I mean dtb version v20 could be:

- New header size with dt_flags added in the header (if this new field is kept).

- Support for the generic tag values and so the notion of 'unknown tag'

With that done, everything else added afterward will have no impact on the dtb format itself.

Only libfdt and dtc will have versions defined at some point with support for some new flags or new keyword.

What do you think about this v20 dtb version?

Quoted 3 lines

It would also be nice to have some docs for the new dtb extensions before or at the same time as this.

Yes, the generic tag value definition.

[1] https://lore.kernel.org/all/[email protected]/

Best regards
Hervé

#9 lore raw

Re: [RFC PATCH 02/77] Introduce v18 dtb version

Quoted 29 lines · Herve Codina

Hi David,

Quoted 19 lines · On Thu, 15 Jan 2026 11:12:49 +1100 David Gibson <[email protected]>…
Quoted 7 lines · Herve Codina

This v18 version will add support for
- metadata in device-tree blobs in order to have a better handling of phandles and unresolved references.
- Addon device-tree blob (successor of device-tree overlay)
- Import and export symbols feature
- multiple trees in a addon device-tree blob (i.e. root device tree and orphan node tree)

So, once this patch is applied, the rest of the series pretty much has to be applied "atomically" - otherwise a version built in the interim will be lying in saying that it supports v18.

I therefore suggest moving any changes that *can* be moved before this patch, should be moved before this patch. That will assist in reviewing and merging the series piecemeal, rather than as a single giant blob.

Quoted 4 lines

Regarding the content itself. It seems like this is a pretty major change to the dtb format - maybe that would suggest bumping the version by more than one (e.g. like we went from v3 to v16 in the past).

Quoted 5 lines

I see your point.

Maybe the Rob's idea related to 'unknown tag' and the suggestion I did [1] related to the generic tag value definition to support those 'unknown tag' could help here.

Having a standard encoding of tag length so unknown tags can be skipped is a reasonable idea. I think you do need provision to mark a tag as "safe to ignore" or not - e.g. something like FDT_BEGIN_NODE could never be safely ignored.

Quoted 8 lines

As a reminder here, this generic tag value definition consist in:
--- 8< ---
A tag value is on 32bits. We can define the structure of this value.
- bit 31 (msb):
- 0: This is not a new kind to tag and so it doesn't follow this definition. All existing tags are in this category
- 1: New kind of tag adopting this definition

Quoted 10 lines

- bits 30..28:
tag data length encoding
0b000: No data related to the tag
0b001: 1 data cell (u32) directly follows the tag
0b010: 2 data cells (2 u32) directly follow the tag
...
0b110: 6 data cells (6 u32) directly follow the tag 0b111: Tag is followed by a cell (u32) indicating the size (in bytes)
of data available just after this cell (including any padding if needed).

I'd suggesting giving a byte length not including alignment padding. That way if you wanted to encode a bytestring in there, you wouldn't need a way of encoding the unpadded length in adddition to the standard way encoding the padded length.

Quoted 11 lines

Because this size include some possible padding, its value is a multiple of 4 bytes.
The offset of the tag + 4 + size points to the next tag.

- bit 27..0
tag specific identifier
--- 8< ---

I mean dtb version v20 could be:

Quoted 7 lines

- New header size with dt_flags added in the header (if this new field is kept).

- Support for the generic tag values and so the notion of 'unknown tag'

With that done, everything else added afterward will have no impact on the dtb format itself.

Well... maybe. It's not entirely clear to me whether all the new tags can be safely ignored by something that doesn't understand them. e.g. a consumer can't safely ignore the tags which give unresolved phandle references if it then expects the phandle values in the actual property values to be correct.

Quoted 11 lines

Only libfdt and dtc will have versions defined at some point with support for some new flags or new keyword.

What do you think about this v20 dtb version?

Quoted 3 lines

It would also be nice to have some docs for the new dtb extensions before or at the same time as this.

Yes, the generic tag value definition.

We'd want that, but it's not enough. The specific tag types should be documented as well.

Quoted 7 lines

[1] https://lore.kernel.org/all/[email protected]/

Best regards
Hervé

Signature · 4 lines
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
#10 lore raw

Re: [RFC PATCH 02/77] Introduce v18 dtb version

Quoted 32 lines · On Mon, 19 Jan 2026 16:13:35 +1100 David Gibson <[email protected]>…
Quoted 31 lines · Herve Codina

Hi David,

Quoted 19 lines · On Thu, 15 Jan 2026 11:12:49 +1100 David Gibson <[email protected]>…
Quoted 7 lines · Herve Codina

This v18 version will add support for
- metadata in device-tree blobs in order to have a better handling of phandles and unresolved references.
- Addon device-tree blob (successor of device-tree overlay)
- Import and export symbols feature
- multiple trees in a addon device-tree blob (i.e. root device tree and orphan node tree)

So, once this patch is applied, the rest of the series pretty much has to be applied "atomically" - otherwise a version built in the interim will be lying in saying that it supports v18.

I therefore suggest moving any changes that *can* be moved before this patch, should be moved before this patch. That will assist in reviewing and merging the series piecemeal, rather than as a single giant blob.

Quoted 4 lines

Regarding the content itself. It seems like this is a pretty major change to the dtb format - maybe that would suggest bumping the version by more than one (e.g. like we went from v3 to v16 in the past).

I see your point.

Quoted 8 lines
Quoted 3 lines

Maybe the Rob's idea related to 'unknown tag' and the suggestion I did [1] related to the generic tag value definition to support those 'unknown tag' could help here.

Having a standard encoding of tag length so unknown tags can be skipped is a reasonable idea. I think you do need provision to mark a tag as "safe to ignore" or not - e.g. something like FDT_BEGIN_NODE could never be safely ignored.

A bit can be used for marking a tag as "safe to ignore if unknown". I can reduce the bits 30..28 field.

bit 30:
- 0b0: Do not ignore this tag if the tag id is unknown.
If this tag id is unknown an error in the parsing should be reported.
- 0b1: This tag can be safely ignore if its id is unknown. I that case the tag and its related data are simply skipped.

bits 29..28:
- 0b00: No data
- 0b01: tag followed by 1 cell (u32) data
- 0b10: tag followed by 2 cells (2 x u32) data
- 0b11: Tag is followed by a cell (u32) indicating the size of following data

Also, it is worth noting that the 0x0....... tag value family can still be used.

Even if related to "old" tags, if a tag in this family is an unknwown tag, the parser will report an error (at least because it doesn't know how to skip the data part).

Quoted 20 lines
Quoted 9 lines

As a reminder here, this generic tag value definition consist in:
--- 8< ---
A tag value is on 32bits. We can define the structure of this value.
- bit 31 (msb):
- 0: This is not a new kind to tag and so it doesn't follow this definition. All existing tags are in this category
- 1: New kind of tag adopting this definition

Quoted 10 lines

- bits 30..28:
tag data length encoding
0b000: No data related to the tag
0b001: 1 data cell (u32) directly follows the tag
0b010: 2 data cells (2 u32) directly follow the tag
...
0b110: 6 data cells (6 u32) directly follow the tag 0b111: Tag is followed by a cell (u32) indicating the size (in bytes)
of data available just after this cell (including any padding if needed).

Quoted 4 lines

I'd suggesting giving a byte length not including alignment padding. That way if you wanted to encode a bytestring in there, you wouldn't need a way of encoding the unpadded length in adddition to the standard way encoding the padded length.

And so, next tag is always length + sizeof(padding). Next tag is aligned on 32bits.

Quoted 17 lines
Quoted 17 lines

Because this size include some possible padding, its value is a multiple of 4 bytes.
The offset of the tag + 4 + size points to the next tag.

- bit 27..0
tag specific identifier
--- 8< ---

I mean dtb version v20 could be:

- New header size with dt_flags added in the header (if this new field is kept).

- Support for the generic tag values and so the notion of 'unknown tag'

Quoted 8 lines
Quoted 2 lines

With that done, everything else added afterward will have no impact on the dtb format itself.

Well... maybe. It's not entirely clear to me whether all the new tags can be safely ignored by something that doesn't understand them. e.g. a consumer can't safely ignore the tags which give unresolved phandle references if it then expects the phandle values in the actual property values to be correct.

I would say that it depends on new (future) tags.

For instance, FDT_EXPORT_SYM, the tag used for exported symbols can be ignore by the bootloader if it doesn't know about this tag.
Indeed, it doesn't need to understand and manipulate this tag. It just needs to keep it in the dtb passed to the kernel.

Quoted 7 lines
Quoted 7 lines

Only libfdt and dtc will have versions defined at some point with support for some new flags or new keyword.

What do you think about this v20 dtb version?

Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

It would also be nice to have some docs for the new dtb extensions before or at the same time as this.

Yes, the generic tag value definition.

We'd want that, but it's not enough. The specific tag types should be documented as well.

Yes they will be documented as soon as they are introduced.

The generic tag value definition is the first step to have in docs to allow the "skip if unknown" feature.

Best regards,
Hervé

#11 lore raw

Re: [RFC PATCH 02/77] Introduce v18 dtb version

Quoted 60 lines · Herve Codina
Quoted 32 lines · On Mon, 19 Jan 2026 16:13:35 +1100 David Gibson <[email protected]>…
Quoted 31 lines · Herve Codina

Hi David,

Quoted 19 lines · On Thu, 15 Jan 2026 11:12:49 +1100 David Gibson <[email protected]>…
Quoted 7 lines · Herve Codina

This v18 version will add support for
- metadata in device-tree blobs in order to have a better handling of phandles and unresolved references.
- Addon device-tree blob (successor of device-tree overlay)
- Import and export symbols feature
- multiple trees in a addon device-tree blob (i.e. root device tree and orphan node tree)

So, once this patch is applied, the rest of the series pretty much has to be applied "atomically" - otherwise a version built in the interim will be lying in saying that it supports v18.

I therefore suggest moving any changes that *can* be moved before this patch, should be moved before this patch. That will assist in reviewing and merging the series piecemeal, rather than as a single giant blob.

Quoted 4 lines

Regarding the content itself. It seems like this is a pretty major change to the dtb format - maybe that would suggest bumping the version by more than one (e.g. like we went from v3 to v16 in the past).

I see your point.

Quoted 8 lines
Quoted 3 lines

Maybe the Rob's idea related to 'unknown tag' and the suggestion I did [1] related to the generic tag value definition to support those 'unknown tag' could help here.

Having a standard encoding of tag length so unknown tags can be skipped is a reasonable idea. I think you do need provision to mark a tag as "safe to ignore" or not - e.g. something like FDT_BEGIN_NODE could never be safely ignored.

A bit can be used for marking a tag as "safe to ignore if unknown". I can reduce the bits 30..28 field.

bit 30:
- 0b0: Do not ignore this tag if the tag id is unknown.
If this tag id is unknown an error in the parsing should be reported.
- 0b1: This tag can be safely ignore if its id is unknown. I that case the tag and its related data are simply skipped.

bits 29..28:
- 0b00: No data
- 0b01: tag followed by 1 cell (u32) data
- 0b10: tag followed by 2 cells (2 x u32) data
- 0b11: Tag is followed by a cell (u32) indicating the size of following data

Quoted 2 lines

Also, it is worth noting that the 0x0....... tag value family can still be used.

Actually, that's a good point. We can do this more simply: the new ranges with defined lengths are only used for ignorable tags. If we need to add new tags which aren't safe to ignore, they go in the 0x0 range, like the existing tags.

Quoted 24 lines

Even if related to "old" tags, if a tag in this family is an unknwown tag, the parser will report an error (at least because it doesn't know how to skip the data part).

Quoted 20 lines
Quoted 19 lines

As a reminder here, this generic tag value definition consist in:
--- 8< ---
A tag value is on 32bits. We can define the structure of this value.
- bit 31 (msb):
- 0: This is not a new kind to tag and so it doesn't follow this definition. All existing tags are in this category
- 1: New kind of tag adopting this definition

- bits 30..28:
tag data length encoding
0b000: No data related to the tag
0b001: 1 data cell (u32) directly follows the tag
0b010: 2 data cells (2 u32) directly follow the tag
...
0b110: 6 data cells (6 u32) directly follow the tag 0b111: Tag is followed by a cell (u32) indicating the size (in bytes)
of data available just after this cell (including any padding if needed).

Quoted 7 lines
Quoted 4 lines

I'd suggesting giving a byte length not including alignment padding. That way if you wanted to encode a bytestring in there, you wouldn't need a way of encoding the unpadded length in adddition to the standard way encoding the padded length.

And so, next tag is always length + sizeof(padding). Next tag is aligned on 32bits.

Exactly. Or to make it clearer that we don't need any additional information, next tag is at ALIGN_UP(length, FDT_TAG_SIZE). We already do something like this with with FDT_BEGIN_NODE tags - we ignore bytes to realign after the node name string.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

Because this size include some possible padding, its value is a multiple of 4 bytes.
The offset of the tag + 4 + size points to the next tag.

- bit 27..0
tag specific identifier
--- 8< ---

I mean dtb version v20 could be:

- New header size with dt_flags added in the header (if this new field is kept).

- Support for the generic tag values and so the notion of 'unknown tag'

With that done, everything else added afterward will have no impact on the dtb format itself.

Quoted 7 lines
Quoted 5 lines

Well... maybe. It's not entirely clear to me whether all the new tags can be safely ignored by something that doesn't understand them. e.g. a consumer can't safely ignore the tags which give unresolved phandle references if it then expects the phandle values in the actual property values to be correct.

I would say that it depends on new (future) tags.

Certainly.

Quoted 4 lines

For instance, FDT_EXPORT_SYM, the tag used for exported symbols can be ignore by the bootloader if it doesn't know about this tag.
Indeed, it doesn't need to understand and manipulate this tag. It just needs to keep it in the dtb passed to the kernel.

Ow, that's when it gets complicated. Whether a tag is safely ignorable depends on what the consumer is doing with it. Fixups and exports can be safely ignored by something just passing it through. However reference fixups *can't* be safely ignored by something that will consult phandles, because they might not be correct until the fixups are applied.

Quoted 22 lines
Quoted 6 lines
Quoted 6 lines

Only libfdt and dtc will have versions defined at some point with support for some new flags or new keyword.

What do you think about this v20 dtb version?

Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

It would also be nice to have some docs for the new dtb extensions before or at the same time as this.

Yes, the generic tag value definition.

We'd want that, but it's not enough. The specific tag types should be documented as well.

Yes they will be documented as soon as they are introduced.

The generic tag value definition is the first step to have in docs to allow the "skip if unknown" feature.

Best regards,
Hervé

Signature · 4 lines
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
#12 lore raw

Re: [RFC PATCH 02/77] Introduce v18 dtb version

In reply to David Gibson
Quoted 82 lines · David Gibson
Quoted 29 lines · Herve Codina

Hi David,

Quoted 19 lines · On Thu, 15 Jan 2026 11:12:49 +1100 David Gibson <[email protected]>…
Quoted 7 lines · Herve Codina

This v18 version will add support for
- metadata in device-tree blobs in order to have a better handling of phandles and unresolved references.
- Addon device-tree blob (successor of device-tree overlay)
- Import and export symbols feature
- multiple trees in a addon device-tree blob (i.e. root device tree and orphan node tree)

So, once this patch is applied, the rest of the series pretty much has to be applied "atomically" - otherwise a version built in the interim will be lying in saying that it supports v18.

I therefore suggest moving any changes that *can* be moved before this patch, should be moved before this patch. That will assist in reviewing and merging the series piecemeal, rather than as a single giant blob.

Quoted 4 lines

Regarding the content itself. It seems like this is a pretty major change to the dtb format - maybe that would suggest bumping the version by more than one (e.g. like we went from v3 to v16 in the past).

Quoted 5 lines

I see your point.

Maybe the Rob's idea related to 'unknown tag' and the suggestion I did [1] related to the generic tag value definition to support those 'unknown tag' could help here.

Having a standard encoding of tag length so unknown tags can be skipped is a reasonable idea. I think you do need provision to mark a tag as "safe to ignore" or not - e.g. something like FDT_BEGIN_NODE could never be safely ignored.

Quoted 8 lines

As a reminder here, this generic tag value definition consist in:
--- 8< ---
A tag value is on 32bits. We can define the structure of this value.
- bit 31 (msb):
- 0: This is not a new kind to tag and so it doesn't follow this definition. All existing tags are in this category
- 1: New kind of tag adopting this definition

Quoted 10 lines

- bits 30..28:
tag data length encoding
0b000: No data related to the tag
0b001: 1 data cell (u32) directly follows the tag
0b010: 2 data cells (2 u32) directly follow the tag
...
0b110: 6 data cells (6 u32) directly follow the tag 0b111: Tag is followed by a cell (u32) indicating the size (in bytes)
of data available just after this cell (including any padding if needed).

I'd suggesting giving a byte length not including alignment padding. That way if you wanted to encode a bytestring in there, you wouldn't need a way of encoding the unpadded length in adddition to the standard way encoding the padded length.

Quoted 16 lines

Because this size include some possible padding, its value is a
multiple of 4 bytes.
The offset of the tag + 4 + size points to the next tag.

- bit 27..0
tag specific identifier
--- 8< ---

I mean dtb version v20 could be:

- New header size with dt_flags added in the header (if this new field is kept).

- Support for the generic tag values and so the notion of 'unknown tag'

Quoted 8 lines
Quoted 2 lines

With that done, everything else added afterward will have no impact on the dtb format itself.

Well... maybe. It's not entirely clear to me whether all the new tags can be safely ignored by something that doesn't understand them. e.g. a consumer can't safely ignore the tags which give unresolved phandle references if it then expects the phandle values in the actual property values to be correct.

I think we'd want some higher level "this is an addon or base DT" than presence of tags. Maybe that's just the version. Perhaps a new header field to say this is a base or addon DT. Or both?

Everything in this series intended for the base DT should be safe to ignore just as __symbols__ (and __local_fixups__ if you add /plugin/) is safe to ignore. It's only software that understands and wants to use the new "addons" that needs to understand.

Rob

#13 lore raw

Re: [RFC PATCH 02/77] Introduce v18 dtb version

Quoted 93 lines · Rob Herring
Quoted 82 lines · David Gibson
Quoted 29 lines · Herve Codina

Hi David,

Quoted 19 lines · On Thu, 15 Jan 2026 11:12:49 +1100 David Gibson <[email protected]>…
Quoted 7 lines · Herve Codina

This v18 version will add support for
- metadata in device-tree blobs in order to have a better handling of phandles and unresolved references.
- Addon device-tree blob (successor of device-tree overlay)
- Import and export symbols feature
- multiple trees in a addon device-tree blob (i.e. root device tree and orphan node tree)

So, once this patch is applied, the rest of the series pretty much has to be applied "atomically" - otherwise a version built in the interim will be lying in saying that it supports v18.

I therefore suggest moving any changes that *can* be moved before this patch, should be moved before this patch. That will assist in reviewing and merging the series piecemeal, rather than as a single giant blob.

Quoted 4 lines

Regarding the content itself. It seems like this is a pretty major change to the dtb format - maybe that would suggest bumping the version by more than one (e.g. like we went from v3 to v16 in the past).

Quoted 5 lines

I see your point.

Maybe the Rob's idea related to 'unknown tag' and the suggestion I did [1] related to the generic tag value definition to support those 'unknown tag' could help here.

Having a standard encoding of tag length so unknown tags can be skipped is a reasonable idea. I think you do need provision to mark a tag as "safe to ignore" or not - e.g. something like FDT_BEGIN_NODE could never be safely ignored.

Quoted 8 lines

As a reminder here, this generic tag value definition consist in:
--- 8< ---
A tag value is on 32bits. We can define the structure of this value.
- bit 31 (msb):
- 0: This is not a new kind to tag and so it doesn't follow this definition. All existing tags are in this category
- 1: New kind of tag adopting this definition

Quoted 10 lines

- bits 30..28:
tag data length encoding
0b000: No data related to the tag
0b001: 1 data cell (u32) directly follows the tag
0b010: 2 data cells (2 u32) directly follow the tag
...
0b110: 6 data cells (6 u32) directly follow the tag 0b111: Tag is followed by a cell (u32) indicating the size (in bytes)
of data available just after this cell (including any padding if needed).

I'd suggesting giving a byte length not including alignment padding. That way if you wanted to encode a bytestring in there, you wouldn't need a way of encoding the unpadded length in adddition to the standard way encoding the padded length.

Quoted 16 lines

Because this size include some possible padding, its value is a
multiple of 4 bytes.
The offset of the tag + 4 + size points to the next tag.

- bit 27..0
tag specific identifier
--- 8< ---

I mean dtb version v20 could be:

- New header size with dt_flags added in the header (if this new field is kept).

- Support for the generic tag values and so the notion of 'unknown tag'

Quoted 8 lines
Quoted 2 lines

With that done, everything else added afterward will have no impact on the dtb format itself.

Well... maybe. It's not entirely clear to me whether all the new tags can be safely ignored by something that doesn't understand them. e.g. a consumer can't safely ignore the tags which give unresolved phandle references if it then expects the phandle values in the actual property values to be correct.

Quoted 3 lines

I think we'd want some higher level "this is an addon or base DT" than presence of tags. Maybe that's just the version. Perhaps a new header field to say this is a base or addon DT. Or both?

I think Herve's flags proposed flags field does that. I tend to prefer the idea of using new and different magic numbers for the variant forms though - makes it really clear that they're a different thing from a "normal" fdt.

Quoted 4 lines

Everything in this series intended for the base DT should be safe to ignore just as __symbols__ (and __local_fixups__ if you add /plugin/) is safe to ignore.

That kind of depends what you're doing with the DT. If you need to do phandle lookups, you can't safely ignore the fixups.

Quoted 5 lines

It's only software that understands and wants to
use the new "addons" that needs to understand.

Rob

Signature · 4 lines
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
#14 lore raw

RFC PATCH 3/77 libfdt: Introduce fdt_next_tag_full() and use it in fdt_next_tag()

In reply to Herve Codina

In v18 dtb new tags are added. Prepare libfdt to handle those new tags.

Keep fdt_next_tag() handling only existing tags and introduce fdt_next_tag_full() to handle new tags.

fdt_next_tag() uses fdt_next_tag_full() but it will filter out new tags when they are introduced to have those new tags transparent for existing fdt_next_tag() callers.

Code that will need to handle those new tags will use explicitly fdt_next_tag_full() to have access to them when they need to.

No new tags have been introduced yet and modifications done here prepare their introduction.

---
 libfdt/fdt.c       | 35 ++++++++++++++++++++++++++++++++++-
 libfdt/libfdt.h    | 18 ++++++++++++++++++
 libfdt/version.lds |  1 +
 3 files changed, 53 insertions(+), 1 deletion(-)
libfdt/fdt.c +34 -1
index 95f644c..ce051a0 100644
@@ -159,7 +159,7 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
 	return fdt_offset_ptr_(fdt, offset);
 }
 
-uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
+uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffset)
 {
 	const fdt32_t *tagp, *lenp;
 	uint32_t tag, len, sum;
@@ -220,6 +220,39 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 	return tag;
 }
 
+uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
+{
+	uint32_t tag, tmp_tag;
+	int tmp_offset, tmp_next;
+
+	/* Retrieve next tag */
+	tag = fdt_next_tag_full(fdt, startoffset, nextoffset);
+
+	/* Look at next one to see what we need to do */
+	tmp_next = *nextoffset;
+	do {
+		tmp_offset = tmp_next;
+		tmp_tag = fdt_next_tag_full(fdt, tmp_offset, &tmp_next);
+		switch (tmp_tag) {
+		case FDT_BEGIN_NODE:
+		case FDT_END_NODE:
+		case FDT_PROP:
+		case FDT_NOP:
+		case FDT_END:
+			/* Next tag is not new tag introduced in v18 -> Ok */
+			*nextoffset = tmp_offset;
+			return tag;
+
+		default:
+			break;
+		}
+	} while (1);
+
+	/* We shouldn't reach this code */
+	*nextoffset = -FDT_ERR_BADSTRUCTURE;
+	return FDT_END;
+}
+
 int fdt_check_node_offset_(const void *fdt, int offset)
 {
 	if (!can_assume(VALID_INPUT)
libfdt/libfdt.h +18 -0
index c5cd35d..d1a9cd5 100644
@@ -154,6 +154,24 @@ static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
  */
 uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
 
+/**
+ * fdt_next_tag_full - get next tag in the device tree without any filtering
+ * @fdt:	Pointer to the device tree blob
+ * @offset:	Offset within the blob to start searching
+ * @nextoffset:	Pointer to variable to store the offset of the next tag
+ *
+ * fdt_next_tag_full() returns the tag type of the next tag in the device tree
+ * blob starting from the given @offset. If @nextoffset is non-NULL, it will
+ * be set to the offset immediately following the tag.
+ * fdt_next_tag() can return only a subset of all possible tags performing some
+ * internal filtering. fdt_next_tag_full() doesn't perform this filtering.
+ *
+ * returns:
+ *	the tag type (FDT_BEGIN_NODE, FDT_END_NODE, FDT_PROP, FDT_NOP, FDT_END),
+ *	FDT_END, if offset is out of bounds
+ */
+uint32_t fdt_next_tag_full(const void *fdt, int offset, int *nextoffset);
+
 /*
  * External helpers to access words from a device tree blob. They're built
  * to work even with unaligned pointers on platforms (such as ARMv5) that don't
libfdt/version.lds +1 -0
index cbfef54..7e2dde2 100644
@@ -52,6 +52,7 @@ LIBFDT_1.2 {
 		fdt_strerror;
 		fdt_offset_ptr;
 		fdt_next_tag;
+		fdt_next_tag_full;
 		fdt_appendprop;
 		fdt_create_empty_tree;
 		fdt_first_property_offset;
Signature · 1 line
2.52.0
#15 lore raw

Re: [RFC PATCH 03/77] libfdt: Introduce fdt_next_tag_full() and use it in fdt_next_tag()

Quoted 4 lines · Herve Codina

In v18 dtb new tags are added. Prepare libfdt to handle those new tags.

Keep fdt_next_tag() handling only existing tags and introduce fdt_next_tag_full() to handle new tags.

Ugh, that's super ugly.

My first inclination is to say that if you're using the low-level fdt_next_tag() interface, it's your responsibility to check the version first - fdt_next_tag() should return... the next tag... and it's the caller's problem if it doesn't know about it.

Maybe that breaks some real user too badly, though. The other approach would be to use the symbol versioning we already have: we bump the libfdt version, and have different versions of fdt_next_tag() depending on the version you're using.

Btw, once you generate a dtb with new tags, its last_compat_version must become v18 as well as it's version - tools need to be aware of the new tags.

Quoted 116 lines

fdt_next_tag() uses fdt_next_tag_full() but it will filter out new tags when they are introduced to have those new tags transparent for existing fdt_next_tag() callers.

Code that will need to handle those new tags will use explicitly fdt_next_tag_full() to have access to them when they need to.

No new tags have been introduced yet and modifications done here prepare their introduction.

---
 libfdt/fdt.c       | 35 ++++++++++++++++++++++++++++++++++-
 libfdt/libfdt.h    | 18 ++++++++++++++++++
 libfdt/version.lds |  1 +
 3 files changed, 53 insertions(+), 1 deletion(-)
libfdt/fdt.c +34 -1
index 95f644c..ce051a0 100644
@@ -159,7 +159,7 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
 	return fdt_offset_ptr_(fdt, offset);
 }
 
-uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
+uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffset)
 {
 	const fdt32_t *tagp, *lenp;
 	uint32_t tag, len, sum;
@@ -220,6 +220,39 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 	return tag;
 }
 
+uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
+{
+	uint32_t tag, tmp_tag;
+	int tmp_offset, tmp_next;
+
+	/* Retrieve next tag */
+	tag = fdt_next_tag_full(fdt, startoffset, nextoffset);
+
+	/* Look at next one to see what we need to do */
+	tmp_next = *nextoffset;
+	do {
+		tmp_offset = tmp_next;
+		tmp_tag = fdt_next_tag_full(fdt, tmp_offset, &tmp_next);
+		switch (tmp_tag) {
+		case FDT_BEGIN_NODE:
+		case FDT_END_NODE:
+		case FDT_PROP:
+		case FDT_NOP:
+		case FDT_END:
+			/* Next tag is not new tag introduced in v18 -> Ok */
+			*nextoffset = tmp_offset;
+			return tag;
+
+		default:
+			break;
+		}
+	} while (1);
+
+	/* We shouldn't reach this code */
+	*nextoffset = -FDT_ERR_BADSTRUCTURE;
+	return FDT_END;
+}
+
 int fdt_check_node_offset_(const void *fdt, int offset)
 {
 	if (!can_assume(VALID_INPUT)
libfdt/libfdt.h +18 -0
index c5cd35d..d1a9cd5 100644
@@ -154,6 +154,24 @@ static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen)
  */
 uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
 
+/**
+ * fdt_next_tag_full - get next tag in the device tree without any filtering
+ * @fdt:	Pointer to the device tree blob
+ * @offset:	Offset within the blob to start searching
+ * @nextoffset:	Pointer to variable to store the offset of the next tag
+ *
+ * fdt_next_tag_full() returns the tag type of the next tag in the device tree
+ * blob starting from the given @offset. If @nextoffset is non-NULL, it will
+ * be set to the offset immediately following the tag.
+ * fdt_next_tag() can return only a subset of all possible tags performing some
+ * internal filtering. fdt_next_tag_full() doesn't perform this filtering.
+ *
+ * returns:
+ *	the tag type (FDT_BEGIN_NODE, FDT_END_NODE, FDT_PROP, FDT_NOP, FDT_END),
+ *	FDT_END, if offset is out of bounds
+ */
+uint32_t fdt_next_tag_full(const void *fdt, int offset, int *nextoffset);
+
 /*
  * External helpers to access words from a device tree blob. They're built
  * to work even with unaligned pointers on platforms (such as ARMv5) that don't
libfdt/version.lds +1 -0
index cbfef54..7e2dde2 100644
@@ -52,6 +52,7 @@ LIBFDT_1.2 {
 		fdt_strerror;
 		fdt_offset_ptr;
 		fdt_next_tag;
+		fdt_next_tag_full;
 		fdt_appendprop;
 		fdt_create_empty_tree;
 		fdt_first_property_offset;
Signature · 1 line
2.52.0
Signature · 4 lines
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
#16 lore raw

RFC PATCH 4/77 dtc: Allow to use data_append_markers() out of data.c

In reply to Herve Codina

With meta-data available in dtb, markers can be set as soon as a dtb is parsed. This will be done in flattree.c using data_append_markers().

Prepare this usage allowing this function to be used out of data.c

---
 data.c | 2 +-
 dtc.h  | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
data.c +1 -1
index 5b25aa0..11b2169 100644
@@ -127,7 +127,7 @@ struct data data_insert_at_marker(struct data d, struct marker *m,
 	return d;
 }
 
-static struct data data_append_markers(struct data d, struct marker *m)
+struct data data_append_markers(struct data d, struct marker *m)
 {
 	struct marker **mp = &d.markers;
 
dtc.h +1 -0
index 186caad..3bbd97e 100644
@@ -187,6 +187,7 @@ struct data data_insert_data(struct data d, struct marker *m, struct data old);
 struct marker *alloc_marker(unsigned int offset, enum markertype type,
 			    char *ref);
 struct data data_add_marker(struct data d, enum markertype type, char *ref);
+struct data data_append_markers(struct data d, struct marker *m);
 
 bool data_is_one_string(struct data d);
 
Signature · 1 line
2.52.0
#17 lore raw

Re: [RFC PATCH 04/77] dtc: Allow to use data_append_markers() out of data.c

Quoted 4 lines · Herve Codina

With meta-data available in dtb, markers can be set as soon as a dtb is parsed. This will be done in flattree.c using data_append_markers().

Prepare this usage allowing this function to be used out of data.c

Trivial enough I'd suggest folding it into the patch that needs to use data_append_markers() elsewhere.

Quoted 36 lines
---
 data.c | 2 +-
 dtc.h  | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
data.c +1 -1
index 5b25aa0..11b2169 100644
@@ -127,7 +127,7 @@ struct data data_insert_at_marker(struct data d, struct marker *m,
 	return d;
 }
 
-static struct data data_append_markers(struct data d, struct marker *m)
+struct data data_append_markers(struct data d, struct marker *m)
 {
 	struct marker **mp = &d.markers;
 
dtc.h +1 -0
index 186caad..3bbd97e 100644
@@ -187,6 +187,7 @@ struct data data_insert_data(struct data d, struct marker *m, struct data old);
 struct marker *alloc_marker(unsigned int offset, enum markertype type,
 			    char *ref);
 struct data data_add_marker(struct data d, enum markertype type, char *ref);
+struct data data_append_markers(struct data d, struct marker *m);
 
 bool data_is_one_string(struct data d);
 
Signature · 1 line
2.52.0
Signature · 4 lines
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
#18 lore raw

RFC PATCH 5/77 fdtdump: Change FDT_PROP prob handling to ease future addition

In reply to Herve Codina

In order to ease future tags addition, perform operation related to FDT_PROP when the tag is explicitly FDT_PROP instead of relying to a kind of default value case.

Handle the FDT_PROP tag exactly in the same way as it is done for other tags.

No functional modification.

---
 fdtdump.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
fdtdump.c +18 -16
index ec25edf..95a2274 100644
@@ -129,23 +129,25 @@ static void dump_blob(void *blob, bool debug)
 			continue;
 		}
 
-		if (tag != FDT_PROP) {
-			fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
-			break;
+		if (tag == FDT_PROP) {
+			sz = fdt32_to_cpu(GET_CELL(p));
+			s = p_strings + fdt32_to_cpu(GET_CELL(p));
+			if (version < 16 && sz >= 8)
+				p = PALIGN(p, 8);
+			t = p;
+
+			p = PALIGN(p + sz, 4);
+
+			dumpf("%04"PRIxPTR": string: %s\n", (uintptr_t)s - blob_off, s);
+			dumpf("%04"PRIxPTR": value\n", (uintptr_t)t - blob_off);
+			printf("%*s%s", depth * shift, "", s);
+			utilfdt_print_data(t, sz);
+			printf(";\n");
+			continue;
 		}
-		sz = fdt32_to_cpu(GET_CELL(p));
-		s = p_strings + fdt32_to_cpu(GET_CELL(p));
-		if (version < 16 && sz >= 8)
-			p = PALIGN(p, 8);
-		t = p;
-
-		p = PALIGN(p + sz, 4);
-
-		dumpf("%04"PRIxPTR": string: %s\n", (uintptr_t)s - blob_off, s);
-		dumpf("%04"PRIxPTR": value\n", (uintptr_t)t - blob_off);
-		printf("%*s%s", depth * shift, "", s);
-		utilfdt_print_data(t, sz);
-		printf(";\n");
+
+		fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
+		break;
 	}
 }
 
Signature · 1 line
2.52.0
Reviewed-by on v1 5/77
#19 lore raw

Re: [RFC PATCH 05/77] fdtdump: Change FDT_PROP prob handling to ease future addition

Quoted 50 lines · Herve Codina

In order to ease future tags addition, perform operation related to FDT_PROP when the tag is explicitly FDT_PROP instead of relying to a kind of default value case.

Handle the FDT_PROP tag exactly in the same way as it is done for other tags.

No functional modification.

---
  fdtdump.c | 34 ++++++++++++++++++----------------
  1 file changed, 18 insertions(+), 16 deletions(-)
fdtdump.c +15 -12
index ec25edf..95a2274 100644
@@ -129,23 +129,25 @@ static void dump_blob(void *blob, bool debug)
  			continue;
  		}
 
-		if (tag != FDT_PROP) {
-			fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
-			break;
+		if (tag == FDT_PROP) {
+			sz = fdt32_to_cpu(GET_CELL(p));
+			s = p_strings + fdt32_to_cpu(GET_CELL(p));
+			if (version < 16 && sz >= 8)
+				p = PALIGN(p, 8);
+			t = p;
+
+			p = PALIGN(p + sz, 4);
+
+			dumpf("%04"PRIxPTR": string: %s\n", (uintptr_t)s - blob_off, s);
+			dumpf("%04"PRIxPTR": value\n", (uintptr_t)t - blob_off);
+			printf("%*s%s", depth * shift, "", s);
+			utilfdt_print_data(t, sz);
+			printf(";\n");
+			continue;
  		}
-		sz = fdt32_to_cpu(GET_CELL(p));
-		s = p_strings + fdt32_to_cpu(GET_CELL(p));
-		if (version < 16 && sz >= 8)
-			p = PALIGN(p, 8);
-		t = p;
-
-		p = PALIGN(p + sz, 4);
-
-		dumpf("%04"PRIxPTR": string: %s\n", (uintptr_t)s - blob_off, s);

fdtdump.c static void dump_blob(void *blob, bool debug) · line 153

Quoted 10 lines
fdtdump.c +3 -4
-		dumpf("%04"PRIxPTR": value\n", (uintptr_t)t - blob_off);
-		printf("%*s%s", depth * shift, "", s);
-		utilfdt_print_data(t, sz);
-		printf(";\n");
+
+		fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
+		break;
  	}
  }
 

This seems reasonable refactor independently from the rest of the patch series.

#20 lore raw

Re: [RFC PATCH 05/77] fdtdump: Change FDT_PROP prob handling to ease future addition

Quoted 56 lines · Ayush Singh
Quoted 54 lines · Herve Codina

In order to ease future tags addition, perform operation related to FDT_PROP when the tag is explicitly FDT_PROP instead of relying to a kind of default value case.

Handle the FDT_PROP tag exactly in the same way as it is done for other tags.

No functional modification.

---
  fdtdump.c | 34 ++++++++++++++++++----------------
  1 file changed, 18 insertions(+), 16 deletions(-)
fdtdump.c +16 -16
index ec25edf..95a2274 100644
@@ -129,23 +129,25 @@ static void dump_blob(void *blob, bool debug)
  			continue;
  		}
-		if (tag != FDT_PROP) {
-			fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
-			break;
+		if (tag == FDT_PROP) {
+			sz = fdt32_to_cpu(GET_CELL(p));
+			s = p_strings + fdt32_to_cpu(GET_CELL(p));
+			if (version < 16 && sz >= 8)
+				p = PALIGN(p, 8);
+			t = p;
+
+			p = PALIGN(p + sz, 4);
+
+			dumpf("%04"PRIxPTR": string: %s\n", (uintptr_t)s - blob_off, s);
+			dumpf("%04"PRIxPTR": value\n", (uintptr_t)t - blob_off);
+			printf("%*s%s", depth * shift, "", s);
+			utilfdt_print_data(t, sz);
+			printf(";\n");
+			continue;
  		}
-		sz = fdt32_to_cpu(GET_CELL(p));
-		s = p_strings + fdt32_to_cpu(GET_CELL(p));
-		if (version < 16 && sz >= 8)
-			p = PALIGN(p, 8);
-		t = p;
-
-		p = PALIGN(p + sz, 4);
-
-		dumpf("%04"PRIxPTR": string: %s\n", (uintptr_t)s - blob_off, s);
-		dumpf("%04"PRIxPTR": value\n", (uintptr_t)t - blob_off);
-		printf("%*s%s", depth * shift, "", s);
-		utilfdt_print_data(t, sz);
-		printf(";\n");
+
Quoted 8 lines

fdtdump.c static void dump_blob(void *blob, bool debug) · line 152

Quoted 4 lines
fdtdump.c +2 -0
+		fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
+		break;
  	}
  }

This seems reasonable refactor independently from the rest of the patch series.

Agreed. Merged.

Quoted 1 line
Signature · 4 lines
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
#21 lore raw

RFC PATCH 6/77 Add support for FDT_REF_LOCAL dtb tag

In reply to Herve Codina

FDT_REF_LOCAL dtb tag is a meta-data tag attached to a property.

It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is local (i.e. the node is present in the device-tree blob).

It is followed by one value:
- offset (32bit):
Offset in the property data where the phandle is available.

Example:
FDT_PROP 0x00000008 xxxxxxxx 0xca 0xfe 0xde 0xca 0x01 0x02 0x03 0x04 FDT_REF_LOCAL 0x00000004

This means that at the offset 4 of the property data, the value (0x01020304) is a phandle and the related node is available in the dtb.

This is what is encoded in the dtb when the related dts has a property with the value set to <0xcafedeca &foo> with 'foo' a reference to an existing node where the phandle value is 0x01020304.

If several local phandles are used in the property data, several FDT_REF_LOCAL are present after the FDT_PROP tag. Each of them points with its offset value to the position of one phandle.

For instance, if a first property with 8 bytes of data has a phandle value at offset 4 and a second property with 16 bytes of data has phandle values at offset 0 and 8, the following tags sequence is present:
FDT_PROP 0x00000008 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000004
FDT_PROP 0x00000010 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000000
FDT_REF_LOCAL 0x00000008

Add support for this new dtb tag.

---
 data.c       |  1 +
 dtc.h        |  1 +
 fdtdump.c    | 14 +++++++++++++-
 flattree.c   | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
 libfdt/fdt.c | 24 ++++++++++++++++++++++--
 libfdt/fdt.h |  1 +
 6 files changed, 84 insertions(+), 4 deletions(-)
data.c +1 -0
index 11b2169..9bae704 100644
@@ -288,6 +288,7 @@ struct marker *alloc_marker(unsigned int offset, enum markertype type,
 	m->type = type;
 	m->ref = ref;
 	m->next = NULL;
+	m->is_local = 0;
 
 	return m;
 }
dtc.h +1 -0
index 3bbd97e..965321c 100644
@@ -128,6 +128,7 @@ struct  marker {
 	enum markertype type;
 	unsigned int offset;
 	char *ref;
+	bool is_local;
 	struct marker *next;
 };
 
fdtdump.c +13 -1
index 95a2274..dffa9a6 100644
@@ -57,8 +57,9 @@ static void dump_blob(void *blob, bool debug)
 	const char *p_strings = (const char *)blob + off_str;
 	uint32_t version = fdt32_to_cpu(bph->version);
 	uint32_t totalsize = fdt32_to_cpu(bph->totalsize);
-	uint32_t tag;
+	uint32_t tag, offset;
 	const char *p, *s, *t;
+	const char *last_prop_name = NULL;
 	int depth, sz, shift;
 	int i;
 	uint64_t addr, size;
@@ -105,6 +106,7 @@ static void dump_blob(void *blob, bool debug)
 		        (uintptr_t)p - blob_off - 4, tag, tagname(tag));
 
 		if (tag == FDT_BEGIN_NODE) {
+			last_prop_name = NULL;
 			s = p;
 			p = PALIGN(p + strlen(s) + 1, 4);
 
@@ -118,6 +120,7 @@ static void dump_blob(void *blob, bool debug)
 		}
 
 		if (tag == FDT_END_NODE) {
+			last_prop_name = NULL;
 			depth--;
 
 			printf("%*s};\n", depth * shift, "");
@@ -143,6 +146,15 @@ static void dump_blob(void *blob, bool debug)
 			printf("%*s%s", depth * shift, "", s);
 			utilfdt_print_data(t, sz);
 			printf(";\n");
+			last_prop_name = s;
+			continue;
+		}
+
+		if (tag == FDT_REF_LOCAL) {
+			offset = fdt32_to_cpu(GET_CELL(p));
+
+			printf("%*s// [FDT_REF_LOCAL] %s[%"PRIu32"]\n", depth * shift, "",
+				last_prop_name, offset);
 			continue;
 		}
 
flattree.c +46 -1

125 lines not on this page · raw message

libfdt/fdt.c +22 -2
index ce051a0..7268fb6 100644
@@ -161,7 +161,7 @@ const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
 
 uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffset)
 {
-	const fdt32_t *tagp, *lenp;
+	const fdt32_t *tagp, *lenp, *tmp32p;
 	uint32_t tag, len, sum;
 	int offset = startoffset;
 	const char *p;
@@ -209,6 +209,14 @@ uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffset)
 	case FDT_NOP:
 		break;
 
+	case FDT_REF_LOCAL:
+		/* Skip offset value */
+		tmp32p = fdt_offset_ptr(fdt, offset, sizeof(*tmp32p));
+		if (!can_assume(VALID_DTB) && !tmp32p)
+			return FDT_END; /* premature end */
+		offset += sizeof(fdt32_t);
+		break;
+
 	default:
 		return FDT_END;
 	}
@@ -239,10 +247,22 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 		case FDT_PROP:
 		case FDT_NOP:
 		case FDT_END:
-			/* Next tag is not new tag introduced in v18 -> Ok */
+			/*
+			 * Next tag is not a meta-data tag -> Ok this next tag
+			 * has to be handle by fd_next_tag().
+			 * Filter out any potential meta-data tag returning
+			 * nextoffset pointing to this current next tag.
+			 */
 			*nextoffset = tmp_offset;
 			return tag;
 
+		case FDT_REF_LOCAL:
+			/*
+			 * Next tag is a meta-data tag present in the middle
+			 * of the structure -> Skip it and look at next one
+			 */
+			break;
+
 		default:
 			break;
 		}
libfdt/fdt.h +1 -0
index 9372353..f8efdf1 100644
@@ -55,6 +55,7 @@ struct fdt_property {
 #define FDT_PROP	0x3		/* Property: name off,
 					   size, content */
 #define FDT_NOP		0x4		/* nop */
+#define FDT_REF_LOCAL   0x5		/* local phandle reference: offset */
 #define FDT_END		0x9
 
 #define FDT_V1_SIZE	(7*sizeof(fdt32_t))
Signature · 1 line
2.52.0
#22 lore raw

Re: [RFC PATCH 06/77] Add support for FDT_REF_LOCAL dtb tag

Quoted 27 lines · Herve Codina

FDT_REF_LOCAL dtb tag is a meta-data tag attached to a property.

It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is local (i.e. the node is present in the device-tree blob).

It is followed by one value:
- offset (32bit):
Offset in the property data where the phandle is available.

Example:
FDT_PROP 0x00000008 xxxxxxxx 0xca 0xfe 0xde 0xca 0x01 0x02 0x03 0x04 FDT_REF_LOCAL 0x00000004

This means that at the offset 4 of the property data, the value (0x01020304) is a phandle and the related node is available in the dtb.

This is what is encoded in the dtb when the related dts has a property with the value set to <0xcafedeca &foo> with 'foo' a reference to an existing node where the phandle value is 0x01020304.

If several local phandles are used in the property data, several FDT_REF_LOCAL are present after the FDT_PROP tag. Each of them points with its offset value to the position of one phandle.

Quoted 9 lines

For instance, if a first property with 8 bytes of data has a phandle value at offset 4 and a second property with 16 bytes of data has phandle values at offset 0 and 8, the following tags sequence is present:
FDT_PROP 0x00000008 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000004
FDT_PROP 0x00000010 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000000
FDT_REF_LOCAL 0x00000008

To follow up on my desire to both be easily extended and have more type info, I have something like this in mind:

FDT_TYPE_INFO 0x10 FDT_REF_LOCAL 0x0 FDT_TYPE_U32 0x4 FDT_REF_LOCAL 0x8 FDT_TYPE_U32 0xc

Length is 16 because I would do u16 for the types and lengths. I'm not sure what the max property length is. In theory 2^32, but I suspect we'd run into other issues (e.g. libfdt offsets are 32-bit on 32-bit systems). We could also do 8 bits for type and 24 bits for offset. Offset could also be relative to the prior offset.

Rob

#23 lore raw

Re: [RFC PATCH 06/77] Add support for FDT_REF_LOCAL dtb tag

Quoted 38 lines · Rob Herring
Quoted 27 lines · Herve Codina

FDT_REF_LOCAL dtb tag is a meta-data tag attached to a property.

It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is local (i.e. the node is present in the device-tree blob).

It is followed by one value:
- offset (32bit):
Offset in the property data where the phandle is available.

Example:
FDT_PROP 0x00000008 xxxxxxxx 0xca 0xfe 0xde 0xca 0x01 0x02 0x03 0x04 FDT_REF_LOCAL 0x00000004

This means that at the offset 4 of the property data, the value (0x01020304) is a phandle and the related node is available in the dtb.

This is what is encoded in the dtb when the related dts has a property with the value set to <0xcafedeca &foo> with 'foo' a reference to an existing node where the phandle value is 0x01020304.

If several local phandles are used in the property data, several FDT_REF_LOCAL are present after the FDT_PROP tag. Each of them points with its offset value to the position of one phandle.

Quoted 9 lines

For instance, if a first property with 8 bytes of data has a phandle value at offset 4 and a second property with 16 bytes of data has phandle values at offset 0 and 8, the following tags sequence is present:
FDT_PROP 0x00000008 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000004
FDT_PROP 0x00000010 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000000
FDT_REF_LOCAL 0x00000008

Quoted 5 lines

To follow up on my desire to both be easily extended and have more type info, I have something like this in mind:

FDT_TYPE_INFO 0x10 FDT_REF_LOCAL 0x0 FDT_TYPE_U32 0x4 FDT_REF_LOCAL 0x8 FDT_TYPE_U32 0xc

I think general type info should be out of scope for this:
* This series is already enormous and complicated without that
* phandles aren't just another type, they have structural relevance which makes them a special case

Plus, I'm actually pretty dubious about adding type information to dtbs in the first place. It gives the impression that dt property values are self-describing, but they're not. If you want a self-describing format, I think you'd be better off dropping the OF-related past entirely, and using json or one of the various other modern self-describing structure data formats.

Quoted 5 lines

Length is 16 because I would do u16 for the types and lengths. I'm not sure what the max property length is. In theory 2^32, but I suspect we'd run into other issues (e.g. libfdt offsets are 32-bit on 32-bit systems). We could also do 8 bits for type and 24 bits for offset. Offset could also be relative to the prior offset.

Structurally dtbs are limited to 2^32 bytes, by policy they're limited to 2^31 bytes (so we can safely store an offset in a signed 32-bit int).

Signature · 4 lines
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
#24 lore raw

Re: [RFC PATCH 06/77] Add support for FDT_REF_LOCAL dtb tag

Quoted 40 lines · David Gibson
Quoted 38 lines · Rob Herring
Quoted 36 lines · Herve Codina

FDT_REF_LOCAL dtb tag is a meta-data tag attached to a property.

It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is local (i.e. the node is present in the device-tree blob).

It is followed by one value:
- offset (32bit):
Offset in the property data where the phandle is available.

Example:
FDT_PROP 0x00000008 xxxxxxxx 0xca 0xfe 0xde 0xca 0x01 0x02 0x03 0x04 FDT_REF_LOCAL 0x00000004

This means that at the offset 4 of the property data, the value (0x01020304) is a phandle and the related node is available in the dtb.

This is what is encoded in the dtb when the related dts has a property with the value set to <0xcafedeca &foo> with 'foo' a reference to an existing node where the phandle value is 0x01020304.

If several local phandles are used in the property data, several FDT_REF_LOCAL are present after the FDT_PROP tag. Each of them points with its offset value to the position of one phandle.

For instance, if a first property with 8 bytes of data has a phandle value at offset 4 and a second property with 16 bytes of data has phandle values at offset 0 and 8, the following tags sequence is present:
FDT_PROP 0x00000008 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000004
FDT_PROP 0x00000010 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000000
FDT_REF_LOCAL 0x00000008

Quoted 8 lines
Quoted 5 lines

To follow up on my desire to both be easily extended and have more type info, I have something like this in mind:

FDT_TYPE_INFO 0x10 FDT_REF_LOCAL 0x0 FDT_TYPE_U32 0x4 FDT_REF_LOCAL 0x8 FDT_TYPE_U32 0xc

I think general type info should be out of scope for this:
* This series is already enormous and complicated without that

It is enormous, but I don't think the intention was to finalize and merge it all at once. I certainly don't intend to review it all now. The final result looks sane to me and with that we have a good idea what information needs to go in the DTB. I think the first step is to define the new metadata tags and what DTB format changes are needed.

Quoted 2 lines

* phandles aren't just another type, they have structural relevance which makes them a special case

Fair enough.

What's similar is we need to define FOO is at offset X just like the markers within dtc. We can add other types later, I'm just asking that the design here for new tags and phandles accounts for that.

Quoted 6 lines

Plus, I'm actually pretty dubious about adding type information to dtbs in the first place. It gives the impression that dt property values are self-describing, but they're not. If you want a self-describing format, I think you'd be better off dropping the OF-related past entirely, and using json or one of the various other modern self-describing structure data formats.

json has no concept of integer sizes (and numbers are floats). The typical work-around for that is encode everything as a string and then we're pretty much back to everything's a byte array. Pretty sure we've been thru this already. So I don't know what format we'd use. I've not come across one. Perhaps just DTS as that does have the type information. :) In any case, I'm not interested in a revolution, just evolution. I want a format that transparently works with only an updated libfdt. Anything else is simply going to go nowhere (as evident by the last 15 years of new DTB format discussions).

I know you aren't a fan of relying on .dts information for type information, but that's not the only source anymore. We now have an entire database of every last property and its type. That could be what's used to populate type information. Again, we don't have to define how we do it now, just allow for it (and any other metadata we have yet to think about) in the DTB format changes.

Rob

#25 lore raw

Re: [RFC PATCH 06/77] Add support for FDT_REF_LOCAL dtb tag

Hi Rob, David,

Quoted 48 lines · On Thu, 15 Jan 2026 09:54:22 -0600 Rob Herring <[email protected]> wrote:
Quoted 46 lines · David Gibson
Quoted 43 lines · Rob Herring
Quoted 27 lines · Herve Codina

FDT_REF_LOCAL dtb tag is a meta-data tag attached to a property.

It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is local (i.e. the node is present in the device-tree blob).

It is followed by one value:
- offset (32bit):
Offset in the property data where the phandle is available.

Example:
FDT_PROP 0x00000008 xxxxxxxx 0xca 0xfe 0xde 0xca 0x01 0x02 0x03 0x04 FDT_REF_LOCAL 0x00000004

This means that at the offset 4 of the property data, the value (0x01020304) is a phandle and the related node is available in the dtb.

This is what is encoded in the dtb when the related dts has a property with the value set to <0xcafedeca &foo> with 'foo' a reference to an existing node where the phandle value is 0x01020304.

If several local phandles are used in the property data, several FDT_REF_LOCAL are present after the FDT_PROP tag. Each of them points with its offset value to the position of one phandle.

Quoted 9 lines

For instance, if a first property with 8 bytes of data has a phandle value at offset 4 and a second property with 16 bytes of data has phandle values at offset 0 and 8, the following tags sequence is present:
FDT_PROP 0x00000008 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000004
FDT_PROP 0x00000010 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000000
FDT_REF_LOCAL 0x00000008

To follow up on my desire to both be easily extended and have more type info, I have something like this in mind:

FDT_TYPE_INFO 0x10 FDT_REF_LOCAL 0x0 FDT_TYPE_U32 0x4 FDT_REF_LOCAL 0x8 FDT_TYPE_U32 0xc

Quoted 8 lines
Quoted 2 lines

I think general type info should be out of scope for this:
* This series is already enormous and complicated without that

It is enormous, but I don't think the intention was to finalize and merge it all at once. I certainly don't intend to review it all now. The final result looks sane to me and with that we have a good idea what information needs to go in the DTB. I think the first step is to define the new metadata tags and what DTB format changes are needed.

Indeed, the goal of this RFC is to give the big picture and open discussions.

FDT_TYPE_INFO tag is a container. It just groups other tags together.

I don't use the term TYPE in the proposal related to generic tag values [1]. I use FDT_INFO_PROPERTY which is more generic.

Best regards,
Hervé

#26 lore raw

Re: [RFC PATCH 06/77] Add support for FDT_REF_LOCAL dtb tag

Quoted 65 lines · On Fri, 16 Jan 2026 11:16:16 +0100 Herve Codina <[email protected]>…

Hi Rob, David,

Quoted 48 lines · On Thu, 15 Jan 2026 09:54:22 -0600 Rob Herring <[email protected]> wrote:
Quoted 46 lines · David Gibson
Quoted 43 lines · Rob Herring
Quoted 27 lines · Herve Codina

FDT_REF_LOCAL dtb tag is a meta-data tag attached to a property.

It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is local (i.e. the node is present in the device-tree blob).

It is followed by one value:
- offset (32bit):
Offset in the property data where the phandle is available.

Example:
FDT_PROP 0x00000008 xxxxxxxx 0xca 0xfe 0xde 0xca 0x01 0x02 0x03 0x04 FDT_REF_LOCAL 0x00000004

This means that at the offset 4 of the property data, the value (0x01020304) is a phandle and the related node is available in the dtb.

This is what is encoded in the dtb when the related dts has a property with the value set to <0xcafedeca &foo> with 'foo' a reference to an existing node where the phandle value is 0x01020304.

If several local phandles are used in the property data, several FDT_REF_LOCAL are present after the FDT_PROP tag. Each of them points with its offset value to the position of one phandle.

Quoted 9 lines

For instance, if a first property with 8 bytes of data has a phandle value at offset 4 and a second property with 16 bytes of data has phandle values at offset 0 and 8, the following tags sequence is present:
FDT_PROP 0x00000008 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000004
FDT_PROP 0x00000010 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000000
FDT_REF_LOCAL 0x00000008

To follow up on my desire to both be easily extended and have more type info, I have something like this in mind:

FDT_TYPE_INFO 0x10 FDT_REF_LOCAL 0x0 FDT_TYPE_U32 0x4 FDT_REF_LOCAL 0x8 FDT_TYPE_U32 0xc

Quoted 8 lines
Quoted 2 lines

I think general type info should be out of scope for this:
* This series is already enormous and complicated without that

It is enormous, but I don't think the intention was to finalize and merge it all at once. I certainly don't intend to review it all now. The final result looks sane to me and with that we have a good idea what information needs to go in the DTB. I think the first step is to define the new metadata tags and what DTB format changes are needed.

Indeed, the goal of this RFC is to give the big picture and open discussions.

Quoted 7 lines

FDT_TYPE_INFO tag is a container. It just groups other tags together.

I don't use the term TYPE in the proposal related to generic tag values [1]. I use FDT_INFO_PROPERTY which is more generic.

Best regards,
Hervé

[1] https://lore.kernel.org/all/[email protected]/

Signature · 3 lines
Hervé Codina, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#27 lore raw

Re: [RFC PATCH 06/77] Add support for FDT_REF_LOCAL dtb tag

In reply to Rob Herring
Quoted 48 lines · Rob Herring
Quoted 46 lines · David Gibson
Quoted 43 lines · Rob Herring
Quoted 27 lines · Herve Codina

FDT_REF_LOCAL dtb tag is a meta-data tag attached to a property.

It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is local (i.e. the node is present in the device-tree blob).

It is followed by one value:
- offset (32bit):
Offset in the property data where the phandle is available.

Example:
FDT_PROP 0x00000008 xxxxxxxx 0xca 0xfe 0xde 0xca 0x01 0x02 0x03 0x04 FDT_REF_LOCAL 0x00000004

This means that at the offset 4 of the property data, the value (0x01020304) is a phandle and the related node is available in the dtb.

This is what is encoded in the dtb when the related dts has a property with the value set to <0xcafedeca &foo> with 'foo' a reference to an existing node where the phandle value is 0x01020304.

If several local phandles are used in the property data, several FDT_REF_LOCAL are present after the FDT_PROP tag. Each of them points with its offset value to the position of one phandle.

Quoted 9 lines

For instance, if a first property with 8 bytes of data has a phandle value at offset 4 and a second property with 16 bytes of data has phandle values at offset 0 and 8, the following tags sequence is present:
FDT_PROP 0x00000008 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000004
FDT_PROP 0x00000010 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000000
FDT_REF_LOCAL 0x00000008

To follow up on my desire to both be easily extended and have more type info, I have something like this in mind:

FDT_TYPE_INFO 0x10 FDT_REF_LOCAL 0x0 FDT_TYPE_U32 0x4 FDT_REF_LOCAL 0x8 FDT_TYPE_U32 0xc

Quoted 8 lines
Quoted 2 lines

I think general type info should be out of scope for this:
* This series is already enormous and complicated without that

It is enormous, but I don't think the intention was to finalize and merge it all at once. I certainly don't intend to review it all now. The final result looks sane to me and with that we have a good idea what information needs to go in the DTB. I think the first step is to define the new metadata tags and what DTB format changes are needed.

I mostly agree. But as noted, we can't advertise v18 (or whatever) support until we actually *do* support it - which would imply having some docs / specs on what exactly is in v18. So the series will need some re-ordering to allow pieces to be merged earlier.

Quoted 9 lines
Quoted 2 lines

* phandles aren't just another type, they have structural relevance which makes them a special case

Fair enough.

What's similar is we need to define FOO is at offset X just like the markers within dtc. We can add other types later, I'm just asking that the design here for new tags and phandles accounts for that.

Quoted 8 lines
Quoted 6 lines

Plus, I'm actually pretty dubious about adding type information to dtbs in the first place. It gives the impression that dt property values are self-describing, but they're not. If you want a self-describing format, I think you'd be better off dropping the OF-related past entirely, and using json or one of the various other modern self-describing structure data formats.

json has no concept of integer sizes (and numbers are floats).

Good point, and dtb has heavier than many need of true 64-bit ints. It's a real half-ton of flies in a mostly pretty decent data model :(.

Quoted 5 lines

The
typical work-around for that is encode everything as a string and then we're pretty much back to everything's a byte array. Pretty sure we've been thru this already. So I don't know what format we'd use. I've not come across one.

ASN.1? CBOR? Messagepack? Protobuf? I don't love any of those, but I'm not sure they'd be *more* clunky than something we cobble together on top of dtb.

Quoted 5 lines

Perhaps just DTS as that does have the type
information. :) In any case, I'm not interested in a revolution, just evolution. I want a format that transparently works with only an updated libfdt. Anything else is simply going to go nowhere (as evident by the last 15 years of new DTB format discussions).

As a rule, I also prefer evolution to revolution. But there can come a point where you're straining the thing you're building on further than makes sense any more.

Quoted 6 lines

I know you aren't a fan of relying on .dts information for type information, but that's not the only source anymore. We now have an entire database of every last property and its type. That could be what's used to populate type information. Again, we don't have to define how we do it now, just allow for it (and any other metadata we have yet to think about) in the DTB format changes.

I guess it depends a bit how you're thinking of this type information. Are you thinking of it as an intrinsic part of the dtb information that a consumer (like the kernel) would use? Something akin to the symbols or relocation information in an ELF object.

Or are you thinking of it as something for the benefit of intermediate tools, that could be stripped out before going to the final consumer? Something like debug symbols in an ELF object.

I'm open to the second approach, although I'm still a bit concerned that once it's there as "debug" information things might start relying on it which shouldn't.

Signature · 4 lines
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
#28 lore raw

RFC PATCH 7/77 livetree: Improve get_node_by_phandle()

In reply to Herve Codina

get_node_by_phandle() allows to get a node based on its phandle value. It checks the phandle value against value available in internal node structure.

This internal phandle value is updated during process_check() and so, get_node_by_phandle() cannot give correct results before the process_check() call.

Improve get_node_by_phandle() to look at node phandle properties when the internal phandle value is not valid.

This allows to return a correct matching node even if process_check() was not called yet.

With the recently introduced FDT_REF_LOCAL dtb tag, this will be needed to update internal phandle references before the call to process_check(). Indeed, this tag allows to identify phandles and internal references need to be updated based on the phandle value before the process_check() call.

---
 livetree.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
livetree.c +20 -1
index f328824..9b67934 100644
@@ -609,16 +609,35 @@ struct node *get_node_by_label(struct node *tree, const char *label)
 	return NULL;
 }
 
+static cell_t get_node_phandle_existing(struct node *node)
+{
+	struct property *prop;
+
+	if (phandle_is_valid(node->phandle))
+		return node->phandle;
+
+	prop = get_property(node, "phandle");
+	if (!prop) {
+		prop = get_property(node, "linux,phandle");
+		if (!prop)
+			return 0;
+	}
+
+	return propval_cell(prop);
+}
+
 struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
 {
 	struct node *child, *node;
+	cell_t tree_phandle;
 
 	if (!phandle_is_valid(phandle)) {
 		assert(generate_fixups);
 		return NULL;
 	}
 
-	if (tree->phandle == phandle) {
+	tree_phandle = get_node_phandle_existing(tree);
+	if (phandle_is_valid(tree_phandle) && tree_phandle == phandle) {
 		if (tree->deleted)
 			return NULL;
 		return tree;
Signature · 1 line
2.52.0
#29 lore raw

Re: [RFC PATCH 07/77] livetree: Improve get_node_by_phandle()

Quoted 11 lines · Herve Codina

get_node_by_phandle() allows to get a node based on its phandle value. It checks the phandle value against value available in internal node structure.

This internal phandle value is updated during process_check() and so, get_node_by_phandle() cannot give correct results before the process_check() call.

Improve get_node_by_phandle() to look at node phandle properties when the internal phandle value is not valid.

Quoted 8 lines

This allows to return a correct matching node even if process_check() was not called yet.

With the recently introduced FDT_REF_LOCAL dtb tag, this will be needed to update internal phandle references before the call to process_check(). Indeed, this tag allows to identify phandles and internal references need to be updated based on the phandle value before the process_check() call.

Having two entirely different paths for get_node_by_phandle() is really ugly.

I suspect a better approach would be to special case updates to the internal phandle field as we parse the phandle properties, rather than doing it as a batch during the checks.

Quoted 10 lines
---
 livetree.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
livetree.c +0 -0
index f328824..9b67934 100644

livetree.c struct node *get_node_by_label(struct node *tree, const char *label) · line 616

Quoted 8 lines
livetree.c +5 -0
@@ -609,16 +609,35 @@ struct node *get_node_by_label(struct node *tree, const char *label)
 	return NULL;
 }
 
+static cell_t get_node_phandle_existing(struct node *node)
+{
+	struct property *prop;
+
+	if (phandle_is_valid(node->phandle))

g> + return node->phandle;

Quoted 13 lines
livetree.c +11 -0
+
+	prop = get_property(node, "phandle");
+	if (!prop) {
+		prop = get_property(node, "linux,phandle");
+		if (!prop)
+			return 0;
+	}
+
+	return propval_cell(prop);
+}
+
 struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
 {

livetree.c struct node *get_node_by_label(struct node *tree, const char *label) · line 639

Quoted 10 lines
livetree.c +2 -1
 	struct node *child, *node;
+	cell_t tree_phandle;
 
 	if (!phandle_is_valid(phandle)) {
 		assert(generate_fixups);
 		return NULL;
 	}
 
-	if (tree->phandle == phandle) {
+	tree_phandle = get_node_phandle_existing(tree);

It's especially nasty that we call the expensive version first, then fall back to the cheap version...

Quoted 8 lines
livetree.c +1 -0
+	if (phandle_is_valid(tree_phandle) && tree_phandle == phandle) {
 		if (tree->deleted)
 			return NULL;
 		return tree;
Signature · 1 line
2.52.0
Signature · 4 lines
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
#30 lore raw

Re: [RFC PATCH 07/77] livetree: Improve get_node_by_phandle()

Hi David,

Quoted 21 lines · On Thu, 15 Jan 2026 11:41:32 +1100 David Gibson <[email protected]>…
Quoted 11 lines · Herve Codina

get_node_by_phandle() allows to get a node based on its phandle value. It checks the phandle value against value available in internal node structure.

This internal phandle value is updated during process_check() and so, get_node_by_phandle() cannot give correct results before the process_check() call.

Improve get_node_by_phandle() to look at node phandle properties when the internal phandle value is not valid.

Quoted 8 lines

This allows to return a correct matching node even if process_check() was not called yet.

With the recently introduced FDT_REF_LOCAL dtb tag, this will be needed to update internal phandle references before the call to process_check(). Indeed, this tag allows to identify phandles and internal references need to be updated based on the phandle value before the process_check() call.

Quoted 6 lines

Having two entirely different paths for get_node_by_phandle() is really ugly.

I suspect a better approach would be to special case updates to the internal phandle field as we parse the phandle properties, rather than doing it as a batch during the checks.

Doing that when we parse the property will be quite complex. Indeed, when we parse a dts, the node internal object is not yet created when the property is parsed.

What I think could be done is to set the phandle field just after the parsing of input (dts or dtb). In current implementation this is done by process_check() when fixup_phandle_references() is called.

This fixup_phandle_references() call should be removed from process_check() and called right after the input parsing.

I you are ok with that, I can propose something in the next iteration.

Best regards,
Hervé

#31 lore raw

Re: [RFC PATCH 07/77] livetree: Improve get_node_by_phandle()

Quoted 29 lines · Herve Codina

Hi David,

Quoted 24 lines · On Thu, 15 Jan 2026 11:41:32 +1100 David Gibson <[email protected]>…
Quoted 11 lines · Herve Codina

get_node_by_phandle() allows to get a node based on its phandle value. It checks the phandle value against value available in internal node structure.

This internal phandle value is updated during process_check() and so, get_node_by_phandle() cannot give correct results before the process_check() call.

Improve get_node_by_phandle() to look at node phandle properties when the internal phandle value is not valid.

Quoted 8 lines

This allows to return a correct matching node even if process_check() was not called yet.

With the recently introduced FDT_REF_LOCAL dtb tag, this will be needed to update internal phandle references before the call to process_check(). Indeed, this tag allows to identify phandles and internal references need to be updated based on the phandle value before the process_check() call.

Having two entirely different paths for get_node_by_phandle() is really ugly.

Quoted 7 lines
Quoted 3 lines

I suspect a better approach would be to special case updates to the internal phandle field as we parse the phandle properties, rather than doing it as a batch during the checks.

Doing that when we parse the property will be quite complex. Indeed, when we parse a dts, the node internal object is not yet created when the property is parsed.

Ah, good point.

Quoted 3 lines

What I think could be done is to set the phandle field just after the parsing of input (dts or dtb). In current implementation this is done by process_check() when fixup_phandle_references() is called.

Oof. So, on the one hand, doing this indexing in the "checks" is kind of weird - I implemented it that way because it just seemed a convenient place that already scanned the full tree and had mechanisms for dependencies between different steps.

However... these dependencies are a bit subtle. Part of the trick here is that the indexing has dependencies on the really basic checks that we don't have invalid or duplicate node/property names. If we moved the phandle indexing before that, we'd have to explicitly deal with the possibility of multiple "phandle" properties and other weirdness.

Maybe we want to split the "checks" into two different phases. One for "structural" checks, which check the basic required properties:
characters in names, no duplicate names, no duplicate phandles. That phase could also handle fixups and indexing that aren't really checks.

A later phase could do the semantic checks (does the interrupts tree
make sense etc.). We could do processing between those two phases if
it makes sense to do so.

Quoted 8 lines

This fixup_phandle_references() call should be removed from process_check() and called right after the input parsing.

I you are ok with that, I can propose something in the next iteration.

Best regards,
Hervé

Signature · 4 lines
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
#32 lore raw

RFC PATCH 8/77 dtc: Introduce update_phandles_ref()

In reply to Herve Codina

With the introduction of FDT_REF_LOCAL dtb tag, a local phandle used by a property is identify when a dtb is parsed.

In order to have consistent internal data, the reference related to this phandle usage needs to be updated based on the phandle value.

This is done by update_phandles_ref().

---
 dtc.c      |  2 ++
 dtc.h      |  2 ++
 livetree.c | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+)
dtc.c +2 -0
index b3445b7..88f03ff 100644
@@ -333,6 +333,8 @@ int main(int argc, char *argv[])
 		generate_fixups = 1;
 	}
 
+	update_phandles_ref(dti);
+
 	process_checks(force, dti);
 
 	if (auto_label_aliases)
dtc.h +2 -0
index 965321c..351fe41 100644
@@ -345,6 +345,8 @@ 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 update_phandles_ref(struct dt_info *dti);
+
 /* Checks */
 
 void parse_checks_option(bool warn, bool error, const char *arg);
livetree.c +38 -0
index 9b67934..9e30a63 100644
@@ -1158,3 +1158,41 @@ 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 update_phandles_ref_internal(struct dt_info *dti, struct node *node)
+{
+	struct node *c;
+	struct property *prop;
+	struct marker *m;
+	struct node *refnode;
+	cell_t phandle;
+
+	for_each_property(node, prop) {
+		m = prop->val.markers;
+		for_each_marker_of_type(m, REF_PHANDLE) {
+			if (m->ref)
+				continue;
+
+			if (m->is_local) {
+				phandle = propval_cell_n(prop,
+							 m->offset / sizeof(cell_t));
+				refnode = get_node_by_phandle(dti->dt, phandle);
+				if (!refnode)
+					die("Node not found for phandle 0x%"PRIx32"\n", phandle);
+
+				m->ref = refnode->fullpath;
+				continue;
+			} else {
+				die("Found a non local phandle without a reference\n");
+			}
+		}
+	}
+
+	for_each_child(node, c)
+		update_phandles_ref_internal(dti, c);
+}
+
+void update_phandles_ref(struct dt_info *dti)
+{
+	update_phandles_ref_internal(dti, dti->dt);
+}
Signature · 1 line
2.52.0
#33 lore raw

Re: [RFC PATCH 08/77] dtc: Introduce update_phandles_ref()

Quoted 53 lines · Herve Codina

With the introduction of FDT_REF_LOCAL dtb tag, a local phandle used by a property is identify when a dtb is parsed.

In order to have consistent internal data, the reference related to this phandle usage needs to be updated based on the phandle value.

This is done by update_phandles_ref().

---
 dtc.c      |  2 ++
 dtc.h      |  2 ++
 livetree.c | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+)
dtc.c +2 -0
index b3445b7..88f03ff 100644
@@ -333,6 +333,8 @@ int main(int argc, char *argv[])
 		generate_fixups = 1;
 	}
 
+	update_phandles_ref(dti);
+
 	process_checks(force, dti);
 
 	if (auto_label_aliases)
dtc.h +2 -0
index 965321c..351fe41 100644
@@ -345,6 +345,8 @@ 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 update_phandles_ref(struct dt_info *dti);
+
 /* Checks */
 
 void parse_checks_option(bool warn, bool error, const char *arg);
livetree.c +4 -0
index 9b67934..9e30a63 100644
@@ -1158,3 +1158,41 @@ 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 update_phandles_ref_internal(struct dt_info *dti, struct node *node)
+{
+	struct node *c;

livetree.c void generate_local_fixups_tree(struct dt_info *dti, const char *name) · line 1174

Quoted 10 lines
livetree.c +10 -0
+	struct property *prop;
+	struct marker *m;
+	struct node *refnode;
+	cell_t phandle;
+
+	for_each_property(node, prop) {
+		m = prop->val.markers;
+		for_each_marker_of_type(m, REF_PHANDLE) {
+			if (m->ref)
+				continue;

IIUC this means that REF_PHANDLE markers can be missing their ref. Allowing the markers to be in an incomplete state is a footgun. If possible it would be better to fully generate the markers when we create them. If not, we should use a different marker type when it's introduced, and convert it later.

I think what's going on here is one type is saying "you have a reference, fill in the phandle", the other is saying "you have a phandle, fill in the reference". Those seem like they should be different types to me, even if they can be converted once all the fixups are applied.

Quoted 28 lines
livetree.c +24 -0
+
+			if (m->is_local) {
+				phandle = propval_cell_n(prop,
+							 m->offset / sizeof(cell_t));
+				refnode = get_node_by_phandle(dti->dt, phandle);
+				if (!refnode)
+					die("Node not found for phandle 0x%"PRIx32"\n", phandle);
+
+				m->ref = refnode->fullpath;
+				continue;
+			} else {
+				die("Found a non local phandle without a reference\n");
+			}
+		}
+	}
+
+	for_each_child(node, c)
+		update_phandles_ref_internal(dti, c);
+}
+
+void update_phandles_ref(struct dt_info *dti)
+{
+	update_phandles_ref_internal(dti, dti->dt);
+}
Signature · 1 line
2.52.0
Signature · 4 lines
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
#34 lore raw

Re: [RFC PATCH 08/77] dtc: Introduce update_phandles_ref()

Quoted 58 lines · On Thu, 15 Jan 2026 11:46:52 +1100 David Gibson <[email protected]>…
Quoted 57 lines · Herve Codina

With the introduction of FDT_REF_LOCAL dtb tag, a local phandle used by a property is identify when a dtb is parsed.

In order to have consistent internal data, the reference related to this phandle usage needs to be updated based on the phandle value.

This is done by update_phandles_ref().

---
 dtc.c      |  2 ++
 dtc.h      |  2 ++
 livetree.c | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+)
dtc.c +2 -0
index b3445b7..88f03ff 100644
@@ -333,6 +333,8 @@ int main(int argc, char *argv[])
 		generate_fixups = 1;
 	}
 
+	update_phandles_ref(dti);
+
 	process_checks(force, dti);
 
 	if (auto_label_aliases)
dtc.h +2 -0
index 965321c..351fe41 100644
@@ -345,6 +345,8 @@ 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 update_phandles_ref(struct dt_info *dti);
+
 /* Checks */
 
 void parse_checks_option(bool warn, bool error, const char *arg);
livetree.c +8 -0
index 9b67934..9e30a63 100644
@@ -1158,3 +1158,41 @@ 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 update_phandles_ref_internal(struct dt_info *dti, struct node *node)
+{
+	struct node *c;
+	struct property *prop;
+	struct marker *m;
+	struct node *refnode;
+	cell_t phandle;
Quoted 8 lines

livetree.c void generate_local_fixups_tree(struct dt_info *dti, const char *name) · line 1174

Quoted 6 lines
livetree.c +6 -0
+
+	for_each_property(node, prop) {
+		m = prop->val.markers;
+		for_each_marker_of_type(m, REF_PHANDLE) {
+			if (m->ref)
+				continue;  

IIUC this means that REF_PHANDLE markers can be missing their ref.

Yes, no ref are present in dtb for phandle pointing to local node, only the phandle value is present. We need at some point to set the ref from this phandle value.

Quoted 10 lines

Allowing the markers to be in an incomplete state is a footgun. If possible it would be better to fully generate the markers when we create them. If not, we should use a different marker type when it's introduced, and convert it later.

I think what's going on here is one type is saying "you have a reference, fill in the phandle", the other is saying "you have a phandle, fill in the reference". Those seem like they should be different types to me, even if they can be converted once all the fixups are applied.

Right, I can introduce
- REF_PHANDLE_FILL_PHANDLE: "you have a phandle, fill in the reference"

- REF_PHANDLE_FILL_REF: "you have a reference, fill the phandle" Well, fill the phandle or not... Indeed, this reference can be external and so this can be an unresolved symbol.

But anyway those new marker types will exist only between the parsing step and the step where we convert them to REF_PHANDLE markers.

Will see what I can propose in the next series iteration.

Best regards,
Hervé

#35 lore raw

Re: [RFC PATCH 08/77] dtc: Introduce update_phandles_ref()

Quoted 88 lines · Herve Codina
Quoted 58 lines · On Thu, 15 Jan 2026 11:46:52 +1100 David Gibson <[email protected]>…
Quoted 57 lines · Herve Codina

With the introduction of FDT_REF_LOCAL dtb tag, a local phandle used by a property is identify when a dtb is parsed.

In order to have consistent internal data, the reference related to this phandle usage needs to be updated based on the phandle value.

This is done by update_phandles_ref().

---
 dtc.c      |  2 ++
 dtc.h      |  2 ++
 livetree.c | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+)
dtc.c +2 -0
index b3445b7..88f03ff 100644
@@ -333,6 +333,8 @@ int main(int argc, char *argv[])
 		generate_fixups = 1;
 	}
 
+	update_phandles_ref(dti);
+
 	process_checks(force, dti);
 
 	if (auto_label_aliases)
dtc.h +2 -0
index 965321c..351fe41 100644
@@ -345,6 +345,8 @@ 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 update_phandles_ref(struct dt_info *dti);
+
 /* Checks */
 
 void parse_checks_option(bool warn, bool error, const char *arg);
livetree.c +8 -0
index 9b67934..9e30a63 100644
@@ -1158,3 +1158,41 @@ 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 update_phandles_ref_internal(struct dt_info *dti, struct node *node)
+{
+	struct node *c;
+	struct property *prop;
+	struct marker *m;
+	struct node *refnode;
+	cell_t phandle;
Quoted 8 lines

livetree.c void generate_local_fixups_tree(struct dt_info *dti, const char *name) · line 1174

Quoted 6 lines
livetree.c +6 -0
+
+	for_each_property(node, prop) {
+		m = prop->val.markers;
+		for_each_marker_of_type(m, REF_PHANDLE) {
+			if (m->ref)
+				continue;  

IIUC this means that REF_PHANDLE markers can be missing their ref.

Yes, no ref are present in dtb for phandle pointing to local node, only the phandle value is present. We need at some point to set the ref from this phandle value.

Quoted 10 lines

Allowing the markers to be in an incomplete state is a footgun. If possible it would be better to fully generate the markers when we create them. If not, we should use a different marker type when it's introduced, and convert it later.

I think what's going on here is one type is saying "you have a reference, fill in the phandle", the other is saying "you have a phandle, fill in the reference". Those seem like they should be different types to me, even if they can be converted once all the fixups are applied.

Right, I can introduce
- REF_PHANDLE_FILL_PHANDLE: "you have a phandle, fill in the reference"

Quoted 6 lines

- REF_PHANDLE_FILL_REF: "you have a reference, fill the phandle" Well, fill the phandle or not... Indeed, this reference can be external and so this can be an unresolved symbol.

But anyway those new marker types will exist only between the parsing step and the step where we convert them to REF_PHANDLE markers.

So REF_PHANDLE always has a complete reference, and a complete-as-possible phandle value (-1 if it's an external reference)? I think that makes sense - I don't love the proposed names for the earlier markers, but better ones aren't immediately occurring to me.

Quoted 8 lines

Will see what I can propose in the next series iteration.

Best regards,
Hervé

Signature · 4 lines
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
#36 lore raw

RFC PATCH 9/77 dtc: Introduce mark_local_phandles()

In reply to Herve Codina

In order to have the new FDT_REF_LOCAL tag present in a dtb, the phandle reference needs to be identify as a local reference.

This is the purpose of mark_local_phandles().

It identifies a phandle reference as a local reference when this reference points to a local node.

With that node, the related FDT_REF_LOCAL tag is set in the dtb.

---
 dtc.c      |  1 +
 dtc.h      |  1 +
 livetree.c | 26 ++++++++++++++++++++++++++
 3 files changed, 28 insertions(+)
dtc.c +1 -0
index 88f03ff..d0b4de3 100644
@@ -334,6 +334,7 @@ int main(int argc, char *argv[])
 	}
 
 	update_phandles_ref(dti);
+	mark_local_phandles(dti);
 
 	process_checks(force, dti);
 
dtc.h +1 -0
index 351fe41..08c9f07 100644
@@ -346,6 +346,7 @@ void generate_fixups_tree(struct dt_info *dti, const char *name);
 void generate_local_fixups_tree(struct dt_info *dti, const char *name);
 
 void update_phandles_ref(struct dt_info *dti);
+void mark_local_phandles(struct dt_info *dti);
 
 /* Checks */
 
livetree.c +26 -0
index 9e30a63..2a0a7ed 100644
@@ -1196,3 +1196,29 @@ void update_phandles_ref(struct dt_info *dti)
 {
 	update_phandles_ref_internal(dti, dti->dt);
 }
+
+static void mark_local_phandles_internal(struct dt_info *dti,
+					 struct node *node)
+{
+	struct node *c;
+	struct property *prop;
+	struct marker *m;
+	struct node *refnode;
+
+	for_each_property(node, prop) {
+		m = prop->val.markers;
+		for_each_marker_of_type(m, REF_PHANDLE) {
+			refnode = get_node_by_ref(dti->dt, m->ref);
+			if (refnode)
+				m->is_local = true;
+		}
+	}
+
+	for_each_child(node, c)
+		mark_local_phandles_internal(dti, c);
+}
+
+void mark_local_phandles(struct dt_info *dti)
+{
+	mark_local_phandles_internal(dti, dti->dt);
+}
Signature · 1 line
2.52.0
#37 lore raw

Re: [RFC PATCH 09/77] dtc: Introduce mark_local_phandles()

Quoted 9 lines · Herve Codina

In order to have the new FDT_REF_LOCAL tag present in a dtb, the phandle reference needs to be identify as a local reference.

This is the purpose of mark_local_phandles().

It identifies a phandle reference as a local reference when this reference points to a local node.

With that node, the related FDT_REF_LOCAL tag is set in the dtb.

I dislike caching redundant information (whether the ref is local) - it's an opportunity for them to get out of sync and cause bugs. Is there a strong case that you can't just determine whether it's local only when you actually go to use it?

Quoted 70 lines
---
 dtc.c      |  1 +
 dtc.h      |  1 +
 livetree.c | 26 ++++++++++++++++++++++++++
 3 files changed, 28 insertions(+)
dtc.c +1 -0
index 88f03ff..d0b4de3 100644
@@ -334,6 +334,7 @@ int main(int argc, char *argv[])
 	}
 
 	update_phandles_ref(dti);
+	mark_local_phandles(dti);
 
 	process_checks(force, dti);
 
dtc.h +1 -0
index 351fe41..08c9f07 100644
@@ -346,6 +346,7 @@ void generate_fixups_tree(struct dt_info *dti, const char *name);
 void generate_local_fixups_tree(struct dt_info *dti, const char *name);
 
 void update_phandles_ref(struct dt_info *dti);
+void mark_local_phandles(struct dt_info *dti);
 
 /* Checks */
 
livetree.c +26 -0
index 9e30a63..2a0a7ed 100644
@@ -1196,3 +1196,29 @@ void update_phandles_ref(struct dt_info *dti)
 {
 	update_phandles_ref_internal(dti, dti->dt);
 }
+
+static void mark_local_phandles_internal(struct dt_info *dti,
+					 struct node *node)
+{
+	struct node *c;
+	struct property *prop;
+	struct marker *m;
+	struct node *refnode;
+
+	for_each_property(node, prop) {
+		m = prop->val.markers;
+		for_each_marker_of_type(m, REF_PHANDLE) {
+			refnode = get_node_by_ref(dti->dt, m->ref);
+			if (refnode)
+				m->is_local = true;
+		}
+	}
+
+	for_each_child(node, c)
+		mark_local_phandles_internal(dti, c);
+}
+
+void mark_local_phandles(struct dt_info *dti)
+{
+	mark_local_phandles_internal(dti, dti->dt);
+}
Signature · 1 line
2.52.0
Signature · 4 lines
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
#38 lore raw

Re: [RFC PATCH 09/77] dtc: Introduce mark_local_phandles()

Hi David,

Quoted 9 lines · On Thu, 15 Jan 2026 11:48:44 +1100 David Gibson <[email protected]>…
Quoted 8 lines · Herve Codina

In order to have the new FDT_REF_LOCAL tag present in a dtb, the phandle reference needs to be identify as a local reference.

This is the purpose of mark_local_phandles().

It identifies a phandle reference as a local reference when this reference points to a local node.

Quoted 6 lines
Quoted 1 line

With that node, the related FDT_REF_LOCAL tag is set in the dtb.

I dislike caching redundant information (whether the ref is local) - it's an opportunity for them to get out of sync and cause bugs. Is there a strong case that you can't just determine whether it's local only when you actually go to use it?

Well, I can't find any strong case.

I would like to avoid passing the full dti (struct dt_info) to flatten_tree() in order to determine if the ref is local or not to set a FDT_REF_LOCAL or a FDT_REF_PHANDLE tag.

Also, this flag, set when a FDT_REF_LOCAL tag is parsed from a dtb, is useful later when the ref has to be found based on the phandle value.

Indeed, because the is_local flag is set, the phandle value available in the property *must* reference an existing node in the dtb.

In other word, in update_phandles_ref_internal(),
--- 8< ---

	if (m->is_local) {
		phandle = propval_cell_n(prop,
					 m->offset / sizeof(cell_t));
		refnode = dti_get_node_by_phandle(dti, phandle);
		if (!refnode)
			die("Node not found for phandle 0x%"PRIx32"\n", phandle);

		m->ref = refnode->fullpath;
		continue;
	} else {
		...

--- 8< ---

Best regards,
Hervé

#39 lore raw

Re: [RFC PATCH 09/77] dtc: Introduce mark_local_phandles()

Quoted 27 lines · Herve Codina

Hi David,

Quoted 9 lines · On Thu, 15 Jan 2026 11:48:44 +1100 David Gibson <[email protected]>…
Quoted 8 lines · Herve Codina

In order to have the new FDT_REF_LOCAL tag present in a dtb, the phandle reference needs to be identify as a local reference.

This is the purpose of mark_local_phandles().

It identifies a phandle reference as a local reference when this reference points to a local node.

Quoted 6 lines
Quoted 1 line

With that node, the related FDT_REF_LOCAL tag is set in the dtb.

I dislike caching redundant information (whether the ref is local) - it's an opportunity for them to get out of sync and cause bugs. Is there a strong case that you can't just determine whether it's local only when you actually go to use it?

Well, I can't find any strong case.

I would like to avoid passing the full dti (struct dt_info) to flatten_tree() in order to determine if the ref is local or not to set a FDT_REF_LOCAL or a FDT_REF_PHANDLE tag.

Quoted 7 lines

Also, this flag, set when a FDT_REF_LOCAL tag is parsed from a dtb, is useful later when the ref has to be found based on the phandle value.

Indeed, because the is_local flag is set, the phandle value available in the property *must* reference an existing node in the dtb.

In other word, in update_phandles_ref_internal(),

Hmm, I see. As with the "known phandle, unknown ref" vs. "known ref, unknown phandle" cases, I think this might be clearer with different marker types. During parse we make everything "known ref, unknown phandle", then later change to either "known ref, resolved to local phandle" or "known ref, needs external resolution" markers.

Quoted 17 lines

--- 8< ---

	if (m->is_local) {
		phandle = propval_cell_n(prop,
					 m->offset / sizeof(cell_t));
		refnode = dti_get_node_by_phandle(dti, phandle);
		if (!refnode)
			die("Node not found for phandle 0x%"PRIx32"\n", phandle);

		m->ref = refnode->fullpath;
		continue;
	} else {
		...

--- 8< ---

Best regards,
Hervé

Signature · 4 lines
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
#40 lore raw

Re: [RFC PATCH 09/77] dtc: Introduce mark_local_phandles()

Quoted 34 lines · On Mon, 19 Jan 2026 16:46:37 +1100 David Gibson <[email protected]>…
Quoted 33 lines · Herve Codina

Hi David,

Quoted 9 lines · On Thu, 15 Jan 2026 11:48:44 +1100 David Gibson <[email protected]>…
Quoted 8 lines · Herve Codina

In order to have the new FDT_REF_LOCAL tag present in a dtb, the phandle reference needs to be identify as a local reference.

This is the purpose of mark_local_phandles().

It identifies a phandle reference as a local reference when this reference points to a local node.

Quoted 6 lines
Quoted 1 line

With that node, the related FDT_REF_LOCAL tag is set in the dtb.

I dislike caching redundant information (whether the ref is local) - it's an opportunity for them to get out of sync and cause bugs. Is there a strong case that you can't just determine whether it's local only when you actually go to use it?

Well, I can't find any strong case.

I would like to avoid passing the full dti (struct dt_info) to flatten_tree() in order to determine if the ref is local or not to set a FDT_REF_LOCAL or a FDT_REF_PHANDLE tag.

Also, this flag, set when a FDT_REF_LOCAL tag is parsed from a dtb, is useful later when the ref has to be found based on the phandle value.

Indeed, because the is_local flag is set, the phandle value available in the property *must* reference an existing node in the dtb.

Quoted 7 lines
Quoted 1 line

In other word, in update_phandles_ref_internal(),

Hmm, I see. As with the "known phandle, unknown ref" vs. "known ref, unknown phandle" cases, I think this might be clearer with different marker types. During parse we make everything "known ref, unknown phandle", then later change to either "known ref, resolved to local phandle" or "known ref, needs external resolution" markers.

When we parse a dtb, we have "Unknown ref, known phandle". FDT_REF_LOCAL identify a local phandle value without any 'ref' involved.

The ref is set after parsing and it is set to the full path of the node matching the phandle value.

Will see what I can do with new markers to identify those different cases.

Quoted 17 lines
Quoted 17 lines

--- 8< ---

	if (m->is_local) {
		phandle = propval_cell_n(prop,
					 m->offset / sizeof(cell_t));
		refnode = dti_get_node_by_phandle(dti, phandle);
		if (!refnode)
			die("Node not found for phandle 0x%"PRIx32"\n", phandle);

		m->ref = refnode->fullpath;
		continue;
	} else {
		...

--- 8< ---

Quoted 4 lines
Quoted 3 lines

Best regards,
Hervé

Best regards,
Hervé

#41 lore raw

RFC PATCH 10/77 tests: Add basic metadata tests

In reply to Herve Codina

This first test is related to local phandle references (FDT_REF_LOCAL dtb tag).

The test pattern used is
- Generate a dts (xxx.dts.dts) from an input dts
- Check this generated dts against expected contents
- Generate a dtb (xxx.dtb) from the same input dts
- Check this generated dtb against expected contents
- Generate a dts (xxx.dtb.dts) from the generated dtb
- Check this generated dts against expected contents
- Generate a dtb (xxx.dtb.dts.dtb) from the generated dts
- Check this generated dtb, expect the same contents as for xxx.dtb

Even if only one meta-data feature is currently tested in this tests introduction, use a loop in order to ease future addition consisting in adding new input dts as soon as new meta-data feature are supported.

---
 tests/meson.build                      |  3 +-
 tests/metadata_reflocal.dtb.dts.expect | 23 ++++++++++
 tests/metadata_reflocal.dtb.expect     | 20 +++++++++
 tests/metadata_reflocal.dts            | 27 ++++++++++++
 tests/metadata_reflocal.dts.dts.expect | 23 ++++++++++
 tests/run_tests.sh                     | 58 +++++++++++++++++++++++++-
 6 files changed, 152 insertions(+), 2 deletions(-)
 create mode 100644 tests/metadata_reflocal.dtb.dts.expect
 create mode 100644 tests/metadata_reflocal.dtb.expect
 create mode 100644 tests/metadata_reflocal.dts
 create mode 100644 tests/metadata_reflocal.dts.dts.expect
tests/meson.build +2 -1
index 37bfd47..e81a2e1 100644
@@ -140,7 +140,8 @@ run_test_types = [
   'fdtget',
   'fdtput',
   'fdtdump',
-  'fdtoverlay'
+  'fdtoverlay',
+  'metadata'
 ]
 run_test_deps = [
   dtc_tools, dumptrees_dtb, tests_exe
tests/metadata_reflocal.dtb.dts.expect new file +23 -0
new file mode 100644
index 0000000..076c17a
@@ -0,0 +1,23 @@
+/dts-v1/;
+
+/ {
+
+	node-a {
+
+		subnode-a {
+			phandle = <0x01>;
+		};
+	};
+
+	node-b {
+		phandle = <0x02>;
+	};
+
+	node-c {
+	};
+
+	node-d {
+		ref-subnode-a = <&{/node-a/subnode-a}>;
+		ref-node-b = <0x123 0x456 &{/node-b} 0x789>;
+	};
+};
tests/metadata_reflocal.dtb.expect new file +20 -0
new file mode 100644
index 0000000..33b3896
@@ -0,0 +1,20 @@
+/dts-v1/;
+
+/ {
+    node-a {
+        subnode-a {
+            phandle = <0x00000001>;
+        };
+    };
+    node-b {
+        phandle = <0x00000002>;
+    };
+    node-c {
+    };
+    node-d {
+        ref-subnode-a = <0x00000001>;
+        // [FDT_REF_LOCAL] ref-subnode-a[0]
+        ref-node-b = <0x00000123 0x00000456 0x00000002 0x00000789>;
+        // [FDT_REF_LOCAL] ref-node-b[8]
+    };
+};
tests/metadata_reflocal.dts new file +27 -0
new file mode 100644
index 0000000..f04d24f
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
+/*
+ * Copyright (C) 2026 Bootlin
+ */
+
+/dts-v1/;
+
+/ {
+	node-a {
+		subnode_a: subnode-a {
+		};
+	};
+
+	node_b: node-b {
+	};
+
+	node-c {
+	};
+
+	node_d: node-d {
+		ref-subnode-a = <&subnode_a>;
+	};
+};
+
+&node_d {
+	ref-node-b = <0x123 0x456 &node_b 0x789>;
+};
tests/metadata_reflocal.dts.dts.expect new file +23 -0
new file mode 100644
index 0000000..b72b545
@@ -0,0 +1,23 @@
+/dts-v1/;
+
+/ {
+
+	node-a {
+
+		subnode_a: subnode-a {
+			phandle = <0x01>;
+		};
+	};
+
+	node_b: node-b {
+		phandle = <0x02>;
+	};
+
+	node-c {
+	};
+
+	node_d: node-d {
+		ref-subnode-a = <&subnode_a>;
+		ref-node-b = <0x123 0x456 &node_b 0x789>;
+	};
+};
tests/run_tests.sh +57 -1

76 lines not on this page · raw message

Signature · 1 line
2.52.0
#42 lore raw

Re: [RFC PATCH 10/77] tests: Add basic metadata tests

Quoted 13 lines · Herve Codina

This first test is related to local phandle references (FDT_REF_LOCAL dtb tag).

The test pattern used is
- Generate a dts (xxx.dts.dts) from an input dts
- Check this generated dts against expected contents
- Generate a dtb (xxx.dtb) from the same input dts
- Check this generated dtb against expected contents
- Generate a dts (xxx.dtb.dts) from the generated dtb
- Check this generated dts against expected contents
- Generate a dtb (xxx.dtb.dts.dtb) from the generated dts
- Check this generated dtb, expect the same contents as for xxx.dtb

Quoted 3 lines

Even if only one meta-data feature is currently tested in this tests introduction, use a loop in order to ease future addition consisting in adding new input dts as soon as new meta-data feature are supported.

As a rule of tumb, I prefer tests to be introduced in the same patch that introduces the feature tested. Usually, I don't care that much, but in a giant series like this, it would really help review (the tests help to document the feature being added without switching between patches).

Quoted 233 lines
---
 tests/meson.build                      |  3 +-
 tests/metadata_reflocal.dtb.dts.expect | 23 ++++++++++
 tests/metadata_reflocal.dtb.expect     | 20 +++++++++
 tests/metadata_reflocal.dts            | 27 ++++++++++++
 tests/metadata_reflocal.dts.dts.expect | 23 ++++++++++
 tests/run_tests.sh                     | 58 +++++++++++++++++++++++++-
 6 files changed, 152 insertions(+), 2 deletions(-)
 create mode 100644 tests/metadata_reflocal.dtb.dts.expect
 create mode 100644 tests/metadata_reflocal.dtb.expect
 create mode 100644 tests/metadata_reflocal.dts
 create mode 100644 tests/metadata_reflocal.dts.dts.expect
tests/meson.build +2 -1
index 37bfd47..e81a2e1 100644
@@ -140,7 +140,8 @@ run_test_types = [
   'fdtget',
   'fdtput',
   'fdtdump',
-  'fdtoverlay'
+  'fdtoverlay',
+  'metadata'
 ]
 run_test_deps = [
   dtc_tools, dumptrees_dtb, tests_exe
tests/metadata_reflocal.dtb.dts.expect new file +23 -0
new file mode 100644
index 0000000..076c17a
@@ -0,0 +1,23 @@
+/dts-v1/;
+
+/ {
+
+	node-a {
+
+		subnode-a {
+			phandle = <0x01>;
+		};
+	};
+
+	node-b {
+		phandle = <0x02>;
+	};
+
+	node-c {
+	};
+
+	node-d {
+		ref-subnode-a = <&{/node-a/subnode-a}>;
+		ref-node-b = <0x123 0x456 &{/node-b} 0x789>;
+	};
+};
tests/metadata_reflocal.dtb.expect new file +20 -0
new file mode 100644
index 0000000..33b3896
@@ -0,0 +1,20 @@
+/dts-v1/;
+
+/ {
+    node-a {
+        subnode-a {
+            phandle = <0x00000001>;
+        };
+    };
+    node-b {
+        phandle = <0x00000002>;
+    };
+    node-c {
+    };
+    node-d {
+        ref-subnode-a = <0x00000001>;
+        // [FDT_REF_LOCAL] ref-subnode-a[0]
+        ref-node-b = <0x00000123 0x00000456 0x00000002 0x00000789>;
+        // [FDT_REF_LOCAL] ref-node-b[8]
+    };
+};
tests/metadata_reflocal.dts new file +27 -0
new file mode 100644
index 0000000..f04d24f
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
+/*
+ * Copyright (C) 2026 Bootlin
+ */
+
+/dts-v1/;
+
+/ {
+	node-a {
+		subnode_a: subnode-a {
+		};
+	};
+
+	node_b: node-b {
+	};
+
+	node-c {
+	};
+
+	node_d: node-d {
+		ref-subnode-a = <&subnode_a>;
+	};
+};
+
+&node_d {
+	ref-node-b = <0x123 0x456 &node_b 0x789>;
+};
tests/metadata_reflocal.dts.dts.expect new file +23 -0
new file mode 100644
index 0000000..b72b545
@@ -0,0 +1,23 @@
+/dts-v1/;
+
+/ {
+
+	node-a {
+
+		subnode_a: subnode-a {
+			phandle = <0x01>;
+		};
+	};
+
+	node_b: node-b {
+		phandle = <0x02>;
+	};
+
+	node-c {
+	};
+
+	node_d: node-d {
+		ref-subnode-a = <&subnode_a>;
+		ref-node-b = <0x123 0x456 &node_b 0x789>;
+	};
+};
tests/run_tests.sh +57 -1
index f07092b..7a8bdbc 100755
@@ -1090,6 +1090,59 @@ fdtoverlay_tests() {
     run_wrap_test test "$bd" = "$pd"
 }
 
+# $1: f1 file
+# $2: f2 file
+check_diff () {
+    printf "diff $1 $2:	"
+    local f1="$1"
+    local f2="$2"
+    (
+        if diff $f1 $f2 >/dev/null; then
+            PASS
+        else
+            if [ -z "$QUIET_TEST" ]; then
+                echo "DIFF :-:"
+                diff -u $f1 $f2
+            fi
+            FAIL "Results differ from expected"
+        fi
+    )
+}
+
+# $1: dtb file
+# $2: out file
+wrap_fdtdump () {
+    printf "wrap_fdtdump $1:	"
+    local dtb="$1"
+    local out="$2"
+    (
+        if $FDTDUMP ${dtb} 2>/dev/null >${out}; then
+            PASS
+        else
+            FAIL
+        fi
+    )
+}
+
+metadata_tests() {
+	for dt in metadata_reflocal; do
+		run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts"
+		base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect"
+		run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts"
+		base_run_test wrap_fdtdump $dt.dtb $dt.dtb.out
+		# Remove unneeded comments
+		sed -i '/^\/\/ /d' $dt.dtb.out
+		base_run_test check_diff $dt.dtb.out "$SRCDIR/$dt.dtb.expect"
+		run_dtc_test -I dtb -O dts -o $dt.dtb.dts $dt.dtb
+		base_run_test check_diff $dt.dtb.dts "$SRCDIR/$dt.dtb.dts.expect"
+		run_dtc_test -I dts -O dtb -o $dt.dtb.dts.dtb $dt.dtb.dts
+		base_run_test wrap_fdtdump $dt.dtb.dts.dtb $dt.dtb.dts.dtb.out
+		# Remove unneeded comments
+		sed -i '/^\/\/ /d' $dt.dtb.dts.dtb.out
+		base_run_test check_diff $dt.dtb.dts.dtb.out "$SRCDIR/$dt.dtb.expect"
+	done
+}
+
 pylibfdt_tests () {
     run_dtc_test -I dts -O dtb -o test_props.dtb "$SRCDIR/test_props.dts"
     TMP=/tmp/tests.stderr.$$
@@ -1129,7 +1182,7 @@ while getopts "vt:me" ARG ; do
 done
 
 if [ -z "$TESTSETS" ]; then
-    TESTSETS="libfdt utilfdt dtc dtbs_equal fdtget fdtput fdtdump fdtoverlay"
+    TESTSETS="libfdt utilfdt dtc dtbs_equal fdtget fdtput fdtdump fdtoverlay metadata"
 
     # Test pylibfdt if the libfdt Python module is available.
     if ! $no_python; then
@@ -1169,6 +1222,9 @@ for set in $TESTSETS; do
         "fdtoverlay")
 	    fdtoverlay_tests
 	    ;;
+	"metadata")
+	    metadata_tests
+	    ;;
     esac
 done
 
Signature · 1 line
2.52.0
Signature · 4 lines
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
#43 lore raw

Re: [RFC PATCH 10/77] tests: Add basic metadata tests

Quoted 18 lines · On Thu, 15 Jan 2026 11:50:56 +1100 David Gibson <[email protected]>…
Quoted 13 lines · Herve Codina

This first test is related to local phandle references (FDT_REF_LOCAL dtb tag).

The test pattern used is
- Generate a dts (xxx.dts.dts) from an input dts
- Check this generated dts against expected contents
- Generate a dtb (xxx.dtb) from the same input dts
- Check this generated dtb against expected contents
- Generate a dts (xxx.dtb.dts) from the generated dtb
- Check this generated dts against expected contents
- Generate a dtb (xxx.dtb.dts.dtb) from the generated dts
- Check this generated dtb, expect the same contents as for xxx.dtb

Quoted 3 lines

Even if only one meta-data feature is currently tested in this tests introduction, use a loop in order to ease future addition consisting in adding new input dts as soon as new meta-data feature are supported.

Quoted 5 lines

As a rule of tumb, I prefer tests to be introduced in the same patch that introduces the feature tested. Usually, I don't care that much, but in a giant series like this, it would really help review (the tests help to document the feature being added without switching between patches).

Hum ok but it is worth noting that a feature needs several patches to be fully supported.

In order to ease the review (maybe I was wrong), I chose to have distinct patches for modification related to new dts keywords and for modification related to new dtb tag and tried to have patches as small as possible.

The last patch of a new feature was a patch adding test.

I am open to remove patches that just add tests. In that case tests will be added in the last patch related to a new feature. You still need to switch between patches in that case.

Further more, during iteration, the last patch of a new feature could be modified just because the test part is present in this patch even if other part of the patch itself is not impacted.

I mean:
- patch 1: related to dts keyword
- patch 2: related to dtb + test

Update patch 1 will imply an update to patch 2.
I am not sure that this will ease the review.

To avoid that, I can merge all patches related to feature into only one patch. This patch can be quite huge and I am not sure that it will be easy to review it.

Once again, I am open to merging patches. Let me know what do you prefer in terms of patch granularity.

Best regards,
Hervé

#44 lore raw

Re: [RFC PATCH 10/77] tests: Add basic metadata tests

Quoted 21 lines · Herve Codina
Quoted 18 lines · On Thu, 15 Jan 2026 11:50:56 +1100 David Gibson <[email protected]>…
Quoted 16 lines · Herve Codina

This first test is related to local phandle references (FDT_REF_LOCAL dtb tag).

The test pattern used is
- Generate a dts (xxx.dts.dts) from an input dts
- Check this generated dts against expected contents
- Generate a dtb (xxx.dtb) from the same input dts
- Check this generated dtb against expected contents
- Generate a dts (xxx.dtb.dts) from the generated dtb
- Check this generated dts against expected contents
- Generate a dtb (xxx.dtb.dts.dtb) from the generated dts
- Check this generated dtb, expect the same contents as for xxx.dtb

Even if only one meta-data feature is currently tested in this tests introduction, use a loop in order to ease future addition consisting in adding new input dts as soon as new meta-data feature are supported.

Quoted 8 lines
Quoted 5 lines

As a rule of tumb, I prefer tests to be introduced in the same patch that introduces the feature tested. Usually, I don't care that much, but in a giant series like this, it would really help review (the tests help to document the feature being added without switching between patches).

Hum ok but it is worth noting that a feature needs several patches to be fully supported.

Right, it's a general guideline, not a hard and fast rule.

In most cases I'd suggest putting the tests in with the patch that adds the piece they need to work. That does mean that if some of the simpler tests can operate with only some of the patches, moving those tests earlier.

Again, only a guideline, but it helps review because the tests act as documentation for the functionality the patch is adding.

Quoted 4 lines

In order to ease the review (maybe I was wrong), I chose to have distinct patches for modification related to new dts keywords and for modification related to new dtb tag and tried to have patches as small as possible.

Small is usually good. However, if it's so small that the patch doesn't express a complete idea so you have to keep referencing surrounding patches to make sense of it, then it's no longer good. Fwiw, think these patches are mostly well divided, but as above, folding tests in with code changes is usually better because the tests help show what the new code is expected to do.

[I will note that having the tests as a separate patch, usuallly *before* the code changes is very useful during development. But git makes it pretty easy to re-order and fold things together when you're ready to post]

Quoted 5 lines

The last patch of a new feature was a patch adding test.

I am open to remove patches that just add tests. In that case tests will be added in the last patch related to a new feature. You still need to switch between patches in that case.

Yes, but not quite as much. And even less if those tests which can be moved earlier are moved earlier.

Quoted 10 lines

Further more, during iteration, the last patch of a new feature could be modified just because the test part is present in this patch even if other part of the patch itself is not impacted.

I mean:
- patch 1: related to dts keyword
- patch 2: related to dtb + test

Update patch 1 will imply an update to patch 2.
I am not sure that this will ease the review.

Point taken. For tests that intrinsically require things from multiple earlier patches, having them separate probably makes sense. Often at least some of the tests can be more closely related to a single patch though. When possible, that's generally preferable.

Quoted 3 lines

To avoid that, I can merge all patches related to feature into only one patch. This patch can be quite huge and I am not sure that it will be easy to review it.

No, definitely don't do that.

Quoted 6 lines

Once again, I am open to merging patches. Let me know what do you prefer in terms of patch granularity.

Best regards,
Hervé

Signature · 4 lines
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
#45 lore raw

RFC PATCH 11/77 Add support for FDT_REF_PHANDLE dtb tag

In reply to Herve Codina

The FDT_REF_PHANDLE dtb tag is similar to the FDT_REF_LOCAL tag except that it identifies a reference to an external phandle. The node referenced by the phandle is not present in the device-tree blob.

The FDT_REF_PHANDLE dtb tag is a meta-data tag attached to a property.

It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is not local node (i.e. the node is not present in the device-tree blob). This tag can be available only in overlay or addon device-tree blobs. The phandle value used in the property has to be resolved when the device-tree blob is applied on top of a base device-tree.

It is followed by two values and a possible alignment padding:
- offset (32bit):
Offset in the property data where the phandle is available.
- label (string including \0):
The label to use to resolve the phandle value.
- padding:

     Padding (0x00) added to have the next tag aligned on 32bit.

Example:
FDT_PROP 0x00000008 xxxxxxxx 0x00 0x01 0x02 0x03 0xff 0xff 0xff 0xff FDT_REF_PHANDLE 0x00000004 "foo1" 0x00 0x00 0x00

This means that at the offset 4 of the property data, the value (0xffffffff) is an unresolved phandle value and the related node is the node referenced by "foo1".

This is what is encoded in the dtb when the related dts has a property with the value set to <0x00010203 &foo1> with 'foo1' a reference to an non local node.

If several non local phandles are used in the property data, several FDT_REF_PHANDLE are present after the FDT_PROP tag. Each of them points with its offset value to the position of one phandle.

For instance, if a first property with 8 bytes of data has a unresolved phandle value at offset 4 referenced by "foo" and a second property with 16 bytes of data has unresolved phandle values at offset 0 and 8 referenced by "bar" and "baz", the following tags sequence is present:
FDT_PROP 0x00000008 xxxxxxxx <data bytes>
FDT_REF_PHANDLE 0x00000004 "foo" 0x00 0x00 0x00
FDT_PROP 0x00000010 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000000 "bar" 0x00 0x00 0x00 FDT_REF_LOCAL 0x00000008 "baz" 0x00 0x00 0x00

Add support for this new dtb tag.

---
 dtc.c        | 12 ++++++++++++
 fdtdump.c    | 10 ++++++++++
 flattree.c   | 37 +++++++++++++++++++++++++++++++++++++
 libfdt/fdt.c | 16 ++++++++++++++++
 libfdt/fdt.h |  2 ++
 5 files changed, 77 insertions(+)
dtc.c +12 -0
index d0b4de3..fe8e8e4 100644
@@ -336,6 +336,18 @@ int main(int argc, char *argv[])
 	update_phandles_ref(dti);
 	mark_local_phandles(dti);
 
+	/*
+	 * With FDT_REF_PHANDLE added in dtbs, we need to identified
+	 * if some unresolved phandle references are allowed in the dtb
+	 * we have parsed (needed for process_check() to run properly).
+	 *
+	 * Identify plugin device-trees (overlays) based on specific node
+	 * presence.
+	 */
+	if (get_subnode(dti->dt, "__fixups__") ||
+	    get_subnode(dti->dt, "__local_fixups__"))
+		dti->dtsflags |= DTSF_PLUGIN;
+
 	process_checks(force, dti);
 
 	if (auto_label_aliases)
fdtdump.c +10 -0
index dffa9a6..7300280 100644
@@ -158,6 +158,16 @@ static void dump_blob(void *blob, bool debug)
 			continue;
 		}
 
+		if (tag == FDT_REF_PHANDLE) {
+			offset = fdt32_to_cpu(GET_CELL(p));
+			s = p;
+			p = PALIGN(p + strlen(s) + 1, 4);
+
+			printf("%*s// [FDT_REF_PHANDLE] %s[%"PRIu32"], ref = %s\n",
+				depth * shift, "", last_prop_name, offset, s);
+			continue;
+		}
+
 		fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
 		break;
 	}
flattree.c +37 -0
index 5c597ad..07f7545 100644
@@ -44,6 +44,7 @@ struct emitter {
 	void (*endnode)(void *, struct label *labels);
 	void (*property)(void *, struct label *labels);
 	void (*ref_local)(void *);
+	void (*ref_phandle)(void *);
 };
 
 static void bin_emit_cell(void *e, cell_t val)
@@ -98,6 +99,11 @@ static void bin_emit_ref_local(void *e)
 	bin_emit_cell(e, FDT_REF_LOCAL);
 }
 
+static void bin_emit_ref_phandle(void *e)
+{
+	bin_emit_cell(e, FDT_REF_PHANDLE);
+}
+
 static struct emitter bin_emitter = {
 	.cell = bin_emit_cell,
 	.string = bin_emit_string,
@@ -107,6 +113,7 @@ static struct emitter bin_emitter = {
 	.endnode = bin_emit_endnode,
 	.property = bin_emit_property,
 	.ref_local = bin_emit_ref_local,
+	.ref_phandle = bin_emit_ref_phandle,
 };
 
 static void emit_label(FILE *f, const char *prefix, const char *label)
@@ -226,6 +233,14 @@ static void asm_emit_ref_local(void *e)
 	asm_emit_cell(e, FDT_REF_LOCAL);
 }
 
+static void asm_emit_ref_phandle(void *e)
+{
+	FILE *f = e;
+
+	fprintf(f, "\t/* FDT_REF_PHANDLE */\n");
+	asm_emit_cell(e, FDT_REF_PHANDLE);
+}
+
 static struct emitter asm_emitter = {
 	.cell = asm_emit_cell,
 	.string = asm_emit_string,
@@ -235,6 +250,7 @@ static struct emitter asm_emitter = {
 	.endnode = asm_emit_endnode,
 	.property = asm_emit_property,
 	.ref_local = asm_emit_ref_local,
+	.ref_phandle = asm_emit_ref_phandle,
 };
 
 static int stringtable_insert(struct data *d, const char *str)
@@ -299,6 +315,15 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
 					emit->cell(etarget, m->offset);
 					continue;
 				}
+
+				if (m->ref[0] == '/')
+					die("Phandle uses a non local reference by path (%s)\n",
+					    m->ref);
+
+				emit->ref_phandle(etarget);
+				emit->cell(etarget, m->offset);
+				emit->string(etarget, m->ref, 0);
+				emit->align(etarget, sizeof(cell_t));
 			}
 		}
 	}
@@ -767,6 +792,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
 	const char *flatname;
 	uint32_t val;
 	uint32_t offset;
+	const char *str;
 
 	node = build_node(NULL, NULL, NULL);
 
@@ -824,6 +850,17 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
 			prop->val = data_append_markers(prop->val, m);
 			break;
 
+		case FDT_REF_PHANDLE:
+			if (!(flags & FTF_REF_XXX))
+				die("REF_PHANDLE tag found in flat tree"
+					" version <18\n");
+
+			offset = flat_read_word(dtbuf);
+			str = flat_read_string(dtbuf);
+			m = alloc_marker(offset, REF_PHANDLE, xstrdup(str));
+			prop->val = data_append_markers(prop->val, m);
+			break;
+
 		default:
 			die("Invalid opcode word %08x in device tree blob\n",
 			    val);
libfdt/fdt.c +16 -0
index 7268fb6..8f3c35d 100644
@@ -217,6 +217,21 @@ uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffset)
 		offset += sizeof(fdt32_t);
 		break;
 
+	case FDT_REF_PHANDLE:
+		/* Skip offset value */
+		tmp32p = fdt_offset_ptr(fdt, offset, sizeof(*tmp32p));
+		if (!can_assume(VALID_DTB) && !tmp32p)
+			return FDT_END; /* premature end */
+		offset += sizeof(fdt32_t);
+
+		/* Skip ref */
+		do {
+			p = fdt_offset_ptr(fdt, offset++, 1);
+		} while (p && (*p != '\0'));
+		if (!can_assume(VALID_DTB) && !p)
+			return FDT_END; /* premature end */
+		break;
+
 	default:
 		return FDT_END;
 	}
@@ -257,6 +272,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 			return tag;
 
 		case FDT_REF_LOCAL:
+		case FDT_REF_PHANDLE:
 			/*
 			 * Next tag is a meta-data tag present in the middle
 			 * of the structure -> Skip it and look at next one
libfdt/fdt.h +2 -0
index f8efdf1..530d2e5 100644
@@ -56,6 +56,8 @@ struct fdt_property {
 					   size, content */
 #define FDT_NOP		0x4		/* nop */
 #define FDT_REF_LOCAL   0x5		/* local phandle reference: offset */
+#define FDT_REF_PHANDLE 0x6		/* external phandle reference: offset,
+					   external label */
 #define FDT_END		0x9
 
 #define FDT_V1_SIZE	(7*sizeof(fdt32_t))
Signature · 1 line
2.52.0
#46 lore raw

Re: [RFC PATCH 11/77] Add support for FDT_REF_PHANDLE dtb tag

Quoted 3 lines · Herve Codina

The FDT_REF_PHANDLE dtb tag is similar to the FDT_REF_LOCAL tag except that it identifies a reference to an external phandle. The node referenced by the phandle is not present in the device-tree blob.

The names FDT_REF_PHANDLE and FDT_REF_LOCAL are perhaps a little misleading - both are marking a phandle, the difference is in the form of reference. That's quite difference from the distinction between the REF_PHANDLE and REF_PATH marker types, where the difference is in what the reference expands to in the property.

Quoted 8 lines

The FDT_REF_PHANDLE dtb tag is a meta-data tag attached to a property.

It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is not local node (i.e. the node is not present in the device-tree blob). This tag can be available only in overlay or addon device-tree blobs. The phandle value used in the property has to be resolved when the device-tree blob is applied on top of a base device-tree.

This is kind of looking ahead, but does that imply that this tag is only valid in addon dtbs?

Quoted 5 lines

It is followed by two values and a possible alignment padding:
- offset (32bit):
Offset in the property data where the phandle is available.
- label (string including \0):
The label to use to resolve the phandle value.

I expect it will become apparent later in the series, but it would be helpful to clarify what the scope of that label is. A single node? The whole tree? Across a tree and all its possible addons?

Quoted 235 lines

- padding:

     Padding (0x00) added to have the next tag aligned on 32bit.

Example:
FDT_PROP 0x00000008 xxxxxxxx 0x00 0x01 0x02 0x03 0xff 0xff 0xff 0xff FDT_REF_PHANDLE 0x00000004 "foo1" 0x00 0x00 0x00

This means that at the offset 4 of the property data, the value (0xffffffff) is an unresolved phandle value and the related node is the node referenced by "foo1".

This is what is encoded in the dtb when the related dts has a property with the value set to <0x00010203 &foo1> with 'foo1' a reference to an non local node.

If several non local phandles are used in the property data, several FDT_REF_PHANDLE are present after the FDT_PROP tag. Each of them points with its offset value to the position of one phandle.

For instance, if a first property with 8 bytes of data has a unresolved phandle value at offset 4 referenced by "foo" and a second property with 16 bytes of data has unresolved phandle values at offset 0 and 8 referenced by "bar" and "baz", the following tags sequence is present:
FDT_PROP 0x00000008 xxxxxxxx <data bytes>
FDT_REF_PHANDLE 0x00000004 "foo" 0x00 0x00 0x00
FDT_PROP 0x00000010 xxxxxxxx <data bytes>
FDT_REF_LOCAL 0x00000000 "bar" 0x00 0x00 0x00 FDT_REF_LOCAL 0x00000008 "baz" 0x00 0x00 0x00

Add support for this new dtb tag.

---
 dtc.c        | 12 ++++++++++++
 fdtdump.c    | 10 ++++++++++
 flattree.c   | 37 +++++++++++++++++++++++++++++++++++++
 libfdt/fdt.c | 16 ++++++++++++++++
 libfdt/fdt.h |  2 ++
 5 files changed, 77 insertions(+)
dtc.c +12 -0
index d0b4de3..fe8e8e4 100644
@@ -336,6 +336,18 @@ int main(int argc, char *argv[])
 	update_phandles_ref(dti);
 	mark_local_phandles(dti);
 
+	/*
+	 * With FDT_REF_PHANDLE added in dtbs, we need to identified
+	 * if some unresolved phandle references are allowed in the dtb
+	 * we have parsed (needed for process_check() to run properly).
+	 *
+	 * Identify plugin device-trees (overlays) based on specific node
+	 * presence.
+	 */
+	if (get_subnode(dti->dt, "__fixups__") ||
+	    get_subnode(dti->dt, "__local_fixups__"))
+		dti->dtsflags |= DTSF_PLUGIN;
+
 	process_checks(force, dti);
 
 	if (auto_label_aliases)
fdtdump.c +10 -0
index dffa9a6..7300280 100644
@@ -158,6 +158,16 @@ static void dump_blob(void *blob, bool debug)
 			continue;
 		}
 
+		if (tag == FDT_REF_PHANDLE) {
+			offset = fdt32_to_cpu(GET_CELL(p));
+			s = p;
+			p = PALIGN(p + strlen(s) + 1, 4);
+
+			printf("%*s// [FDT_REF_PHANDLE] %s[%"PRIu32"], ref = %s\n",
+				depth * shift, "", last_prop_name, offset, s);
+			continue;
+		}
+
 		fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
 		break;
 	}
flattree.c +37 -0
index 5c597ad..07f7545 100644
@@ -44,6 +44,7 @@ struct emitter {
 	void (*endnode)(void *, struct label *labels);
 	void (*property)(void *, struct label *labels);
 	void (*ref_local)(void *);
+	void (*ref_phandle)(void *);
 };
 
 static void bin_emit_cell(void *e, cell_t val)
@@ -98,6 +99,11 @@ static void bin_emit_ref_local(void *e)
 	bin_emit_cell(e, FDT_REF_LOCAL);
 }
 
+static void bin_emit_ref_phandle(void *e)
+{
+	bin_emit_cell(e, FDT_REF_PHANDLE);
+}
+
 static struct emitter bin_emitter = {
 	.cell = bin_emit_cell,
 	.string = bin_emit_string,
@@ -107,6 +113,7 @@ static struct emitter bin_emitter = {
 	.endnode = bin_emit_endnode,
 	.property = bin_emit_property,
 	.ref_local = bin_emit_ref_local,
+	.ref_phandle = bin_emit_ref_phandle,
 };
 
 static void emit_label(FILE *f, const char *prefix, const char *label)
@@ -226,6 +233,14 @@ static void asm_emit_ref_local(void *e)
 	asm_emit_cell(e, FDT_REF_LOCAL);
 }
 
+static void asm_emit_ref_phandle(void *e)
+{
+	FILE *f = e;
+
+	fprintf(f, "\t/* FDT_REF_PHANDLE */\n");
+	asm_emit_cell(e, FDT_REF_PHANDLE);
+}
+
 static struct emitter asm_emitter = {
 	.cell = asm_emit_cell,
 	.string = asm_emit_string,
@@ -235,6 +250,7 @@ static struct emitter asm_emitter = {
 	.endnode = asm_emit_endnode,
 	.property = asm_emit_property,
 	.ref_local = asm_emit_ref_local,
+	.ref_phandle = asm_emit_ref_phandle,
 };
 
 static int stringtable_insert(struct data *d, const char *str)
@@ -299,6 +315,15 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
 					emit->cell(etarget, m->offset);
 					continue;
 				}
+
+				if (m->ref[0] == '/')
+					die("Phandle uses a non local reference by path (%s)\n",
+					    m->ref);
+
+				emit->ref_phandle(etarget);
+				emit->cell(etarget, m->offset);
+				emit->string(etarget, m->ref, 0);
+				emit->align(etarget, sizeof(cell_t));
 			}
 		}
 	}
@@ -767,6 +792,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
 	const char *flatname;
 	uint32_t val;
 	uint32_t offset;
+	const char *str;
 
 	node = build_node(NULL, NULL, NULL);
 
@@ -824,6 +850,17 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
 			prop->val = data_append_markers(prop->val, m);
 			break;
 
+		case FDT_REF_PHANDLE:
+			if (!(flags & FTF_REF_XXX))
+				die("REF_PHANDLE tag found in flat tree"
+					" version <18\n");
+
+			offset = flat_read_word(dtbuf);
+			str = flat_read_string(dtbuf);
+			m = alloc_marker(offset, REF_PHANDLE, xstrdup(str));
+			prop->val = data_append_markers(prop->val, m);
+			break;
+
 		default:
 			die("Invalid opcode word %08x in device tree blob\n",
 			    val);
libfdt/fdt.c +16 -0
index 7268fb6..8f3c35d 100644
@@ -217,6 +217,21 @@ uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffset)
 		offset += sizeof(fdt32_t);
 		break;
 
+	case FDT_REF_PHANDLE:
+		/* Skip offset value */
+		tmp32p = fdt_offset_ptr(fdt, offset, sizeof(*tmp32p));
+		if (!can_assume(VALID_DTB) && !tmp32p)
+			return FDT_END; /* premature end */
+		offset += sizeof(fdt32_t);
+
+		/* Skip ref */
+		do {
+			p = fdt_offset_ptr(fdt, offset++, 1);
+		} while (p && (*p != '\0'));
+		if (!can_assume(VALID_DTB) && !p)
+			return FDT_END; /* premature end */
+		break;
+
 	default:
 		return FDT_END;
 	}
@@ -257,6 +272,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 			return tag;
 
 		case FDT_REF_LOCAL:
+		case FDT_REF_PHANDLE:
 			/*
 			 * Next tag is a meta-data tag present in the middle
 			 * of the structure -> Skip it and look at next one
libfdt/fdt.h +2 -0
index f8efdf1..530d2e5 100644
@@ -56,6 +56,8 @@ struct fdt_property {
 					   size, content */
 #define FDT_NOP		0x4		/* nop */
 #define FDT_REF_LOCAL   0x5		/* local phandle reference: offset */
+#define FDT_REF_PHANDLE 0x6		/* external phandle reference: offset,
+					   external label */
 #define FDT_END		0x9
 
 #define FDT_V1_SIZE	(7*sizeof(fdt32_t))
Signature · 1 line
2.52.0
Signature · 4 lines
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
#47 lore raw

Re: [RFC PATCH 11/77] Add support for FDT_REF_PHANDLE dtb tag

Hi David,

Quoted 10 lines · On Thu, 15 Jan 2026 12:24:49 +1100 David Gibson <[email protected]>…
Quoted 3 lines · Herve Codina

The FDT_REF_PHANDLE dtb tag is similar to the FDT_REF_LOCAL tag except that it identifies a reference to an external phandle. The node referenced by the phandle is not present in the device-tree blob.

The names FDT_REF_PHANDLE and FDT_REF_LOCAL are perhaps a little misleading - both are marking a phandle, the difference is in the form of reference. That's quite difference from the distinction between the REF_PHANDLE and REF_PATH marker types, where the difference is in what the reference expands to in the property.

I am agree.

FDT_PHANDLE: A local phandle with the value known.
FDT_PHANDLE_REF: An external phandle, its value need to be resolved ?

This is aligned with FDT_EXPORT_SYM / FDT_EXPORT_SYM_REF.

Or maybe:
FDT_TYPE_PHANDLE
FDT_TYPE_PHANDLE_REF

"TYPE" has been mentioned by Rob in the "FDT_TYPE_U32" context.

Any other ideas are welcome.

Quoted 10 lines
Quoted 9 lines

The FDT_REF_PHANDLE dtb tag is a meta-data tag attached to a property.

It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is not local node (i.e. the node is not present in the device-tree blob). This tag can be available only in overlay or addon device-tree blobs. The phandle value used in the property has to be resolved when the device-tree blob is applied on top of a base device-tree.

Quoted 2 lines

This is kind of looking ahead, but does that imply that this tag is only valid in addon dtbs?

addon dtbs for sure but also overlay (plugin) dtbs.

Quoted 10 lines
Quoted 6 lines

It is followed by two values and a possible alignment padding:
- offset (32bit):
Offset in the property data where the phandle is available.
- label (string including \0):
The label to use to resolve the phandle value.

I expect it will become apparent later in the series, but it would be helpful to clarify what the scope of that label is. A single node? The whole tree? Across a tree and all its possible addons?

This label is the unresolved reference. Its scope is the dtb.

For instance, "prop = < 0 1 &foo>;" in a dts with the node referenced by &foo not present in this dts (possible for addons and plugins) will lead to 'FDT_REF_PHANDLE 8 "foo"'

The way "foo" is used when the dtb is applied is covered later in the series.

It will be resolved with import/export mechanism (when the addon is applied).

Also it can be a namespace label reference (see patch 66 for the definition of namespace label reference) and here also it will be resolved thanks to import/export mechanism. Namespace label references can only be present in addons.

Best regards,
Hervé

#48 lore raw

Re: [RFC PATCH 11/77] Add support for FDT_REF_PHANDLE dtb tag

Quoted 16 lines · Herve Codina

Hi David,

Quoted 10 lines · On Thu, 15 Jan 2026 12:24:49 +1100 David Gibson <[email protected]>…
Quoted 3 lines · Herve Codina

The FDT_REF_PHANDLE dtb tag is similar to the FDT_REF_LOCAL tag except that it identifies a reference to an external phandle. The node referenced by the phandle is not present in the device-tree blob.

The names FDT_REF_PHANDLE and FDT_REF_LOCAL are perhaps a little misleading - both are marking a phandle, the difference is in the form of reference. That's quite difference from the distinction between the REF_PHANDLE and REF_PATH marker types, where the difference is in what the reference expands to in the property.

Quoted 4 lines

I am agree.

FDT_PHANDLE: A local phandle with the value known.
FDT_PHANDLE_REF: An external phandle, its value need to be resolved ?

Yeah, I think that works.

Quoted 7 lines

This is aligned with FDT_EXPORT_SYM / FDT_EXPORT_SYM_REF.

Or maybe:
FDT_TYPE_PHANDLE
FDT_TYPE_PHANDLE_REF

"TYPE" has been mentioned by Rob in the "FDT_TYPE_U32" context.

I don't especially like this. phandles do have a bearing on types. But as I said to Rob, I think they're a sufficiently special case, that I'd prefer not to handle them as just an aspect of a more general "types" system.

Btw, since we're looking at dtb changes anyway, one possibility would be to no longer encode a node's phandle as a property, but include it as a new field in the FDT_BEGIN_NODE tag. Putting it in a property was always a bit of a hack - in traditional OF, it was generally the node's address in memory, not something from a property. Doing it that way might side step some messy edge cases like dealing with improperly encoded "linux,phandle" properties.

Quoted 11 lines

Any other ideas are welcome.

Quoted 9 lines
Quoted 8 lines

The FDT_REF_PHANDLE dtb tag is a meta-data tag attached to a property.

It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is not local node (i.e. the node is not present in the device-tree blob). This tag can be available only in overlay or addon device-tree blobs. The phandle value used in the property has to be resolved when the device-tree blob is applied on top of a base device-tree.

Quoted 4 lines
Quoted 2 lines

This is kind of looking ahead, but does that imply that this tag is only valid in addon dtbs?

addon dtbs for sure but also overlay (plugin) dtbs.

I don't really understand how they would be used for plugins - I thought the idea was that addons would more or less obsolete plugins.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

It is followed by two values and a possible alignment padding:
- offset (32bit):
Offset in the property data where the phandle is available.
- label (string including \0):
The label to use to resolve the phandle value.

Quoted 5 lines
Quoted 3 lines

I expect it will become apparent later in the series, but it would be helpful to clarify what the scope of that label is. A single node? The whole tree? Across a tree and all its possible addons?

This label is the unresolved reference. Its scope is the dtb.

"the dtb" being a single addon, yes? That could have several meanings in the base tree depending on where the addon is attached, yes?

Quoted 18 lines

For instance, "prop = < 0 1 &foo>;" in a dts with the node referenced by &foo not present in this dts (possible for addons and plugins) will lead to 'FDT_REF_PHANDLE 8 "foo"'

The way "foo" is used when the dtb is applied is covered later in the series.

It will be resolved with import/export mechanism (when the addon is applied).

Also it can be a namespace label reference (see patch 66 for the definition of namespace label reference) and here also it will be resolved thanks to import/export mechanism. Namespace label references can only be present in addons.

Best regards,
Hervé

Signature · 4 lines
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
#49 lore raw

Re: [RFC PATCH 11/77] Add support for FDT_REF_PHANDLE dtb tag

Hi David,

Quoted 30 lines · On Mon, 19 Jan 2026 16:40:12 +1100 David Gibson <[email protected]>…
Quoted 16 lines · Herve Codina

Hi David,

Quoted 10 lines · On Thu, 15 Jan 2026 12:24:49 +1100 David Gibson <[email protected]>…
Quoted 3 lines · Herve Codina

The FDT_REF_PHANDLE dtb tag is similar to the FDT_REF_LOCAL tag except that it identifies a reference to an external phandle. The node referenced by the phandle is not present in the device-tree blob.

The names FDT_REF_PHANDLE and FDT_REF_LOCAL are perhaps a little misleading - both are marking a phandle, the difference is in the form of reference. That's quite difference from the distinction between the REF_PHANDLE and REF_PATH marker types, where the difference is in what the reference expands to in the property.

Quoted 4 lines

I am agree.

FDT_PHANDLE: A local phandle with the value known.
FDT_PHANDLE_REF: An external phandle, its value need to be resolved ?

Yeah, I think that works.

Quoted 6 lines

This is aligned with FDT_EXPORT_SYM / FDT_EXPORT_SYM_REF.

Or maybe:
FDT_TYPE_PHANDLE
FDT_TYPE_PHANDLE_REF

Quoted 6 lines
Quoted 1 line

"TYPE" has been mentioned by Rob in the "FDT_TYPE_U32" context.

I don't especially like this. phandles do have a bearing on types. But as I said to Rob, I think they're a sufficiently special case, that I'd prefer not to handle them as just an aspect of a more general "types" system.

Ok, I will not use 'TYPE' in the name of those tags.

Quoted 20 lines

Btw, since we're looking at dtb changes anyway, one possibility would be to no longer encode a node's phandle as a property, but include it as a new field in the FDT_BEGIN_NODE tag. Putting it in a property was always a bit of a hack - in traditional OF, it was generally the node's address in memory, not something from a property. Doing it that way might side step some messy edge cases like dealing with improperly encoded "linux,phandle" properties.

Quoted 11 lines

Any other ideas are welcome.

Quoted 9 lines
Quoted 8 lines

The FDT_REF_PHANDLE dtb tag is a meta-data tag attached to a property.

It indicates that the property defined before this tag (FDT_PROP) uses a phandle value and the node related to this phandle value is not local node (i.e. the node is not present in the device-tree blob). This tag can be available only in overlay or addon device-tree blobs. The phandle value used in the property has to be resolved when the device-tree blob is applied on top of a base device-tree.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

This is kind of looking ahead, but does that imply that this tag is only valid in addon dtbs?

addon dtbs for sure but also overlay (plugin) dtbs.

I don't really understand how they would be used for plugins - I thought the idea was that addons would more or less obsolete plugins.

They won't be used in plugins. Other mechanism are available in plugind. My idea was to to keep things consistent.

I mean, pluggin dtb can have metadata. Having metadata doesn't mean that they must be used.

FDT_REF_PHANDLE (or other name) makes sense in plugin dtb.

Is FDT_REF_PHANDLE valid for plugin dtb, the answer is yes.

Will FDT_REF_PHANDLE be used for symbol resolution in the plugin case, the answer is no, other mechanisme are used (__fixups__ node).

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

It is followed by two values and a possible alignment padding:
- offset (32bit):
Offset in the property data where the phandle is available.
- label (string including \0):
The label to use to resolve the phandle value.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

I expect it will become apparent later in the series, but it would be helpful to clarify what the scope of that label is. A single node? The whole tree? Across a tree and all its possible addons?

This label is the unresolved reference. Its scope is the dtb.

"the dtb" being a single addon, yes? That could have several meanings in the base tree depending on where the addon is attached, yes?

yes, the addon dtb is for a single addon.

yes, depending on where the addon is attached, the symbol resolution can reach different nodes. Is that several "meanings", not sure.

From the addon: prop = <&i2c>;

Depending on node the addon is applied this could be resolved to the node i2c@xxxx or i2c@yyyy but for sure it will be resolved to a node describing an i2c controller.

Quoted 8 lines
Quoted 8 lines

For instance, "prop = < 0 1 &foo>;" in a dts with the node referenced by &foo not present in this dts (possible for addons and plugins) will lead to 'FDT_REF_PHANDLE 8 "foo"'

The way "foo" is used when the dtb is applied is covered later in the series.

Quoted 8 lines
Quoted 8 lines

It will be resolved with import/export mechanism (when the addon is applied).

Also it can be a namespace label reference (see patch 66 for the definition of namespace label reference) and here also it will be resolved thanks to import/export mechanism. Namespace label references can only be present in addons.

Best regards,
Hervé

#50 lore raw

RFC PATCH 12/77 tests: metadata: Add external phandle reference tests

In reply to Herve Codina

Add tests related to external phandle references (FDT_REF_PHANDLE dtb tag).

---
 tests/metadata_refphandle.dtb.dts.expect | 17 +++++++++++++++++
 tests/metadata_refphandle.dtb.expect     | 16 ++++++++++++++++
 tests/metadata_refphandle.dts            | 11 +++++++++++
 tests/metadata_refphandle.dts.dts.expect | 17 +++++++++++++++++
 tests/run_tests.sh                       |  2 +-
 5 files changed, 62 insertions(+), 1 deletion(-)
 create mode 100644 tests/metadata_refphandle.dtb.dts.expect
 create mode 100644 tests/metadata_refphandle.dtb.expect
 create mode 100644 tests/metadata_refphandle.dts
 create mode 100644 tests/metadata_refphandle.dts.dts.expect
tests/metadata_refphandle.dtb.dts.expect new file +17 -0
new file mode 100644
index 0000000..c229ec1
@@ -0,0 +1,17 @@
+/dts-v1/;
+
+/ {
+
+	fragment@0 {
+		target = <&test>;
+
+		__overlay__ {
+			ref = <&node_a>;
+		};
+	};
+
+	__fixups__ {
+		test = "/fragment@0:target:0";
+		node_a = "/fragment@0/__overlay__:ref:0";
+	};
+};
tests/metadata_refphandle.dtb.expect new file +16 -0
new file mode 100644
index 0000000..b2f5f95
@@ -0,0 +1,16 @@
+/dts-v1/;
+
+/ {
+    fragment@0 {
+        target = <0xffffffff>;
+        // [FDT_REF_PHANDLE] target[0], ref = test
+        __overlay__ {
+            ref = <0xffffffff>;
+            // [FDT_REF_PHANDLE] ref[0], ref = node_a
+        };
+    };
+    __fixups__ {
+        test = "/fragment@0:target:0";
+        node_a = "/fragment@0/__overlay__:ref:0";
+    };
+};
tests/metadata_refphandle.dts new file +11 -0
new file mode 100644
index 0000000..b8aa650
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
+/*
+ * Copyright (C) 2026 Bootlin
+ */
+
+/dts-v1/;
+/plugin/;
+
+&test {
+	ref = <&node_a>;
+};
tests/metadata_refphandle.dts.dts.expect new file +17 -0
new file mode 100644
index 0000000..c229ec1
@@ -0,0 +1,17 @@
+/dts-v1/;
+
+/ {
+
+	fragment@0 {
+		target = <&test>;
+
+		__overlay__ {
+			ref = <&node_a>;
+		};
+	};
+
+	__fixups__ {
+		test = "/fragment@0:target:0";
+		node_a = "/fragment@0/__overlay__:ref:0";
+	};
+};
tests/run_tests.sh +1 -1
index 7a8bdbc..423812e 100755
@@ -1125,7 +1125,7 @@ wrap_fdtdump () {
 }
 
 metadata_tests() {
-	for dt in metadata_reflocal; do
+	for dt in metadata_reflocal metadata_refphandle; do
 		run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts"
 		base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect"
 		run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts"
Signature · 1 line
2.52.0
#51 lore raw

RFC PATCH 13/77 Introduce dt_flags field in dtb header

In reply to Herve Codina

There is no simple way to identify a kind of dtb.

A dtb can be a "standard" device-tree blob but with the future support for addon dtb, a dtb could be an addon dtb.

Whereas, looking at node structures and name, we can identify if a "standard" dtb is a pure base device-tree or an overlay device-tree, this will be no more possible with addons. Indeed, specific node such as __local_fixups__ and/or __fixups__ present in overlays will be no more present in addons.

In order to avoid any complex and error prone searches in the dtb structure to identify whether or not a dtb is an addon, encode this information directly in the dtb itself.

This is the purpose of the dt_flags field.

Prepare the support for 'addon' flag introducing the dt_flags field in the dtb header.

---
 fdtdump.c               |  4 ++++
 flattree.c              | 17 +++++++++++++----
 libfdt/fdt.h            |  5 ++++-
 libfdt/fdt_rw.c         |  4 ++++
 libfdt/libfdt.h         |  1 +
 tests/pylibfdt_tests.py |  6 +++---
 tests/testutils.c       |  2 +-
 tests/trees.S           |  1 +
 8 files changed, 31 insertions(+), 9 deletions(-)
fdtdump.c +4 -0
index 7300280..5c78559 100644
@@ -87,6 +87,10 @@ static void dump_blob(void *blob, bool debug)
 	if (version >= 17)
 		printf("// size_dt_struct:\t0x%"PRIx32"\n",
 		       fdt32_to_cpu(bph->size_dt_struct));
+	if (version >= 18) {
+		printf("// dt_flags:\t\t0x%"PRIx32"\n",
+		       fdt32_to_cpu(bph->dt_flags));
+	}
 	printf("\n");
 
 	for (i = 0; ; i++) {
flattree.c +13 -4
index 07f7545..2e2ffcb 100644
@@ -14,6 +14,7 @@
 #define FTF_STRUCTSIZE	0x20
 #define FTF_NOPS	0x40
 #define FTF_REF_XXX	0x80
+#define FTF_DTFLAGS	0x100
 
 static struct version_info {
 	int version;
@@ -32,7 +33,8 @@ static struct version_info {
 	{17, 16, FDT_V17_SIZE,
 	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS},
 	{18, 18, FDT_V18_SIZE,
-	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS|FTF_REF_XXX},
+	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS|FTF_REF_XXX|
+	 FTF_DTFLAGS},
 };
 
 struct emitter {
@@ -370,7 +372,7 @@ static struct data flatten_reserve_list(struct reserve_info *reservelist,
 static void make_fdt_header(struct fdt_header *fdt,
 			    struct version_info *vi,
 			    int reservesize, int dtsize, int strsize,
-			    int boot_cpuid_phys)
+			    int boot_cpuid_phys, uint32_t dt_flags)
 {
 	int reserve_off;
 
@@ -397,6 +399,8 @@ static void make_fdt_header(struct fdt_header *fdt,
 		fdt->size_dt_strings = cpu_to_fdt32(strsize);
 	if (vi->flags & FTF_STRUCTSIZE)
 		fdt->size_dt_struct = cpu_to_fdt32(dtsize);
+	if (vi->flags & FTF_DTFLAGS)
+		fdt->dt_flags = cpu_to_fdt32(dt_flags);
 }
 
 void dt_to_blob(FILE *f, struct dt_info *dti, int version)
@@ -424,7 +428,7 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int version)
 
 	/* Make header */
 	make_fdt_header(&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len,
-			dti->boot_cpuid_phys);
+			dti->boot_cpuid_phys, 0);
 
 	/*
 	 * If the user asked for more space than is used, adjust the totalsize.
@@ -555,6 +559,11 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version)
 			symprefix, symprefix);
 	}
 
+	if (vi->flags & FTF_DTFLAGS) {
+		fprintf(f, "\t/* dt_flags */\n");
+		asm_emit_cell(f, 0);
+	}
+
 	/*
 	 * Reserve map entries.
 	 * Align the reserve map to a doubleword boundary.
@@ -980,7 +989,7 @@ struct dt_info *dt_from_blob(const char *fname)
 	}
 
 	if (version >= 18)
-		flags |= FTF_REF_XXX;
+		flags |= FTF_REF_XXX | FTF_DTFLAGS;
 
 	inbuf_init(&memresvbuf,
 		   blob + off_mem_rsvmap, blob + totalsize);
libfdt/fdt.h +4 -1
index 530d2e5..128e7bc 100644
@@ -26,6 +26,9 @@ struct fdt_header {
 
 	/* version 17 fields below */
 	fdt32_t size_dt_struct;		 /* size of the structure block */
+
+	/* version 18 fields below */
+	fdt32_t dt_flags;		/* Ored value of FDT_FLAG_XXXX */
 };
 
 struct fdt_reserve_entry {
@@ -65,6 +68,6 @@ struct fdt_property {
 #define FDT_V3_SIZE	(FDT_V2_SIZE + sizeof(fdt32_t))
 #define FDT_V16_SIZE	FDT_V3_SIZE
 #define FDT_V17_SIZE	(FDT_V16_SIZE + sizeof(fdt32_t))
-#define FDT_V18_SIZE	FDT_V17_SIZE
+#define FDT_V18_SIZE	(FDT_V17_SIZE + sizeof(fdt32_t))
 
 #endif /* FDT_H */
libfdt/fdt_rw.c +4 -0
index 00e32bb..1528b33 100644
@@ -457,6 +457,8 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
 			return err;
 		fdt_set_version(buf, 18);
 		fdt_set_last_comp_version(buf, 18);
+		if (can_assume(LATEST) || fdt_version(fdt) < 18)
+			fdt_set_dt_flags(buf, 0);
 		fdt_set_size_dt_struct(buf, struct_size);
 		fdt_set_totalsize(buf, bufsize);
 		return 0;
@@ -487,6 +489,8 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
 	fdt_set_totalsize(buf, bufsize);
 	fdt_set_version(buf, 18);
 	fdt_set_last_comp_version(buf, 18);
+	if (can_assume(LATEST) || fdt_version(fdt) < 18)
+		fdt_set_dt_flags(buf, 0);
 	fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt));
 
 	return 0;
libfdt/libfdt.h +1 -0
index d1a9cd5..9777f32 100644
@@ -319,6 +319,7 @@ fdt_set_hdr_(last_comp_version)
 fdt_set_hdr_(boot_cpuid_phys)
 fdt_set_hdr_(size_dt_strings)
 fdt_set_hdr_(size_dt_struct)
+fdt_set_hdr_(dt_flags)
 #undef fdt_set_hdr_
 
 /**
tests/pylibfdt_tests.py +3 -3
index 373e11a..7d5ab0b 100644
@@ -285,9 +285,9 @@ class PyLibfdtBasicTests(unittest.TestCase):
         """Test that we can access the header values"""
         self.assertEqual(self.fdt.magic(), 0xd00dfeed)
         self.assertEqual(self.fdt.totalsize(), len(self.fdt._fdt))
-        self.assertEqual(self.fdt.off_dt_struct(), 88)
-        self.assertEqual(self.fdt.off_dt_strings(), 652)
-        self.assertEqual(self.fdt.off_mem_rsvmap(), 40)
+        self.assertEqual(self.fdt.off_dt_struct(), 96)
+        self.assertEqual(self.fdt.off_dt_strings(), 660)
+        self.assertEqual(self.fdt.off_mem_rsvmap(), 48)
         self.assertEqual(self.fdt.version(), 18)
         self.assertEqual(self.fdt.last_comp_version(), 16)
         self.assertEqual(self.fdt.boot_cpuid_phys(), 0)
tests/testutils.c +1 -1
index 54da2e4..2d5cfb3 100644
@@ -344,7 +344,7 @@ void *open_blob_rw(const void *blob)
 {
 	int err;
 	void *buf;
-	int newsize = fdt_totalsize(blob) + 8;
+	int newsize = fdt_totalsize(blob) + 8 + 4;
 
 	buf = xmalloc(newsize);
 	err = fdt_open_into(blob, buf, newsize);
tests/trees.S +1 -0
index ecd43bc..56c1002 100644
@@ -22,6 +22,7 @@
 	fdtlong	0
 	fdtlong	(\tree\()_strings_end - \tree\()_strings)
 	fdtlong	(\tree\()_struct_end - \tree\()_struct)
+	fdtlong	0
 	.endm
 
 	.macro	rsvmape	addrh, addrl, lenh, lenl
Signature · 1 line
2.52.0
#52 lore raw

Re: [RFC PATCH 13/77] Introduce dt_flags field in dtb header

Quoted 11 lines · Herve Codina

There is no simple way to identify a kind of dtb.

A dtb can be a "standard" device-tree blob but with the future support for addon dtb, a dtb could be an addon dtb.

Whereas, looking at node structures and name, we can identify if a "standard" dtb is a pure base device-tree or an overlay device-tree, this will be no more possible with addons. Indeed, specific node such as __local_fixups__ and/or __fixups__ present in overlays will be no more present in addons.

Quoted 8 lines

In order to avoid any complex and error prone searches in the dtb structure to identify whether or not a dtb is an addon, encode this information directly in the dtb itself.

This is the purpose of the dt_flags field.

Prepare the support for 'addon' flag introducing the dt_flags field in the dtb header.

Do you have any more flags in mind?

If this is just for identifying addons, I'd suggest using a different magic number, instead.

Quoted 175 lines
---
 fdtdump.c               |  4 ++++
 flattree.c              | 17 +++++++++++++----
 libfdt/fdt.h            |  5 ++++-
 libfdt/fdt_rw.c         |  4 ++++
 libfdt/libfdt.h         |  1 +
 tests/pylibfdt_tests.py |  6 +++---
 tests/testutils.c       |  2 +-
 tests/trees.S           |  1 +
 8 files changed, 31 insertions(+), 9 deletions(-)
fdtdump.c +4 -0
index 7300280..5c78559 100644
@@ -87,6 +87,10 @@ static void dump_blob(void *blob, bool debug)
 	if (version >= 17)
 		printf("// size_dt_struct:\t0x%"PRIx32"\n",
 		       fdt32_to_cpu(bph->size_dt_struct));
+	if (version >= 18) {
+		printf("// dt_flags:\t\t0x%"PRIx32"\n",
+		       fdt32_to_cpu(bph->dt_flags));
+	}
 	printf("\n");
 
 	for (i = 0; ; i++) {
flattree.c +13 -4
index 07f7545..2e2ffcb 100644
@@ -14,6 +14,7 @@
 #define FTF_STRUCTSIZE	0x20
 #define FTF_NOPS	0x40
 #define FTF_REF_XXX	0x80
+#define FTF_DTFLAGS	0x100
 
 static struct version_info {
 	int version;
@@ -32,7 +33,8 @@ static struct version_info {
 	{17, 16, FDT_V17_SIZE,
 	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS},
 	{18, 18, FDT_V18_SIZE,
-	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS|FTF_REF_XXX},
+	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS|FTF_REF_XXX|
+	 FTF_DTFLAGS},
 };
 
 struct emitter {
@@ -370,7 +372,7 @@ static struct data flatten_reserve_list(struct reserve_info *reservelist,
 static void make_fdt_header(struct fdt_header *fdt,
 			    struct version_info *vi,
 			    int reservesize, int dtsize, int strsize,
-			    int boot_cpuid_phys)
+			    int boot_cpuid_phys, uint32_t dt_flags)
 {
 	int reserve_off;
 
@@ -397,6 +399,8 @@ static void make_fdt_header(struct fdt_header *fdt,
 		fdt->size_dt_strings = cpu_to_fdt32(strsize);
 	if (vi->flags & FTF_STRUCTSIZE)
 		fdt->size_dt_struct = cpu_to_fdt32(dtsize);
+	if (vi->flags & FTF_DTFLAGS)
+		fdt->dt_flags = cpu_to_fdt32(dt_flags);
 }
 
 void dt_to_blob(FILE *f, struct dt_info *dti, int version)
@@ -424,7 +428,7 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int version)
 
 	/* Make header */
 	make_fdt_header(&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len,
-			dti->boot_cpuid_phys);
+			dti->boot_cpuid_phys, 0);
 
 	/*
 	 * If the user asked for more space than is used, adjust the totalsize.
@@ -555,6 +559,11 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version)
 			symprefix, symprefix);
 	}
 
+	if (vi->flags & FTF_DTFLAGS) {
+		fprintf(f, "\t/* dt_flags */\n");
+		asm_emit_cell(f, 0);
+	}
+
 	/*
 	 * Reserve map entries.
 	 * Align the reserve map to a doubleword boundary.
@@ -980,7 +989,7 @@ struct dt_info *dt_from_blob(const char *fname)
 	}
 
 	if (version >= 18)
-		flags |= FTF_REF_XXX;
+		flags |= FTF_REF_XXX | FTF_DTFLAGS;
 
 	inbuf_init(&memresvbuf,
 		   blob + off_mem_rsvmap, blob + totalsize);
libfdt/fdt.h +4 -1
index 530d2e5..128e7bc 100644
@@ -26,6 +26,9 @@ struct fdt_header {
 
 	/* version 17 fields below */
 	fdt32_t size_dt_struct;		 /* size of the structure block */
+
+	/* version 18 fields below */
+	fdt32_t dt_flags;		/* Ored value of FDT_FLAG_XXXX */
 };
 
 struct fdt_reserve_entry {
@@ -65,6 +68,6 @@ struct fdt_property {
 #define FDT_V3_SIZE	(FDT_V2_SIZE + sizeof(fdt32_t))
 #define FDT_V16_SIZE	FDT_V3_SIZE
 #define FDT_V17_SIZE	(FDT_V16_SIZE + sizeof(fdt32_t))
-#define FDT_V18_SIZE	FDT_V17_SIZE
+#define FDT_V18_SIZE	(FDT_V17_SIZE + sizeof(fdt32_t))
 
 #endif /* FDT_H */
libfdt/fdt_rw.c +4 -0
index 00e32bb..1528b33 100644
@@ -457,6 +457,8 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
 			return err;
 		fdt_set_version(buf, 18);
 		fdt_set_last_comp_version(buf, 18);
+		if (can_assume(LATEST) || fdt_version(fdt) < 18)
+			fdt_set_dt_flags(buf, 0);
 		fdt_set_size_dt_struct(buf, struct_size);
 		fdt_set_totalsize(buf, bufsize);
 		return 0;
@@ -487,6 +489,8 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)
 	fdt_set_totalsize(buf, bufsize);
 	fdt_set_version(buf, 18);
 	fdt_set_last_comp_version(buf, 18);
+	if (can_assume(LATEST) || fdt_version(fdt) < 18)
+		fdt_set_dt_flags(buf, 0);
 	fdt_set_boot_cpuid_phys(buf, fdt_boot_cpuid_phys(fdt));
 
 	return 0;
libfdt/libfdt.h +1 -0
index d1a9cd5..9777f32 100644
@@ -319,6 +319,7 @@ fdt_set_hdr_(last_comp_version)
 fdt_set_hdr_(boot_cpuid_phys)
 fdt_set_hdr_(size_dt_strings)
 fdt_set_hdr_(size_dt_struct)
+fdt_set_hdr_(dt_flags)
 #undef fdt_set_hdr_
 
 /**
tests/pylibfdt_tests.py +3 -3
index 373e11a..7d5ab0b 100644
@@ -285,9 +285,9 @@ class PyLibfdtBasicTests(unittest.TestCase):
         """Test that we can access the header values"""
         self.assertEqual(self.fdt.magic(), 0xd00dfeed)
         self.assertEqual(self.fdt.totalsize(), len(self.fdt._fdt))
-        self.assertEqual(self.fdt.off_dt_struct(), 88)
-        self.assertEqual(self.fdt.off_dt_strings(), 652)
-        self.assertEqual(self.fdt.off_mem_rsvmap(), 40)
+        self.assertEqual(self.fdt.off_dt_struct(), 96)
+        self.assertEqual(self.fdt.off_dt_strings(), 660)
+        self.assertEqual(self.fdt.off_mem_rsvmap(), 48)
         self.assertEqual(self.fdt.version(), 18)
         self.assertEqual(self.fdt.last_comp_version(), 16)
         self.assertEqual(self.fdt.boot_cpuid_phys(), 0)
tests/testutils.c +0 -0
index 54da2e4..2d5cfb3 100644

tests/testutils.c void *open_blob_rw(const void *blob) · line 347

Quoted 5 lines
tests/testutils.c +1 -1
@@ -344,7 +344,7 @@ void *open_blob_rw(const void *blob)
 {
 	int err;
 	void *buf;
-	int newsize = fdt_totalsize(blob) + 8;
+	int newsize = fdt_totalsize(blob) + 8 + 4;

Kind of pre-existing, but a comment explaining where the 8 and the 4 come from would be nice.

Quoted 18 lines
tests/testutils.c +0 -0
 	buf = xmalloc(newsize);
 	err = fdt_open_into(blob, buf, newsize);
tests/trees.S +1 -0
index ecd43bc..56c1002 100644
@@ -22,6 +22,7 @@
 	fdtlong	0
 	fdtlong	(\tree\()_strings_end - \tree\()_strings)
 	fdtlong	(\tree\()_struct_end - \tree\()_struct)
+	fdtlong	0
 	.endm
 
 	.macro	rsvmape	addrh, addrl, lenh, lenl
Signature · 1 line
2.52.0
Signature · 4 lines
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
#53 lore raw

RFC PATCH 14/77 tests: metadata: Add a first test related to the dt_flags header field

In reply to Herve Codina

A new field has been recently added to the dtb header: dt_flags.

Even if this field is not yet used to encode meaningful information, add a basic test related to this field (presence and its 0 default value).

---
 tests/metadata_dtflags0.dtb.expect |  1 +
 tests/metadata_dtflags0.dts        | 10 ++++++++++
 tests/run_tests.sh                 |  6 ++++++
 3 files changed, 17 insertions(+)
 create mode 100644 tests/metadata_dtflags0.dtb.expect
 create mode 100644 tests/metadata_dtflags0.dts
tests/metadata_dtflags0.dtb.expect new file +1 -0
new file mode 100644
index 0000000..cefed4d
@@ -0,0 +1 @@
+// dt_flags:		0x0
tests/metadata_dtflags0.dts new file +10 -0
new file mode 100644
index 0000000..3ef867e
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
+/*
+ * Copyright (C) 2026 Bootlin
+ */
+
+/dts-v1/;
+
+/ {
+	prop = <1>;
+};
tests/run_tests.sh +6 -0
index 423812e..496fcb9 100755
@@ -1141,6 +1141,12 @@ metadata_tests() {
 		sed -i '/^\/\/ /d' $dt.dtb.dts.dtb.out
 		base_run_test check_diff $dt.dtb.dts.dtb.out "$SRCDIR/$dt.dtb.expect"
 	done
+
+	run_dtc_test -I dts -O dtb -o metadata_dtflags0.dtb "$SRCDIR/metadata_dtflags0.dts"
+	base_run_test wrap_fdtdump metadata_dtflags0.dtb metadata_dtflags0.dtb.out
+	# Keep only lines containing 'dt_flags'
+	sed -i '/dt_flags/!d' metadata_dtflags0.dtb.out
+	base_run_test check_diff metadata_dtflags0.dtb.out "$SRCDIR/metadata_dtflags0.dtb.expect"
 }
 
 pylibfdt_tests () {
Signature · 1 line
2.52.0
#54 lore raw

RFC PATCH 15/77 Add support for /addon/ keyword

In reply to Herve Codina

The dts /addon/ keyword allows to mark a dts as an addon dts.

This is similar to /plugin/ used for overlay dts but specific to addon dts.

It is also worth noting that a dts tagged with /addon/ will lead to a dtb with the dt_flags set to FDT_FLAG_ADDON (0x1).

This allows to identify without any ambiguity an addon dts and an addon dtb.

---
 checks.c        | 26 +++++++++++++-------------
 dtc-lexer.l     |  5 +++++
 dtc-parser.y    |  5 +++++
 dtc.h           |  1 +
 fdtdump.c       |  6 +++++-
 flattree.c      | 18 ++++++++++++++----
 libfdt/fdt.h    |  1 +
 libfdt/libfdt.h |  1 +
 treesource.c    |  5 ++++-
 9 files changed, 49 insertions(+), 19 deletions(-)
checks.c +13 -13
index 041e565..2be19c0 100644
@@ -616,7 +616,7 @@ static void fixup_phandle_references(struct check *c, struct dt_info *dti,
 
 			refnode = get_node_by_ref(dt, m->ref);
 			if (! refnode) {
-				if (!(dti->dtsflags & DTSF_PLUGIN))
+				if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)))
 					FAIL(c, dti, node, "Reference to non-existent node or "
 							"label \"%s\"\n", m->ref);
 				else /* mark the entry as unresolved */
@@ -718,8 +718,8 @@ static void check_alias_paths(struct check *c, struct dt_info *dti,
 			continue;
 		}
 
-		/* This check does not work for overlays with external paths */
-		if (!(dti->dtsflags & DTSF_PLUGIN) &&
+		/* This check does not work for overlays nor addons with external paths */
+		if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)) &&
 		    (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val))) {
 			FAIL_PROP(c, dti, node, prop, "aliases property is not a valid node (%s)",
 				  prop->val.val);
@@ -1417,8 +1417,8 @@ static void check_property_phandle_args(struct check *c,
 		 * entries when each index position has a specific definition.
 		 */
 		if (!phandle_is_valid(phandle)) {
-			/* Give up if this is an overlay with external references */
-			if (dti->dtsflags & DTSF_PLUGIN)
+			/* Give up if this is an overlay or addon with external references */
+			if (dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON))
 				break;
 
 			cellsize = 0;
@@ -1651,8 +1651,8 @@ static void check_interrupt_map(struct check *c,
 
 		phandle = propval_cell_n(irq_map_prop, cell);
 		if (!phandle_is_valid(phandle)) {
-			/* Give up if this is an overlay with external references */
-			if (!(dti->dtsflags & DTSF_PLUGIN))
+			/* Give up if this is an overlay or an addon with external references */
+			if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)))
 				FAIL_PROP(c, dti, node, irq_map_prop,
 					  "Cell %zu is not a phandle(%d)",
 					  cell, phandle);
@@ -1720,9 +1720,9 @@ static void check_interrupts_property(struct check *c,
 		if (prop) {
 			phandle = propval_cell(prop);
 			if (!phandle_is_valid(phandle)) {
-				/* Give up if this is an overlay with
+				/* Give up if this is an overlay with or an addon
 				 * external references */
-				if (dti->dtsflags & DTSF_PLUGIN)
+				if (dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON))
 					return;
 				FAIL_PROP(c, dti, parent, prop, "Invalid phandle");
 				continue;
@@ -1838,8 +1838,8 @@ static void check_graph_port(struct check *c, struct dt_info *dti,
 
 	check_graph_reg(c, dti, node);
 
-	/* skip checks below for overlays */
-	if (dti->dtsflags & DTSF_PLUGIN)
+	/* skip checks below for overlays or addons */
+	if (dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON))
 		return;
 
 	if (!strprefixeq(node->name, node->basenamelen, "port"))
@@ -1880,8 +1880,8 @@ static void check_graph_endpoint(struct check *c, struct dt_info *dti,
 
 	check_graph_reg(c, dti, node);
 
-	/* skip checks below for overlays */
-	if (dti->dtsflags & DTSF_PLUGIN)
+	/* skip checks below for overlays or addons */
+	if (dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON))
 		return;
 
 	if (!strprefixeq(node->name, node->basenamelen, "endpoint"))
dtc-lexer.l +5 -0
index 15d585c..a4a8e0b 100644
@@ -111,6 +111,11 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
 			return DT_PLUGIN;
 		}
 
+<*>"/addon/"	{
+			DPRINT("Keyword: /addon/\n");
+			return DT_ADDON;
+		}
+
 <*>"/memreserve/"	{
 			DPRINT("Keyword: /memreserve/\n");
 			BEGIN_DEFAULT();
dtc-parser.y +5 -0
index 4d5eece..d8914d2 100644
@@ -53,6 +53,7 @@ static bool is_ref_relative(const char *ref)
 
 %token DT_V1
 %token DT_PLUGIN
+%token DT_ADDON
 %token DT_MEMRESERVE
 %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR
 %token DT_BITS
@@ -120,6 +121,10 @@ header:
 		{
 			$$ = DTSF_V1 | DTSF_PLUGIN;
 		}
+	| DT_V1 ';' DT_ADDON ';'
+		{
+			$$ = DTSF_V1 | DTSF_ADDON;
+		}
 	;
 
 headers:
dtc.h +1 -0
index 08c9f07..c0fffd2 100644
@@ -336,6 +336,7 @@ struct dt_info {
 /* DTS version flags definitions */
 #define DTSF_V1		0x0001	/* /dts-v1/ */
 #define DTSF_PLUGIN	0x0002	/* /plugin/ */
+#define DTSF_ADDON	0x0004	/* /addon/ */
 
 struct dt_info *build_dt_info(unsigned int dtsflags,
 			      struct reserve_info *reservelist,
fdtdump.c +5 -1
index 5c78559..9b6f41a 100644
@@ -67,7 +67,6 @@ static void dump_blob(void *blob, bool debug)
 	depth = 0;
 	shift = 4;
 
-	printf("/dts-v1/;\n");
 	printf("// magic:\t\t0x%"PRIx32"\n", fdt32_to_cpu(bph->magic));
 	printf("// totalsize:\t\t0x%"PRIx32" (%"PRIu32")\n",
 	       totalsize, totalsize);
@@ -91,6 +90,11 @@ static void dump_blob(void *blob, bool debug)
 		printf("// dt_flags:\t\t0x%"PRIx32"\n",
 		       fdt32_to_cpu(bph->dt_flags));
 	}
+	printf("/dts-v1/;\n");
+	if (version >= 18) {
+		if (fdt32_to_cpu(bph->dt_flags) & FDT_FLAG_ADDON)
+			printf("/addon/;\n");
+	}
 	printf("\n");
 
 	for (i = 0; ; i++) {
flattree.c +14 -4
index 2e2ffcb..bedb286 100644
@@ -412,6 +412,7 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int version)
 	struct data dtbuf      = empty_data;
 	struct data strbuf     = empty_data;
 	struct fdt_header fdt;
+	uint32_t dt_flags = 0;
 	int padlen = 0;
 
 	for (i = 0; i < ARRAY_SIZE(version_table); i++) {
@@ -421,6 +422,8 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int version)
 	if (!vi)
 		die("Unknown device tree blob version %d\n", version);
 
+	dt_flags |= dti->dtsflags & DTSF_ADDON ? FDT_FLAG_ADDON : 0;
+
 	flatten_tree(dti->dt, &bin_emitter, &dtbuf, &strbuf, vi);
 	bin_emit_cell(&dtbuf, FDT_END);
 
@@ -428,7 +431,7 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int version)
 
 	/* Make header */
 	make_fdt_header(&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len,
-			dti->boot_cpuid_phys, 0);
+			dti->boot_cpuid_phys, dt_flags);
 
 	/*
 	 * If the user asked for more space than is used, adjust the totalsize.
@@ -511,6 +514,7 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version)
 	struct data strbuf = empty_data;
 	struct reserve_info *re;
 	const char *symprefix = "dt";
+	uint32_t dt_flags = 0;
 
 	for (i = 0; i < ARRAY_SIZE(version_table); i++) {
 		if (version_table[i].version == version)
@@ -519,6 +523,8 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version)
 	if (!vi)
 		die("Unknown device tree blob version %d\n", version);
 
+	dt_flags |= dti->dtsflags & DTSF_ADDON ? FDT_FLAG_ADDON : 0;
+
 	fprintf(f, "/* autogenerated by dtc, do not edit */\n\n");
 
 	emit_label(f, symprefix, "blob_start");
@@ -561,7 +567,7 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version)
 
 	if (vi->flags & FTF_DTFLAGS) {
 		fprintf(f, "\t/* dt_flags */\n");
-		asm_emit_cell(f, 0);
+		asm_emit_cell(f, dt_flags);
 	}
 
 	/*
@@ -897,6 +903,7 @@ struct dt_info *dt_from_blob(const char *fname)
 	struct node *tree;
 	uint32_t val;
 	int flags = 0;
+	unsigned int dtsflags = 0;
 
 	f = srcfile_relative_open(fname, NULL);
 
@@ -988,8 +995,11 @@ struct dt_info *dt_from_blob(const char *fname)
 		flags |= FTF_NOPS;
 	}
 
-	if (version >= 18)
+	if (version >= 18) {
 		flags |= FTF_REF_XXX | FTF_DTFLAGS;
+		dtsflags |= fdt32_to_cpu(fdt->dt_flags) & FDT_FLAG_ADDON ?
+				DTSF_ADDON : 0;
+	}
 
 	inbuf_init(&memresvbuf,
 		   blob + off_mem_rsvmap, blob + totalsize);
@@ -1012,5 +1022,5 @@ struct dt_info *dt_from_blob(const char *fname)
 
 	fclose(f);
 
-	return build_dt_info(DTSF_V1, reservelist, tree, boot_cpuid_phys);
+	return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_phys);
 }
libfdt/fdt.h +1 -0
index 128e7bc..94f65e6 100644
@@ -51,6 +51,7 @@ struct fdt_property {
 #endif /* !__ASSEMBLER__ */
 
 #define FDT_MAGIC	0xd00dfeed	/* 4: version, 4: total size */
+#define FDT_FLAG_ADDON  0x1
 #define FDT_TAGSIZE	sizeof(fdt32_t)
 
 #define FDT_BEGIN_NODE	0x1		/* Start node: full name */
libfdt/libfdt.h +1 -0
index 9777f32..37459a6 100644
@@ -302,6 +302,7 @@ int fdt_next_subnode(const void *fdt, int offset);
 #define fdt_boot_cpuid_phys(fdt)	(fdt_get_header(fdt, boot_cpuid_phys))
 #define fdt_size_dt_strings(fdt)	(fdt_get_header(fdt, size_dt_strings))
 #define fdt_size_dt_struct(fdt)		(fdt_get_header(fdt, size_dt_struct))
+#define fdt_dt_flags(fdt)		(fdt_get_header(fdt, dt_flags))
 
 #define fdt_set_hdr_(name) \
 	static inline void fdt_set_##name(void *fdt, uint32_t val) \
treesource.c +4 -1
index d25f01f..1db6390 100644
@@ -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_ADDON)
+		fprintf(f, "/addon/;\n");
+	fprintf(f, "\n");
 
 	for (re = dti->reservelist; re; re = re->next) {
 		struct label *l;
Signature · 1 line
2.52.0
#55 lore raw

RFC PATCH 16/77 tests: metadata: Add a test related to addon dt_flags header value

In reply to Herve Codina

Addon dtbs leads to the dt_flags header field set to FDT_FLAG_ADDON (0x1).

Add a specific test to check this value.

---
 tests/metadata_dtflags1.dtb.expect |  1 +
 tests/metadata_dtflags1.dts        | 11 +++++++++++
 tests/run_tests.sh                 |  6 ++++++
 3 files changed, 18 insertions(+)
 create mode 100644 tests/metadata_dtflags1.dtb.expect
 create mode 100644 tests/metadata_dtflags1.dts
tests/metadata_dtflags1.dtb.expect new file +1 -0
new file mode 100644
index 0000000..00f98f3
@@ -0,0 +1 @@
+// dt_flags:		0x1
tests/metadata_dtflags1.dts new file +11 -0
new file mode 100644
index 0000000..d2b2295
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
+/*
+ * Copyright (C) 2026 Bootlin
+ */
+
+/dts-v1/;
+/addon/;
+
+/ {
+	prop = <1>;
+};
tests/run_tests.sh +6 -0
index 496fcb9..688d81d 100755
@@ -1147,6 +1147,12 @@ metadata_tests() {
 	# Keep only lines containing 'dt_flags'
 	sed -i '/dt_flags/!d' metadata_dtflags0.dtb.out
 	base_run_test check_diff metadata_dtflags0.dtb.out "$SRCDIR/metadata_dtflags0.dtb.expect"
+
+	run_dtc_test -I dts -O dtb -o metadata_dtflags1.dtb "$SRCDIR/metadata_dtflags1.dts"
+	base_run_test wrap_fdtdump metadata_dtflags1.dtb metadata_dtflags1.dtb.out
+	# Keep only lines containing 'dt_flags'
+	sed -i '/dt_flags/!d' metadata_dtflags1.dtb.out
+	base_run_test check_diff metadata_dtflags1.dtb.out "$SRCDIR/metadata_dtflags1.dtb.expect"
 }
 
 pylibfdt_tests () {
Signature · 1 line
2.52.0
#56 lore raw

RFC PATCH 17/77 tests: metadata: Add a basic addon test

In reply to Herve Codina

Support for addon dts (/addon/ keyword) and addon dtb (FDT_FLAG_ADDON header flag) have been recently introduced.

Even if the FDT_FLAG_ADDON dtb flag itself has its own test already available, add a basic addon test in the metadata 'dts->dts and dts->dtb->dts' test patterns to check that addon dts/dtb are handled correctly.

---
 tests/metadata_addon_base.dtb.dts.expect | 10 ++++++++++
 tests/metadata_addon_base.dtb.expect     | 10 ++++++++++
 tests/metadata_addon_base.dts            | 14 ++++++++++++++
 tests/metadata_addon_base.dts.dts.expect | 10 ++++++++++
 tests/run_tests.sh                       |  3 ++-
 5 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 tests/metadata_addon_base.dtb.dts.expect
 create mode 100644 tests/metadata_addon_base.dtb.expect
 create mode 100644 tests/metadata_addon_base.dts
 create mode 100644 tests/metadata_addon_base.dts.dts.expect
tests/metadata_addon_base.dtb.dts.expect new file +10 -0
new file mode 100644
index 0000000..739f9db
@@ -0,0 +1,10 @@
+/dts-v1/;
+/addon/;
+
+/ {
+
+	node-a {
+		prop = <0x01>;
+		ref-base = <&base>;
+	};
+};
tests/metadata_addon_base.dtb.expect new file +10 -0
new file mode 100644
index 0000000..6c2a89a
@@ -0,0 +1,10 @@
+/dts-v1/;
+/addon/;
+
+/ {
+    node-a {
+        prop = <0x00000001>;
+        ref-base = <0xffffffff>;
+        // [FDT_REF_PHANDLE] ref-base[0], ref = base
+    };
+};
tests/metadata_addon_base.dts new file +14 -0
new file mode 100644
index 0000000..5e29cef
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
+/*
+ * Copyright (C) 2026 Bootlin
+ */
+
+/dts-v1/;
+/addon/;
+
+/ {
+	node-a {
+		prop = <1>;
+		ref-base = <&base>;
+	};
+};
tests/metadata_addon_base.dts.dts.expect new file +10 -0
new file mode 100644
index 0000000..739f9db
@@ -0,0 +1,10 @@
+/dts-v1/;
+/addon/;
+
+/ {
+
+	node-a {
+		prop = <0x01>;
+		ref-base = <&base>;
+	};
+};
tests/run_tests.sh +2 -1
index 688d81d..def1a7e 100755
@@ -1125,7 +1125,8 @@ wrap_fdtdump () {
 }
 
 metadata_tests() {
-	for dt in metadata_reflocal metadata_refphandle; do
+	for dt in metadata_reflocal metadata_refphandle \
+		  metadata_addon_base; do
 		run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts"
 		base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect"
 		run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts"
Signature · 1 line
2.52.0
#57 lore raw

RFC PATCH 18/77 dtc-parser.y: Avoid an empty proplist

In reply to Herve Codina

In the dts parser grammar, a nodedef is defined by
'{' proplist subnodes '}' ';'
with both proplist and subnodes that can be empty lists.

Soon a new list will be added in the nodedef related to export symbol list.

Having all those lists with support for empty lists will lead to some Bison warnings:
warning: 4 shift/reduce conflicts [-Wconflicts-sr]
warning: 1 reduce/reduce conflict [-Wconflicts-rr]

The simpler way to remove those warning and thus have a robust parsing is to avoid those empty lists.

Update the proplist definition and nodedef definition to avoid those multiple empty lists. Instead of allowing a proplist to be an empty list, force the list to be a non empty one and update the nodedef to handle explicitly the absence of the proplist to support the case where no properties are available, i.e. the case of a node composed only of sub-nodes.

This doesn't change the functional behavior.

---
 dtc-parser.y | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
dtc-parser.y +6 -2
index d8914d2..2e152b0 100644
@@ -272,12 +272,16 @@ nodedef:
 		{
 			$$ = build_node($2, $3, &@$);
 		}
+	| '{' subnodes '}' ';'
+		{
+			$$ = build_node(NULL, $2, &@$);
+		}
 	;
 
 proplist:
-	  /* empty */
+	  propdef
 		{
-			$$ = NULL;
+			$$ = chain_property($1, NULL);
 		}
 	| proplist propdef
 		{
Signature · 1 line
2.52.0
#58 lore raw

Re: [RFC PATCH 18/77] dtc-parser.y: Avoid an empty proplist

Quoted 22 lines · Herve Codina

In the dts parser grammar, a nodedef is defined by
'{' proplist subnodes '}' ';'
with both proplist and subnodes that can be empty lists.

Soon a new list will be added in the nodedef related to export symbol list.

Having all those lists with support for empty lists will lead to some Bison warnings:
warning: 4 shift/reduce conflicts [-Wconflicts-sr]
warning: 1 reduce/reduce conflict [-Wconflicts-rr]

The simpler way to remove those warning and thus have a robust parsing is to avoid those empty lists.

Update the proplist definition and nodedef definition to avoid those multiple empty lists. Instead of allowing a proplist to be an empty list, force the list to be a non empty one and update the nodedef to handle explicitly the absence of the proplist to support the case where no properties are available, i.e. the case of a node composed only of sub-nodes.

Quoted 3 lines

This doesn't change the functional behavior.

I think it makes sense to apply this on its own before the rest of the series, but the commit message will want rewording for that context.

Quoted 31 lines
---
 dtc-parser.y | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
dtc-parser.y +6 -2
index d8914d2..2e152b0 100644
@@ -272,12 +272,16 @@ nodedef:
 		{
 			$$ = build_node($2, $3, &@$);
 		}
+	| '{' subnodes '}' ';'
+		{
+			$$ = build_node(NULL, $2, &@$);
+		}
 	;
 
 proplist:
-	  /* empty */
+	  propdef
 		{
-			$$ = NULL;
+			$$ = chain_property($1, NULL);
 		}
 	| proplist propdef
 		{
Signature · 1 line
2.52.0
Signature · 4 lines
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
#59 lore raw

Re: [RFC PATCH 18/77] dtc-parser.y: Avoid an empty proplist

Hi David,

On Thu, 15 Jan 2026 12:34:19 +1100
David Gibson <[email protected]> wrote:

...

Quoted 4 lines

I think it makes sense to apply this on its own before the rest of the series, but the commit message will want rewording for that context.

I will do this rewording and I will move the patch at the begining of the series in the next iteration.

Best regards,
Hervé

#60 lore raw

RFC PATCH 19/77 dtc: Introduce export symbols

In reply to Herve Codina

Export symbols allow to define a list of symbols exported at a given node level. Those exported symbols can be used by an addon when the addon is applied on the node exporting the symbols. In order to perform its symbol resolution. Any unresolved phandle value will be resolved using those exported symbols.

The feature is similar to __symbols__ involved with overlay but while all symbols are visible with __symbols__, only specific symbols (exported symbols) are visible with export symbols.

Also an exported symbol has a specific name and this name has to used for symbol resolution. Having this specific name allows to:

- Have several nodes providing the same exported symbols

    name but each of them pointing to different nodes.

    Without looking at the detail of the syntax, node-a and node-b
    export the same symbol foo but pointing to different node.
      node-a {
        /* export foo -> /path/foo1 */
      };
      node-b {
        /* export foo -> /path/foo2 */
      };

    This allow to have the exact same addon referencing 'foo' applied
    either on node-a or node-b.

- Have several board describing a well defined node even if resources

    needed for exported symbols are not the same.

    On board A, the 'ctrl' exported symbols points to some ctrl device
    available on the SoC:
      node {
        /* export 'ctrl' -> /soc/ctrl@1000
      };

    On board B, the ctrl device used is on a i2c bus
      node {
        /* export 'ctrl' -> /soc/i2c@5000/ctrl@10
      };

    The addon can be used on board A and board B without any
    modification. It uses 'ctrl' exported by the node the it is applied
    to.

Introduce the 'symbol' internal data structure and the export symbol list related to a node.

No functional change yet but preparation for the future support for export symbol parsing.

---
 dtc-parser.y |  6 +++---
 dtc.h        | 13 ++++++++++++-
 flattree.c   |  2 +-
 fstree.c     |  2 +-
 livetree.c   |  7 ++++---
 5 files changed, 21 insertions(+), 9 deletions(-)
dtc-parser.y +3 -3
index 2e152b0..9c93673 100644
@@ -183,7 +183,7 @@ devicetree:
 			else if (is_ref_relative($1))
 				ERROR(&@2, "Label-relative reference %s not supported in plugin", $1);
 			$$ = add_orphan_node(
-					name_node(build_node(NULL, NULL, NULL),
+					name_node(build_node(NULL, NULL, NULL, NULL),
 						  ""),
 					$2, $1);
 		}
@@ -270,11 +270,11 @@ devicetree:
 nodedef:
 	  '{' proplist subnodes '}' ';'
 		{
-			$$ = build_node($2, $3, &@$);
+			$$ = build_node($2, $3, NULL, &@$);
 		}
 	| '{' subnodes '}' ';'
 		{
-			$$ = build_node(NULL, $2, &@$);
+			$$ = build_node(NULL, $2, NULL, &@$);
 		}
 	;
 
dtc.h +12 -1
index c0fffd2..6508694 100644
@@ -204,6 +204,16 @@ struct label {
 	struct label *next;
 };
 
+struct symbol {
+	bool is_local;
+	char *name;
+	char *ref;
+	cell_t phandle;
+	char *fullpath;
+	struct symbol *next;
+	struct srcpos *srcpos;
+};
+
 struct bus_type {
 	const char *name;
 };
@@ -224,6 +234,7 @@ struct node {
 	char *name;
 	struct property *proplist;
 	struct node *children;
+	struct symbol *exportsymlist;
 
 	struct node *parent;
 	struct node *next_sibling;
@@ -272,7 +283,7 @@ struct property *chain_property(struct property *first, struct property *list);
 struct property *reverse_properties(struct property *first);
 
 struct node *build_node(struct property *proplist, struct node *children,
-			struct srcpos *srcpos);
+			struct symbol *exportsymlist, struct srcpos *srcpos);
 struct node *build_node_delete(struct srcpos *srcpos);
 struct node *name_node(struct node *node, const char *name);
 struct node *omit_node_if_unused(struct node *node);
flattree.c +1 -1
index bedb286..36b795d 100644
@@ -809,7 +809,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
 	uint32_t offset;
 	const char *str;
 
-	node = build_node(NULL, NULL, NULL);
+	node = build_node(NULL, NULL, NULL, NULL);
 
 	flatname = flat_read_string(dtbuf);
 
fstree.c +1 -1
index 0f9a534..445ae53 100644
@@ -19,7 +19,7 @@ static struct node *read_fstree(const char *dirname)
 	if (!d)
 		die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno));
 
-	tree = build_node(NULL, NULL, NULL);
+	tree = build_node(NULL, NULL, NULL, NULL);
 
 	while ((de = readdir(d)) != NULL) {
 		char *tmpname;
livetree.c +4 -3
index 2a0a7ed..0050492 100644
@@ -86,7 +86,7 @@ struct property *reverse_properties(struct property *first)
 }
 
 struct node *build_node(struct property *proplist, struct node *children,
-			struct srcpos *srcpos)
+			struct symbol *exportsymlist, struct srcpos *srcpos)
 {
 	struct node *new = xmalloc(sizeof(*new));
 	struct node *child;
@@ -95,6 +95,7 @@ struct node *build_node(struct property *proplist, struct node *children,
 
 	new->proplist = reverse_properties(proplist);
 	new->children = children;
+	new->exportsymlist = exportsymlist;
 	new->srcpos = srcpos_copy(srcpos);
 
 	for_each_child(new, child) {
@@ -248,7 +249,7 @@ struct node * add_orphan_node(struct node *dt, struct node *new_node, char *ref)
 	xasprintf(&name, "fragment@%u",
 			next_orphan_fragment++);
 	name_node(new_node, "__overlay__");
-	node = build_node(p, new_node, NULL);
+	node = build_node(p, new_node, NULL, NULL);
 	name_node(node, name);
 	free(name);
 
@@ -892,7 +893,7 @@ static struct node *build_and_name_child_node(struct node *parent, const char *n
 {
 	struct node *node;
 
-	node = build_node(NULL, NULL, NULL);
+	node = build_node(NULL, NULL, NULL, NULL);
 	name_node(node, name);
 	add_child(parent, node);
 
Signature · 1 line
2.52.0
#61 lore raw

Re: [RFC PATCH 19/77] dtc: Introduce export symbols

Quoted 3 lines · Herve Codina

Export symbols allow to define a list of symbols exported at a given node level. Those exported symbols can be used by an addon when the addon is applied on the node exporting the symbols.

This seems to imply an addon always applies at a single node location. I'm not sure that's a good design choice, since I don't see how it covers the case of something that connects to several connectors.

Quoted 7 lines

In order to perform
its symbol resolution. Any unresolved phandle value will be resolved using those exported symbols.

The feature is similar to __symbols__ involved with overlay but while all symbols are visible with __symbols__, only specific symbols (exported symbols) are visible with export symbols.

This paragraph doesn't make sense to me. What's a "symbol" if it's not something in __symbols__ or export symbols?

Quoted 5 lines

Also an exported symbol has a specific name and this name has to used for symbol resolution. Having this specific name allows to:

- Have several nodes providing the same exported symbols name but each of them pointing to different nodes.

That's not a property of having a specific name, that's a property of being local to a node.

Quoted 179 lines
    Without looking at the detail of the syntax, node-a and node-b
    export the same symbol foo but pointing to different node.
      node-a {
        /* export foo -> /path/foo1 */
      };
      node-b {
        /* export foo -> /path/foo2 */
      };

    This allow to have the exact same addon referencing 'foo' applied
    either on node-a or node-b.

- Have several board describing a well defined node even if resources

    needed for exported symbols are not the same.

    On board A, the 'ctrl' exported symbols points to some ctrl device
    available on the SoC:
      node {
        /* export 'ctrl' -> /soc/ctrl@1000
      };

    On board B, the ctrl device used is on a i2c bus
      node {
        /* export 'ctrl' -> /soc/i2c@5000/ctrl@10
      };

    The addon can be used on board A and board B without any
    modification. It uses 'ctrl' exported by the node the it is applied
    to.

Introduce the 'symbol' internal data structure and the export symbol list related to a node.

No functional change yet but preparation for the future support for export symbol parsing.

---
 dtc-parser.y |  6 +++---
 dtc.h        | 13 ++++++++++++-
 flattree.c   |  2 +-
 fstree.c     |  2 +-
 livetree.c   |  7 ++++---
 5 files changed, 21 insertions(+), 9 deletions(-)
dtc-parser.y +3 -3
index 2e152b0..9c93673 100644
@@ -183,7 +183,7 @@ devicetree:
 			else if (is_ref_relative($1))
 				ERROR(&@2, "Label-relative reference %s not supported in plugin", $1);
 			$$ = add_orphan_node(
-					name_node(build_node(NULL, NULL, NULL),
+					name_node(build_node(NULL, NULL, NULL, NULL),
 						  ""),
 					$2, $1);
 		}
@@ -270,11 +270,11 @@ devicetree:
 nodedef:
 	  '{' proplist subnodes '}' ';'
 		{
-			$$ = build_node($2, $3, &@$);
+			$$ = build_node($2, $3, NULL, &@$);
 		}
 	| '{' subnodes '}' ';'
 		{
-			$$ = build_node(NULL, $2, &@$);
+			$$ = build_node(NULL, $2, NULL, &@$);
 		}
 	;
 
dtc.h +12 -1
index c0fffd2..6508694 100644
@@ -204,6 +204,16 @@ struct label {
 	struct label *next;
 };
 
+struct symbol {
+	bool is_local;
+	char *name;
+	char *ref;
+	cell_t phandle;
+	char *fullpath;
+	struct symbol *next;
+	struct srcpos *srcpos;
+};
+
 struct bus_type {
 	const char *name;
 };
@@ -224,6 +234,7 @@ struct node {
 	char *name;
 	struct property *proplist;
 	struct node *children;
+	struct symbol *exportsymlist;
 
 	struct node *parent;
 	struct node *next_sibling;
@@ -272,7 +283,7 @@ struct property *chain_property(struct property *first, struct property *list);
 struct property *reverse_properties(struct property *first);
 
 struct node *build_node(struct property *proplist, struct node *children,
-			struct srcpos *srcpos);
+			struct symbol *exportsymlist, struct srcpos *srcpos);
 struct node *build_node_delete(struct srcpos *srcpos);
 struct node *name_node(struct node *node, const char *name);
 struct node *omit_node_if_unused(struct node *node);
flattree.c +1 -1
index bedb286..36b795d 100644
@@ -809,7 +809,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
 	uint32_t offset;
 	const char *str;
 
-	node = build_node(NULL, NULL, NULL);
+	node = build_node(NULL, NULL, NULL, NULL);
 
 	flatname = flat_read_string(dtbuf);
 
fstree.c +1 -1
index 0f9a534..445ae53 100644
@@ -19,7 +19,7 @@ static struct node *read_fstree(const char *dirname)
 	if (!d)
 		die("Couldn't opendir() \"%s\": %s\n", dirname, strerror(errno));
 
-	tree = build_node(NULL, NULL, NULL);
+	tree = build_node(NULL, NULL, NULL, NULL);
 
 	while ((de = readdir(d)) != NULL) {
 		char *tmpname;
livetree.c +4 -3
index 2a0a7ed..0050492 100644
@@ -86,7 +86,7 @@ struct property *reverse_properties(struct property *first)
 }
 
 struct node *build_node(struct property *proplist, struct node *children,
-			struct srcpos *srcpos)
+			struct symbol *exportsymlist, struct srcpos *srcpos)
 {
 	struct node *new = xmalloc(sizeof(*new));
 	struct node *child;
@@ -95,6 +95,7 @@ struct node *build_node(struct property *proplist, struct node *children,
 
 	new->proplist = reverse_properties(proplist);
 	new->children = children;
+	new->exportsymlist = exportsymlist;
 	new->srcpos = srcpos_copy(srcpos);
 
 	for_each_child(new, child) {
@@ -248,7 +249,7 @@ struct node * add_orphan_node(struct node *dt, struct node *new_node, char *ref)
 	xasprintf(&name, "fragment@%u",
 			next_orphan_fragment++);
 	name_node(new_node, "__overlay__");
-	node = build_node(p, new_node, NULL);
+	node = build_node(p, new_node, NULL, NULL);
 	name_node(node, name);
 	free(name);
 
@@ -892,7 +893,7 @@ static struct node *build_and_name_child_node(struct node *parent, const char *n
 {
 	struct node *node;
 
-	node = build_node(NULL, NULL, NULL);
+	node = build_node(NULL, NULL, NULL, NULL);
 	name_node(node, name);
 	add_child(parent, node);
 
Signature · 1 line
2.52.0
Signature · 4 lines
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
#62 lore raw

Re: [RFC PATCH 19/77] dtc: Introduce export symbols

Hi David,

Quoted 8 lines · On Thu, 15 Jan 2026 16:52:26 +1100 David Gibson <[email protected]>…
Quoted 3 lines · Herve Codina

Export symbols allow to define a list of symbols exported at a given node level. Those exported symbols can be used by an addon when the addon is applied on the node exporting the symbols.

This seems to imply an addon always applies at a single node location. I'm not sure that's a good design choice, since I don't see how it covers the case of something that connects to several connectors.

Apply the addon on a node that knows about those connectors.

Quoted 11 lines
Quoted 8 lines

In order to perform
its symbol resolution. Any unresolved phandle value will be resolved using those exported symbols.

The feature is similar to __symbols__ involved with overlay but while all symbols are visible with __symbols__, only specific symbols (exported symbols) are visible with export symbols.

This paragraph doesn't make sense to me. What's a "symbol" if it's not something in __symbols__ or export symbols?

An imported symbols ?

/import/ foo "blabla";

from the addon point of view where this /import/ is present, 'foo' is a symbol.

Quoted 9 lines
Quoted 6 lines

Also an exported symbol has a specific name and this name has to used for symbol resolution. Having this specific name allows to:

- Have several nodes providing the same exported symbols name but each of them pointing to different nodes.

That's not a property of having a specific name, that's a property of being local to a node.

Yes, exactly. I will reword.

Best regards,
Hervé

#63 lore raw

Re: [RFC PATCH 19/77] dtc: Introduce export symbols

Quoted 10 lines · Herve Codina

Hi David,

Quoted 5 lines · On Thu, 15 Jan 2026 16:52:26 +1100 David Gibson <[email protected]>…
Quoted 3 lines · Herve Codina

Export symbols allow to define a list of symbols exported at a given node level. Those exported symbols can be used by an addon when the addon is applied on the node exporting the symbols.

Quoted 5 lines
Quoted 3 lines

This seems to imply an addon always applies at a single node location. I'm not sure that's a good design choice, since I don't see how it covers the case of something that connects to several connectors.

Apply the addon on a node that knows about those connectors.

That seems limiting to me, because it requires the base tree to know about all possible connector combinations, which I'm not sure is feasible. If I understood Geert(?)'s case properly, there are use cases where a board might have, say, six "type foo" connectors, and an addon board could connect to any two of those. Of a board might have 3 "type foo" and 3 "type bar" connectors and an addon board needs to connect to (any) of each. It seems much more natural to me that at attach time you say
"addon foo 0 => board foo 1, addon foo 1 => board foo 5"
or "addon foo 0 => board foo 2, addon bar 0 => board bar 1"

Rather than the board itself having to anticipate all combinations.

Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

In order to perform
its symbol resolution. Any unresolved phandle value will be resolved using those exported symbols.

The feature is similar to __symbols__ involved with overlay but while all symbols are visible with __symbols__, only specific symbols (exported symbols) are visible with export symbols.

This paragraph doesn't make sense to me. What's a "symbol" if it's not something in __symbols__ or export symbols?

Quoted 6 lines

An imported symbols ?

/import/ foo "blabla";

from the addon point of view where this /import/ is present, 'foo' is a symbol.

I guess, but existing plugin stuff doesn't really have imported symbols, so the example doesn't really illuminate the difference from the status quo.

Quoted 14 lines
Quoted 8 lines
Quoted 5 lines

Also an exported symbol has a specific name and this name has to used for symbol resolution. Having this specific name allows to:

- Have several nodes providing the same exported symbols name but each of them pointing to different nodes.

That's not a property of having a specific name, that's a property of being local to a node.

Yes, exactly. I will reword.

Best regards,
Hervé

Signature · 4 lines
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
#64 lore raw

Re: [RFC PATCH 19/77] dtc: Introduce export symbols

Hi David,

Quoted 17 lines · On Mon, 19 Jan 2026 16:51:21 +1100 David Gibson <[email protected]>…
Quoted 10 lines · Herve Codina

Hi David,

Quoted 5 lines · On Thu, 15 Jan 2026 16:52:26 +1100 David Gibson <[email protected]>…
Quoted 3 lines · Herve Codina

Export symbols allow to define a list of symbols exported at a given node level. Those exported symbols can be used by an addon when the addon is applied on the node exporting the symbols.

Quoted 5 lines
Quoted 3 lines

This seems to imply an addon always applies at a single node location. I'm not sure that's a good design choice, since I don't see how it covers the case of something that connects to several connectors.

Apply the addon on a node that knows about those connectors.

Quoted 10 lines

That seems limiting to me, because it requires the base tree to know about all possible connector combinations, which I'm not sure is feasible. If I understood Geert(?)'s case properly, there are use cases where a board might have, say, six "type foo" connectors, and an addon board could connect to any two of those. Of a board might have 3 "type foo" and 3 "type bar" connectors and an addon board needs to connect to (any) of each. It seems much more natural to me that at attach time you say
"addon foo 0 => board foo 1, addon foo 1 => board foo 5"
or "addon foo 0 => board foo 2, addon bar 0 => board bar 1"

Who can perform this mapping ?

The user applying the addon if a tool is used such as fdtaddon for instance (even if this kind of mapping is not yet available in fdtaddon I proposed).

Or a driver that knows about the board connectors.

This driver will apply the addon dtb and provide custom mapping between symbols expected by the addon (/import/) and symbols provided by the board.

Quoted 16 lines

Rather than the board itself having to anticipate all combinations.

Quoted 13 lines
Quoted 10 lines
Quoted 7 lines

In order to perform
its symbol resolution. Any unresolved phandle value will be resolved using those exported symbols.

The feature is similar to __symbols__ involved with overlay but while all symbols are visible with __symbols__, only specific symbols (exported symbols) are visible with export symbols.

This paragraph doesn't make sense to me. What's a "symbol" if it's not something in __symbols__ or export symbols?

An imported symbols ?

Quoted 8 lines
Quoted 4 lines

/import/ foo "blabla";

from the addon point of view where this /import/ is present, 'foo' is a symbol.

I guess, but existing plugin stuff doesn't really have imported symbols, so the example doesn't really illuminate the difference from the status quo.

A plugin need to know about all possible symbols available on the board is applied too. This is the purpose of __symbols__. This just means that for plugin all possible symbols are imported and symbol translation is not possible.

A plugin is designed for a specific base board. It needs to know about each busses and how they are wired.

I mean a plugin references i2c5, the i2c controller number 5, and i2c5 needs to be present in __symbols__.

The target property in __overlay__ identify the target node. Here also, this is dependent on the board the plugin is applied to.

Addons depend only on the node, describing the connector, they are applied to. They do not depend on the full specific board where this connector is available.

Two different boards can have the same connector available and a given board can have two connectors of the same family the addon can be connected to.

Best regards,
Hervé

#65 lore raw

Re: [RFC PATCH 19/77] dtc: Introduce export symbols

Quoted 33 lines · Herve Codina

Hi David,

Quoted 17 lines · On Mon, 19 Jan 2026 16:51:21 +1100 David Gibson <[email protected]>…
Quoted 10 lines · Herve Codina

Hi David,

Quoted 5 lines · On Thu, 15 Jan 2026 16:52:26 +1100 David Gibson <[email protected]>…
Quoted 3 lines · Herve Codina

Export symbols allow to define a list of symbols exported at a given node level. Those exported symbols can be used by an addon when the addon is applied on the node exporting the symbols.

Quoted 5 lines
Quoted 3 lines

This seems to imply an addon always applies at a single node location. I'm not sure that's a good design choice, since I don't see how it covers the case of something that connects to several connectors.

Apply the addon on a node that knows about those connectors.

Quoted 10 lines

That seems limiting to me, because it requires the base tree to know about all possible connector combinations, which I'm not sure is feasible. If I understood Geert(?)'s case properly, there are use cases where a board might have, say, six "type foo" connectors, and an addon board could connect to any two of those. Of a board might have 3 "type foo" and 3 "type bar" connectors and an addon board needs to connect to (any) of each. It seems much more natural to me that at attach time you say
"addon foo 0 => board foo 1, addon foo 1 => board foo 5"
or "addon foo 0 => board foo 2, addon bar 0 => board bar 1"

Quoted 6 lines

Who can perform this mapping ?

The user applying the addon if a tool is used such as fdtaddon for instance (even if this kind of mapping is not yet available in fdtaddon I proposed).

Or a driver that knows about the board connectors.

Either or. From the point of view of the design, I'm thinking of this being specified by the "client" - that is by whatever is initiating the application of the addon. That could come directly from user input, but in cases where the connectors are sufficiently probable, something automated could also supply the information.

Quoted 41 lines

This driver will apply the addon dtb and provide custom mapping between symbols expected by the addon (/import/) and symbols provided by the board.

Quoted 16 lines

Rather than the board itself having to anticipate all combinations.

Quoted 13 lines
Quoted 10 lines
Quoted 7 lines

In order to perform
its symbol resolution. Any unresolved phandle value will be resolved using those exported symbols.

The feature is similar to __symbols__ involved with overlay but while all symbols are visible with __symbols__, only specific symbols (exported symbols) are visible with export symbols.

This paragraph doesn't make sense to me. What's a "symbol" if it's not something in __symbols__ or export symbols?

An imported symbols ?

Quoted 8 lines
Quoted 4 lines

/import/ foo "blabla";

from the addon point of view where this /import/ is present, 'foo' is a symbol.

I guess, but existing plugin stuff doesn't really have imported symbols, so the example doesn't really illuminate the difference from the status quo.

A plugin need to know about all possible symbols available on the board is applied too. This is the purpose of __symbols__. This just means that for plugin all possible symbols are imported and symbol translation is not possible.

A plugin is designed for a specific base board. It needs to know about each busses and how they are wired.

I mean a plugin references i2c5, the i2c controller number 5, and i2c5 needs to be present in __symbols__.

The target property in __overlay__ identify the target node. Here also, this is dependent on the board the plugin is applied to.

Quoted 6 lines

Addons depend only on the node, describing the connector, they are applied to. They do not depend on the full specific board where this connector is available.

Two different boards can have the same connector available and a given board can have two connectors of the same family the addon can be connected to.

Ok, I think I see what you're getting at.

Signature · 4 lines
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
#66 lore raw

RFC PATCH 20/77 dtc: Add support for /export/ dts keyword parsing

In reply to Herve Codina

The /export/ dts keyword is the keyword used to define an exported symbol at a given node level.

This keyword can be present in a node definition (after properties and before subnodes) to export a symbol. If several symbols need to be exported, several /export/ keywords are present.

The syntax used is the following:
/export/ name: reference;

with:
name: The name of the exported symbol
reference: The reference of a node the symbol is pointing to.

For instance:
- Reference by label:
/export/ foo: &foo1;

The exported symbol foo references the node identified by the label foo1.

- Reference by path:
/export/ foo: &{/path/to/foo@100};

The exported symbol foo references the node at /path/to/foo@100.

Add support for /export/ dts keyword.

---
 dtc-lexer.l  |  6 ++++
 dtc-parser.y | 53 ++++++++++++++++++++++++++++++++++
 dtc.h        |  8 ++++++
 livetree.c   | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 147 insertions(+)
dtc-lexer.l +6 -0
index a4a8e0b..90fe70e 100644
@@ -149,6 +149,12 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
 			return DT_OMIT_NO_REF;
 		}
 
+<*>"/export/" 	{
+			DPRINT("Keyword: /export/\n");
+			BEGIN_DEFAULT();
+			return DT_EXPORT;
+		}
+
 <*>{LABEL}:	{
 			DPRINT("Label: %s\n", yytext);
 			yylval.labelref = xstrdup(yytext);
dtc-parser.y +53 -0

83 lines not on this page · raw message

dtc.h +8 -0
index 6508694..0bf5ba5 100644
@@ -273,6 +273,9 @@ struct node {
 	for_each_child_withdel(n, c) \
 		if (!(c)->deleted)
 
+#define for_each_symbol(s0, s) \
+	for ((s) = (s0); (s); (s) = (s)->next)
+
 void add_label(struct label **labels, char *label);
 void delete_labels(struct label **labels);
 
@@ -282,6 +285,11 @@ struct property *build_property_delete(const char *name);
 struct property *chain_property(struct property *first, struct property *list);
 struct property *reverse_properties(struct property *first);
 
+struct symbol *build_exportsym(const char *name, const char *ref, cell_t phandle,
+			       struct srcpos *srcpos);
+struct symbol *chain_symbol(struct symbol *first, struct symbol *list);
+struct symbol *reverse_symbol(struct symbol *list);
+
 struct node *build_node(struct property *proplist, struct node *children,
 			struct symbol *exportsymlist, struct srcpos *srcpos);
 struct node *build_node_delete(struct srcpos *srcpos);
livetree.c +80 -0

98 lines not on this page · raw message

Signature · 1 line
2.52.0
#67 lore raw

Re: [RFC PATCH 20/77] dtc: Add support for /export/ dts keyword parsing

Quoted 119 lines · Herve Codina

The /export/ dts keyword is the keyword used to define an exported symbol at a given node level.

This keyword can be present in a node definition (after properties and before subnodes) to export a symbol. If several symbols need to be exported, several /export/ keywords are present.

The syntax used is the following:
/export/ name: reference;

with:
name: The name of the exported symbol
reference: The reference of a node the symbol is pointing to.

For instance:
- Reference by label:
/export/ foo: &foo1;

The exported symbol foo references the node identified by the label foo1.

- Reference by path:
/export/ foo: &{/path/to/foo@100};

The exported symbol foo references the node at /path/to/foo@100.

Add support for /export/ dts keyword.

---
 dtc-lexer.l  |  6 ++++
 dtc-parser.y | 53 ++++++++++++++++++++++++++++++++++
 dtc.h        |  8 ++++++
 livetree.c   | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 147 insertions(+)
dtc-lexer.l +6 -0
index a4a8e0b..90fe70e 100644
@@ -149,6 +149,12 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
 			return DT_OMIT_NO_REF;
 		}
 
+<*>"/export/" 	{
+			DPRINT("Keyword: /export/\n");
+			BEGIN_DEFAULT();
+			return DT_EXPORT;
+		}
+
 <*>{LABEL}:	{
 			DPRINT("Label: %s\n", yytext);
 			yylval.labelref = xstrdup(yytext);
dtc-parser.y +37 -0
index 9c93673..a0d0aef 100644
@@ -46,6 +46,8 @@ static bool is_ref_relative(const char *ref)
 	struct property *proplist;
 	struct node *node;
 	struct node *nodelist;
+	struct symbol *symbol;
+	struct symbol *exportlist;
 	struct reserve_info *re;
 	uint64_t integer;
 	unsigned int flags;
@@ -60,6 +62,7 @@ static bool is_ref_relative(const char *ref)
 %token DT_DEL_PROP
 %token DT_DEL_NODE
 %token DT_OMIT_NO_REF
+%token DT_EXPORT
 %token <propnodename> DT_PROPNODENAME
 %token <integer> DT_LITERAL
 %token <integer> DT_CHAR_LITERAL
@@ -80,6 +83,8 @@ static bool is_ref_relative(const char *ref)
 %type <data> bytestring
 %type <prop> propdef
 %type <proplist> proplist
+%type <symbol> exportdef
+%type <exportlist> exportlist
 %type <labelref> dt_ref
 
 %type <node> devicetree
@@ -276,6 +281,49 @@ nodedef:
 		{
 			$$ = build_node(NULL, $2, NULL, &@$);
 		}
+	| '{' proplist exportlist subnodes '}' ';'
+		{
+			/*
+			 * exportlist is created with chain_symbol() and so it
+			 * is created in reverse order. Reverse it now to have
+			 * it in correct order
+			 */
+			$$ = build_node($2, $4, reverse_symbol($3), &@$);
+		}
+	| '{' exportlist subnodes '}' ';'
+		{
+			/*
+			 * exportlist is created with chain_symbol() and so it
+			 * is created in reverse order. Reverse it now to have
+			 * it in correct order
+			 */
+			$$ = build_node(NULL, $3, reverse_symbol($2), &@$);
+		}
+	;
+
+exportlist:
+	  exportdef
+		{
+			$$ = chain_symbol($1, NULL);
+		}
+	| exportlist exportdef
+		{
+			$$ = chain_symbol($2, $1);
+		}
+	| exportlist propdef
+		{
+			ERROR(&@2, "Properties must precede exports");

dtc-parser.y nodedef: · line 325

Quoted 10 lines
dtc-parser.y +10 -0
+			YYERROR;
+		}
+	;
+
+exportdef:
+	DT_EXPORT DT_LABEL dt_ref ';'
+		{
+			$$ = build_exportsym($2, $3, 0, &@$);
+			free($2);
+			free($3);

I mostly don't bother with free()s in dtc, on the grounds that it's generally a short-lived process - essentially using the process context as a crude pool allocator.

Quoted 151 lines
dtc-parser.y +6 -0
+		}
 	;
 
 proplist:
@@ -576,6 +624,11 @@ subnodes:
 			ERROR(&@2, "Properties must precede subnodes");
 			YYERROR;
 		}
+	| subnode exportdef
+		{
+			ERROR(&@2, "Exports must precede subnodes");
+			YYERROR;
+		}
 	;
 
 subnode:
dtc.h +8 -0
index 6508694..0bf5ba5 100644
@@ -273,6 +273,9 @@ struct node {
 	for_each_child_withdel(n, c) \
 		if (!(c)->deleted)
 
+#define for_each_symbol(s0, s) \
+	for ((s) = (s0); (s); (s) = (s)->next)
+
 void add_label(struct label **labels, char *label);
 void delete_labels(struct label **labels);
 
@@ -282,6 +285,11 @@ struct property *build_property_delete(const char *name);
 struct property *chain_property(struct property *first, struct property *list);
 struct property *reverse_properties(struct property *first);
 
+struct symbol *build_exportsym(const char *name, const char *ref, cell_t phandle,
+			       struct srcpos *srcpos);
+struct symbol *chain_symbol(struct symbol *first, struct symbol *list);
+struct symbol *reverse_symbol(struct symbol *list);
+
 struct node *build_node(struct property *proplist, struct node *children,
 			struct symbol *exportsymlist, struct srcpos *srcpos);
 struct node *build_node_delete(struct srcpos *srcpos);
livetree.c +80 -0
index 0050492..4458437 100644
@@ -36,6 +36,57 @@ void delete_labels(struct label **labels)
 		label->deleted = 1;
 }
 
+struct symbol *build_exportsym(const char *name, const char *ref, cell_t phandle,
+			       struct srcpos *srcpos)
+{
+	struct symbol *new = xmalloc(sizeof(*new));
+
+	memset(new, 0, sizeof(*new));
+
+	new->name = xstrdup(name);
+	new->ref = ref ? xstrdup(ref) : NULL;
+	new->phandle = phandle;
+	new->srcpos = srcpos_copy(srcpos);
+
+	return new;
+}
+
+struct symbol *chain_symbol(struct symbol *first, struct symbol *list)
+{
+	assert(first->next == NULL);
+
+	first->next = list;
+	return first;
+}
+
+struct symbol *reverse_symbol(struct symbol *list)
+{
+	struct symbol *p = list;
+	struct symbol *head = NULL;
+	struct symbol *next;
+
+	while (p) {
+		next = p->next;
+		p->next = head;
+		head = p;
+		p = next;
+	}
+	return head;
+}
+
+static void add_symbol(struct symbol **list, struct symbol *new)
+{
+	struct symbol **s;
+
+	new->next = NULL;
+
+	s = list;
+	while (*s)
+		s = &((*s)->next);
+
+	*s = new;
+}
+
 struct property *build_property(const char *name, struct data val,
 				struct srcpos *srcpos)
 {
@@ -144,6 +195,7 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
 {
 	struct property *new_prop, *old_prop;
 	struct node *new_child, *old_child;
+	struct symbol *new_sym, *old_sym;
 	struct label *l;
 
 	old_node->deleted = 0;
@@ -217,6 +269,34 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
 			add_child(old_node, new_child);
 	}
 
+	/* Merge exported symbols. If there is a collision, keep the new one */
+	while (new_node->exportsymlist) {
+		/* Pop the symbol off the list */
+		new_sym = new_node->exportsymlist;
+		new_node->exportsymlist = new_sym->next;
+		new_sym->next = NULL;
+
+		/* Look for a collision, set new value if there is */
+		for_each_symbol(old_node->exportsymlist, old_sym) {
+			if (streq(old_sym->name, new_sym->name)) {
+				old_sym->is_local = new_sym->is_local;
+				free(old_sym->ref);
+				old_sym->ref = new_sym->ref;
+				old_sym->phandle = new_sym->phandle;
+				old_sym->fullpath = new_sym->fullpath;
+				srcpos_free(old_sym->srcpos);
+				old_sym->srcpos = new_sym->srcpos;
+				free(new_sym);
+				new_sym = NULL;
+				break;
+			}
+		}
+
+		/* if no collision occurred, add symbol to the old node list. */
+		if (new_sym)
+			add_symbol(&old_node->exportsymlist, new_sym);
+	}
+
 	old_node->srcpos = srcpos_extend(old_node->srcpos, new_node->srcpos);
 
 	/* The new node contents are now merged into the old node.  Free
Signature · 1 line
2.52.0
Signature · 4 lines
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
#68 lore raw

RFC PATCH 21/77 checks: Handle export symbols in fixup_phandle_references()

In reply to Herve Codina

Export symbols use phandle references.

Referenced nodes must have a phandle property set in order to have those references working.

fixup_phandle_references() does the needed operation for properties that use a phandle.

Extend fixup_phandle_references() to perform exact same operation for export symbols.

---
 checks.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
checks.c +22 -2
index 2be19c0..d1e215e 100644
@@ -604,12 +604,13 @@ static void fixup_phandle_references(struct check *c, struct dt_info *dti,
 				     struct node *node)
 {
 	struct node *dt = dti->dt;
+	struct symbol *exportsym;
 	struct property *prop;
+	struct node *refnode;
+	cell_t phandle;
 
 	for_each_property(node, prop) {
 		struct marker *m = prop->val.markers;
-		struct node *refnode;
-		cell_t phandle;
 
 		for_each_marker_of_type(m, REF_PHANDLE) {
 			assert(m->offset + sizeof(cell_t) <= prop->val.len);
@@ -631,6 +632,25 @@ static void fixup_phandle_references(struct check *c, struct dt_info *dti,
 			reference_node(refnode);
 		}
 	}
+
+	for_each_symbol(node->exportsymlist, exportsym) {
+		refnode = get_node_by_ref(dt, exportsym->ref);
+		if (!refnode) {
+			if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON))) {
+				FAIL(c, dti, node,
+				     "Export \"%s\" references to non-existent node or label \"%s\"\n",
+				     exportsym->name, exportsym->ref);
+			}
+			exportsym->phandle = cpu_to_fdt32(0xffffffff);
+			continue;
+		}
+
+		/* Create the phandle property for this referenced node */
+		phandle = get_node_phandle(dt, refnode);
+		exportsym->phandle = phandle;
+
+		reference_node(refnode);
+	}
 }
 ERROR(phandle_references, fixup_phandle_references, NULL,
       &duplicate_node_names, &explicit_phandles);
Signature · 1 line
2.52.0
#69 lore raw

RFC PATCH 22/77 dtc: Add export symbols (/export/ keyword) in generated dts file

In reply to Herve Codina

The export symbols (/export/ keyword) parsing from a dts file is supported.

Add the support for this keyword in the dts file generation.

---
 treesource.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
treesource.c +13 -0
index 1db6390..9effe38 100644
@@ -320,6 +320,7 @@ static void write_propval(FILE *f, struct property *prop)
 
 static void write_tree_source_node(FILE *f, struct node *tree, int level)
 {
+	struct symbol *exportsym;
 	struct property *prop;
 	struct node *child;
 	struct label *l;
@@ -349,6 +350,18 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
 		fprintf(f, "%s", prop->name);
 		write_propval(f, prop);
 	}
+
+	if (tree->exportsymlist)
+		fprintf(f, "\n");
+	for_each_symbol(tree->exportsymlist, exportsym) {
+		write_prefix(f, level+1);
+		fprintf(f, "/export/ %s: ", exportsym->name);
+		if (exportsym->ref[0] == '/')
+			fprintf(f, "&{%s};\n", exportsym->ref);
+		else
+			fprintf(f, "&%s;\n", exportsym->ref);
+	}
+
 	for_each_child(tree, child) {
 		fprintf(f, "\n");
 		write_tree_source_node(f, child, level+1);
Signature · 1 line
2.52.0
#70 lore raw

RFC PATCH 23/77 dtc: Introduce mark_local_exports()

In reply to Herve Codina

In order to have correct tags set in dtb, an export symbol has to be identified as a "local" export symbol when it references a local node.

This is done for phandles used by properties in mark_local_phandles().

The same operation is needed for export symbols. This is the purpose of mark_local_exports().

---
 dtc.c      |  2 ++
 dtc.h      |  2 ++
 livetree.c | 23 +++++++++++++++++++++++
 3 files changed, 27 insertions(+)
dtc.c +2 -0
index fe8e8e4..030bfa2 100644
@@ -336,6 +336,8 @@ int main(int argc, char *argv[])
 	update_phandles_ref(dti);
 	mark_local_phandles(dti);
 
+	mark_local_exports(dti);
+
 	/*
 	 * With FDT_REF_PHANDLE added in dtbs, we need to identified
 	 * if some unresolved phandle references are allowed in the dtb
dtc.h +2 -0
index 0bf5ba5..ea073c2 100644
@@ -368,6 +368,8 @@ void generate_local_fixups_tree(struct dt_info *dti, const char *name);
 void update_phandles_ref(struct dt_info *dti);
 void mark_local_phandles(struct dt_info *dti);
 
+void mark_local_exports(struct dt_info *dti);
+
 /* Checks */
 
 void parse_checks_option(bool warn, bool error, const char *arg);
livetree.c +23 -0
index 4458437..0e756b8 100644
@@ -1303,3 +1303,26 @@ void mark_local_phandles(struct dt_info *dti)
 {
 	mark_local_phandles_internal(dti, dti->dt);
 }
+
+static void mark_local_exports_internal(struct dt_info *dti,
+					struct node *node)
+{
+	struct node *c;
+	struct symbol *exportsym;
+	struct node *refnode;
+
+	for_each_symbol(node->exportsymlist, exportsym) {
+		refnode = get_node_by_ref(dti->dt, exportsym->ref);
+		if (refnode)
+			exportsym->is_local = true;
+	}
+
+	for_each_child(node, c)
+		mark_local_exports_internal(dti, c);
+}
+
+void mark_local_exports(struct dt_info *dti)
+{
+	mark_local_exports_internal(dti, dti->dt);
+
+}
Signature · 1 line
2.52.0
#71 lore raw

Re: [RFC PATCH 23/77] dtc: Introduce mark_local_exports()

Quoted 8 lines · Herve Codina

In order to have correct tags set in dtb, an export symbol has to be identified as a "local" export symbol when it references a local node.

This is done for phandles used by properties in mark_local_phandles().

The same operation is needed for export symbols. This is the purpose of mark_local_exports().

Again, I don't like caching this information. Can you determine this just at the time you specifically use it?

Quoted 69 lines
---
 dtc.c      |  2 ++
 dtc.h      |  2 ++
 livetree.c | 23 +++++++++++++++++++++++
 3 files changed, 27 insertions(+)
dtc.c +2 -0
index fe8e8e4..030bfa2 100644
@@ -336,6 +336,8 @@ int main(int argc, char *argv[])
 	update_phandles_ref(dti);
 	mark_local_phandles(dti);
 
+	mark_local_exports(dti);
+
 	/*
 	 * With FDT_REF_PHANDLE added in dtbs, we need to identified
 	 * if some unresolved phandle references are allowed in the dtb
dtc.h +2 -0
index 0bf5ba5..ea073c2 100644
@@ -368,6 +368,8 @@ void generate_local_fixups_tree(struct dt_info *dti, const char *name);
 void update_phandles_ref(struct dt_info *dti);
 void mark_local_phandles(struct dt_info *dti);
 
+void mark_local_exports(struct dt_info *dti);
+
 /* Checks */
 
 void parse_checks_option(bool warn, bool error, const char *arg);
livetree.c +23 -0
index 4458437..0e756b8 100644
@@ -1303,3 +1303,26 @@ void mark_local_phandles(struct dt_info *dti)
 {
 	mark_local_phandles_internal(dti, dti->dt);
 }
+
+static void mark_local_exports_internal(struct dt_info *dti,
+					struct node *node)
+{
+	struct node *c;
+	struct symbol *exportsym;
+	struct node *refnode;
+
+	for_each_symbol(node->exportsymlist, exportsym) {
+		refnode = get_node_by_ref(dti->dt, exportsym->ref);
+		if (refnode)
+			exportsym->is_local = true;
+	}
+
+	for_each_child(node, c)
+		mark_local_exports_internal(dti, c);
+}
+
+void mark_local_exports(struct dt_info *dti)
+{
+	mark_local_exports_internal(dti, dti->dt);
+
+}
Signature · 1 line
2.52.0
Signature · 4 lines
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
#72 lore raw

RFC PATCH 24/77 dtc: Introduce update_exports_ref()

In reply to Herve Codina

In order to have consistent internal data when a export symbol using a local phandle is parsed from a dtb, the reference related to this phandle usage needs to be updated based on the phandle value.

This is done for phandles used by properties in update_phandles_ref().

The same operation is needed for export symbols. This is the purpose of update_exports_ref().

---
 dtc.c      |  1 +
 dtc.h      |  1 +
 livetree.c | 30 ++++++++++++++++++++++++++++++
 3 files changed, 32 insertions(+)
dtc.c +1 -0
index 030bfa2..e0a0b54 100644
@@ -336,6 +336,7 @@ int main(int argc, char *argv[])
 	update_phandles_ref(dti);
 	mark_local_phandles(dti);
 
+	update_exports_ref(dti);
 	mark_local_exports(dti);
 
 	/*
dtc.h +1 -0
index ea073c2..024e172 100644
@@ -368,6 +368,7 @@ void generate_local_fixups_tree(struct dt_info *dti, const char *name);
 void update_phandles_ref(struct dt_info *dti);
 void mark_local_phandles(struct dt_info *dti);
 
+void update_exports_ref(struct dt_info *dti);
 void mark_local_exports(struct dt_info *dti);
 
 /* Checks */
livetree.c +30 -0
index 0e756b8..7cf3ee5 100644
@@ -1304,6 +1304,36 @@ void mark_local_phandles(struct dt_info *dti)
 	mark_local_phandles_internal(dti, dti->dt);
 }
 
+static void update_exports_ref_internal(struct dt_info *dti, struct node *node)
+{
+	struct node *c;
+	struct symbol *exportsym;
+	struct node *refnode;
+
+	for_each_symbol(node->exportsymlist, exportsym) {
+		if (exportsym->ref)
+			continue;
+
+		if (exportsym->is_local) {
+			refnode = get_node_by_phandle(dti->dt, exportsym->phandle);
+			if (!refnode)
+				die("Node not found for phandle 0x%"PRIx32"\n", exportsym->phandle);
+
+			exportsym->ref = refnode->fullpath;
+		} else {
+			die("Found a non local phandle without a reference\n");
+		}
+	}
+
+	for_each_child(node, c)
+		update_exports_ref_internal(dti, c);
+}
+
+void update_exports_ref(struct dt_info *dti)
+{
+	update_exports_ref_internal(dti, dti->dt);
+}
+
 static void mark_local_exports_internal(struct dt_info *dti,
 					struct node *node)
 {
Signature · 1 line
2.52.0
#73 lore raw

RFC PATCH 25/77 Add support for FDT_EXPORT_SYM dtb tag

In reply to Herve Codina

The FDT_EXPORT_SYM dtb tag is a meta-data tag defining an exported symbol. It can be present in a node bloc meaning that a symbol is exported at this node level. The node pointed to by this symbol is a local node and identified by a phandle value.

The tag is followed by two values and a possible alignment padding:
- name (string including \0)
The export symbol name. I.e. the name used to reference this exported symbol.
- padding:

      Padding (0x00) added to have the next value aligned on 32bit.

- phandle (32bit)
The phandle value identifying the node referenced by this symbol.

Example:
FDT_EXPORT_SYM 'foo1' 0x00 0x00 0x00 0x00000004

This means that 'foo1' is an exported symbol and the node referenced by this symbol is the node with the phandle value equals 4.

This is what is encoded in the dtb when the related dts has the following exported symbol defined:

    /export/ foo1: &foo;

with 'foo' a reference to an existing node where the phandle value is 0x0000004.

If several symbols are exported at a given node level, several FDT_EXPORT_SYM are present. Each of them defining one symbol.

For instance, exporting 'foo' pointing to phandle 4 and 'bar' pointing to phandle 8 leads to the following sequence:
FDT_EXPORT_SYM 'foo' 0x00 0x00 0x00 0x00000004 FDT_EXPORT_SYM 'bar' 0x00 0x00 0x00 0x00000008

Add support for this new dtb tag.

---
 dtc.h                    |  1 +
 fdtdump.c                | 12 +++++++++-
 flattree.c               | 47 ++++++++++++++++++++++++++++++++++++++--
 libfdt/fdt.c             | 17 +++++++++++++++
 libfdt/fdt.h             |  2 ++
 libfdt/libfdt_internal.h |  1 +
 livetree.c               |  2 +-
 7 files changed, 78 insertions(+), 4 deletions(-)
dtc.h +1 -0
index 024e172..22816ba 100644
@@ -289,6 +289,7 @@ struct symbol *build_exportsym(const char *name, const char *ref, cell_t phandle
 			       struct srcpos *srcpos);
 struct symbol *chain_symbol(struct symbol *first, struct symbol *list);
 struct symbol *reverse_symbol(struct symbol *list);
+void add_symbol(struct symbol **list, struct symbol *new);
 
 struct node *build_node(struct property *proplist, struct node *children,
 			struct symbol *exportsymlist, struct srcpos *srcpos);
fdtdump.c +11 -1
index 9b6f41a..d1af5b6 100644
@@ -57,7 +57,7 @@ static void dump_blob(void *blob, bool debug)
 	const char *p_strings = (const char *)blob + off_str;
 	uint32_t version = fdt32_to_cpu(bph->version);
 	uint32_t totalsize = fdt32_to_cpu(bph->totalsize);
-	uint32_t tag, offset;
+	uint32_t tag, offset, val32;
 	const char *p, *s, *t;
 	const char *last_prop_name = NULL;
 	int depth, sz, shift;
@@ -176,6 +176,16 @@ static void dump_blob(void *blob, bool debug)
 			continue;
 		}
 
+		if (tag == FDT_EXPORT_SYM) {
+			s = p;
+			p = PALIGN(p + strlen(s) + 1, 4);
+			val32 = fdt32_to_cpu(GET_CELL(p));
+
+			printf("%*s// [FDT_EXPORT_SYM] '%s' -> phandle 0x%08"PRIx32"\n",
+				depth * shift, "", s, val32);
+			continue;
+		}
+
 		fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
 		break;
 	}
flattree.c +45 -2

122 lines not on this page · raw message

libfdt/fdt.c +17 -0
index 8f3c35d..44d7399 100644
@@ -232,6 +232,22 @@ uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffset)
 			return FDT_END; /* premature end */
 		break;
 
+	case FDT_EXPORT_SYM:
+		/* Skip name */
+		do {
+			p = fdt_offset_ptr(fdt, offset++, 1);
+		} while (p && (*p != '\0'));
+		if (!can_assume(VALID_DTB) && !p)
+			return FDT_END; /* premature end */
+		offset = FDT_CELLALIGN(offset);
+
+		/* Skip phandle */
+		tmp32p = fdt_offset_ptr(fdt, offset, sizeof(*tmp32p));
+		if (!can_assume(VALID_DTB) && !tmp32p)
+			return FDT_END; /* premature end */
+		offset += sizeof(fdt32_t);
+		break;
+
 	default:
 		return FDT_END;
 	}
@@ -273,6 +289,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 
 		case FDT_REF_LOCAL:
 		case FDT_REF_PHANDLE:
+		case FDT_EXPORT_SYM:
 			/*
 			 * Next tag is a meta-data tag present in the middle
 			 * of the structure -> Skip it and look at next one
libfdt/fdt.h +2 -0
index 94f65e6..e85bc07 100644
@@ -53,6 +53,7 @@ struct fdt_property {
 #define FDT_MAGIC	0xd00dfeed	/* 4: version, 4: total size */
 #define FDT_FLAG_ADDON  0x1
 #define FDT_TAGSIZE	sizeof(fdt32_t)
+#define FDT_CELLSIZE	sizeof(fdt32_t)
 
 #define FDT_BEGIN_NODE	0x1		/* Start node: full name */
 #define FDT_END_NODE	0x2		/* End node */
@@ -63,6 +64,7 @@ struct fdt_property {
 #define FDT_REF_PHANDLE 0x6		/* external phandle reference: offset,
 					   external label */
 #define FDT_END		0x9
+#define FDT_EXPORT_SYM	0xa		/* export symbol: name, phandle value */
 
 #define FDT_V1_SIZE	(7*sizeof(fdt32_t))
 #define FDT_V2_SIZE	(FDT_V1_SIZE + sizeof(fdt32_t))
libfdt/libfdt_internal.h +1 -0
index 0e103ca..d80d218 100644
@@ -9,6 +9,7 @@
 
 #define FDT_ALIGN(x, a)		(((x) + (a) - 1) & ~((a) - 1))
 #define FDT_TAGALIGN(x)		(FDT_ALIGN((x), FDT_TAGSIZE))
+#define FDT_CELLALIGN(x)	(FDT_ALIGN((x), FDT_CELLSIZE))
 
 int32_t fdt_ro_probe_(const void *fdt);
 #define FDT_RO_PROBE(fdt)						\
livetree.c +1 -1
index 7cf3ee5..7efa1da 100644
@@ -74,7 +74,7 @@ struct symbol *reverse_symbol(struct symbol *list)
 	return head;
 }
 
-static void add_symbol(struct symbol **list, struct symbol *new)
+void add_symbol(struct symbol **list, struct symbol *new)
 {
 	struct symbol **s;
 
Signature · 1 line
2.52.0
#74 lore raw

Re: [RFC PATCH 25/77] Add support for FDT_EXPORT_SYM dtb tag

Quoted 10 lines · Herve Codina

The FDT_EXPORT_SYM dtb tag is a meta-data tag defining an exported symbol. It can be present in a node bloc meaning that a symbol is exported at this node level. The node pointed to by this symbol is a local node and identified by a phandle value.

The tag is followed by two values and a possible alignment padding:
- name (string including \0)
The export symbol name. I.e. the name used to reference this exported symbol.
- padding:

Quoted 4 lines
      Padding (0x00) added to have the next value aligned on 32bit.

- phandle (32bit)
The phandle value identifying the node referenced by this
symbol.

I'd suggest putting the phandle before the name, to avoid internal padding.

Quoted 298 lines

Example:
FDT_EXPORT_SYM 'foo1' 0x00 0x00 0x00 0x00000004

This means that 'foo1' is an exported symbol and the node referenced by this symbol is the node with the phandle value equals 4.

This is what is encoded in the dtb when the related dts has the following exported symbol defined:

    /export/ foo1: &foo;

with 'foo' a reference to an existing node where the phandle value is 0x0000004.

If several symbols are exported at a given node level, several FDT_EXPORT_SYM are present. Each of them defining one symbol.

For instance, exporting 'foo' pointing to phandle 4 and 'bar' pointing to phandle 8 leads to the following sequence:
FDT_EXPORT_SYM 'foo' 0x00 0x00 0x00 0x00000004 FDT_EXPORT_SYM 'bar' 0x00 0x00 0x00 0x00000008

Add support for this new dtb tag.

---
 dtc.h                    |  1 +
 fdtdump.c                | 12 +++++++++-
 flattree.c               | 47 ++++++++++++++++++++++++++++++++++++++--
 libfdt/fdt.c             | 17 +++++++++++++++
 libfdt/fdt.h             |  2 ++
 libfdt/libfdt_internal.h |  1 +
 livetree.c               |  2 +-
 7 files changed, 78 insertions(+), 4 deletions(-)
dtc.h +1 -0
index 024e172..22816ba 100644
@@ -289,6 +289,7 @@ struct symbol *build_exportsym(const char *name, const char *ref, cell_t phandle
 			       struct srcpos *srcpos);
 struct symbol *chain_symbol(struct symbol *first, struct symbol *list);
 struct symbol *reverse_symbol(struct symbol *list);
+void add_symbol(struct symbol **list, struct symbol *new);
 
 struct node *build_node(struct property *proplist, struct node *children,
 			struct symbol *exportsymlist, struct srcpos *srcpos);
fdtdump.c +11 -1
index 9b6f41a..d1af5b6 100644
@@ -57,7 +57,7 @@ static void dump_blob(void *blob, bool debug)
 	const char *p_strings = (const char *)blob + off_str;
 	uint32_t version = fdt32_to_cpu(bph->version);
 	uint32_t totalsize = fdt32_to_cpu(bph->totalsize);
-	uint32_t tag, offset;
+	uint32_t tag, offset, val32;
 	const char *p, *s, *t;
 	const char *last_prop_name = NULL;
 	int depth, sz, shift;
@@ -176,6 +176,16 @@ static void dump_blob(void *blob, bool debug)
 			continue;
 		}
 
+		if (tag == FDT_EXPORT_SYM) {
+			s = p;
+			p = PALIGN(p + strlen(s) + 1, 4);
+			val32 = fdt32_to_cpu(GET_CELL(p));
+
+			printf("%*s// [FDT_EXPORT_SYM] '%s' -> phandle 0x%08"PRIx32"\n",
+				depth * shift, "", s, val32);
+			continue;
+		}
+
 		fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
 		break;
 	}
flattree.c +45 -2
index 36b795d..bd52e81 100644
@@ -15,6 +15,7 @@
 #define FTF_NOPS	0x40
 #define FTF_REF_XXX	0x80
 #define FTF_DTFLAGS	0x100
+#define FTF_EXPORT_IMPORT_SYM 0x200
 
 static struct version_info {
 	int version;
@@ -34,7 +35,7 @@ static struct version_info {
 	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS},
 	{18, 18, FDT_V18_SIZE,
 	 FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS|FTF_REF_XXX|
-	 FTF_DTFLAGS},
+	 FTF_DTFLAGS|FTF_EXPORT_IMPORT_SYM},
 };
 
 struct emitter {
@@ -47,6 +48,7 @@ struct emitter {
 	void (*property)(void *, struct label *labels);
 	void (*ref_local)(void *);
 	void (*ref_phandle)(void *);
+	void (*export_sym)(void *);
 };
 
 static void bin_emit_cell(void *e, cell_t val)
@@ -106,6 +108,11 @@ static void bin_emit_ref_phandle(void *e)
 	bin_emit_cell(e, FDT_REF_PHANDLE);
 }
 
+static void bin_emit_export_sym(void *e)
+{
+	bin_emit_cell(e, FDT_EXPORT_SYM);
+}
+
 static struct emitter bin_emitter = {
 	.cell = bin_emit_cell,
 	.string = bin_emit_string,
@@ -116,6 +123,7 @@ static struct emitter bin_emitter = {
 	.property = bin_emit_property,
 	.ref_local = bin_emit_ref_local,
 	.ref_phandle = bin_emit_ref_phandle,
+	.export_sym = bin_emit_export_sym,
 };
 
 static void emit_label(FILE *f, const char *prefix, const char *label)
@@ -243,6 +251,14 @@ static void asm_emit_ref_phandle(void *e)
 	asm_emit_cell(e, FDT_REF_PHANDLE);
 }
 
+static void asm_emit_export_sym(void *e)
+{
+	FILE *f = e;
+
+	fprintf(f, "\t/* FDT_EXPORT_SYM */\n");
+	asm_emit_cell(e, FDT_EXPORT_SYM);
+}
+
 static struct emitter asm_emitter = {
 	.cell = asm_emit_cell,
 	.string = asm_emit_string,
@@ -253,6 +269,7 @@ static struct emitter asm_emitter = {
 	.property = asm_emit_property,
 	.ref_local = asm_emit_ref_local,
 	.ref_phandle = asm_emit_ref_phandle,
+	.export_sym = asm_emit_export_sym,
 };
 
 static int stringtable_insert(struct data *d, const char *str)
@@ -274,6 +291,7 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
 			 void *etarget, struct data *strbuf,
 			 struct version_info *vi)
 {
+	struct symbol *exportsym;
 	struct property *prop;
 	struct node *child;
 	bool seen_name_prop = false;
@@ -342,6 +360,18 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
 		emit->align(etarget, sizeof(cell_t));
 	}
 
+	if (vi->flags & FTF_EXPORT_IMPORT_SYM) {
+		for_each_symbol(tree->exportsymlist, exportsym) {
+			if (exportsym->is_local) {
+				emit->export_sym(etarget);
+				emit->string(etarget, exportsym->name, 0);
+				emit->align(etarget, sizeof(cell_t));
+				emit->cell(etarget, exportsym->phandle);
+				continue;
+			}
+		}
+	}
+
 	for_each_child(tree, child) {
 		flatten_tree(child, emit, etarget, strbuf, vi);
 	}
@@ -820,9 +850,11 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
 		node->name = xstrdup(flatname);
 
 	do {
+		struct symbol *exportsym;
 		struct property *prop;
 		struct node *child;
 		struct marker *m;
+		cell_t phandle;
 
 		val = flat_read_word(dtbuf);
 		switch (val) {
@@ -876,6 +908,17 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
 			prop->val = data_append_markers(prop->val, m);
 			break;
 
+		case FDT_EXPORT_SYM:
+			if (!(flags & FTF_EXPORT_IMPORT_SYM))
+				die("FDT_EXPORT_SYM tag found in flat tree"
+					" version <18\n");
+			str = flat_read_string(dtbuf);
+			phandle = flat_read_word(dtbuf);
+			exportsym = build_exportsym(str, NULL, phandle, NULL);
+			exportsym->is_local = true;
+			add_symbol(&node->exportsymlist, exportsym);
+			break;
+
 		default:
 			die("Invalid opcode word %08x in device tree blob\n",
 			    val);
@@ -996,7 +1039,7 @@ struct dt_info *dt_from_blob(const char *fname)
 	}
 
 	if (version >= 18) {
-		flags |= FTF_REF_XXX | FTF_DTFLAGS;
+		flags |= FTF_REF_XXX | FTF_DTFLAGS | FTF_EXPORT_IMPORT_SYM;
 		dtsflags |= fdt32_to_cpu(fdt->dt_flags) & FDT_FLAG_ADDON ?
 				DTSF_ADDON : 0;
 	}
libfdt/fdt.c +17 -0
index 8f3c35d..44d7399 100644
@@ -232,6 +232,22 @@ uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffset)
 			return FDT_END; /* premature end */
 		break;
 
+	case FDT_EXPORT_SYM:
+		/* Skip name */
+		do {
+			p = fdt_offset_ptr(fdt, offset++, 1);
+		} while (p && (*p != '\0'));
+		if (!can_assume(VALID_DTB) && !p)
+			return FDT_END; /* premature end */
+		offset = FDT_CELLALIGN(offset);
+
+		/* Skip phandle */
+		tmp32p = fdt_offset_ptr(fdt, offset, sizeof(*tmp32p));
+		if (!can_assume(VALID_DTB) && !tmp32p)
+			return FDT_END; /* premature end */
+		offset += sizeof(fdt32_t);
+		break;
+
 	default:
 		return FDT_END;
 	}
@@ -273,6 +289,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 
 		case FDT_REF_LOCAL:
 		case FDT_REF_PHANDLE:
+		case FDT_EXPORT_SYM:
 			/*
 			 * Next tag is a meta-data tag present in the middle
 			 * of the structure -> Skip it and look at next one
libfdt/fdt.h +2 -0
index 94f65e6..e85bc07 100644
@@ -53,6 +53,7 @@ struct fdt_property {
 #define FDT_MAGIC	0xd00dfeed	/* 4: version, 4: total size */
 #define FDT_FLAG_ADDON  0x1
 #define FDT_TAGSIZE	sizeof(fdt32_t)
+#define FDT_CELLSIZE	sizeof(fdt32_t)
 
 #define FDT_BEGIN_NODE	0x1		/* Start node: full name */
 #define FDT_END_NODE	0x2		/* End node */
@@ -63,6 +64,7 @@ struct fdt_property {
 #define FDT_REF_PHANDLE 0x6		/* external phandle reference: offset,
 					   external label */
 #define FDT_END		0x9
+#define FDT_EXPORT_SYM	0xa		/* export symbol: name, phandle value */
 
 #define FDT_V1_SIZE	(7*sizeof(fdt32_t))
 #define FDT_V2_SIZE	(FDT_V1_SIZE + sizeof(fdt32_t))
libfdt/libfdt_internal.h +1 -0
index 0e103ca..d80d218 100644
@@ -9,6 +9,7 @@
 
 #define FDT_ALIGN(x, a)		(((x) + (a) - 1) & ~((a) - 1))
 #define FDT_TAGALIGN(x)		(FDT_ALIGN((x), FDT_TAGSIZE))
+#define FDT_CELLALIGN(x)	(FDT_ALIGN((x), FDT_CELLSIZE))
 
 int32_t fdt_ro_probe_(const void *fdt);
 #define FDT_RO_PROBE(fdt)						\
livetree.c +1 -1
index 7cf3ee5..7efa1da 100644
@@ -74,7 +74,7 @@ struct symbol *reverse_symbol(struct symbol *list)
 	return head;
 }
 
-static void add_symbol(struct symbol **list, struct symbol *new)
+void add_symbol(struct symbol **list, struct symbol *new)
 {
 	struct symbol **s;
 
Signature · 1 line
2.52.0
Signature · 4 lines
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
#75 lore raw

RFC PATCH 26/77 tests: metadata: Add export symbols with local references tests

In reply to Herve Codina

Add tests related to export symbols using local phandle references (FDT_EXPORT_SYM dtb tag).

---
 .../metadata_exportsyms_local.dtb.dts.expect  | 26 +++++++++++++++++
 tests/metadata_exportsyms_local.dtb.expect    | 20 +++++++++++++
 tests/metadata_exportsyms_local.dts           | 28 +++++++++++++++++++
 .../metadata_exportsyms_local.dts.dts.expect  | 26 +++++++++++++++++
 tests/run_tests.sh                            |  2 +-
 5 files changed, 101 insertions(+), 1 deletion(-)
 create mode 100644 tests/metadata_exportsyms_local.dtb.dts.expect
 create mode 100644 tests/metadata_exportsyms_local.dtb.expect
 create mode 100644 tests/metadata_exportsyms_local.dts
 create mode 100644 tests/metadata_exportsyms_local.dts.dts.expect
tests/metadata_exportsyms_local.dtb.dts.expect new file +26 -0
new file mode 100644
index 0000000..ac3d5b3
@@ -0,0 +1,26 @@
+/dts-v1/;
+
+/ {
+
+	node-a {
+	};
+
+	node-b {
+		phandle = <0x03>;
+	};
+
+	node-c {
+
+		sub-node {
+			phandle = <0x02>;
+		};
+	};
+
+	node-d {
+		phandle = <0x01>;
+
+		/export/ node_d: &{/node-d};
+		/export/ subnode_c: &{/node-c/sub-node};
+		/export/ node_b: &{/node-b};
+	};
+};
tests/metadata_exportsyms_local.dtb.expect new file +20 -0
new file mode 100644
index 0000000..2002553
@@ -0,0 +1,20 @@
+/dts-v1/;
+
+/ {
+    node-a {
+    };
+    node-b {
+        phandle = <0x00000003>;
+    };
+    node-c {
+        sub-node {
+            phandle = <0x00000002>;
+        };
+    };
+    node-d {
+        phandle = <0x00000001>;
+        // [FDT_EXPORT_SYM] 'node_d' -> phandle 0x00000001
+        // [FDT_EXPORT_SYM] 'subnode_c' -> phandle 0x00000002
+        // [FDT_EXPORT_SYM] 'node_b' -> phandle 0x00000003
+    };
+};
tests/metadata_exportsyms_local.dts new file +28 -0
new file mode 100644
index 0000000..10e6e47
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
+/*
+ * Copyright (C) 2026 Bootlin
+ */
+
+/dts-v1/;
+
+/ {
+	node-a {
+	};
+
+	node_b: node-b {
+	};
+
+	node-c {
+		sub_node: sub-node {
+		};
+	};
+
+	node_d: node-d {
+		/export/ node_d: &node_d;
+		/export/ subnode_c: &sub_node;
+	};
+};
+
+&node_d {
+	/export/ node_b: &node_b;
+};
tests/metadata_exportsyms_local.dts.dts.expect new file +26 -0
new file mode 100644
index 0000000..4723e7e
@@ -0,0 +1,26 @@
+/dts-v1/;
+
+/ {
+
+	node-a {
+	};
+
+	node_b: node-b {
+		phandle = <0x03>;
+	};
+
+	node-c {
+
+		sub_node: sub-node {
+			phandle = <0x02>;
+		};
+	};
+
+	node_d: node-d {
+		phandle = <0x01>;
+
+		/export/ node_d: &node_d;
+		/export/ subnode_c: &sub_node;
+		/export/ node_b: &node_b;
+	};
+};
tests/run_tests.sh +1 -1
index def1a7e..ed3a240 100755
@@ -1126,7 +1126,7 @@ wrap_fdtdump () {
 
 metadata_tests() {
 	for dt in metadata_reflocal metadata_refphandle \
-		  metadata_addon_base; do
+		  metadata_addon_base metadata_exportsyms_local; do
 		run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts"
 		base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect"
 		run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts"
Signature · 1 line
2.52.0
#76 lore raw

RFC PATCH 27/77 dtc: Add support for export symbols sorting

In reply to Herve Codina

dtc can sort items when the command line --sort option is set.

Add support for export symbols sorting when this option is used.

---
 livetree.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
livetree.c +37 -0
index 7efa1da..1de5990 100644
@@ -916,6 +916,42 @@ static void sort_properties(struct node *node)
 	free(tbl);
 }
 
+static int cmp_symbol(const void *ax, const void *bx)
+{
+	const struct symbol *a, *b;
+
+	a = *((const struct symbol * const *)ax);
+	b = *((const struct symbol * const *)bx);
+
+	return strcmp(a->name, b->name);
+}
+
+static void sort_exportsyms(struct node *node)
+{
+	int n = 0, i = 0;
+	struct symbol *symbol, **tbl;
+
+	for_each_symbol(node->exportsymlist, symbol)
+		n++;
+
+	if (n == 0)
+		return;
+
+	tbl = xmalloc(n * sizeof(*tbl));
+
+	for_each_symbol(node->exportsymlist, symbol)
+		tbl[i++] = symbol;
+
+	qsort(tbl, n, sizeof(*tbl), cmp_symbol);
+
+	node->exportsymlist = tbl[0];
+	for (i = 0; i < (n-1); i++)
+		tbl[i]->next = tbl[i+1];
+	tbl[n-1]->next = NULL;
+
+	free(tbl);
+}
+
 static int cmp_subnode(const void *ax, const void *bx)
 {
 	const struct node *a, *b;
@@ -957,6 +993,7 @@ static void sort_node(struct node *node)
 	struct node *c;
 
 	sort_properties(node);
+	sort_exportsyms(node);
 	sort_subnodes(node);
 	for_each_child_withdel(node, c)
 		sort_node(c);
Signature · 1 line
2.52.0
#77 lore raw

RFC PATCH 28/77 tests: metadata: Add a test for export symbols sorting

In reply to Herve Codina

dtc is able to sort the export symbols list when the --sort option is used.

Add a test for this feature.

---
 tests/metadata_sort.dtb.dts.expect | 18 ++++++++++++++++++
 tests/metadata_sort.dtb.expect     | 15 +++++++++++++++
 tests/metadata_sort.dts            | 21 +++++++++++++++++++++
 tests/run_tests.sh                 |  8 ++++++++
 4 files changed, 62 insertions(+)
 create mode 100644 tests/metadata_sort.dtb.dts.expect
 create mode 100644 tests/metadata_sort.dtb.expect
 create mode 100644 tests/metadata_sort.dts
tests/metadata_sort.dtb.dts.expect new file +18 -0
new file mode 100644
index 0000000..f07a42b
@@ -0,0 +1,18 @@
+/dts-v1/;
+/addon/;
+
+/ {
+
+	node-a {
+		prop_a = <0x1c8>;
+		prop_b = <0x7b>;
+
+		/export/ a: &{/node-b};
+		/export/ ba: &{/node-b};
+		/export/ bb: &{/node-b};
+	};
+
+	node-b {
+		phandle = <0x01>;
+	};
+};
tests/metadata_sort.dtb.expect new file +15 -0
new file mode 100644
index 0000000..7856894
@@ -0,0 +1,15 @@
+/dts-v1/;
+/addon/;
+
+/ {
+    node-a {
+        prop_a = <0x000001c8>;
+        prop_b = <0x0000007b>;
+        // [FDT_EXPORT_SYM] 'a' -> phandle 0x00000001
+        // [FDT_EXPORT_SYM] 'ba' -> phandle 0x00000001
+        // [FDT_EXPORT_SYM] 'bb' -> phandle 0x00000001
+    };
+    node-b {
+        phandle = <0x00000001>;
+    };
+};
tests/metadata_sort.dts new file +21 -0
new file mode 100644
index 0000000..7d1cca7
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
+/*
+ * Copyright (C) 2026 Bootlin
+ */
+
+/dts-v1/;
+/addon/;
+
+/ {
+	node_b: node-b {
+	};
+
+	node-a {
+		prop_b = <123>;
+		prop_a = <456>;
+
+		/export/ ba: &node_b;
+		/export/ bb: &node_b;
+		/export/ a: &node_b;
+	};
+};
tests/run_tests.sh +8 -0
index ed3a240..fc270e2 100755
@@ -1154,6 +1154,14 @@ metadata_tests() {
 	# Keep only lines containing 'dt_flags'
 	sed -i '/dt_flags/!d' metadata_dtflags1.dtb.out
 	base_run_test check_diff metadata_dtflags1.dtb.out "$SRCDIR/metadata_dtflags1.dtb.expect"
+
+	run_dtc_test -I dts -O dtb -s -o metadata_sort.dtb "$SRCDIR/metadata_sort.dts"
+	base_run_test wrap_fdtdump metadata_sort.dtb metadata_sort.dtb.out
+	# Remove unneeded comments
+	sed -i '/^\/\/ /d' metadata_sort.dtb.out
+	base_run_test check_diff metadata_sort.dtb.out "$SRCDIR/metadata_sort.dtb.expect"
+	run_dtc_test -I dtb -O dts -o metadata_sort.dtb.dts metadata_sort.dtb
+	base_run_test check_diff metadata_sort.dtb.dts "$SRCDIR/metadata_sort.dtb.dts.expect"
 }
 
 pylibfdt_tests () {
Signature · 1 line
2.52.0
#78 lore raw

RFC PATCH 29/77 Add support for FDT_EXPORT_SYM_REF dtb tag

In reply to Herve Codina

The FDT_EXPORT_SYM_REF dtb tag is similar to the FDT_EXPORT_SYM tag except that it identifies a reference to an external phandle. The node referenced by the phandle is not present in the device-tree blob.

The FDT_EXPORT_SYM_REF dtb tag is a meta-data tag defining an exported symbol. It can be present in a node bloc meaning that a symbol is exported at this node level. The node pointed to by this symbol is not a local node (i.e. the node is not present in the device-tree blob.). This tag can be available only in overlay or addon device-tree blobs. The symbol has to be resolved when the device-tree blob is applied on top of a base device-tree.

It is followed by three values and a possible alignment padding:
- name (string including \0)
The export symbol name. I.e. the name used to reference this exported symbol.
- padding:

      Padding (0x00) added to have the next value aligned on 32bit.
  - phandle (32bit)
      A placeholder for a phandle value.
      This placeholder can be used during some dtb manipulation to store
      a temporary phandle value.
      In terms of FDT_EXPORT_SYM_REF definition, it has no meaningful
      signification and will be probably set to 0xffffffff, the
      unresolved phandle value.
  - label (string including \0):
      The label to use to resolve this symbol. This label is the
      reference to the external phandle.
  - padding:
      Padding (0x00) added to have the next value aligned on 32bit.

Example:
FDT_EXPORT_SYM_REF 'foo1' 0x00 0x00 0x00 0xffffffff 'foo_a' 0x00 0x00

This means that 'foo1' is an exported symbol and the node referenced by this symbol is external to the dtb (unresolved symbol). This external node is referenced by the "foo_a" label.

This is what is encoded in the dtb when the related dts has the following exported symbol defined:

    /export/ foo1: &foo_a;

with 'foo_a' a reference to a non local node.

If several non local symbols are exported at a given node level, several FDT_EXPORT_SYM_REF are present. Each of them defining one symbol.

For instance, exporting 'foo1' pointing the node referenced by 'foo_a' and exporting 'bar1' pointing to the node referenced by 'bar_b' leads to the following sequence:
FDT_EXPORT_SYM_REF 'foo1' 0x00 0x00 0x00 'foo_a' 0x00 0x00 FDT_EXPORT_SYM_REF 'bar1' 0x00 0x00 0x00 'bar_b' 0x00 0x00

Add support for this new dtb tag.

---
 fdtdump.c    | 12 ++++++++++++
 flattree.c   | 40 ++++++++++++++++++++++++++++++++++++++++
 libfdt/fdt.c | 24 ++++++++++++++++++++++++
 libfdt/fdt.h |  2 ++
 4 files changed, 78 insertions(+)
fdtdump.c +12 -0
index d1af5b6..8baadc4 100644
@@ -186,6 +186,18 @@ static void dump_blob(void *blob, bool debug)
 			continue;
 		}
 
+		if (tag == FDT_EXPORT_SYM_REF) {
+			s = p;
+			p = PALIGN(p + strlen(s) + 1, 4);
+			val32 = fdt32_to_cpu(GET_CELL(p));
+			t = p;
+			p = PALIGN(p + strlen(t) + 1, 4);
+
+			printf("%*s// [FDT_EXPORT_SYM_REF] '%s' -> '%s'\n", depth * shift, "",
+				s, t);
+			continue;
+		}
+
 		fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
 		break;
 	}
flattree.c +40 -0
index bd52e81..d970259 100644
@@ -49,6 +49,7 @@ struct emitter {
 	void (*ref_local)(void *);
 	void (*ref_phandle)(void *);
 	void (*export_sym)(void *);
+	void (*export_sym_ref)(void *);
 };
 
 static void bin_emit_cell(void *e, cell_t val)
@@ -113,6 +114,11 @@ static void bin_emit_export_sym(void *e)
 	bin_emit_cell(e, FDT_EXPORT_SYM);
 }
 
+static void bin_emit_export_sym_ref(void *e)
+{
+	bin_emit_cell(e, FDT_EXPORT_SYM_REF);
+}
+
 static struct emitter bin_emitter = {
 	.cell = bin_emit_cell,
 	.string = bin_emit_string,
@@ -124,6 +130,7 @@ static struct emitter bin_emitter = {
 	.ref_local = bin_emit_ref_local,
 	.ref_phandle = bin_emit_ref_phandle,
 	.export_sym = bin_emit_export_sym,
+	.export_sym_ref = bin_emit_export_sym_ref,
 };
 
 static void emit_label(FILE *f, const char *prefix, const char *label)
@@ -259,6 +266,14 @@ static void asm_emit_export_sym(void *e)
 	asm_emit_cell(e, FDT_EXPORT_SYM);
 }
 
+static void asm_emit_export_sym_ref(void *e)
+{
+	FILE *f = e;
+
+	fprintf(f, "\t/* FDT_EXPORT_SYM_REF */\n");
+	asm_emit_cell(e, FDT_EXPORT_SYM_REF);
+}
+
 static struct emitter asm_emitter = {
 	.cell = asm_emit_cell,
 	.string = asm_emit_string,
@@ -270,6 +285,7 @@ static struct emitter asm_emitter = {
 	.ref_local = asm_emit_ref_local,
 	.ref_phandle = asm_emit_ref_phandle,
 	.export_sym = asm_emit_export_sym,
+	.export_sym = asm_emit_export_sym_ref,
 };
 
 static int stringtable_insert(struct data *d, const char *str)
@@ -369,6 +385,18 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
 				emit->cell(etarget, exportsym->phandle);
 				continue;
 			}
+
+			if (exportsym->ref[0] == '/')
+				die("Export symbol uses a non local reference by path (%s)\n",
+				    m->ref);
+
+			emit->export_sym_ref(etarget);
+			emit->string(etarget, exportsym->name, 0);
+			emit->align(etarget, sizeof(cell_t));
+			/* Placeholder for the phandle */
+			emit->cell(etarget, exportsym->phandle);
+			emit->string(etarget, exportsym->ref, 0);
+			emit->align(etarget, sizeof(cell_t));
 		}
 	}
 
@@ -838,6 +866,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
 	uint32_t val;
 	uint32_t offset;
 	const char *str;
+	const char *str2;
 
 	node = build_node(NULL, NULL, NULL, NULL);
 
@@ -919,6 +948,17 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
 			add_symbol(&node->exportsymlist, exportsym);
 			break;
 
+		case FDT_EXPORT_SYM_REF:
+			if (!(flags & FTF_EXPORT_IMPORT_SYM))
+				die("FDT_EXPORT_SYM_REF tag found in flat tree"
+					" version <18\n");
+			str = flat_read_string(dtbuf); /* Name */
+			phandle = flat_read_word(dtbuf); /* Phandle */
+			str2 = flat_read_string(dtbuf); /* Ref */
+			exportsym = build_exportsym(str, str2, phandle, NULL);
+			add_symbol(&node->exportsymlist, exportsym);
+			break;
+
 		default:
 			die("Invalid opcode word %08x in device tree blob\n",
 			    val);
libfdt/fdt.c +24 -0
index 44d7399..febfa71 100644
@@ -248,6 +248,29 @@ uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffset)
 		offset += sizeof(fdt32_t);
 		break;
 
+	case FDT_EXPORT_SYM_REF:
+		/* Skip name */
+		do {
+			p = fdt_offset_ptr(fdt, offset++, 1);
+		} while (p && (*p != '\0'));
+		if (!can_assume(VALID_DTB) && !p)
+			return FDT_END; /* premature end */
+		offset = FDT_CELLALIGN(offset);
+
+		/* Skip phandle */
+		tmp32p = fdt_offset_ptr(fdt, offset, sizeof(*tmp32p));
+		if (!can_assume(VALID_DTB) && !tmp32p)
+			return FDT_END; /* premature end */
+		offset += sizeof(fdt32_t);
+
+		/* Skip external name */
+		do {
+			p = fdt_offset_ptr(fdt, offset++, 1);
+		} while (p && (*p != '\0'));
+		if (!can_assume(VALID_DTB) && !p)
+			return FDT_END; /* premature end */
+		break;
+
 	default:
 		return FDT_END;
 	}
@@ -290,6 +313,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 		case FDT_REF_LOCAL:
 		case FDT_REF_PHANDLE:
 		case FDT_EXPORT_SYM:
+		case FDT_EXPORT_SYM_REF:
 			/*
 			 * Next tag is a meta-data tag present in the middle
 			 * of the structure -> Skip it and look at next one
libfdt/fdt.h +2 -0
index e85bc07..c23723b 100644
@@ -65,6 +65,8 @@ struct fdt_property {
 					   external label */
 #define FDT_END		0x9
 #define FDT_EXPORT_SYM	0xa		/* export symbol: name, phandle value */
+#define FDT_EXPORT_SYM_REF 0xb		/* export symbol: name, phandle value (maybe
+					   unresolved), external label */
 
 #define FDT_V1_SIZE	(7*sizeof(fdt32_t))
 #define FDT_V2_SIZE	(FDT_V1_SIZE + sizeof(fdt32_t))
Signature · 1 line
2.52.0
#79 lore raw

Re: [RFC PATCH 29/77] Add support for FDT_EXPORT_SYM_REF dtb tag

Quoted 17 lines · Herve Codina

The FDT_EXPORT_SYM_REF dtb tag is similar to the FDT_EXPORT_SYM tag except that it identifies a reference to an external phandle. The node referenced by the phandle is not present in the device-tree blob.

The FDT_EXPORT_SYM_REF dtb tag is a meta-data tag defining an exported symbol. It can be present in a node bloc meaning that a symbol is exported at this node level. The node pointed to by this symbol is not a local node (i.e. the node is not present in the device-tree blob.). This tag can be available only in overlay or addon device-tree blobs. The symbol has to be resolved when the device-tree blob is applied on top of a base device-tree.

It is followed by three values and a possible alignment padding:
- name (string including \0)
The export symbol name. I.e. the name used to reference this exported symbol.
- padding:

Quoted 5 lines
      Padding (0x00) added to have the next value aligned on 32bit.

- phandle (32bit)
A placeholder for a phandle value.
This placeholder can be used during some dtb manipulation to store a temporary phandle value.

Yuck.

Quoted 222 lines

In terms of FDT_EXPORT_SYM_REF definition, it has no meaningful signification and will be probably set to 0xffffffff, the unresolved phandle value.
- label (string including \0):
The label to use to resolve this symbol. This label is the reference to the external phandle.
- padding:

      Padding (0x00) added to have the next value aligned on 32bit.

Example:
FDT_EXPORT_SYM_REF 'foo1' 0x00 0x00 0x00 0xffffffff 'foo_a' 0x00 0x00

This means that 'foo1' is an exported symbol and the node referenced by this symbol is external to the dtb (unresolved symbol). This external node is referenced by the "foo_a" label.

This is what is encoded in the dtb when the related dts has the following exported symbol defined:

    /export/ foo1: &foo_a;

with 'foo_a' a reference to a non local node.

If several non local symbols are exported at a given node level, several FDT_EXPORT_SYM_REF are present. Each of them defining one symbol.

For instance, exporting 'foo1' pointing the node referenced by 'foo_a' and exporting 'bar1' pointing to the node referenced by 'bar_b' leads to the following sequence:
FDT_EXPORT_SYM_REF 'foo1' 0x00 0x00 0x00 'foo_a' 0x00 0x00 FDT_EXPORT_SYM_REF 'bar1' 0x00 0x00 0x00 'bar_b' 0x00 0x00

Add support for this new dtb tag.

---
 fdtdump.c    | 12 ++++++++++++
 flattree.c   | 40 ++++++++++++++++++++++++++++++++++++++++
 libfdt/fdt.c | 24 ++++++++++++++++++++++++
 libfdt/fdt.h |  2 ++
 4 files changed, 78 insertions(+)
fdtdump.c +12 -0
index d1af5b6..8baadc4 100644
@@ -186,6 +186,18 @@ static void dump_blob(void *blob, bool debug)
 			continue;
 		}
 
+		if (tag == FDT_EXPORT_SYM_REF) {
+			s = p;
+			p = PALIGN(p + strlen(s) + 1, 4);
+			val32 = fdt32_to_cpu(GET_CELL(p));
+			t = p;
+			p = PALIGN(p + strlen(t) + 1, 4);
+
+			printf("%*s// [FDT_EXPORT_SYM_REF] '%s' -> '%s'\n", depth * shift, "",
+				s, t);
+			continue;
+		}
+
 		fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
 		break;
 	}
flattree.c +40 -0
index bd52e81..d970259 100644
@@ -49,6 +49,7 @@ struct emitter {
 	void (*ref_local)(void *);
 	void (*ref_phandle)(void *);
 	void (*export_sym)(void *);
+	void (*export_sym_ref)(void *);
 };
 
 static void bin_emit_cell(void *e, cell_t val)
@@ -113,6 +114,11 @@ static void bin_emit_export_sym(void *e)
 	bin_emit_cell(e, FDT_EXPORT_SYM);
 }
 
+static void bin_emit_export_sym_ref(void *e)
+{
+	bin_emit_cell(e, FDT_EXPORT_SYM_REF);
+}
+
 static struct emitter bin_emitter = {
 	.cell = bin_emit_cell,
 	.string = bin_emit_string,
@@ -124,6 +130,7 @@ static struct emitter bin_emitter = {
 	.ref_local = bin_emit_ref_local,
 	.ref_phandle = bin_emit_ref_phandle,
 	.export_sym = bin_emit_export_sym,
+	.export_sym_ref = bin_emit_export_sym_ref,
 };
 
 static void emit_label(FILE *f, const char *prefix, const char *label)
@@ -259,6 +266,14 @@ static void asm_emit_export_sym(void *e)
 	asm_emit_cell(e, FDT_EXPORT_SYM);
 }
 
+static void asm_emit_export_sym_ref(void *e)
+{
+	FILE *f = e;
+
+	fprintf(f, "\t/* FDT_EXPORT_SYM_REF */\n");
+	asm_emit_cell(e, FDT_EXPORT_SYM_REF);
+}
+
 static struct emitter asm_emitter = {
 	.cell = asm_emit_cell,
 	.string = asm_emit_string,
@@ -270,6 +285,7 @@ static struct emitter asm_emitter = {
 	.ref_local = asm_emit_ref_local,
 	.ref_phandle = asm_emit_ref_phandle,
 	.export_sym = asm_emit_export_sym,
+	.export_sym = asm_emit_export_sym_ref,
 };
 
 static int stringtable_insert(struct data *d, const char *str)
@@ -369,6 +385,18 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
 				emit->cell(etarget, exportsym->phandle);
 				continue;
 			}
+
+			if (exportsym->ref[0] == '/')
+				die("Export symbol uses a non local reference by path (%s)\n",
+				    m->ref);
+
+			emit->export_sym_ref(etarget);
+			emit->string(etarget, exportsym->name, 0);
+			emit->align(etarget, sizeof(cell_t));
+			/* Placeholder for the phandle */
+			emit->cell(etarget, exportsym->phandle);
+			emit->string(etarget, exportsym->ref, 0);
+			emit->align(etarget, sizeof(cell_t));
 		}
 	}
 
@@ -838,6 +866,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
 	uint32_t val;
 	uint32_t offset;
 	const char *str;
+	const char *str2;
 
 	node = build_node(NULL, NULL, NULL, NULL);
 
@@ -919,6 +948,17 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
 			add_symbol(&node->exportsymlist, exportsym);
 			break;
 
+		case FDT_EXPORT_SYM_REF:
+			if (!(flags & FTF_EXPORT_IMPORT_SYM))
+				die("FDT_EXPORT_SYM_REF tag found in flat tree"
+					" version <18\n");
+			str = flat_read_string(dtbuf); /* Name */
+			phandle = flat_read_word(dtbuf); /* Phandle */
+			str2 = flat_read_string(dtbuf); /* Ref */
+			exportsym = build_exportsym(str, str2, phandle, NULL);
+			add_symbol(&node->exportsymlist, exportsym);
+			break;
+
 		default:
 			die("Invalid opcode word %08x in device tree blob\n",
 			    val);
libfdt/fdt.c +24 -0
index 44d7399..febfa71 100644
@@ -248,6 +248,29 @@ uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffset)
 		offset += sizeof(fdt32_t);
 		break;
 
+	case FDT_EXPORT_SYM_REF:
+		/* Skip name */
+		do {
+			p = fdt_offset_ptr(fdt, offset++, 1);
+		} while (p && (*p != '\0'));
+		if (!can_assume(VALID_DTB) && !p)
+			return FDT_END; /* premature end */
+		offset = FDT_CELLALIGN(offset);
+
+		/* Skip phandle */
+		tmp32p = fdt_offset_ptr(fdt, offset, sizeof(*tmp32p));
+		if (!can_assume(VALID_DTB) && !tmp32p)
+			return FDT_END; /* premature end */
+		offset += sizeof(fdt32_t);
+
+		/* Skip external name */
+		do {
+			p = fdt_offset_ptr(fdt, offset++, 1);
+		} while (p && (*p != '\0'));
+		if (!can_assume(VALID_DTB) && !p)
+			return FDT_END; /* premature end */
+		break;
+
 	default:
 		return FDT_END;
 	}
@@ -290,6 +313,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 		case FDT_REF_LOCAL:
 		case FDT_REF_PHANDLE:
 		case FDT_EXPORT_SYM:
+		case FDT_EXPORT_SYM_REF:
 			/*
 			 * Next tag is a meta-data tag present in the middle
 			 * of the structure -> Skip it and look at next one
libfdt/fdt.h +2 -0
index e85bc07..c23723b 100644
@@ -65,6 +65,8 @@ struct fdt_property {
 					   external label */
 #define FDT_END		0x9
 #define FDT_EXPORT_SYM	0xa		/* export symbol: name, phandle value */
+#define FDT_EXPORT_SYM_REF 0xb		/* export symbol: name, phandle value (maybe
+					   unresolved), external label */
 
 #define FDT_V1_SIZE	(7*sizeof(fdt32_t))
 #define FDT_V2_SIZE	(FDT_V1_SIZE + sizeof(fdt32_t))
Signature · 1 line
2.52.0
Signature · 4 lines
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
#80 lore raw

Re: [RFC PATCH 29/77] Add support for FDT_EXPORT_SYM_REF dtb tag

Hi David,

Quoted 24 lines · On Thu, 15 Jan 2026 17:25:58 +1100 David Gibson <[email protected]>…
Quoted 17 lines · Herve Codina

The FDT_EXPORT_SYM_REF dtb tag is similar to the FDT_EXPORT_SYM tag except that it identifies a reference to an external phandle. The node referenced by the phandle is not present in the device-tree blob.

The FDT_EXPORT_SYM_REF dtb tag is a meta-data tag defining an exported symbol. It can be present in a node bloc meaning that a symbol is exported at this node level. The node pointed to by this symbol is not a local node (i.e. the node is not present in the device-tree blob.). This tag can be available only in overlay or addon device-tree blobs. The symbol has to be resolved when the device-tree blob is applied on top of a base device-tree.

It is followed by three values and a possible alignment padding:
- name (string including \0)
The export symbol name. I.e. the name used to reference this exported symbol.
- padding:

Quoted 5 lines
      Padding (0x00) added to have the next value aligned on 32bit.

- phandle (32bit)
A placeholder for a phandle value.
This placeholder can be used during some dtb manipulation to store a temporary phandle value.

Quoted 1 line

Yuck.

Will see what I can do to avoid this placeholder.

I need to store the phandle value related to this symbol during the symbol resolution. This is done by addon_resolve_phandles() available in libfdt/fdt_addon.c in patch 70.

libfdt is not designed to perform allocation to store temporary values. It manipulates data directly mapped from dtb working with offset in dtb blob without any other kind of object. No specific objects (C struct) for node, properties, markers, ...

To have an area for this phandle value, a room reserved in dtb was really the easier way.

But well, I understand your "yuck".

I think it will be quite tricky to store this temporary phandle value without allocating some additional data.

This placeholder simplified a lot of things but well, I think I need to find an other solution.

If anyone has any ideas to store the temporary phandle value, I am all ears.

Best regards,
Hervé

#81 lore raw

Re: [RFC PATCH 29/77] Add support for FDT_EXPORT_SYM_REF dtb tag

Quoted 33 lines · Herve Codina

Hi David,

Quoted 24 lines · On Thu, 15 Jan 2026 17:25:58 +1100 David Gibson <[email protected]>…
Quoted 17 lines · Herve Codina

The FDT_EXPORT_SYM_REF dtb tag is similar to the FDT_EXPORT_SYM tag except that it identifies a reference to an external phandle. The node referenced by the phandle is not present in the device-tree blob.

The FDT_EXPORT_SYM_REF dtb tag is a meta-data tag defining an exported symbol. It can be present in a node bloc meaning that a symbol is exported at this node level. The node pointed to by this symbol is not a local node (i.e. the node is not present in the device-tree blob.). This tag can be available only in overlay or addon device-tree blobs. The symbol has to be resolved when the device-tree blob is applied on top of a base device-tree.

It is followed by three values and a possible alignment padding:
- name (string including \0)
The export symbol name. I.e. the name used to reference this exported symbol.
- padding:

Quoted 5 lines
      Padding (0x00) added to have the next value aligned on 32bit.

- phandle (32bit)
A placeholder for a phandle value.
This placeholder can be used during some dtb manipulation to store a temporary phandle value.

Quoted 1 line

Yuck.

Will see what I can do to avoid this placeholder.

Quoted 8 lines

I need to store the phandle value related to this symbol during the symbol resolution. This is done by addon_resolve_phandles() available in libfdt/fdt_addon.c in patch 70.

libfdt is not designed to perform allocation to store temporary values. It manipulates data directly mapped from dtb working with offset in dtb blob without any other kind of object. No specific objects (C struct) for node, properties, markers, ...

I know. I designed it that way.

Tangent: I have thought that it might be useful to have a diffferent dt library designed for non-flat trees - i.e. using allocations and pointers to allow O(1) edits (as well as import/export to flat tree, of course). I think that would better suit some of the more complex tree manipulation many things are doing these days. I've never had remotely enough time to look into it, but fwiw, I think the idea's good.

Quoted 4 lines

To have an area for this phandle value, a room reserved in dtb was really the easier way.

But well, I understand your "yuck".

Yeah, I do realise that lack of free space to put things can make things really tricky. I hope we can find a way around this.

Quoted 12 lines

I think it will be quite tricky to store this temporary phandle value without allocating some additional data.

This placeholder simplified a lot of things but well, I think I need to find an other solution.

If anyone has any ideas to store the temporary phandle value, I am all ears.

Best regards,
Hervé

Signature · 4 lines
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
#82 lore raw

RFC PATCH 30/77 tests: metadata: Add export symbols with external references tests

In reply to Herve Codina

Add tests related to export symbols using external references (FDT_EXPORT_SYM_REF dtb tag).

---
 tests/metadata_exportsyms_ref.dtb.dts.expect | 25 +++++++++++++++++++
 tests/metadata_exportsyms_ref.dtb.expect     | 18 ++++++++++++++
 tests/metadata_exportsyms_ref.dts            | 26 ++++++++++++++++++++
 tests/metadata_exportsyms_ref.dts.dts.expect | 25 +++++++++++++++++++
 tests/run_tests.sh                           |  3 ++-
 5 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100644 tests/metadata_exportsyms_ref.dtb.dts.expect
 create mode 100644 tests/metadata_exportsyms_ref.dtb.expect
 create mode 100644 tests/metadata_exportsyms_ref.dts
 create mode 100644 tests/metadata_exportsyms_ref.dts.dts.expect
tests/metadata_exportsyms_ref.dtb.dts.expect new file +25 -0
new file mode 100644
index 0000000..d2c3320
@@ -0,0 +1,25 @@
+/dts-v1/;
+/addon/;
+
+/ {
+
+	node-a {
+	};
+
+	node-b {
+	};
+
+	node-c {
+
+		sub-node {
+
+			/export/ ref_base_node_a: &base_node_a;
+			/export/ ref_base_node_b: &base_node_b;
+		};
+	};
+
+	node-d {
+
+		/export/ ref_base_node_c: &base_node_c;
+	};
+};
tests/metadata_exportsyms_ref.dtb.expect new file +18 -0
new file mode 100644
index 0000000..395861b
@@ -0,0 +1,18 @@
+/dts-v1/;
+/addon/;
+
+/ {
+    node-a {
+    };
+    node-b {
+    };
+    node-c {
+        sub-node {
+            // [FDT_EXPORT_SYM_REF] 'ref_base_node_a' -> 'base_node_a'
+            // [FDT_EXPORT_SYM_REF] 'ref_base_node_b' -> 'base_node_b'
+        };
+    };
+    node-d {
+        // [FDT_EXPORT_SYM_REF] 'ref_base_node_c' -> 'base_node_c'
+    };
+};
tests/metadata_exportsyms_ref.dts new file +26 -0
new file mode 100644
index 0000000..c094be1
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
+/*
+ * Copyright (C) 2026 Bootlin
+ */
+
+/dts-v1/;
+/addon/;
+
+/ {
+	node-a {
+	};
+
+	node-b {
+	};
+
+	node-c {
+		sub_node: sub-node {
+			/export/ ref_base_node_a: &base_node_a;
+			/export/ ref_base_node_b: &base_node_b;
+		};
+	};
+
+	node-d {
+		/export/ ref_base_node_c: &base_node_c;
+	};
+};
tests/metadata_exportsyms_ref.dts.dts.expect new file +25 -0
new file mode 100644
index 0000000..2654df1
@@ -0,0 +1,25 @@
+/dts-v1/;
+/addon/;
+
+/ {
+
+	node-a {
+	};
+
+	node-b {
+	};
+
+	node-c {
+
+		sub_node: sub-node {
+
+			/export/ ref_base_node_a: &base_node_a;
+			/export/ ref_base_node_b: &base_node_b;
+		};
+	};
+
+	node-d {
+
+		/export/ ref_base_node_c: &base_node_c;
+	};
+};
tests/run_tests.sh +2 -1
index fc270e2..1973525 100755
@@ -1126,7 +1126,8 @@ wrap_fdtdump () {
 
 metadata_tests() {
 	for dt in metadata_reflocal metadata_refphandle \
-		  metadata_addon_base metadata_exportsyms_local; do
+		  metadata_addon_base metadata_exportsyms_local \
+		  metadata_exportsyms_ref; do
 		run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts"
 		base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect"
 		run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts"
Signature · 1 line
2.52.0
#83 lore raw

RFC PATCH 31/77 dtc: Introduce import symbols

In reply to Herve Codina

Import symbols allow to define a list of symbols imported and used by an addon.

Those symbols have to be resolved when the addon is applied on a base device-tree and will involved exported symbols provided at the node the addon is applied to.

Import symbols are similar in term of feature to __fixups__ available in device-tree overlays.

The goal is to identify symbols which are used by an addon but not defined by the addon itself. Those specific symbols are the imported symbols.

Introduce the import symbols list related to an addon. No functional change yet but preparation for the future support for import symbol parsing.

---
 dtc-parser.y | 3 ++-
 dtc.h        | 4 +++-
 flattree.c   | 2 +-
 fstree.c     | 2 +-
 livetree.c   | 4 +++-
 5 files changed, 10 insertions(+), 5 deletions(-)
dtc-parser.y +2 -1
index a0d0aef..4e46e9d 100644
@@ -113,7 +113,8 @@ sourcefile:
 	  headers memreserves devicetree
 		{
 			parser_output = build_dt_info($1, $2, $3,
-			                              guess_boot_cpuid($3));
+			                              guess_boot_cpuid($3),
+						      NULL);
 		}
 	;
 
dtc.h +3 -1
index 22816ba..796ed51 100644
@@ -350,6 +350,7 @@ struct dt_info {
 	struct reserve_info *reservelist;
 	uint32_t boot_cpuid_phys;
 	struct node *dt;		/* the device tree */
+	struct symbol *importsymlist;	/* Import symbol list */
 	const char *outname;		/* filename being written to, "-" for stdout */
 };
 
@@ -360,7 +361,8 @@ struct dt_info {
 
 struct dt_info *build_dt_info(unsigned int dtsflags,
 			      struct reserve_info *reservelist,
-			      struct node *tree, uint32_t boot_cpuid_phys);
+			      struct node *tree, uint32_t boot_cpuid_phys,
+			      struct symbol *importsymlist);
 void sort_tree(struct dt_info *dti);
 void generate_label_tree(struct dt_info *dti, const char *name, bool allocph);
 void generate_fixups_tree(struct dt_info *dti, const char *name);
flattree.c +1 -1
index d970259..47a289f 100644
@@ -1105,5 +1105,5 @@ struct dt_info *dt_from_blob(const char *fname)
 
 	fclose(f);
 
-	return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_phys);
+	return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_phys, NULL);
 }
fstree.c +1 -1
index 445ae53..a6aaf1e 100644
@@ -72,5 +72,5 @@ struct dt_info *dt_from_fs(const char *dirname)
 	tree = read_fstree(dirname);
 	tree = name_node(tree, "");
 
-	return build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree));
+	return build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree), NULL);
 }
livetree.c +3 -1
index 1de5990..4ec9609 100644
@@ -531,7 +531,8 @@ struct reserve_info *add_reserve_entry(struct reserve_info *list,
 
 struct dt_info *build_dt_info(unsigned int dtsflags,
 			      struct reserve_info *reservelist,
-			      struct node *tree, uint32_t boot_cpuid_phys)
+			      struct node *tree, uint32_t boot_cpuid_phys,
+			      struct symbol *importsymlist)
 {
 	struct dt_info *dti;
 
@@ -540,6 +541,7 @@ struct dt_info *build_dt_info(unsigned int dtsflags,
 	dti->reservelist = reservelist;
 	dti->dt = tree;
 	dti->boot_cpuid_phys = boot_cpuid_phys;
+	dti->importsymlist = importsymlist;
 
 	return dti;
 }
Signature · 1 line
2.52.0
#84 lore raw

RFC PATCH 32/77 dtc-parser: Introduce last_header_flags

In reply to Herve Codina

The parser needs to get header flags value in different places.

It relies on the fact that the rule used to parse the dts file is always
headers memreserves devicetree

With that only rule to parse the file, it uses '$<flags>-1' construct to get the flags value.

With the future introduction of import symbols parsing, this rule will change and the parser couldn't rely anymore on '$<flags>-1' to get flags value. Indeed, import symbols parsing will add a new optional symbol in this rule leading to two possible rules (with and without the new symbol) to parse the source file.

Introduce the last_header_flags variable to explicitly keep track of flags while also being agnostic of the rule structure and use this new variable instead of '$<flags>-1'.

---
 dtc-parser.y | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)
dtc-parser.y +9 -19
index 4e46e9d..48c40e8 100644
@@ -24,6 +24,8 @@ extern void yyerror(char const *s);
 extern struct dt_info *parser_output;
 extern bool treesource_error;
 
+unsigned int last_header_flags;
+
 static bool is_ref_relative(const char *ref)
 {
 	return ref[0] != '/' && strchr(&ref[1], '/');
@@ -122,14 +124,17 @@ header:
 	  DT_V1 ';'
 		{
 			$$ = DTSF_V1;
+			last_header_flags = $$;
 		}
 	| DT_V1 ';' DT_PLUGIN ';'
 		{
 			$$ = DTSF_V1 | DTSF_PLUGIN;
+			last_header_flags = $$;
 		}
 	| DT_V1 ';' DT_ADDON ';'
 		{
 			$$ = DTSF_V1 | DTSF_ADDON;
+			last_header_flags = $$;
 		}
 	;
 
@@ -179,12 +184,7 @@ devicetree:
 		}
 	| dt_ref nodedef
 		{
-			/*
-			 * We rely on the rule being always:
-			 *   versioninfo plugindecl memreserves devicetree
-			 * so $-1 is what we want (plugindecl)
-			 */
-			if (!($<flags>-1 & DTSF_PLUGIN))
+			if (!(last_header_flags & DTSF_PLUGIN))
 				ERROR(&@2, "Label or path %s not found", $1);
 			else if (is_ref_relative($1))
 				ERROR(&@2, "Label-relative reference %s not supported in plugin", $1);
@@ -197,7 +197,7 @@ devicetree:
 		{
 			struct node *target = get_node_by_ref($1, $3);
 
-			if (($<flags>-1 & DTSF_PLUGIN) && is_ref_relative($3))
+			if ((last_header_flags & DTSF_PLUGIN) && is_ref_relative($3))
 				ERROR(&@2, "Label-relative reference %s not supported in plugin", $3);
 
 			if (target) {
@@ -209,12 +209,7 @@ devicetree:
 		}
 	| devicetree DT_PATH_REF nodedef
 		{
-			/*
-			 * We rely on the rule being always:
-			 *   versioninfo plugindecl memreserves devicetree
-			 * so $-1 is what we want (plugindecl)
-			 */
-			if ($<flags>-1 & DTSF_PLUGIN) {
+			if (last_header_flags & DTSF_PLUGIN) {
 				if (is_ref_relative($2))
 					ERROR(&@2, "Label-relative reference %s not supported in plugin", $2);
 				add_orphan_node($1, $3, $2);
@@ -235,12 +230,7 @@ devicetree:
 			if (target) {
 				merge_nodes(target, $3);
 			} else {
-				/*
-				 * We rely on the rule being always:
-				 *   versioninfo plugindecl memreserves devicetree
-				 * so $-1 is what we want (plugindecl)
-				 */
-				if ($<flags>-1 & DTSF_PLUGIN)
+				if (last_header_flags & DTSF_PLUGIN)
 					add_orphan_node($1, $3, $2);
 				else
 					ERROR(&@2, "Label or path %s not found", $2);
Signature · 1 line
2.52.0
#85 lore raw

Re: [RFC PATCH 32/77] dtc-parser: Introduce last_header_flags

Quoted 14 lines · Herve Codina

The parser needs to get header flags value in different places.

It relies on the fact that the rule used to parse the dts file is always
headers memreserves devicetree

With that only rule to parse the file, it uses '$<flags>-1' construct to get the flags value.

With the future introduction of import symbols parsing, this rule will change and the parser couldn't rely anymore on '$<flags>-1' to get flags value. Indeed, import symbols parsing will add a new optional symbol in this rule leading to two possible rules (with and without the new symbol) to parse the source file.

Quoted 3 lines

Introduce the last_header_flags variable to explicitly keep track of flags while also being agnostic of the rule structure and use this new variable instead of '$<flags>-1'.

I'm not sure this approach is safe: I'm not sure bison guarantees that semantic rules will always be executed in the same order, so using global variables is risky.

Quoted 92 lines
---
 dtc-parser.y | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)
dtc-parser.y +9 -19
index 4e46e9d..48c40e8 100644
@@ -24,6 +24,8 @@ extern void yyerror(char const *s);
 extern struct dt_info *parser_output;
 extern bool treesource_error;
 
+unsigned int last_header_flags;
+
 static bool is_ref_relative(const char *ref)
 {
 	return ref[0] != '/' && strchr(&ref[1], '/');
@@ -122,14 +124,17 @@ header:
 	  DT_V1 ';'
 		{
 			$$ = DTSF_V1;
+			last_header_flags = $$;
 		}
 	| DT_V1 ';' DT_PLUGIN ';'
 		{
 			$$ = DTSF_V1 | DTSF_PLUGIN;
+			last_header_flags = $$;
 		}
 	| DT_V1 ';' DT_ADDON ';'
 		{
 			$$ = DTSF_V1 | DTSF_ADDON;
+			last_header_flags = $$;
 		}
 	;
 
@@ -179,12 +184,7 @@ devicetree:
 		}
 	| dt_ref nodedef
 		{
-			/*
-			 * We rely on the rule being always:
-			 *   versioninfo plugindecl memreserves devicetree
-			 * so $-1 is what we want (plugindecl)
-			 */
-			if (!($<flags>-1 & DTSF_PLUGIN))
+			if (!(last_header_flags & DTSF_PLUGIN))
 				ERROR(&@2, "Label or path %s not found", $1);
 			else if (is_ref_relative($1))
 				ERROR(&@2, "Label-relative reference %s not supported in plugin", $1);
@@ -197,7 +197,7 @@ devicetree:
 		{
 			struct node *target = get_node_by_ref($1, $3);
 
-			if (($<flags>-1 & DTSF_PLUGIN) && is_ref_relative($3))
+			if ((last_header_flags & DTSF_PLUGIN) && is_ref_relative($3))
 				ERROR(&@2, "Label-relative reference %s not supported in plugin", $3);
 
 			if (target) {
@@ -209,12 +209,7 @@ devicetree:
 		}
 	| devicetree DT_PATH_REF nodedef
 		{
-			/*
-			 * We rely on the rule being always:
-			 *   versioninfo plugindecl memreserves devicetree
-			 * so $-1 is what we want (plugindecl)
-			 */
-			if ($<flags>-1 & DTSF_PLUGIN) {
+			if (last_header_flags & DTSF_PLUGIN) {
 				if (is_ref_relative($2))
 					ERROR(&@2, "Label-relative reference %s not supported in plugin", $2);
 				add_orphan_node($1, $3, $2);
@@ -235,12 +230,7 @@ devicetree:
 			if (target) {
 				merge_nodes(target, $3);
 			} else {
-				/*
-				 * We rely on the rule being always:
-				 *   versioninfo plugindecl memreserves devicetree
-				 * so $-1 is what we want (plugindecl)
-				 */
-				if ($<flags>-1 & DTSF_PLUGIN)
+				if (last_header_flags & DTSF_PLUGIN)
 					add_orphan_node($1, $3, $2);
 				else
 					ERROR(&@2, "Label or path %s not found", $2);
Signature · 1 line
2.52.0
Signature · 4 lines
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
#86 lore raw

Re: [RFC PATCH 32/77] dtc-parser: Introduce last_header_flags

Quoted 15 lines · On Thu, 15 Jan 2026 17:31:24 +1100 David Gibson <[email protected]>…
Quoted 14 lines · Herve Codina

The parser needs to get header flags value in different places.

It relies on the fact that the rule used to parse the dts file is always
headers memreserves devicetree

With that only rule to parse the file, it uses '$<flags>-1' construct to get the flags value.

With the future introduction of import symbols parsing, this rule will change and the parser couldn't rely anymore on '$<flags>-1' to get flags value. Indeed, import symbols parsing will add a new optional symbol in this rule leading to two possible rules (with and without the new symbol) to parse the source file.

Quoted 7 lines
Quoted 3 lines

Introduce the last_header_flags variable to explicitly keep track of flags while also being agnostic of the rule structure and use this new variable instead of '$<flags>-1'.

I'm not sure this approach is safe: I'm not sure bison guarantees that semantic rules will always be executed in the same order, so using global variables is risky.

if rules were not executed in the same order '$<flags>-1' construct would not work.

The problem is not the order. I don't think the order will change. The problem is related to the number of items on stack.

With import symbols, that the stack will be:
header memreserved devicetree
or
header memreserved importsyms devicetree

Using '$-1' will no more be possible. Indeed, '$-1' from the devicetree rule will reference 'header' in one case and 'memreserved' in the other case.

Without a global variable, I don't know how to reference 'header' (or flags value) in all cases.

Any better ideas are welcome.

Best regards,
Hervé

#87 lore raw

Re: [RFC PATCH 32/77] dtc-parser: Introduce last_header_flags

Quoted 22 lines · Herve Codina
Quoted 19 lines · On Thu, 15 Jan 2026 17:31:24 +1100 David Gibson <[email protected]>…
Quoted 17 lines · Herve Codina

The parser needs to get header flags value in different places.

It relies on the fact that the rule used to parse the dts file is always
headers memreserves devicetree

With that only rule to parse the file, it uses '$<flags>-1' construct to get the flags value.

With the future introduction of import symbols parsing, this rule will change and the parser couldn't rely anymore on '$<flags>-1' to get flags value. Indeed, import symbols parsing will add a new optional symbol in this rule leading to two possible rules (with and without the new symbol) to parse the source file.

Introduce the last_header_flags variable to explicitly keep track of flags while also being agnostic of the rule structure and use this new variable instead of '$<flags>-1'.

Quoted 6 lines
Quoted 3 lines

I'm not sure this approach is safe: I'm not sure bison guarantees that semantic rules will always be executed in the same order, so using global variables is risky.

if rules were not executed in the same order '$<flags>-1' construct would not work.

Uhh.. I'm pretty sure $<flags>-1 only depends on the parse tree structure, not the order in which the actual semantic rule code fragments run.

Quoted 8 lines

The problem is not the order. I don't think the order will change. The problem is related to the number of items on stack.

With import symbols, that the stack will be:
header memreserved devicetree
or
header memreserved importsyms devicetree

Quoted 8 lines

Using '$-1' will no more be possible. Indeed, '$-1' from the devicetree rule will reference 'header' in one case and 'memreserved' in the other case.

Without a global variable, I don't know how to reference 'header' (or flags value) in all cases.

Any better ideas are welcome.

Ok, I'll try to look into it and see what I can come up with.

Signature · 4 lines
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
#88 lore raw

RFC PATCH 33/77 dtc: Add support for /import/ dts keyword parsing

In reply to Herve Codina

The /import/ dts keyword is the keyword used to define an imported symbol used by an addon device-tree.

An imported symbol is not related to a specific node and it is global to a whole addon. It can be present after the header definition (and the possible memreserves definition) and before the devicetree nodes definition.

If several symbols are imported, several /import/ keyword are present.

The syntax used is the following:
/import/ name: compatible;

with:
name: The name of the imported symbol
compatible: a string indicating the kind of symbol is expected. This
compatible string can be used when the addon is applied in order to help the symbol resolution.

For instance:
/import/ foo: "bar, foo";

The foo symbol is expected by the addon and should be "bar, foo" compatible.

The addon uses this symbol (i.e. it references it) but it doesn't define the symbol itself.

From the addon point of view, foo is an unresolved symbol and it will be resolved when the addon is applied.

Add support for /import/ dts keyword.

---
 dtc-lexer.l  |  6 ++++++
 dtc-parser.y | 45 +++++++++++++++++++++++++++++++++++++++++++++
 dtc.h        |  3 +++
 livetree.c   | 13 +++++++++++++
 4 files changed, 67 insertions(+)
dtc-lexer.l +6 -0
index 90fe70e..cb616f9 100644
@@ -155,6 +155,12 @@ static void PRINTF(1, 2) lexical_error(const char *fmt, ...);
 			return DT_EXPORT;
 		}
 
+<*>"/import/" 	{
+			DPRINT("Keyword: /import/\n");
+			BEGIN_DEFAULT();
+			return DT_IMPORT;
+		}
+
 <*>{LABEL}:	{
 			DPRINT("Label: %s\n", yytext);
 			yylval.labelref = xstrdup(yytext);
dtc-parser.y +45 -0

75 lines not on this page · raw message

dtc.h +3 -0
index 796ed51..4ebe576 100644
@@ -207,6 +207,7 @@ struct label {
 struct symbol {
 	bool is_local;
 	char *name;
+	char *compatible;
 	char *ref;
 	cell_t phandle;
 	char *fullpath;
@@ -287,6 +288,8 @@ struct property *reverse_properties(struct property *first);
 
 struct symbol *build_exportsym(const char *name, const char *ref, cell_t phandle,
 			       struct srcpos *srcpos);
+struct symbol *build_importsym(const char *name, const char *compatible,
+			       struct srcpos *srcpos);
 struct symbol *chain_symbol(struct symbol *first, struct symbol *list);
 struct symbol *reverse_symbol(struct symbol *list);
 void add_symbol(struct symbol **list, struct symbol *new);
livetree.c +13 -0
index 4ec9609..dac5359 100644
@@ -51,6 +51,19 @@ struct symbol *build_exportsym(const char *name, const char *ref, cell_t phandle
 	return new;
 }
 
+struct symbol *build_importsym(const char *name, const char *compatible, struct srcpos *srcpos)
+{
+	struct symbol *new = xmalloc(sizeof(*new));
+
+	memset(new, 0, sizeof(*new));
+
+	new->name = xstrdup(name);
+	new->compatible = xstrdup(compatible);
+	new->srcpos = srcpos_copy(srcpos);
+
+	return new;
+}
+
 struct symbol *chain_symbol(struct symbol *first, struct symbol *list)
 {
 	assert(first->next == NULL);
Signature · 1 line
2.52.0
#89 lore raw

RFC PATCH 34/77 dtc: Add import symbols (/import/ keyword) in generated dts file

In reply to Herve Codina

The import symbols (/import/ keyword) parsing from a dts file is supported.

Add the support for this keyword in the dts file generation.

---
 treesource.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
treesource.c +10 -0
index 9effe38..04f65bb 100644
@@ -381,6 +381,7 @@ static void write_tree_source_node(FILE *f, struct node *tree, int level)
 void dt_to_source(FILE *f, struct dt_info *dti)
 {
 	struct reserve_info *re;
+	struct symbol *importsym;
 
 	fprintf(f, "/dts-v1/;\n");
 	if (dti->dtsflags & DTSF_ADDON)
@@ -397,5 +398,14 @@ void dt_to_source(FILE *f, struct dt_info *dti)
 			(unsigned long long)re->size);
 	}
 
+	if (dti->importsymlist) {
+		for_each_symbol(dti->importsymlist, importsym) {
+			fprintf(f, "/import/ %s: \"%s\";\n",
+				importsym->name,
+				importsym->compatible);
+		}
+		fprintf(f, "\n");
+	}
+
 	write_tree_source_node(f, dti->dt, 0);
 }
Signature · 1 line
2.52.0
#90 lore raw

RFC PATCH 35/77 Add support for FDT_IMPORT_SYM dtb tag

In reply to Herve Codina

The FDT_IMPORT_SYM dtb tag is a meta-data tag defining an imported symbol. It can be present globally in an addon dtb (i.e. outside nodes definition) meaning that this symbol needs to be resolved when the dtb is applied.

The tag is followed by two values and possible alignment paddings:
- name (string including \0)
The import symbol name. I.e. the name used to reference this imported symbol.
- padding:

      Padding (0x00) added to have the next value aligned on 32bit.
  - compatible (string including \0)
      The compatible string that can be used for symbol resolution.
      This string can be an empty string if it is not relevant.
  - padding:
      Padding (0x00) added to have the next value aligned on 32bit.

Example:
FDT_IMPORT_SYM 'foo1' 0x00 0x00 0x00 'bar,foo'

This means that 'foo1' is an imported symbol and it is 'bar,foo' compatible.

This is what is encoded in the dtb when the related dts has the following imported symbol defined:

    /import/ foo1: "bar,foo";

If several symbols are imported, several FDT_IMPORT_SYM are present. Each of them defining one imported symbol. For instance, importing 'foo1' ("bar,foo" compatible) and 'baz1' ("bar,baz" compatible) leads to the following sequence:
FDT_IMPORT_SYM 'foo1' 0x00 0x00 0x00 'bar,foo' FDT_IMPORT_SYM 'baz1' 0x00 0x00 0x00 'bar,baz'

If FDT_IMPORT_SYM tags are present in the dtb, they are present after the root node definition (i.e. after the FDT_END_NODE related to the first FDT_BEGIN_NODE).

Add support for this new dtb tag.

---
 fdtdump.c    | 11 +++++++++
 flattree.c   | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 libfdt/fdt.c | 28 ++++++++++++++++++++++
 libfdt/fdt.h |  1 +
 4 files changed, 107 insertions(+), 1 deletion(-)
fdtdump.c +11 -0
index 8baadc4..04e6e38 100644
@@ -198,6 +198,17 @@ static void dump_blob(void *blob, bool debug)
 			continue;
 		}
 
+		if (tag == FDT_IMPORT_SYM) {
+			s = p;
+			p = PALIGN(p + strlen(s) + 1, 4);
+			t = p;
+			p = PALIGN(p + strlen(t) + 1, 4);
+
+			printf("%*s// [FDT_IMPORT_SYM] '%s' (%s)\n", depth * shift, "",
+				s, t);
+			continue;
+		}
+
 		fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
 		break;
 	}
flattree.c +67 -1

138 lines not on this page · raw message

libfdt/fdt.c +28 -0
index febfa71..c169dd9 100644
@@ -271,6 +271,23 @@ uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffset)
 			return FDT_END; /* premature end */
 		break;
 
+	case FDT_IMPORT_SYM:
+		/* Skip name */
+		do {
+			p = fdt_offset_ptr(fdt, offset++, 1);
+		} while (p && (*p != '\0'));
+		if (!can_assume(VALID_DTB) && !p)
+			return FDT_END; /* premature end */
+		offset = FDT_CELLALIGN(offset);
+
+		/* Skip compatible */
+		do {
+			p = fdt_offset_ptr(fdt, offset++, 1);
+		} while (p && (*p != '\0'));
+		if (!can_assume(VALID_DTB) && !p)
+			return FDT_END; /* premature end */
+		break;
+
 	default:
 		return FDT_END;
 	}
@@ -286,6 +303,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 {
 	uint32_t tag, tmp_tag;
 	int tmp_offset, tmp_next;
+	int is_skip_to_end = 0;
 
 	/* Retrieve next tag */
 	tag = fdt_next_tag_full(fdt, startoffset, nextoffset);
@@ -300,6 +318,9 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 		case FDT_END_NODE:
 		case FDT_PROP:
 		case FDT_NOP:
+			if (is_skip_to_end)
+				break;
+
 		case FDT_END:
 			/*
 			 * Next tag is not a meta-data tag -> Ok this next tag
@@ -320,6 +341,13 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 			 */
 			break;
 
+		case FDT_IMPORT_SYM:
+			/* Those tags are available at the root level, after the
+			 * root node -> Skip everything until FDT_END
+			 */
+			is_skip_to_end = 1;
+			break;
+
 		default:
 			break;
 		}
libfdt/fdt.h +1 -0
index c23723b..b6c23ef 100644
@@ -67,6 +67,7 @@ struct fdt_property {
 #define FDT_EXPORT_SYM	0xa		/* export symbol: name, phandle value */
 #define FDT_EXPORT_SYM_REF 0xb		/* export symbol: name, phandle value (maybe
 					   unresolved), external label */
+#define FDT_IMPORT_SYM	0xc		/* import symbol: name, compatible */
 
 #define FDT_V1_SIZE	(7*sizeof(fdt32_t))
 #define FDT_V2_SIZE	(FDT_V1_SIZE + sizeof(fdt32_t))
Signature · 1 line
2.52.0
#91 lore raw

Re: [RFC PATCH 35/77] Add support for FDT_IMPORT_SYM dtb tag

Quoted 34 lines · Herve Codina

The FDT_IMPORT_SYM dtb tag is a meta-data tag defining an imported symbol. It can be present globally in an addon dtb (i.e. outside nodes definition) meaning that this symbol needs to be resolved when the dtb is applied.

The tag is followed by two values and possible alignment paddings:
- name (string including \0)
The import symbol name. I.e. the name used to reference this imported symbol.
- padding:

      Padding (0x00) added to have the next value aligned on 32bit.
  - compatible (string including \0)
      The compatible string that can be used for symbol resolution.
      This string can be an empty string if it is not relevant.
  - padding:
      Padding (0x00) added to have the next value aligned on 32bit.

Example:
FDT_IMPORT_SYM 'foo1' 0x00 0x00 0x00 'bar,foo'

This means that 'foo1' is an imported symbol and it is 'bar,foo' compatible.

This is what is encoded in the dtb when the related dts has the following imported symbol defined:

    /import/ foo1: "bar,foo";

If several symbols are imported, several FDT_IMPORT_SYM are present. Each of them defining one imported symbol. For instance, importing 'foo1' ("bar,foo" compatible) and 'baz1' ("bar,baz" compatible) leads to the following sequence:
FDT_IMPORT_SYM 'foo1' 0x00 0x00 0x00 'bar,foo' FDT_IMPORT_SYM 'baz1' 0x00 0x00 0x00 'bar,baz'

Quoted 5 lines

If FDT_IMPORT_SYM tags are present in the dtb, they are present after the root node definition (i.e. after the FDT_END_NODE related to the first FDT_BEGIN_NODE).

Add support for this new dtb tag.

Since these are global to the whole tree, would a new block make more sense?

Quoted 261 lines
---
 fdtdump.c    | 11 +++++++++
 flattree.c   | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 libfdt/fdt.c | 28 ++++++++++++++++++++++
 libfdt/fdt.h |  1 +
 4 files changed, 107 insertions(+), 1 deletion(-)
fdtdump.c +11 -0
index 8baadc4..04e6e38 100644
@@ -198,6 +198,17 @@ static void dump_blob(void *blob, bool debug)
 			continue;
 		}
 
+		if (tag == FDT_IMPORT_SYM) {
+			s = p;
+			p = PALIGN(p + strlen(s) + 1, 4);
+			t = p;
+			p = PALIGN(p + strlen(t) + 1, 4);
+
+			printf("%*s// [FDT_IMPORT_SYM] '%s' (%s)\n", depth * shift, "",
+				s, t);
+			continue;
+		}
+
 		fprintf(stderr, "%*s ** Unknown tag 0x%08"PRIx32"\n", depth * shift, "", tag);
 		break;
 	}
flattree.c +67 -1
index 47a289f..add02f0 100644
@@ -50,6 +50,7 @@ struct emitter {
 	void (*ref_phandle)(void *);
 	void (*export_sym)(void *);
 	void (*export_sym_ref)(void *);
+	void (*import_sym)(void *);
 };
 
 static void bin_emit_cell(void *e, cell_t val)
@@ -119,6 +120,11 @@ static void bin_emit_export_sym_ref(void *e)
 	bin_emit_cell(e, FDT_EXPORT_SYM_REF);
 }
 
+static void bin_emit_import_sym(void *e)
+{
+	bin_emit_cell(e, FDT_IMPORT_SYM);
+}
+
 static struct emitter bin_emitter = {
 	.cell = bin_emit_cell,
 	.string = bin_emit_string,
@@ -131,6 +137,7 @@ static struct emitter bin_emitter = {
 	.ref_phandle = bin_emit_ref_phandle,
 	.export_sym = bin_emit_export_sym,
 	.export_sym_ref = bin_emit_export_sym_ref,
+	.import_sym = bin_emit_import_sym,
 };
 
 static void emit_label(FILE *f, const char *prefix, const char *label)
@@ -274,6 +281,17 @@ static void asm_emit_export_sym_ref(void *e)
 	asm_emit_cell(e, FDT_EXPORT_SYM_REF);
 }
 
+static void asm_emit_import_sym(void *e)
+{
+	/*
+	 * Import symbols are an feature introduced for addons.
+	 * Addons device-tree blob have to reason to be in the asm format.
+	 *
+	 * Need to be implemented if really needed.
+	 */
+	die("FDT_IMPORT_SYM not supported in asm output\n");
+}
+
 static struct emitter asm_emitter = {
 	.cell = asm_emit_cell,
 	.string = asm_emit_string,
@@ -286,6 +304,7 @@ static struct emitter asm_emitter = {
 	.ref_phandle = asm_emit_ref_phandle,
 	.export_sym = asm_emit_export_sym,
 	.export_sym = asm_emit_export_sym_ref,
+	.import_sym = asm_emit_import_sym,
 };
 
 static int stringtable_insert(struct data *d, const char *str)
@@ -461,6 +480,26 @@ static void make_fdt_header(struct fdt_header *fdt,
 		fdt->dt_flags = cpu_to_fdt32(dt_flags);
 }
 
+static void flatten_imports(struct symbol *importsymlist, struct emitter *emit,
+			 void *etarget, struct version_info *vi, uint32_t dt_flags)
+{
+	struct symbol *importsym;
+
+	if (!(vi->flags & FTF_EXPORT_IMPORT_SYM))
+		return;
+
+	if (!(dt_flags & FDT_FLAG_ADDON) && importsymlist)
+		die("Only addons can have an import list\n");
+
+	for_each_symbol(importsymlist, importsym) {
+		emit->import_sym(etarget);
+		emit->string(etarget, importsym->name, 0);
+		emit->align(etarget, sizeof(cell_t));
+		emit->string(etarget, importsym->compatible, 0);
+		emit->align(etarget, sizeof(cell_t));
+	}
+}
+
 void dt_to_blob(FILE *f, struct dt_info *dti, int version)
 {
 	struct version_info *vi = NULL;
@@ -483,6 +522,7 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int version)
 	dt_flags |= dti->dtsflags & DTSF_ADDON ? FDT_FLAG_ADDON : 0;
 
 	flatten_tree(dti->dt, &bin_emitter, &dtbuf, &strbuf, vi);
+	flatten_imports(dti->importsymlist, &bin_emitter, &dtbuf, vi, dt_flags);
 	bin_emit_cell(&dtbuf, FDT_END);
 
 	reservebuf = flatten_reserve_list(dti->reservelist, vi);
@@ -574,6 +614,9 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version)
 	const char *symprefix = "dt";
 	uint32_t dt_flags = 0;
 
+	if (dti->importsymlist)
+		die("Import symbols not supported in asm format\n");
+
 	for (i = 0; i < ARRAY_SIZE(version_table); i++) {
 		if (version_table[i].version == version)
 			vi = &version_table[i];
@@ -810,6 +853,16 @@ static struct property *flat_read_property(struct inbuf *dtbuf,
 	return build_property(name, val, NULL);
 }
 
+static struct symbol *flat_read_importsym(struct inbuf *inb)
+{
+	const char *name;
+	const char *compatible;
+
+	name = flat_read_string(inb);
+	compatible =  flat_read_string(inb);
+
+	return build_importsym(name, compatible, NULL);
+}
 
 static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb)
 {
@@ -984,6 +1037,8 @@ struct dt_info *dt_from_blob(const char *fname)
 	int sizeleft;
 	struct reserve_info *reservelist;
 	struct node *tree;
+	struct symbol *importsymlist = NULL;
+	struct symbol *importsym;
 	uint32_t val;
 	int flags = 0;
 	unsigned int dtsflags = 0;
@@ -1098,6 +1153,17 @@ struct dt_info *dt_from_blob(const char *fname)
 	tree = unflatten_tree(&dtbuf, &strbuf, "", flags);
 
 	val = flat_read_word(&dtbuf);
+
+	if (dtsflags & DTSF_ADDON) {
+		if (flags & FTF_EXPORT_IMPORT_SYM) {
+			while (val == FDT_IMPORT_SYM) {
+				importsym = flat_read_importsym(&dtbuf);
+				add_symbol(&importsymlist, importsym);
+				val = flat_read_word(&dtbuf);
+			}
+		}
+	}
+
 	if (val != FDT_END)
 		die("Device tree blob doesn't end with FDT_END\n");
 
@@ -1105,5 +1171,5 @@ struct dt_info *dt_from_blob(const char *fname)
 
 	fclose(f);
 
-	return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_phys, NULL);
+	return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_phys, importsymlist);
 }
libfdt/fdt.c +28 -0
index febfa71..c169dd9 100644
@@ -271,6 +271,23 @@ uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffset)
 			return FDT_END; /* premature end */
 		break;
 
+	case FDT_IMPORT_SYM:
+		/* Skip name */
+		do {
+			p = fdt_offset_ptr(fdt, offset++, 1);
+		} while (p && (*p != '\0'));
+		if (!can_assume(VALID_DTB) && !p)
+			return FDT_END; /* premature end */
+		offset = FDT_CELLALIGN(offset);
+
+		/* Skip compatible */
+		do {
+			p = fdt_offset_ptr(fdt, offset++, 1);
+		} while (p && (*p != '\0'));
+		if (!can_assume(VALID_DTB) && !p)
+			return FDT_END; /* premature end */
+		break;
+
 	default:
 		return FDT_END;
 	}
@@ -286,6 +303,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 {
 	uint32_t tag, tmp_tag;
 	int tmp_offset, tmp_next;
+	int is_skip_to_end = 0;
 
 	/* Retrieve next tag */
 	tag = fdt_next_tag_full(fdt, startoffset, nextoffset);
@@ -300,6 +318,9 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 		case FDT_END_NODE:
 		case FDT_PROP:
 		case FDT_NOP:
+			if (is_skip_to_end)
+				break;
+
 		case FDT_END:
 			/*
 			 * Next tag is not a meta-data tag -> Ok this next tag
@@ -320,6 +341,13 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 			 */
 			break;
 
+		case FDT_IMPORT_SYM:
+			/* Those tags are available at the root level, after the
+			 * root node -> Skip everything until FDT_END
+			 */
+			is_skip_to_end = 1;
+			break;
+
 		default:
 			break;
 		}
libfdt/fdt.h +1 -0
index c23723b..b6c23ef 100644
@@ -67,6 +67,7 @@ struct fdt_property {
 #define FDT_EXPORT_SYM	0xa		/* export symbol: name, phandle value */
 #define FDT_EXPORT_SYM_REF 0xb		/* export symbol: name, phandle value (maybe
 					   unresolved), external label */
+#define FDT_IMPORT_SYM	0xc		/* import symbol: name, compatible */
 
 #define FDT_V1_SIZE	(7*sizeof(fdt32_t))
 #define FDT_V2_SIZE	(FDT_V1_SIZE + sizeof(fdt32_t))
Signature · 1 line
2.52.0
Signature · 4 lines
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
#92 lore raw

Re: [RFC PATCH 35/77] Add support for FDT_IMPORT_SYM dtb tag

Hi David,

Quoted 35 lines · On Thu, 15 Jan 2026 17:41:11 +1100 David Gibson <[email protected]>…
Quoted 34 lines · Herve Codina

The FDT_IMPORT_SYM dtb tag is a meta-data tag defining an imported symbol. It can be present globally in an addon dtb (i.e. outside nodes definition) meaning that this symbol needs to be resolved when the dtb is applied.

The tag is followed by two values and possible alignment paddings:
- name (string including \0)
The import symbol name. I.e. the name used to reference this imported symbol.
- padding:

      Padding (0x00) added to have the next value aligned on 32bit.
  - compatible (string including \0)
      The compatible string that can be used for symbol resolution.
      This string can be an empty string if it is not relevant.
  - padding:
      Padding (0x00) added to have the next value aligned on 32bit.

Example:
FDT_IMPORT_SYM 'foo1' 0x00 0x00 0x00 'bar,foo'

This means that 'foo1' is an imported symbol and it is 'bar,foo' compatible.

This is what is encoded in the dtb when the related dts has the following imported symbol defined:

    /import/ foo1: "bar,foo";

If several symbols are imported, several FDT_IMPORT_SYM are present. Each of them defining one imported symbol. For instance, importing 'foo1' ("bar,foo" compatible) and 'baz1' ("bar,baz" compatible) leads to the following sequence:
FDT_IMPORT_SYM 'foo1' 0x00 0x00 0x00 'bar,foo' FDT_IMPORT_SYM 'baz1' 0x00 0x00 0x00 'bar,baz'

Quoted 8 lines
Quoted 5 lines

If FDT_IMPORT_SYM tags are present in the dtb, they are present after the root node definition (i.e. after the FDT_END_NODE related to the first FDT_BEGIN_NODE).

Add support for this new dtb tag.

Since these are global to the whole tree, would a new block make more sense?

I don't know.

Exports symbols are in node blocs and that makes sense. I wouldn't expect imports out of the dtb "structure block".

They could be grouped into an other tag, FDT_INFO_DTB for instance (part of the "structure block").

If you think that a new block is really relevant, I can implement this new block.

Best regards,
Hervé

#93 lore raw

Re: [RFC PATCH 35/77] Add support for FDT_IMPORT_SYM dtb tag

Quoted 51 lines · Herve Codina

Hi David,

Quoted 35 lines · On Thu, 15 Jan 2026 17:41:11 +1100 David Gibson <[email protected]>…
Quoted 34 lines · Herve Codina

The FDT_IMPORT_SYM dtb tag is a meta-data tag defining an imported symbol. It can be present globally in an addon dtb (i.e. outside nodes definition) meaning that this symbol needs to be resolved when the dtb is applied.

The tag is followed by two values and possible alignment paddings:
- name (string including \0)
The import symbol name. I.e. the name used to reference this imported symbol.
- padding:

      Padding (0x00) added to have the next value aligned on 32bit.
  - compatible (string including \0)
      The compatible string that can be used for symbol resolution.
      This string can be an empty string if it is not relevant.
  - padding:
      Padding (0x00) added to have the next value aligned on 32bit.

Example:
FDT_IMPORT_SYM 'foo1' 0x00 0x00 0x00 'bar,foo'

This means that 'foo1' is an imported symbol and it is 'bar,foo' compatible.

This is what is encoded in the dtb when the related dts has the following imported symbol defined:

    /import/ foo1: "bar,foo";

If several symbols are imported, several FDT_IMPORT_SYM are present. Each of them defining one imported symbol. For instance, importing 'foo1' ("bar,foo" compatible) and 'baz1' ("bar,baz" compatible) leads to the following sequence:
FDT_IMPORT_SYM 'foo1' 0x00 0x00 0x00 'bar,foo' FDT_IMPORT_SYM 'baz1' 0x00 0x00 0x00 'bar,baz'

Quoted 8 lines
Quoted 5 lines

If FDT_IMPORT_SYM tags are present in the dtb, they are present after the root node definition (i.e. after the FDT_END_NODE related to the first FDT_BEGIN_NODE).

Add support for this new dtb tag.

Since these are global to the whole tree, would a new block make more sense?

I don't know.

Quoted 8 lines

Exports symbols are in node blocs and that makes sense. I wouldn't expect imports out of the dtb "structure block".

They could be grouped into an other tag, FDT_INFO_DTB for instance (part of the "structure block").

If you think that a new block is really relevant, I can implement this new block.

On further thought, I don't think this is a good idea. For one thing adding an extra block makes resizing edits way harder to implement. For another adding support for multiple upstream connectors might mean they're no longer quite as global as they are.

Signature · 4 lines
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
#94 lore raw

RFC PATCH 36/77 tests: metadata: Add import symbols tests

In reply to Herve Codina

Add tests related to import symbols (FDT_IMPORT_SYM dtb tag).

---
 tests/metadata_importsyms.dtb.dts.expect |  9 +++++++++
 tests/metadata_importsyms.dtb.expect     |  8 ++++++++
 tests/metadata_importsyms.dts            | 14 ++++++++++++++
 tests/metadata_importsyms.dts.dts.expect |  9 +++++++++
 tests/run_tests.sh                       | 10 +++++-----
 5 files changed, 45 insertions(+), 5 deletions(-)
 create mode 100644 tests/metadata_importsyms.dtb.dts.expect
 create mode 100644 tests/metadata_importsyms.dtb.expect
 create mode 100644 tests/metadata_importsyms.dts
 create mode 100644 tests/metadata_importsyms.dts.dts.expect
tests/metadata_importsyms.dtb.dts.expect new file +9 -0
new file mode 100644
index 0000000..eabf8c7
@@ -0,0 +1,9 @@
+/dts-v1/;
+/addon/;
+
+/import/ base_a: "foo,bar";
+/import/ base_b: "foo,baz";
+
+/ {
+	prop = <0x01>;
+};
tests/metadata_importsyms.dtb.expect new file +8 -0
new file mode 100644
index 0000000..2177026
@@ -0,0 +1,8 @@
+/dts-v1/;
+/addon/;
+
+/ {
+    prop = <0x00000001>;
+};
+// [FDT_IMPORT_SYM] 'base_a' (foo,bar)
+// [FDT_IMPORT_SYM] 'base_b' (foo,baz)
tests/metadata_importsyms.dts new file +14 -0
new file mode 100644
index 0000000..671586d
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
+/*
+ * Copyright (C) 2026 Bootlin
+ */
+
+/dts-v1/;
+/addon/;
+
+/import/ base_a: "foo,bar";
+/import/ base_b: "foo,baz";
+
+/ {
+	prop = <1>;
+};
tests/metadata_importsyms.dts.dts.expect new file +9 -0
new file mode 100644
index 0000000..eabf8c7
@@ -0,0 +1,9 @@
+/dts-v1/;
+/addon/;
+
+/import/ base_a: "foo,bar";
+/import/ base_b: "foo,baz";
+
+/ {
+	prop = <0x01>;
+};
tests/run_tests.sh +5 -5
index 1973525..5368db9 100755
@@ -1127,20 +1127,20 @@ wrap_fdtdump () {
 metadata_tests() {
 	for dt in metadata_reflocal metadata_refphandle \
 		  metadata_addon_base metadata_exportsyms_local \
-		  metadata_exportsyms_ref; do
+		  metadata_exportsyms_ref metadata_importsyms; do
 		run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts"
 		base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect"
 		run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts"
 		base_run_test wrap_fdtdump $dt.dtb $dt.dtb.out
-		# Remove unneeded comments
-		sed -i '/^\/\/ /d' $dt.dtb.out
+		# Remove unneeded comments, keep comments in the form '// [xxxx'
+		sed -i '/^\/\/ [^\[]/d' $dt.dtb.out
 		base_run_test check_diff $dt.dtb.out "$SRCDIR/$dt.dtb.expect"
 		run_dtc_test -I dtb -O dts -o $dt.dtb.dts $dt.dtb
 		base_run_test check_diff $dt.dtb.dts "$SRCDIR/$dt.dtb.dts.expect"
 		run_dtc_test -I dts -O dtb -o $dt.dtb.dts.dtb $dt.dtb.dts
 		base_run_test wrap_fdtdump $dt.dtb.dts.dtb $dt.dtb.dts.dtb.out
-		# Remove unneeded comments
-		sed -i '/^\/\/ /d' $dt.dtb.dts.dtb.out
+		# Remove unneeded comments, keep comments in the form '// [xxxx'
+		sed -i '/^\/\/ [^\[]/d' $dt.dtb.dts.dtb.out
 		base_run_test check_diff $dt.dtb.dts.dtb.out "$SRCDIR/$dt.dtb.expect"
 	done
 
Signature · 1 line
2.52.0
#95 lore raw

RFC PATCH 37/77 dtc: Add support for import symbols sorting

In reply to Herve Codina

dtc can sort items when the command line --sort option is set.

Add support for import symbols sorting when this option is used.

---
 livetree.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
livetree.c +27 -0
index dac5359..285f6e1 100644
@@ -1014,9 +1014,36 @@ static void sort_node(struct node *node)
 		sort_node(c);
 }
 
+static void sort_importsyms(struct dt_info *dti)
+{
+	int n = 0, i = 0;
+	struct symbol *symbol, **tbl;
+
+	for_each_symbol(dti->importsymlist, symbol)
+		n++;
+
+	if (n == 0)
+		return;
+
+	tbl = xmalloc(n * sizeof(*tbl));
+
+	for_each_symbol(dti->importsymlist, symbol)
+		tbl[i++] = symbol;
+
+	qsort(tbl, n, sizeof(*tbl), cmp_symbol);
+
+	dti->importsymlist = tbl[0];
+	for (i = 0; i < (n-1); i++)
+		tbl[i]->next = tbl[i+1];
+	tbl[n-1]->next = NULL;
+
+	free(tbl);
+}
+
 void sort_tree(struct dt_info *dti)
 {
 	sort_reserve_entries(dti);
+	sort_importsyms(dti);
 	sort_node(dti->dt);
 }
 
Signature · 1 line
2.52.0
#96 lore raw

RFC PATCH 38/77 tests: metadata: Improve sort test to check for import symbols sorting

In reply to Herve Codina

dtc is able to sort the import symbols list when the --sort option is used.

Improve the metadata sort test to perform a check for this feature.

---
 tests/metadata_sort.dtb.dts.expect | 4 ++++
 tests/metadata_sort.dtb.expect     | 3 +++
 tests/metadata_sort.dts            | 4 ++++
 tests/run_tests.sh                 | 4 ++--
 4 files changed, 13 insertions(+), 2 deletions(-)
tests/metadata_sort.dtb.dts.expect +4 -0
index f07a42b..270c06d 100644
@@ -1,6 +1,10 @@
 /dts-v1/;
 /addon/;
 
+/import/ abc: "foo,bar";
+/import/ de1: "foo,bar";
+/import/ de2: "foo,bar";
+
 / {
 
 	node-a {
tests/metadata_sort.dtb.expect +3 -0
index 7856894..0dacab7 100644
@@ -13,3 +13,6 @@
         phandle = <0x00000001>;
     };
 };
+// [FDT_IMPORT_SYM] 'abc' (foo,bar)
+// [FDT_IMPORT_SYM] 'de1' (foo,bar)
+// [FDT_IMPORT_SYM] 'de2' (foo,bar)
tests/metadata_sort.dts +4 -0
index 7d1cca7..e523e20 100644
@@ -6,6 +6,10 @@
 /dts-v1/;
 /addon/;
 
+/import/ de1: "foo,bar";
+/import/ abc: "foo,bar";
+/import/ de2: "foo,bar";
+
 / {
 	node_b: node-b {
 	};
tests/run_tests.sh +2 -2
index 5368db9..a5e31df 100755
@@ -1158,8 +1158,8 @@ metadata_tests() {
 
 	run_dtc_test -I dts -O dtb -s -o metadata_sort.dtb "$SRCDIR/metadata_sort.dts"
 	base_run_test wrap_fdtdump metadata_sort.dtb metadata_sort.dtb.out
-	# Remove unneeded comments
-	sed -i '/^\/\/ /d' metadata_sort.dtb.out
+	# Remove unneeded comments, keep comments in the form '// [xxxx'
+	sed -i '/^\/\/ [^\[]/d' metadata_sort.dtb.out
 	base_run_test check_diff metadata_sort.dtb.out "$SRCDIR/metadata_sort.dtb.expect"
 	run_dtc_test -I dtb -O dts -o metadata_sort.dtb.dts metadata_sort.dtb
 	base_run_test check_diff metadata_sort.dtb.dts "$SRCDIR/metadata_sort.dtb.dts.expect"
Signature · 1 line
2.52.0
#97 lore raw

RFC PATCH 39/77 check: Get 'chosen' node using get_subnode()

In reply to Herve Codina

get_node_by_path() is going to be replaced by a more generic function in order to handle orphan node support for addon device-tree.

The 'chosen' node is a subnode of the root node and can perfectly be retrieved using get_subnode().

In preparation of the future change related to get_node_by_path(), replace its usage to get the 'chosen' node by call to get_subnode().

The modification doesn't introduce any functional changes.

---
 checks.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
checks.c +1 -2
index d1e215e..9744431 100644
@@ -1341,8 +1341,7 @@ static void check_obsolete_chosen_interrupt_controller(struct check *c,
 	if (node != dt)
 		return;
 
-
-	chosen = get_node_by_path(dt, "/chosen");
+	chosen = get_subnode(dt, "chosen");
 	if (!chosen)
 		return;
 
Signature · 1 line
2.52.0
#98 lore raw

RFC PATCH 40/77 dtc: Introduce dti_get_node_by_path()

In reply to Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree.

To prepare this change, introduce and use dti_get_node_by_path().

dti_get_node_by_path() retrieves a node by its path like get_node_by_path() but it works at the struct dt_info level.

It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced.

This introduction doesn't lead to any functional changes.

---
 checks.c   |  2 +-
 dtc.h      |  3 ++-
 livetree.c | 15 ++++++++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)
checks.c +1 -1
index 9744431..b2b1bf7 100644
@@ -740,7 +740,7 @@ static void check_alias_paths(struct check *c, struct dt_info *dti,
 
 		/* This check does not work for overlays nor addons with external paths */
 		if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)) &&
-		    (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val))) {
+		    (!prop->val.val || !dti_get_node_by_path(dti, prop->val.val))) {
 			FAIL_PROP(c, dti, node, prop, "aliases property is not a valid node (%s)",
 				  prop->val.val);
 			continue;
dtc.h +2 -1
index 4ebe576..8ba093f 100644
@@ -323,7 +323,6 @@ struct property *get_property_by_label(struct node *tree, const char *label,
 struct marker *get_marker_label(struct node *tree, const char *label,
 				struct node **node, struct property **prop);
 struct node *get_subnode(struct node *node, const char *nodename);
-struct node *get_node_by_path(struct node *tree, const char *path);
 struct node *get_node_by_label(struct node *tree, const char *label);
 struct node *get_node_by_phandle(struct node *tree, cell_t phandle);
 struct node *get_node_by_ref(struct node *tree, const char *ref);
@@ -357,6 +356,8 @@ struct dt_info {
 	const char *outname;		/* filename being written to, "-" for stdout */
 };
 
+struct node *dti_get_node_by_path(struct dt_info *dti, const char *path);
+
 /* DTS version flags definitions */
 #define DTSF_V1		0x0001	/* /dts-v1/ */
 #define DTSF_PLUGIN	0x0002	/* /plugin/ */
livetree.c +14 -1
index 285f6e1..23ba957 100644
@@ -659,7 +659,7 @@ struct node *get_subnode(struct node *node, const char *nodename)
 	return NULL;
 }
 
-struct node *get_node_by_path(struct node *tree, const char *path)
+static struct node *get_node_by_path(struct node *tree, const char *path)
 {
 	const char *p;
 	struct node *child;
@@ -785,6 +785,19 @@ struct node *get_node_by_ref(struct node *tree, const char *ref)
 	return target;
 }
 
+struct node *dti_get_node_by_path(struct dt_info *dti, const char *path)
+{
+	struct node *node;
+
+	if (dti->dt) {
+		node = get_node_by_path(dti->dt, path);
+		if (node)
+			return node;
+	}
+
+	return NULL;
+}
+
 static void add_phandle_property(struct node *node,
 				 const char *name, int format)
 {
Signature · 1 line
2.52.0
#99 lore raw

Re: [RFC PATCH 40/77] dtc: Introduce dti_get_node_by_path()

Quoted 4 lines · Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

This doesn't make sense to me. The new function still just takes a single path, nothing to specify which tree that path is looked up in.

You can probably guarantee that labels and phandles are unique across all the trees. Not paths, though.

Quoted 93 lines

Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree.

To prepare this change, introduce and use dti_get_node_by_path().

dti_get_node_by_path() retrieves a node by its path like get_node_by_path() but it works at the struct dt_info level.

It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced.

This introduction doesn't lead to any functional changes.

---
 checks.c   |  2 +-
 dtc.h      |  3 ++-
 livetree.c | 15 ++++++++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)
checks.c +1 -1
index 9744431..b2b1bf7 100644
@@ -740,7 +740,7 @@ static void check_alias_paths(struct check *c, struct dt_info *dti,
 
 		/* This check does not work for overlays nor addons with external paths */
 		if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)) &&
-		    (!prop->val.val || !get_node_by_path(dti->dt, prop->val.val))) {
+		    (!prop->val.val || !dti_get_node_by_path(dti, prop->val.val))) {
 			FAIL_PROP(c, dti, node, prop, "aliases property is not a valid node (%s)",
 				  prop->val.val);
 			continue;
dtc.h +2 -1
index 4ebe576..8ba093f 100644
@@ -323,7 +323,6 @@ struct property *get_property_by_label(struct node *tree, const char *label,
 struct marker *get_marker_label(struct node *tree, const char *label,
 				struct node **node, struct property **prop);
 struct node *get_subnode(struct node *node, const char *nodename);
-struct node *get_node_by_path(struct node *tree, const char *path);
 struct node *get_node_by_label(struct node *tree, const char *label);
 struct node *get_node_by_phandle(struct node *tree, cell_t phandle);
 struct node *get_node_by_ref(struct node *tree, const char *ref);
@@ -357,6 +356,8 @@ struct dt_info {
 	const char *outname;		/* filename being written to, "-" for stdout */
 };
 
+struct node *dti_get_node_by_path(struct dt_info *dti, const char *path);
+
 /* DTS version flags definitions */
 #define DTSF_V1		0x0001	/* /dts-v1/ */
 #define DTSF_PLUGIN	0x0002	/* /plugin/ */
livetree.c +14 -1
index 285f6e1..23ba957 100644
@@ -659,7 +659,7 @@ struct node *get_subnode(struct node *node, const char *nodename)
 	return NULL;
 }
 
-struct node *get_node_by_path(struct node *tree, const char *path)
+static struct node *get_node_by_path(struct node *tree, const char *path)
 {
 	const char *p;
 	struct node *child;
@@ -785,6 +785,19 @@ struct node *get_node_by_ref(struct node *tree, const char *ref)
 	return target;
 }
 
+struct node *dti_get_node_by_path(struct dt_info *dti, const char *path)
+{
+	struct node *node;
+
+	if (dti->dt) {
+		node = get_node_by_path(dti->dt, path);
+		if (node)
+			return node;
+	}
+
+	return NULL;
+}
+
 static void add_phandle_property(struct node *node,
 				 const char *name, int format)
 {
Signature · 1 line
2.52.0
Signature · 4 lines
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
#100 lore raw

Re: [RFC PATCH 40/77] dtc: Introduce dti_get_node_by_path()

Hi David,

Quoted 6 lines · On Thu, 15 Jan 2026 17:47:29 +1100 David Gibson <[email protected]>…
Quoted 4 lines · Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

Quoted 6 lines

This doesn't make sense to me. The new function still just takes a single path, nothing to specify which tree that path is looked up in.

You can probably guarantee that labels and phandles are unique across all the trees. Not paths, though.

Paths can be unique across all trees. The tree needs to be indicated in the path. Starting by '/' is the root tree.

For orphans, I proposed "$<orphan_name>/<path>" in patch 64 introducing references by path for orphan nodes and so, for orphan trees.

Best regards,
Hervé

#101 lore raw

Re: [RFC PATCH 40/77] dtc: Introduce dti_get_node_by_path()

Quoted 14 lines · Herve Codina

Hi David,

Quoted 9 lines · On Thu, 15 Jan 2026 17:47:29 +1100 David Gibson <[email protected]>…
Quoted 4 lines · Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

This doesn't make sense to me. The new function still just takes a single path, nothing to specify which tree that path is looked up in.

Quoted 6 lines
Quoted 3 lines

You can probably guarantee that labels and phandles are unique across all the trees. Not paths, though.

Paths can be unique across all trees. The tree needs to be indicated in the path. Starting by '/' is the root tree.

Oh, ok. That wasn't clear from this patch, and I must have missed it in my cursory look at the later patches. I had the mistaken impression this just looked for the same path in each orphan tree.

Quoted 6 lines

For orphans, I proposed "$<orphan_name>/<path>" in patch 64 introducing references by path for orphan nodes and so, for orphan trees.

Best regards,
Hervé

Signature · 4 lines
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
#102 lore raw

RFC PATCH 41/77 dtc: Introduce dti_get_node_by_label()

In reply to Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree.

To prepare this change, introduce and use dti_get_node_by_label().

dti_get_node_by_label() retrieves a node by its label like get_node_by_label() but it works at the struct dt_info level.

It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced.

This introduction doesn't lead to any functional changes.

---
 checks.c   |  2 +-
 dtc.h      |  2 +-
 livetree.c | 15 ++++++++++++++-
 3 files changed, 16 insertions(+), 3 deletions(-)
checks.c +1 -1
index b2b1bf7..a76e96a 100644
@@ -444,7 +444,7 @@ static void check_duplicate_label(struct check *c, struct dt_info *dti,
 	struct property *otherprop = NULL;
 	struct marker *othermark = NULL;
 
-	othernode = get_node_by_label(dt, label);
+	othernode = dti_get_node_by_label(dti, label);
 
 	if (!othernode)
 		otherprop = get_property_by_label(dt, label, &othernode);
dtc.h +1 -1
index 8ba093f..3dce237 100644
@@ -323,7 +323,6 @@ struct property *get_property_by_label(struct node *tree, const char *label,
 struct marker *get_marker_label(struct node *tree, const char *label,
 				struct node **node, struct property **prop);
 struct node *get_subnode(struct node *node, const char *nodename);
-struct node *get_node_by_label(struct node *tree, const char *label);
 struct node *get_node_by_phandle(struct node *tree, cell_t phandle);
 struct node *get_node_by_ref(struct node *tree, const char *ref);
 cell_t get_node_phandle(struct node *root, struct node *node);
@@ -357,6 +356,7 @@ struct dt_info {
 };
 
 struct node *dti_get_node_by_path(struct dt_info *dti, const char *path);
+struct node *dti_get_node_by_label(struct dt_info *dti, const char *label);
 
 /* DTS version flags definitions */
 #define DTSF_V1		0x0001	/* /dts-v1/ */
livetree.c +14 -1
index 23ba957..771ff3d 100644
@@ -685,7 +685,7 @@ static struct node *get_node_by_path(struct node *tree, const char *path)
 	return NULL;
 }
 
-struct node *get_node_by_label(struct node *tree, const char *label)
+static struct node *get_node_by_label(struct node *tree, const char *label)
 {
 	struct node *child, *node;
 	struct label *l;
@@ -798,6 +798,19 @@ struct node *dti_get_node_by_path(struct dt_info *dti, const char *path)
 	return NULL;
 }
 
+struct node *dti_get_node_by_label(struct dt_info *dti, const char *label)
+{
+	struct node *node;
+
+	if (dti->dt) {
+		node = get_node_by_label(dti->dt, label);
+		if (node)
+			return node;
+	}
+
+	return NULL;
+}
+
 static void add_phandle_property(struct node *node,
 				 const char *name, int format)
 {
Signature · 1 line
2.52.0
#103 lore raw

RFC PATCH 42/77 dtc: Introduce dti_get_node_by_phandle()

In reply to Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree.

To prepare this change, introduce and use dti_get_node_by_phandle().

dti_get_node_by_phandle() retrieves a node by its phandle value like get_node_by_phandle() but it works at the struct dt_info level.

It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced.

This introduction doesn't lead to any functional changes.

---
 checks.c   | 14 +++++---------
 dtc.h      |  2 +-
 livetree.c | 19 ++++++++++++++++---
 3 files changed, 22 insertions(+), 13 deletions(-)
checks.c +5 -9
index a76e96a..fd22524 100644
@@ -533,7 +533,6 @@ static cell_t check_phandle_prop(struct check *c, struct dt_info *dti,
 static void check_explicit_phandles(struct check *c, struct dt_info *dti,
 				    struct node *node)
 {
-	struct node *root = dti->dt;
 	struct node *other;
 	cell_t phandle, linux_phandle;
 
@@ -555,7 +554,7 @@ static void check_explicit_phandles(struct check *c, struct dt_info *dti,
 	if (linux_phandle && !phandle)
 		phandle = linux_phandle;
 
-	other = get_node_by_phandle(root, phandle);
+	other = dti_get_node_by_phandle(dti, phandle);
 	if (other && (other != node)) {
 		FAIL(c, dti, node, "duplicated phandle 0x%x (seen before at %s)",
 		     phandle, other->fullpath);
@@ -1414,7 +1413,6 @@ static void check_property_phandle_args(struct check *c,
 					struct property *prop,
 					const struct provider *provider)
 {
-	struct node *root = dti->dt;
 	unsigned int cell, cellsize = 0;
 
 	if (!is_multiple_of(prop->val.len, sizeof(cell_t))) {
@@ -1457,7 +1455,7 @@ static void check_property_phandle_args(struct check *c,
 					  cell);
 		}
 
-		provider_node = get_node_by_phandle(root, phandle);
+		provider_node = dti_get_node_by_phandle(dti, phandle);
 		if (!provider_node) {
 			FAIL_PROP(c, dti, node, prop,
 				  "Could not get phandle node for (cell %d)",
@@ -1624,7 +1622,6 @@ static void check_interrupt_map(struct check *c,
 				struct dt_info *dti,
 				struct node *node)
 {
-	struct node *root = dti->dt;
 	struct property *prop, *irq_map_prop;
 	size_t cellsize, cell, map_cells;
 
@@ -1678,7 +1675,7 @@ static void check_interrupt_map(struct check *c,
 			break;
 		}
 
-		provider_node = get_node_by_phandle(root, phandle);
+		provider_node = dti_get_node_by_phandle(dti, phandle);
 		if (!provider_node) {
 			FAIL_PROP(c, dti, node, irq_map_prop,
 				  "Could not get phandle(%d) node for (cell %zu)",
@@ -1716,7 +1713,6 @@ static void check_interrupts_property(struct check *c,
 				      struct dt_info *dti,
 				      struct node *node)
 {
-	struct node *root = dti->dt;
 	struct node *irq_node = NULL, *parent = node;
 	struct property *irq_prop, *prop = NULL;
 	cell_t irq_cells, phandle;
@@ -1747,7 +1743,7 @@ static void check_interrupts_property(struct check *c,
 				continue;
 			}
 
-			irq_node = get_node_by_phandle(root, phandle);
+			irq_node = dti_get_node_by_phandle(dti, phandle);
 			if (!irq_node) {
 				FAIL_PROP(c, dti, parent, prop, "Bad phandle");
 				return;
@@ -1882,7 +1878,7 @@ static struct node *get_remote_endpoint(struct check *c, struct dt_info *dti,
 	if (!phandle_is_valid(phandle))
 		return NULL;
 
-	node = get_node_by_phandle(dti->dt, phandle);
+	node = dti_get_node_by_phandle(dti, phandle);
 	if (!node)
 		FAIL_PROP(c, dti, endpoint, prop, "graph phandle is not valid");
 
dtc.h +1 -1
index 3dce237..7d53fcb 100644
@@ -323,7 +323,6 @@ struct property *get_property_by_label(struct node *tree, const char *label,
 struct marker *get_marker_label(struct node *tree, const char *label,
 				struct node **node, struct property **prop);
 struct node *get_subnode(struct node *node, const char *nodename);
-struct node *get_node_by_phandle(struct node *tree, cell_t phandle);
 struct node *get_node_by_ref(struct node *tree, const char *ref);
 cell_t get_node_phandle(struct node *root, struct node *node);
 
@@ -357,6 +356,7 @@ struct dt_info {
 
 struct node *dti_get_node_by_path(struct dt_info *dti, const char *path);
 struct node *dti_get_node_by_label(struct dt_info *dti, const char *label);
+struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle);
 
 /* DTS version flags definitions */
 #define DTSF_V1		0x0001	/* /dts-v1/ */
livetree.c +16 -3
index 771ff3d..a551307 100644
@@ -722,7 +722,7 @@ static cell_t get_node_phandle_existing(struct node *node)
 	return propval_cell(prop);
 }
 
-struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
+static struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
 {
 	struct node *child, *node;
 	cell_t tree_phandle;
@@ -811,6 +811,19 @@ struct node *dti_get_node_by_label(struct dt_info *dti, const char *label)
 	return NULL;
 }
 
+struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle)
+{
+	struct node *node;
+
+	if (dti->dt) {
+		node = get_node_by_phandle(dti->dt, phandle);
+		if (node)
+			return node;
+	}
+
+	return NULL;
+}
+
 static void add_phandle_property(struct node *node,
 				 const char *name, int format)
 {
@@ -1362,7 +1375,7 @@ static void update_phandles_ref_internal(struct dt_info *dti, struct node *node)
 			if (m->is_local) {
 				phandle = propval_cell_n(prop,
 							 m->offset / sizeof(cell_t));
-				refnode = get_node_by_phandle(dti->dt, phandle);
+				refnode = dti_get_node_by_phandle(dti, phandle);
 				if (!refnode)
 					die("Node not found for phandle 0x%"PRIx32"\n", phandle);
 
@@ -1420,7 +1433,7 @@ static void update_exports_ref_internal(struct dt_info *dti, struct node *node)
 			continue;
 
 		if (exportsym->is_local) {
-			refnode = get_node_by_phandle(dti->dt, exportsym->phandle);
+			refnode = dti_get_node_by_phandle(dti, exportsym->phandle);
 			if (!refnode)
 				die("Node not found for phandle 0x%"PRIx32"\n", exportsym->phandle);
 
Signature · 1 line
2.52.0
#104 lore raw

RFC PATCH 43/77 dtc: Introduce dti_get_node_by_ref()

In reply to Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree.

To prepare this change, introduce and use dti_get_node_by_ref().

dti_get_node_by_ref() retrieves a node by a reference (a label or a path) like get_node_by_ref() but it works at the struct dt_info level.

It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced.

This introduction doesn't lead to any functional changes.

---
 checks.c     | 10 ++++------
 dtc-parser.y | 22 +++++++++++++++++-----
 dtc.h        |  2 +-
 livetree.c   | 19 ++++++++++++++++---
 4 files changed, 38 insertions(+), 15 deletions(-)
checks.c +4 -6
index fd22524..a47870d 100644
@@ -486,7 +486,6 @@ ERROR(duplicate_label, check_duplicate_label_node, NULL);
 static cell_t check_phandle_prop(struct check *c, struct dt_info *dti,
 				 struct node *node, const char *propname)
 {
-	struct node *root = dti->dt;
 	struct property *prop;
 	struct marker *m;
 	cell_t phandle;
@@ -504,7 +503,7 @@ static cell_t check_phandle_prop(struct check *c, struct dt_info *dti,
 	m = prop->val.markers;
 	for_each_marker_of_type(m, REF_PHANDLE) {
 		assert(m->offset == 0);
-		if (node != get_node_by_ref(root, m->ref))
+		if (node != dti_get_node_by_ref(dti, m->ref))
 			/* "Set this node's phandle equal to some
 			 * other node's phandle".  That's nonsensical
 			 * by construction. */ {
@@ -614,7 +613,7 @@ static void fixup_phandle_references(struct check *c, struct dt_info *dti,
 		for_each_marker_of_type(m, REF_PHANDLE) {
 			assert(m->offset + sizeof(cell_t) <= prop->val.len);
 
-			refnode = get_node_by_ref(dt, m->ref);
+			refnode = dti_get_node_by_ref(dti, m->ref);
 			if (! refnode) {
 				if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON)))
 					FAIL(c, dti, node, "Reference to non-existent node or "
@@ -633,7 +632,7 @@ static void fixup_phandle_references(struct check *c, struct dt_info *dti,
 	}
 
 	for_each_symbol(node->exportsymlist, exportsym) {
-		refnode = get_node_by_ref(dt, exportsym->ref);
+		refnode = dti_get_node_by_ref(dti, exportsym->ref);
 		if (!refnode) {
 			if (!(dti->dtsflags & (DTSF_PLUGIN | DTSF_ADDON))) {
 				FAIL(c, dti, node,
@@ -657,7 +656,6 @@ ERROR(phandle_references, fixup_phandle_references, NULL,
 static void fixup_path_references(struct check *c, struct dt_info *dti,
 				  struct node *node)
 {
-	struct node *dt = dti->dt;
 	struct property *prop;
 
 	for_each_property(node, prop) {
@@ -668,7 +666,7 @@ static void fixup_path_references(struct check *c, struct dt_info *dti,
 		for_each_marker_of_type(m, REF_PATH) {
 			assert(m->offset <= prop->val.len);
 
-			refnode = get_node_by_ref(dt, m->ref);
+			refnode = dti_get_node_by_ref(dti, m->ref);
 			if (!refnode) {
 				FAIL(c, dti, node, "Reference to non-existent node or label \"%s\"\n",
 				     m->ref);
dtc-parser.y +17 -5
index 61ebde2..08b3642 100644
@@ -31,6 +31,18 @@ static bool is_ref_relative(const char *ref)
 	return ref[0] != '/' && strchr(&ref[1], '/');
 }
 
+static struct node *parser_get_node_by_ref(struct node *dt, const char *ref)
+{
+	/*
+	 * Use a temporary dt_info in order to use dti_get_node_by_ref()
+	 */
+	struct dt_info dti = {};
+
+	dti.dt = dt;
+
+	return dti_get_node_by_ref(&dti, ref);
+}
+
 %}
 
 %union {
@@ -240,7 +252,7 @@ devicetree:
 		}
 	| devicetree DT_LABEL dt_ref nodedef
 		{
-			struct node *target = get_node_by_ref($1, $3);
+			struct node *target = parser_get_node_by_ref($1, $3);
 
 			if ((last_header_flags & DTSF_PLUGIN) && is_ref_relative($3))
 				ERROR(&@2, "Label-relative reference %s not supported in plugin", $3);
@@ -259,7 +271,7 @@ devicetree:
 					ERROR(&@2, "Label-relative reference %s not supported in plugin", $2);
 				add_orphan_node($1, $3, $2);
 			} else {
-				struct node *target = get_node_by_ref($1, $2);
+				struct node *target = parser_get_node_by_ref($1, $2);
 
 				if (target)
 					merge_nodes(target, $3);
@@ -270,7 +282,7 @@ devicetree:
 		}
 	| devicetree DT_LABEL_REF nodedef
 		{
-			struct node *target = get_node_by_ref($1, $2);
+			struct node *target = parser_get_node_by_ref($1, $2);
 
 			if (target) {
 				merge_nodes(target, $3);
@@ -284,7 +296,7 @@ devicetree:
 		}
 	| devicetree DT_DEL_NODE dt_ref ';'
 		{
-			struct node *target = get_node_by_ref($1, $3);
+			struct node *target = parser_get_node_by_ref($1, $3);
 
 			if (target)
 				delete_node(target);
@@ -296,7 +308,7 @@ devicetree:
 		}
 	| devicetree DT_OMIT_NO_REF dt_ref ';'
 		{
-			struct node *target = get_node_by_ref($1, $3);
+			struct node *target = parser_get_node_by_ref($1, $3);
 
 			if (target)
 				omit_node_if_unused(target);
dtc.h +1 -1
index 7d53fcb..832265c 100644
@@ -323,7 +323,6 @@ struct property *get_property_by_label(struct node *tree, const char *label,
 struct marker *get_marker_label(struct node *tree, const char *label,
 				struct node **node, struct property **prop);
 struct node *get_subnode(struct node *node, const char *nodename);
-struct node *get_node_by_ref(struct node *tree, const char *ref);
 cell_t get_node_phandle(struct node *root, struct node *node);
 
 uint32_t guess_boot_cpuid(struct node *tree);
@@ -357,6 +356,7 @@ struct dt_info {
 struct node *dti_get_node_by_path(struct dt_info *dti, const char *path);
 struct node *dti_get_node_by_label(struct dt_info *dti, const char *label);
 struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle);
+struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref);
 
 /* DTS version flags definitions */
 #define DTSF_V1		0x0001	/* /dts-v1/ */
livetree.c +16 -3
index a551307..f1c7e27 100644
@@ -748,7 +748,7 @@ static struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
 	return NULL;
 }
 
-struct node *get_node_by_ref(struct node *tree, const char *ref)
+static struct node *get_node_by_ref(struct node *tree, const char *ref)
 {
 	struct node *target = tree;
 	const char *label = NULL, *path = NULL;
@@ -824,6 +824,19 @@ struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle)
 	return NULL;
 }
 
+struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref)
+{
+	struct node *node;
+
+	if (dti->dt) {
+		node = get_node_by_ref(dti->dt, ref);
+		if (node)
+			return node;
+	}
+
+	return NULL;
+}
+
 static void add_phandle_property(struct node *node,
 				 const char *name, int format)
 {
@@ -1407,7 +1420,7 @@ static void mark_local_phandles_internal(struct dt_info *dti,
 	for_each_property(node, prop) {
 		m = prop->val.markers;
 		for_each_marker_of_type(m, REF_PHANDLE) {
-			refnode = get_node_by_ref(dti->dt, m->ref);
+			refnode = dti_get_node_by_ref(dti, m->ref);
 			if (refnode)
 				m->is_local = true;
 		}
@@ -1460,7 +1473,7 @@ static void mark_local_exports_internal(struct dt_info *dti,
 	struct node *refnode;
 
 	for_each_symbol(node->exportsymlist, exportsym) {
-		refnode = get_node_by_ref(dti->dt, exportsym->ref);
+		refnode = dti_get_node_by_ref(dti, exportsym->ref);
 		if (refnode)
 			exportsym->is_local = true;
 	}
Signature · 1 line
2.52.0
#105 lore raw

RFC PATCH 44/77 dtc: Introduce dti_get_node_phandle()

In reply to Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree.

To prepare this change, introduce and use dti_get_node_phandle().

dti_get_node_phandle() get the phandle value related to a node and allocate a new value if the node doesn't have yet a phandle value.

It behaves in the same way as get_node_phandle() but it works at the struct dt_info level.

It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced.

This introduction doesn't lead to any functional changes.

---
 checks.c   | 5 ++---
 dtc.h      | 2 +-
 livetree.c | 7 +++----
 3 files changed, 6 insertions(+), 8 deletions(-)
checks.c +2 -3
index a47870d..7dd5032 100644
@@ -601,7 +601,6 @@ ERROR(name_properties, check_name_properties, NULL, &name_is_string);
 static void fixup_phandle_references(struct check *c, struct dt_info *dti,
 				     struct node *node)
 {
-	struct node *dt = dti->dt;
 	struct symbol *exportsym;
 	struct property *prop;
 	struct node *refnode;
@@ -624,7 +623,7 @@ static void fixup_phandle_references(struct check *c, struct dt_info *dti,
 				continue;
 			}
 
-			phandle = get_node_phandle(dt, refnode);
+			phandle = dti_get_node_phandle(dti, refnode);
 			*((fdt32_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
 
 			reference_node(refnode);
@@ -644,7 +643,7 @@ static void fixup_phandle_references(struct check *c, struct dt_info *dti,
 		}
 
 		/* Create the phandle property for this referenced node */
-		phandle = get_node_phandle(dt, refnode);
+		phandle = dti_get_node_phandle(dti, refnode);
 		exportsym->phandle = phandle;
 
 		reference_node(refnode);
dtc.h +1 -1
index 832265c..f7b0b23 100644
@@ -323,7 +323,6 @@ struct property *get_property_by_label(struct node *tree, const char *label,
 struct marker *get_marker_label(struct node *tree, const char *label,
 				struct node **node, struct property **prop);
 struct node *get_subnode(struct node *node, const char *nodename);
-cell_t get_node_phandle(struct node *root, struct node *node);
 
 uint32_t guess_boot_cpuid(struct node *tree);
 
@@ -357,6 +356,7 @@ struct node *dti_get_node_by_path(struct dt_info *dti, const char *path);
 struct node *dti_get_node_by_label(struct dt_info *dti, const char *label);
 struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle);
 struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref);
+cell_t dti_get_node_phandle(struct dt_info *dti, struct node *node);
 
 /* DTS version flags definitions */
 #define DTSF_V1		0x0001	/* /dts-v1/ */
livetree.c +3 -4
index f1c7e27..a4917d1 100644
@@ -853,14 +853,14 @@ static void add_phandle_property(struct node *node,
 	add_property(node, build_property(name, d, NULL));
 }
 
-cell_t get_node_phandle(struct node *root, struct node *node)
+cell_t dti_get_node_phandle(struct dt_info *dti, struct node *node)
 {
 	static cell_t phandle = 1; /* FIXME: ick, static local */
 
 	if (phandle_is_valid(node->phandle))
 		return node->phandle;
 
-	while (get_node_by_phandle(root, phandle))
+	while (dti_get_node_by_phandle(dti, phandle))
 		phandle++;
 
 	node->phandle = phandle;
@@ -1143,7 +1143,6 @@ static void generate_label_tree_internal(struct dt_info *dti,
 					 struct node *an, struct node *node,
 					 bool allocph)
 {
-	struct node *dt = dti->dt;
 	struct node *c;
 	struct property *p;
 	struct label *l;
@@ -1173,7 +1172,7 @@ static void generate_label_tree_internal(struct dt_info *dti,
 
 		/* force allocation of a phandle for this node */
 		if (allocph)
-			(void)get_node_phandle(dt, node);
+			(void)dti_get_node_phandle(dti, node);
 	}
 
 	for_each_child(node, c)
Signature · 1 line
2.52.0
#106 lore raw

RFC PATCH 45/77 dtc: Introduce dti_get_property_by_label()

In reply to Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree.

To prepare this change, introduce and use dti_get_property_by_label().

dti_get_property_by_label() retrieves a property (and the related node) by its label like get_property_by_label() but it works at the struct dt_info level.

It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced.

This introduction doesn't lead to any functional changes.

---
 checks.c   |  2 +-
 dtc.h      |  5 +++--
 livetree.c | 18 +++++++++++++++++-
 3 files changed, 21 insertions(+), 4 deletions(-)
checks.c +1 -1
index 7dd5032..75040c0 100644
@@ -447,7 +447,7 @@ static void check_duplicate_label(struct check *c, struct dt_info *dti,
 	othernode = dti_get_node_by_label(dti, label);
 
 	if (!othernode)
-		otherprop = get_property_by_label(dt, label, &othernode);
+		otherprop = dti_get_property_by_label(dti, label, &othernode);
 	if (!othernode)
 		othermark = get_marker_label(dt, label, &othernode,
 					       &otherprop);
dtc.h +3 -2
index f7b0b23..399e7fa 100644
@@ -318,8 +318,6 @@ const char *get_unitname(struct node *node);
 struct property *get_property(struct node *node, const char *propname);
 cell_t propval_cell(struct property *prop);
 cell_t propval_cell_n(struct property *prop, unsigned int n);
-struct property *get_property_by_label(struct node *tree, const char *label,
-				       struct node **node);
 struct marker *get_marker_label(struct node *tree, const char *label,
 				struct node **node, struct property **prop);
 struct node *get_subnode(struct node *node, const char *nodename);
@@ -357,6 +355,9 @@ struct node *dti_get_node_by_label(struct dt_info *dti, const char *label);
 struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle);
 struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref);
 cell_t dti_get_node_phandle(struct dt_info *dti, struct node *node);
+struct property *dti_get_property_by_label(struct dt_info *dti,
+					   const char *label,
+					   struct node **node);
 
 /* DTS version flags definitions */
 #define DTSF_V1		0x0001	/* /dts-v1/ */
livetree.c +17 -1
index a4917d1..d023075 100644
@@ -594,7 +594,7 @@ cell_t propval_cell_n(struct property *prop, unsigned int n)
 	return fdt32_to_cpu(*((fdt32_t *)prop->val.val + n));
 }
 
-struct property *get_property_by_label(struct node *tree, const char *label,
+static struct property *get_property_by_label(struct node *tree, const char *label,
 				       struct node **node)
 {
 	struct property *prop;
@@ -837,6 +837,22 @@ struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref)
 	return NULL;
 }
 
+struct property *dti_get_property_by_label(struct dt_info *dti,
+					   const char *label,
+					   struct node **node)
+{
+	struct property *property;
+
+	if (dti->dt) {
+		property = get_property_by_label(dti->dt, label, node);
+		if (property)
+			return property;
+	}
+
+	*node = NULL;
+	return NULL;
+}
+
 static void add_phandle_property(struct node *node,
 				 const char *name, int format)
 {
Signature · 1 line
2.52.0
#107 lore raw

RFC PATCH 46/77 dtc: Introduce dti_get_marker_label()

In reply to Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree.

To prepare this change, introduce and use dti_get_marker_label().

dti_get_marker_label() retrieves a marker and its related node and property based on the label value. It behaves in the same way as get_marker_label() but it works at the struct dt_info level.

It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced.

This introduction doesn't lead to any functional changes.

---
 checks.c   |  5 ++---
 dtc.h      |  4 ++--
 livetree.c | 18 +++++++++++++++++-
 3 files changed, 21 insertions(+), 6 deletions(-)
checks.c +2 -3
index 75040c0..0a855f9 100644
@@ -439,7 +439,6 @@ static void check_duplicate_label(struct check *c, struct dt_info *dti,
 				  const char *label, struct node *node,
 				  struct property *prop, struct marker *mark)
 {
-	struct node *dt = dti->dt;
 	struct node *othernode = NULL;
 	struct property *otherprop = NULL;
 	struct marker *othermark = NULL;
@@ -449,8 +448,8 @@ static void check_duplicate_label(struct check *c, struct dt_info *dti,
 	if (!othernode)
 		otherprop = dti_get_property_by_label(dti, label, &othernode);
 	if (!othernode)
-		othermark = get_marker_label(dt, label, &othernode,
-					       &otherprop);
+		othermark = dti_get_marker_label(dti, label, &othernode,
+						 &otherprop);
 
 	if (!othernode)
 		return;
dtc.h +2 -2
index 399e7fa..d45a84c 100644
@@ -318,8 +318,6 @@ const char *get_unitname(struct node *node);
 struct property *get_property(struct node *node, const char *propname);
 cell_t propval_cell(struct property *prop);
 cell_t propval_cell_n(struct property *prop, unsigned int n);
-struct marker *get_marker_label(struct node *tree, const char *label,
-				struct node **node, struct property **prop);
 struct node *get_subnode(struct node *node, const char *nodename);
 
 uint32_t guess_boot_cpuid(struct node *tree);
@@ -358,6 +356,8 @@ cell_t dti_get_node_phandle(struct dt_info *dti, struct node *node);
 struct property *dti_get_property_by_label(struct dt_info *dti,
 					   const char *label,
 					   struct node **node);
+struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
+				    struct node **node, struct property **prop);
 
 /* DTS version flags definitions */
 #define DTSF_V1		0x0001	/* /dts-v1/ */
livetree.c +17 -1
index d023075..79f7b55 100644
@@ -620,7 +620,7 @@ static struct property *get_property_by_label(struct node *tree, const char *lab
 	return NULL;
 }
 
-struct marker *get_marker_label(struct node *tree, const char *label,
+static struct marker *get_marker_label(struct node *tree, const char *label,
 				struct node **node, struct property **prop)
 {
 	struct marker *m;
@@ -853,6 +853,22 @@ struct property *dti_get_property_by_label(struct dt_info *dti,
 	return NULL;
 }
 
+struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
+				    struct node **node, struct property **prop)
+{
+	struct marker *marker;
+
+	if (dti->dt) {
+		marker = get_marker_label(dti->dt, label, node, prop);
+		if (marker)
+			return marker;
+	}
+
+	*prop = NULL;
+	*node = NULL;
+	return NULL;
+}
+
 static void add_phandle_property(struct node *node,
 				 const char *name, int format)
 {
Signature · 1 line
2.52.0
#108 lore raw

Re: [RFC PATCH 46/77] dtc: Introduce dti_get_marker_label()

Quoted 11 lines · Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree.

To prepare this change, introduce and use dti_get_marker_label().

Quoted 8 lines

dti_get_marker_label() retrieves a marker and its related node and property based on the label value. It behaves in the same way as get_marker_label() but it works at the struct dt_info level.

It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced.

This introduction doesn't lead to any functional changes.

For all of these functions, if the new one is basically replacing the old one, don't change the name, just change the signature.

Quoted 93 lines
---
 checks.c   |  5 ++---
 dtc.h      |  4 ++--
 livetree.c | 18 +++++++++++++++++-
 3 files changed, 21 insertions(+), 6 deletions(-)
checks.c +2 -3
index 75040c0..0a855f9 100644
@@ -439,7 +439,6 @@ static void check_duplicate_label(struct check *c, struct dt_info *dti,
 				  const char *label, struct node *node,
 				  struct property *prop, struct marker *mark)
 {
-	struct node *dt = dti->dt;
 	struct node *othernode = NULL;
 	struct property *otherprop = NULL;
 	struct marker *othermark = NULL;
@@ -449,8 +448,8 @@ static void check_duplicate_label(struct check *c, struct dt_info *dti,
 	if (!othernode)
 		otherprop = dti_get_property_by_label(dti, label, &othernode);
 	if (!othernode)
-		othermark = get_marker_label(dt, label, &othernode,
-					       &otherprop);
+		othermark = dti_get_marker_label(dti, label, &othernode,
+						 &otherprop);
 
 	if (!othernode)
 		return;
dtc.h +2 -2
index 399e7fa..d45a84c 100644
@@ -318,8 +318,6 @@ const char *get_unitname(struct node *node);
 struct property *get_property(struct node *node, const char *propname);
 cell_t propval_cell(struct property *prop);
 cell_t propval_cell_n(struct property *prop, unsigned int n);
-struct marker *get_marker_label(struct node *tree, const char *label,
-				struct node **node, struct property **prop);
 struct node *get_subnode(struct node *node, const char *nodename);
 
 uint32_t guess_boot_cpuid(struct node *tree);
@@ -358,6 +356,8 @@ cell_t dti_get_node_phandle(struct dt_info *dti, struct node *node);
 struct property *dti_get_property_by_label(struct dt_info *dti,
 					   const char *label,
 					   struct node **node);
+struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
+				    struct node **node, struct property **prop);
 
 /* DTS version flags definitions */
 #define DTSF_V1		0x0001	/* /dts-v1/ */
livetree.c +17 -1
index d023075..79f7b55 100644
@@ -620,7 +620,7 @@ static struct property *get_property_by_label(struct node *tree, const char *lab
 	return NULL;
 }
 
-struct marker *get_marker_label(struct node *tree, const char *label,
+static struct marker *get_marker_label(struct node *tree, const char *label,
 				struct node **node, struct property **prop)
 {
 	struct marker *m;
@@ -853,6 +853,22 @@ struct property *dti_get_property_by_label(struct dt_info *dti,
 	return NULL;
 }
 
+struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
+				    struct node **node, struct property **prop)
+{
+	struct marker *marker;
+
+	if (dti->dt) {
+		marker = get_marker_label(dti->dt, label, node, prop);
+		if (marker)
+			return marker;
+	}
+
+	*prop = NULL;
+	*node = NULL;
+	return NULL;
+}
+
 static void add_phandle_property(struct node *node,
 				 const char *name, int format)
 {
Signature · 1 line
2.52.0
Signature · 4 lines
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
#109 lore raw

Re: [RFC PATCH 46/77] dtc: Introduce dti_get_marker_label()

Quoted 16 lines · On Thu, 15 Jan 2026 17:51:30 +1100 David Gibson <[email protected]>…
Quoted 15 lines · Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree.

To prepare this change, introduce and use dti_get_marker_label().

dti_get_marker_label() retrieves a marker and its related node and property based on the label value. It behaves in the same way as get_marker_label() but it works at the struct dt_info level.

Quoted 7 lines
Quoted 4 lines

It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced.

This introduction doesn't lead to any functional changes.

For all of these functions, if the new one is basically replacing the old one, don't change the name, just change the signature.

The old function is kept an used internally (move to static). It is not a simple replacement.

When I introduce orphan node later on, those dti_xxxx() functions call the old function multiple times. One call for the root tree and other calls for orphan trees.

But anyway, If you prefer keeping the old name with a new signature, I can do the following:
- move function_name() to __function_name()
- Update the function_name() signature and call __function_name().

Best regards
Hervé

#110 lore raw

Re: [RFC PATCH 46/77] dtc: Introduce dti_get_marker_label()

Quoted 22 lines · Herve Codina
Quoted 19 lines · On Thu, 15 Jan 2026 17:51:30 +1100 David Gibson <[email protected]>…
Quoted 18 lines · Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree.

To prepare this change, introduce and use dti_get_marker_label().

dti_get_marker_label() retrieves a marker and its related node and property based on the label value. It behaves in the same way as get_marker_label() but it works at the struct dt_info level.

It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

This introduction doesn't lead to any functional changes.

For all of these functions, if the new one is basically replacing the old one, don't change the name, just change the signature.

The old function is kept an used internally (move to static). It is not a simple replacement.

It's a replacement in the sense that all the existing callers are moving to the new function.

Quoted 8 lines

When I introduce orphan node later on, those dti_xxxx() functions call the old function multiple times. One call for the root tree and other calls for orphan trees.

But anyway, If you prefer keeping the old name with a new signature, I can do the following:
- move function_name() to __function_name()
- Update the function_name() signature and call __function_name().

That's a better plan. Except don't use __function_name(). _ prefixed names are reserved for the C library. Use a _ suffix instead (e.g. see fdt_get_property_by_offset_()).

Signature · 4 lines
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
#111 lore raw

RFC PATCH 47/77 dtc: Introduce dti_fill_fullpaths()

In reply to Herve Codina

The future introduction of orphan nodes for addons device-tree will lead to more than one tree in the addons data. Those trees will be:
- the classical root tree starting at the root node
- trees related to orphan nodes

Also, an addon device-tree can have only trees based on orphan nodes. In other words an addon device-tree is valid without having the classical 'root' tree.

To prepare this change, introduce and use dti_fill_fullpaths().

dti_fill_fullpaths() builds fullpaths of nodes available in a tree like fill_fullpaths() but it works at the struct dt_info level.

It handles the case where a 'root' device-tree is not present and will handle orphan nodes trees as soon as they will be introduced.

This introduction doesn't lead to any functional changes.

---
 dtc.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
dtc.c +8 -1
index e0a0b54..59f4d77 100644
@@ -45,6 +45,13 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
 		fill_fullpaths(child, tree->fullpath);
 }
 
+static void dti_fill_fullpaths(struct dt_info *dti)
+{
+	/* Fill fullpaths for the root node */
+	if (dti->dt)
+		fill_fullpaths(dti->dt, "");
+}
+
 /* Usage related data. */
 static const char usage_synopsis[] = "dtc [options] <input file>";
 static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@LAThv";
@@ -326,7 +333,7 @@ int main(int argc, char *argv[])
 	if (cmdline_boot_cpuid != -1)
 		dti->boot_cpuid_phys = cmdline_boot_cpuid;
 
-	fill_fullpaths(dti->dt, "");
+	dti_fill_fullpaths(dti);
 
 	/* on a plugin, generate by default */
 	if (dti->dtsflags & DTSF_PLUGIN) {
Signature · 1 line
2.52.0
#112 lore raw

RFC PATCH 48/77 dtc: Introduce orphan nodes

In reply to Herve Codina

Orphans nodes can be present in plugin and addon device-trees.

Those nodes are nodes without a parent. The root device-tree node is a particular orphan node and is not part of those 'orphan' nodes group.

The orphan nodes group is related to nodes identified by a reference in addons or plugins device-trees. For instance, the following node can be described in addons and plugins (overlay) device-trees:
--- 8< ---

   &foo {
	subnode {
		prop  = <1>;
	};

};
--- 8< ---

The foo referenced node described here has no parent. Indeed, it is not a child of the root node.

This kind of node is legit in plugins and addons device-tree in order to perform modification on existing node when the plugin or addon dtb is applied. The foo referenced node is an existing node in the base tree an the subnode node is added to the foo referenced node chen the dtb is applied. Even if foo itself doesn't exists in the plugin or addon device-tree, it needs to be referenced and modifications expected need to be described (new sub-node for instance).

In plugin dts, when a orphan node is parsed, the dts structure is changed and the orphan node is merged in the /fragment@n/__overlay__ node. The foo referenced node mentioned in the previous snippet is transformed to:
--- 8< ---

   / {
	fragment@0 {
		target = <&foo>;

		__overlay__ {
			subnode {
				prop = <0x01>;
			};
		};
	};

	__fixups__ {
		foo = "/fragment@0:target:0";
	};

};
--- 8< ---

With this mechanism, the orphan node itself doesn't exist anymore in resulting plugin dtb but the resulting device-tree contains meta-data mixed with pure 'device-tree' data.

Addons have been introduced to avoid this kind of mixing.

For addons, instead of changing the device-tree structure to add something similar to fragments and __overlay__ present in plugins, the orphan node will be present as a new dtb block and will be identified as orphan thanks to meta-data added in dtb.

Modification done in this commit doesn't add functional changes but just introduce orphan nodes entry points in data structures and functions in order to prepare future changes related to parsing/generating dts and dtb files.

---
 dtc-parser.y | 4 ++--
 dtc.h        | 7 ++++++-
 flattree.c   | 3 ++-
 fstree.c     | 3 ++-
 livetree.c   | 4 +++-
 5 files changed, 15 insertions(+), 6 deletions(-)
dtc-parser.y +2 -2
index 08b3642..626a232 100644
@@ -132,7 +132,7 @@ sourcefile:
 		{
 			parser_output = build_dt_info($1, $2, $3,
 			                              guess_boot_cpuid($3),
-						      NULL);
+						      NULL, NULL);
 		}
 	|  headers memreserves importlist devicetree
 		{
@@ -143,7 +143,7 @@ sourcefile:
 			 */
 			parser_output = build_dt_info($1, $2, $4,
 			                              $4 ? guess_boot_cpuid($4) : 0,
-			                              reverse_symbol($3));
+			                              reverse_symbol($3), NULL);
 		}
 	;
 
dtc.h +6 -1
index d45a84c..399beee 100644
@@ -277,6 +277,9 @@ struct node {
 #define for_each_symbol(s0, s) \
 	for ((s) = (s0); (s); (s) = (s)->next)
 
+#define for_each_orphan(o0, o) \
+	for ((o) = (o0); (o); (o) = (o)->next_sibling)
+
 void add_label(struct label **labels, char *label);
 void delete_labels(struct label **labels);
 
@@ -345,6 +348,7 @@ struct dt_info {
 	uint32_t boot_cpuid_phys;
 	struct node *dt;		/* the device tree */
 	struct symbol *importsymlist;	/* Import symbol list */
+	struct node *orphanlist;	/* orphan nodes list */
 	const char *outname;		/* filename being written to, "-" for stdout */
 };
 
@@ -367,7 +371,8 @@ struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
 struct dt_info *build_dt_info(unsigned int dtsflags,
 			      struct reserve_info *reservelist,
 			      struct node *tree, uint32_t boot_cpuid_phys,
-			      struct symbol *importsymlist);
+			      struct symbol *importsymlist,
+			      struct node *orphanlist);
 void sort_tree(struct dt_info *dti);
 void generate_label_tree(struct dt_info *dti, const char *name, bool allocph);
 void generate_fixups_tree(struct dt_info *dti, const char *name);
flattree.c +2 -1
index add02f0..412c7f8 100644
@@ -1171,5 +1171,6 @@ struct dt_info *dt_from_blob(const char *fname)
 
 	fclose(f);
 
-	return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_phys, importsymlist);
+	return build_dt_info(DTSF_V1 | dtsflags, reservelist, tree, boot_cpuid_phys,
+			     importsymlist, NULL);
 }
fstree.c +2 -1
index a6aaf1e..2be1ffa 100644
@@ -72,5 +72,6 @@ struct dt_info *dt_from_fs(const char *dirname)
 	tree = read_fstree(dirname);
 	tree = name_node(tree, "");
 
-	return build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree), NULL);
+	return build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree), NULL,
+			     NULL);
 }
livetree.c +3 -1
index 79f7b55..057997a 100644
@@ -545,7 +545,8 @@ struct reserve_info *add_reserve_entry(struct reserve_info *list,
 struct dt_info *build_dt_info(unsigned int dtsflags,
 			      struct reserve_info *reservelist,
 			      struct node *tree, uint32_t boot_cpuid_phys,
-			      struct symbol *importsymlist)
+			      struct symbol *importsymlist,
+			      struct node *orphanlist)
 {
 	struct dt_info *dti;
 
@@ -555,6 +556,7 @@ struct dt_info *build_dt_info(unsigned int dtsflags,
 	dti->dt = tree;
 	dti->boot_cpuid_phys = boot_cpuid_phys;
 	dti->importsymlist = importsymlist;
+	dti->orphanlist = orphanlist;
 
 	return dti;
 }
Signature · 1 line
2.52.0
#113 lore raw

RFC PATCH 49/77 dtc: Handle orphan nodes in dti_get_xxx_by_yyy()

In reply to Herve Codina

Orphan nodes have been introduced recently.

Retrieving a node, a property and/or a marker from an orphan node tree is perfectly legit.

Those retrievals are performed by the dti_get_xxx_by_yyy() functions family.

Update them to handle orphan nodes.

---
 livetree.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
livetree.c +42 -0
index 057997a..fa9daff 100644
@@ -789,6 +789,7 @@ static struct node *get_node_by_ref(struct node *tree, const char *ref)
 
 struct node *dti_get_node_by_path(struct dt_info *dti, const char *path)
 {
+	struct node *orphan;
 	struct node *node;
 
 	if (dti->dt) {
@@ -797,11 +798,18 @@ struct node *dti_get_node_by_path(struct dt_info *dti, const char *path)
 			return node;
 	}
 
+	for_each_orphan(dti->orphanlist, orphan) {
+		node = get_node_by_path(orphan, path);
+		if (node)
+			return node;
+	}
+
 	return NULL;
 }
 
 struct node *dti_get_node_by_label(struct dt_info *dti, const char *label)
 {
+	struct node *orphan;
 	struct node *node;
 
 	if (dti->dt) {
@@ -810,11 +818,18 @@ struct node *dti_get_node_by_label(struct dt_info *dti, const char *label)
 			return node;
 	}
 
+	for_each_orphan(dti->orphanlist, orphan) {
+		node = get_node_by_label(orphan, label);
+		if (node)
+			return node;
+	}
+
 	return NULL;
 }
 
 struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle)
 {
+	struct node *orphan;
 	struct node *node;
 
 	if (dti->dt) {
@@ -823,11 +838,18 @@ struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle)
 			return node;
 	}
 
+	for_each_orphan(dti->orphanlist, orphan) {
+		node = get_node_by_phandle(orphan, phandle);
+		if (node)
+			return node;
+	}
+
 	return NULL;
 }
 
 struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref)
 {
+	struct node *orphan;
 	struct node *node;
 
 	if (dti->dt) {
@@ -836,6 +858,12 @@ struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref)
 			return node;
 	}
 
+	for_each_orphan(dti->orphanlist, orphan) {
+		node = get_node_by_ref(orphan, ref);
+		if (node)
+			return node;
+	}
+
 	return NULL;
 }
 
@@ -844,6 +872,7 @@ struct property *dti_get_property_by_label(struct dt_info *dti,
 					   struct node **node)
 {
 	struct property *property;
+	struct node *orphan;
 
 	if (dti->dt) {
 		property = get_property_by_label(dti->dt, label, node);
@@ -851,6 +880,12 @@ struct property *dti_get_property_by_label(struct dt_info *dti,
 			return property;
 	}
 
+	for_each_orphan(dti->orphanlist, orphan) {
+		property = get_property_by_label(orphan, label, node);
+		if (property)
+			return property;
+	}
+
 	*node = NULL;
 	return NULL;
 }
@@ -859,6 +894,7 @@ struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
 				    struct node **node, struct property **prop)
 {
 	struct marker *marker;
+	struct node *orphan;
 
 	if (dti->dt) {
 		marker = get_marker_label(dti->dt, label, node, prop);
@@ -866,6 +902,12 @@ struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
 			return marker;
 	}
 
+	for_each_orphan(dti->orphanlist, orphan) {
+		marker = get_marker_label(orphan, label, node, prop);
+		if (marker)
+			return marker;
+	}
+
 	*prop = NULL;
 	*node = NULL;
 	return NULL;
Signature · 1 line
2.52.0
#114 lore raw

Re: [RFC PATCH 49/77] dtc: Handle orphan nodes in dti_get_xxx_by_yyy()

Quoted 9 lines · Herve Codina

Orphan nodes have been introduced recently.

Retrieving a node, a property and/or a marker from an orphan node tree is perfectly legit.

Those retrievals are performed by the dti_get_xxx_by_yyy() functions family.

Update them to handle orphan nodes.

I think at least some of the orphan node stuff can be separated from the import/export symbol stuff, and dtb changes. That can be reviewed and merged first, which will simplify the review task.

The idea is this: at the moment, when we have multiple tree sections in the dts, we merge them all together into a single tree as we parse. The idea would be that we first make a list of all those sections, then perform the merge as a separate step from parsing.

Quoted 134 lines
---
 livetree.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
livetree.c +42 -0
index 057997a..fa9daff 100644
@@ -789,6 +789,7 @@ static struct node *get_node_by_ref(struct node *tree, const char *ref)
 
 struct node *dti_get_node_by_path(struct dt_info *dti, const char *path)
 {
+	struct node *orphan;
 	struct node *node;
 
 	if (dti->dt) {
@@ -797,11 +798,18 @@ struct node *dti_get_node_by_path(struct dt_info *dti, const char *path)
 			return node;
 	}
 
+	for_each_orphan(dti->orphanlist, orphan) {
+		node = get_node_by_path(orphan, path);
+		if (node)
+			return node;
+	}
+
 	return NULL;
 }
 
 struct node *dti_get_node_by_label(struct dt_info *dti, const char *label)
 {
+	struct node *orphan;
 	struct node *node;
 
 	if (dti->dt) {
@@ -810,11 +818,18 @@ struct node *dti_get_node_by_label(struct dt_info *dti, const char *label)
 			return node;
 	}
 
+	for_each_orphan(dti->orphanlist, orphan) {
+		node = get_node_by_label(orphan, label);
+		if (node)
+			return node;
+	}
+
 	return NULL;
 }
 
 struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle)
 {
+	struct node *orphan;
 	struct node *node;
 
 	if (dti->dt) {
@@ -823,11 +838,18 @@ struct node *dti_get_node_by_phandle(struct dt_info *dti, cell_t phandle)
 			return node;
 	}
 
+	for_each_orphan(dti->orphanlist, orphan) {
+		node = get_node_by_phandle(orphan, phandle);
+		if (node)
+			return node;
+	}
+
 	return NULL;
 }
 
 struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref)
 {
+	struct node *orphan;
 	struct node *node;
 
 	if (dti->dt) {
@@ -836,6 +858,12 @@ struct node *dti_get_node_by_ref(struct dt_info *dti, const char *ref)
 			return node;
 	}
 
+	for_each_orphan(dti->orphanlist, orphan) {
+		node = get_node_by_ref(orphan, ref);
+		if (node)
+			return node;
+	}
+
 	return NULL;
 }
 
@@ -844,6 +872,7 @@ struct property *dti_get_property_by_label(struct dt_info *dti,
 					   struct node **node)
 {
 	struct property *property;
+	struct node *orphan;
 
 	if (dti->dt) {
 		property = get_property_by_label(dti->dt, label, node);
@@ -851,6 +880,12 @@ struct property *dti_get_property_by_label(struct dt_info *dti,
 			return property;
 	}
 
+	for_each_orphan(dti->orphanlist, orphan) {
+		property = get_property_by_label(orphan, label, node);
+		if (property)
+			return property;
+	}
+
 	*node = NULL;
 	return NULL;
 }
@@ -859,6 +894,7 @@ struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
 				    struct node **node, struct property **prop)
 {
 	struct marker *marker;
+	struct node *orphan;
 
 	if (dti->dt) {
 		marker = get_marker_label(dti->dt, label, node, prop);
@@ -866,6 +902,12 @@ struct marker *dti_get_marker_label(struct dt_info *dti, const char *label,
 			return marker;
 	}
 
+	for_each_orphan(dti->orphanlist, orphan) {
+		marker = get_marker_label(orphan, label, node, prop);
+		if (marker)
+			return marker;
+	}
+
 	*prop = NULL;
 	*node = NULL;
 	return NULL;
Signature · 1 line
2.52.0
Signature · 4 lines
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
#115 lore raw

RFC PATCH 50/77 dtc: Handle orphan nodes in mark_local_xxx() and update_xxx_ref()

In reply to Herve Codina

Orphan nodes have been introduced recently.

mark_local_phandles() and mark_local_exports() mark phandles and export symbols as local when they reference a local node (i.e. a node in the current device-tree).

update_phandles_ref() and update_exports_ref() update references pointing to local nodes.

Those phandles, export symbols and references can involve orphan trees.

Indeed, even if an orphan node itself is not present in the current device-tree, its subnodes are fully described in the current device-tree and so, those subnodes have to be considered as local nodes.

Update those functions to handle orphan nodes.

---
 livetree.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
livetree.c +19 -0
index fa9daff..52c55be 100644
@@ -1481,7 +1481,12 @@ static void update_phandles_ref_internal(struct dt_info *dti, struct node *node)
 
 void update_phandles_ref(struct dt_info *dti)
 {
+	struct node *orphan;
+
 	update_phandles_ref_internal(dti, dti->dt);
+
+	for_each_orphan(dti->orphanlist, orphan)
+		update_phandles_ref_internal(dti, orphan);
 }
 
 static void mark_local_phandles_internal(struct dt_info *dti,
@@ -1507,7 +1512,12 @@ static void mark_local_phandles_internal(struct dt_info *dti,
 
 void mark_local_phandles(struct dt_info *dti)
 {
+	struct node *orphan;
+
 	mark_local_phandles_internal(dti, dti->dt);
+
+	for_each_orphan(dti->orphanlist, orphan)
+		mark_local_phandles_internal(dti, orphan);
 }
 
 static void update_exports_ref_internal(struct dt_info *dti, struct node *node)
@@ -1537,7 +1547,12 @@ static void update_exports_ref_internal(struct dt_info *dti, struct node *node)
 
 void update_exports_ref(struct dt_info *dti)
 {
+	struct node *orphan;
+
 	update_exports_ref_internal(dti, dti->dt);
+
+	for_each_orphan(dti->orphanlist, orphan)
+		update_exports_ref_internal(dti, orphan);
 }
 
 static void mark_local_exports_internal(struct dt_info *dti,
@@ -1559,6 +1574,10 @@ static void mark_local_exports_internal(struct dt_info *dti,
 
 void mark_local_exports(struct dt_info *dti)
 {
+	struct node *orphan;
+
 	mark_local_exports_internal(dti, dti->dt);
 
+	for_each_orphan(dti->orphanlist, orphan)
+		mark_local_exports_internal(dti, orphan);
 }
Signature · 1 line
2.52.0
#116 lore raw

RFC PATCH 51/77 dtc: Avoid NULL fullpath for nodes in orphan trees

In reply to Herve Codina

Orphan nodes have been introduced recently.

The process_checks() function uses fullpath in several places and crashes due NULL pointer dereferences if fullpath is NULL.

In order to have process_checks() function running without crashes with orphan trees (i.e. trees based on orphan nodes), the fullpath of node available in those orphan trees must not be NULL.

Fullpath values are built by dti_fill_fullpaths(). Update it to handle fullpath in trees based on orphan nodes.

Use a simple "__orphan__/" prefix to avoid the NULL pointer and to be distinct from the root node ("/" prefix).

It is worth noting that this "__orphan__/" prefix is a temporary prefix and it will be change later when support for reference by path involving nodes in orphan tree is added.

---
 dtc.c | 5 +++++
 1 file changed, 5 insertions(+)
dtc.c +5 -0
index 59f4d77..5cf8f31 100644
@@ -47,9 +47,14 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
 
 static void dti_fill_fullpaths(struct dt_info *dti)
 {
+	struct node *orphan;
+
 	/* Fill fullpaths for the root node */
 	if (dti->dt)
 		fill_fullpaths(dti->dt, "");
+
+	for_each_orphan(dti->orphanlist, orphan)
+		fill_fullpaths(orphan, "__orphan__/");
 }
 
 /* Usage related data. */
Signature · 1 line
2.52.0
#117 lore raw

Re: [RFC PATCH 51/77] dtc: Avoid NULL fullpath for nodes in orphan trees

Quoted 12 lines · Herve Codina

Orphan nodes have been introduced recently.

The process_checks() function uses fullpath in several places and crashes due NULL pointer dereferences if fullpath is NULL.

In order to have process_checks() function running without crashes with orphan trees (i.e. trees based on orphan nodes), the fullpath of node available in those orphan trees must not be NULL.

Fullpath values are built by dti_fill_fullpaths(). Update it to handle fullpath in trees based on orphan nodes.

Quoted 6 lines

Use a simple "__orphan__/" prefix to avoid the NULL pointer and to be distinct from the root node ("/" prefix).

It is worth noting that this "__orphan__/" prefix is a temporary prefix and it will be change later when support for reference by path involving nodes in orphan tree is added.

It might be simpler to eliminate the fullpath field entirely, and instead have a function that calculates fullpaths at the point you need them.

Quoted 29 lines
---
 dtc.c | 5 +++++
 1 file changed, 5 insertions(+)
dtc.c +5 -0
index 59f4d77..5cf8f31 100644
@@ -47,9 +47,14 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
 
 static void dti_fill_fullpaths(struct dt_info *dti)
 {
+	struct node *orphan;
+
 	/* Fill fullpaths for the root node */
 	if (dti->dt)
 		fill_fullpaths(dti->dt, "");
+
+	for_each_orphan(dti->orphanlist, orphan)
+		fill_fullpaths(orphan, "__orphan__/");
 }
 
 /* Usage related data. */
Signature · 1 line
2.52.0
Signature · 4 lines
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
#118 lore raw

Re: [RFC PATCH 51/77] dtc: Avoid NULL fullpath for nodes in orphan trees

Quoted 16 lines · On Thu, 15 Jan 2026 17:56:07 +1100 David Gibson <[email protected]>…
Quoted 15 lines · Herve Codina

Orphan nodes have been introduced recently.

The process_checks() function uses fullpath in several places and crashes due NULL pointer dereferences if fullpath is NULL.

In order to have process_checks() function running without crashes with orphan trees (i.e. trees based on orphan nodes), the fullpath of node available in those orphan trees must not be NULL.

Fullpath values are built by dti_fill_fullpaths(). Update it to handle fullpath in trees based on orphan nodes.

Use a simple "__orphan__/" prefix to avoid the NULL pointer and to be distinct from the root node ("/" prefix).

Quoted 7 lines
Quoted 3 lines

It is worth noting that this "__orphan__/" prefix is a temporary prefix and it will be change later when support for reference by path involving nodes in orphan tree is added.

It might be simpler to eliminate the fullpath field entirely, and instead have a function that calculates fullpaths at the point you need them.

I am not sure it will be simpler.

I would prefer keeping dti_fill_fullpaths() for the moment.

This could be change later when things are more stable.

Many thinks are under discussion and changing all users of the the fullpath field now will introduce more complexity which is not needed right now.

Best regards,
Hervé

#119 lore raw

RFC PATCH 52/77 checks: Perform checks for orphan nodes

In reply to Herve Codina

Orphan nodes have been introduced recently.

Those nodes and related trees need to be handled by the check process.

Indeed, in addition to performing checks, phandles are allocated and referenced nodes are marked 'referenced' during the check process.

Take into account orphan nodes in check process.

---
 checks.c | 4 ++++
 1 file changed, 4 insertions(+)
checks.c +4 -0
index 0a855f9..3ed3a0c 100644
@@ -155,6 +155,7 @@ static bool is_multiple_of(int multiple, int divisor)
 static bool run_check(struct check *c, struct dt_info *dti)
 {
 	struct node *dt = dti->dt;
+	struct node *orphan;
 	bool error = false;
 	int i;
 
@@ -180,6 +181,9 @@ static bool run_check(struct check *c, struct dt_info *dti)
 
 	check_nodes_props(c, dti, dt);
 
+	for_each_orphan(dti->orphanlist, orphan)
+		check_nodes_props(c, dti, orphan);
+
 	if (c->status == UNCHECKED)
 		c->status = PASSED;
 
Signature · 1 line
2.52.0
#120 lore raw

RFC PATCH 53/77 dtc: Rename add_orphan_node() to plugin_add_orphan_node()

In reply to Herve Codina

add_orphan_node() is used when a orphan node is parsed in a plugin (overlay) device-tree.

This function creates some device-tree nodes (/fragment@n/__overlay__) in order to merge the parsed orphan node.

This is specific to plugin device-trees and cannot be used for addon device-trees.

In order to clarify that add_orphan_node() is specific to plugin device-trees and to prepare the support for orphan node parsing in the addon context, rename current add_orphan_node() to plugin_add_orphan_node().

---
 dtc-parser.y | 6 +++---
 dtc.h        | 3 ++-
 livetree.c   | 3 ++-
 3 files changed, 7 insertions(+), 5 deletions(-)
dtc-parser.y +3 -3
index 626a232..2b5b3c4 100644
@@ -245,7 +245,7 @@ devicetree:
 				ERROR(&@2, "Label or path %s not found", $1);
 			else if (is_ref_relative($1))
 				ERROR(&@2, "Label-relative reference %s not supported in plugin", $1);
-			$$ = add_orphan_node(
+			$$ = plugin_add_orphan_node(
 					name_node(build_node(NULL, NULL, NULL, NULL),
 						  ""),
 					$2, $1);
@@ -269,7 +269,7 @@ devicetree:
 			if (last_header_flags & DTSF_PLUGIN) {
 				if (is_ref_relative($2))
 					ERROR(&@2, "Label-relative reference %s not supported in plugin", $2);
-				add_orphan_node($1, $3, $2);
+				plugin_add_orphan_node($1, $3, $2);
 			} else {
 				struct node *target = parser_get_node_by_ref($1, $2);
 
@@ -288,7 +288,7 @@ devicetree:
 				merge_nodes(target, $3);
 			} else {
 				if (last_header_flags & DTSF_PLUGIN)
-					add_orphan_node($1, $3, $2);
+					plugin_add_orphan_node($1, $3, $2);
 				else
 					ERROR(&@2, "Label or path %s not found", $2);
 			}
dtc.h +2 -1
index 399beee..e463756 100644
@@ -305,7 +305,8 @@ struct node *omit_node_if_unused(struct node *node);
 struct node *reference_node(struct node *node);
 struct node *chain_node(struct node *first, struct node *list);
 struct node *merge_nodes(struct node *old_node, struct node *new_node);
-struct node *add_orphan_node(struct node *old_node, struct node *new_node, char *ref);
+struct node *plugin_add_orphan_node(struct node *old_node, struct node *new_node,
+				    char *ref);
 
 void add_property(struct node *node, struct property *prop);
 void delete_property_by_name(struct node *node, char *name);
livetree.c +2 -1
index 52c55be..a21dfc1 100644
@@ -319,7 +319,8 @@ struct node *merge_nodes(struct node *old_node, struct node *new_node)
 	return old_node;
 }
 
-struct node * add_orphan_node(struct node *dt, struct node *new_node, char *ref)
+struct node *plugin_add_orphan_node(struct node *dt, struct node *new_node,
+				    char *ref)
 {
 	static unsigned int next_orphan_fragment = 0;
 	struct node *node;
Signature · 1 line
2.52.0
#121 lore raw

RFC PATCH 54/77 dtc: Add basic support for addon orphan nodes dts parsing

In reply to Herve Codina

Orphan nodes are nodes without a parent. The root device-tree node is a particular orphan node and is not part of those 'orphan' nodes group.

The orphan nodes group is related to nodes identified by a reference in addons or plugins device-trees. For instance, int the following snippet, foo is an orphan node:
--- 8< ---
/addon/

   &foo {
       subnode {
           prop  = <1>;
       };
   };
   --- 8< ---

The foo referenced node described has no parent. Indeed, it is not a child of the root node.

This kind of node is legit in addons device-tree in order to perform modification on existing node when the addon dtb is applied.

Add support for addon orphan node in dts parsing.

Compared to plugin (overlay) orphan node parsing, the orphan node parsed in the addon context do not lead to any change in the device-tree structure. '/fragment@0/__overlay__' or similar kind of structure is not needed for addons.

---
 checks.c     | 14 ++++++++++--
 dtc-parser.y | 60 +++++++++++++++++++++++++++++++++++-----------------
 dtc.h        |  4 ++++
 livetree.c   | 30 ++++++++++++++++++++++++++
 treesource.c |  2 ++
 5 files changed, 89 insertions(+), 21 deletions(-)
checks.c +12 -2
index 3ed3a0c..83a0f6e 100644
@@ -317,7 +317,12 @@ ERROR(duplicate_property_names, check_duplicate_property_names, NULL);
 static void check_node_name_chars(struct check *c, struct dt_info *dti,
 				  struct node *node)
 {
-	size_t n = strspn(node->name, c->data);
+	size_t n;
+
+	if ((dti->dtsflags & DTSF_ADDON) && node->ref)
+		return; /* Checking name doesn't make sense for an orphan node */
+
+	n = strspn(node->name, c->data);
 
 	if (n < strlen(node->name))
 		FAIL(c, dti, node, "Bad character '%c' in node name",
@@ -328,7 +333,12 @@ ERROR(node_name_chars, check_node_name_chars, NODECHARS);
 static void check_node_name_chars_strict(struct check *c, struct dt_info *dti,
 					 struct node *node)
 {
-	size_t n = strspn(node->name, c->data);
+	size_t n;
+
+	if ((dti->dtsflags & DTSF_ADDON) && node->ref)
+		return; /* Checking name doesn't make sense for an orphan node */
+
+	n = strspn(node->name, c->data);
 
 	if (n < node->basenamelen)
 		FAIL(c, dti, node, "Character '%c' not recommended in node name",
dtc-parser.y +41 -19

134 lines not on this page · raw message

dtc.h +4 -0
index e463756..a3e29a6 100644
@@ -250,6 +250,8 @@ struct node {
 	const struct bus_type *bus;
 	struct srcpos *srcpos;
 
+	const char *ref; /* Use only for orphan nodes */
+
 	bool omit_if_unused, is_referenced;
 };
 
@@ -307,6 +309,8 @@ struct node *chain_node(struct node *first, struct node *list);
 struct node *merge_nodes(struct node *old_node, struct node *new_node);
 struct node *plugin_add_orphan_node(struct node *old_node, struct node *new_node,
 				    char *ref);
+struct node *orphan_node(struct node *node, const char *ref);
+void addon_add_orphan_node(struct node **dt_orphan, struct node *new_orphan);
 
 void add_property(struct node *node, struct property *prop);
 void delete_property_by_name(struct node *node, char *name);
livetree.c +30 -0
index a21dfc1..eaface5 100644
@@ -351,6 +351,36 @@ struct node *plugin_add_orphan_node(struct node *dt, struct node *new_node,
 	return dt;
 }
 
+struct node *orphan_node(struct node *node, const char *ref)
+{
+	node->ref = xstrdup(ref);
+
+	return node;
+}
+
+void addon_add_orphan_node(struct node **dt_orphan, struct node *new_orphan)
+{
+	struct node **last_orphan;
+	char *name;
+
+	/*
+	 * For addon orphan node, the node name is set to '&reference'
+	 * This ease the dts file generation and the usage of existing code
+	 */
+	xasprintf(&name, "&%s", new_orphan->ref);
+
+	name_node(new_orphan, name);
+	free(name);
+
+	new_orphan->next_sibling = NULL;
+
+	last_orphan = dt_orphan;
+	while (*last_orphan)
+		last_orphan = &((*last_orphan)->next_sibling);
+
+	*last_orphan = new_orphan;
+}
+
 struct node *chain_node(struct node *first, struct node *list)
 {
 	assert(first->next_sibling == NULL);
treesource.c +2 -0
index 04f65bb..77ff4fb 100644
@@ -12,11 +12,13 @@ extern YYLTYPE yylloc;
 
 struct dt_info *parser_output;
 bool treesource_error;
+struct node *parser_orphanlist;
 
 struct dt_info *dt_from_source(const char *fname)
 {
 	parser_output = NULL;
 	treesource_error = false;
+	parser_orphanlist = NULL;
 
 	srcfile_push(fname);
 	yyin = current_srcfile->f;
Signature · 1 line
2.52.0
#122 lore raw

RFC PATCH 55/77 dtc: Add orphan nodes in generated dts file

In reply to Herve Codina

Orphan nodes parsing from an addon dts file is supported.

Add the support for orphan nodes in the dts file generation.

---
 treesource.c | 6 ++++++
 1 file changed, 6 insertions(+)
treesource.c +6 -0
index 77ff4fb..bc5d847 100644
@@ -384,6 +384,7 @@ void dt_to_source(FILE *f, struct dt_info *dti)
 {
 	struct reserve_info *re;
 	struct symbol *importsym;
+	struct node *orphan;
 
 	fprintf(f, "/dts-v1/;\n");
 	if (dti->dtsflags & DTSF_ADDON)
@@ -410,4 +411,9 @@ void dt_to_source(FILE *f, struct dt_info *dti)
 	}
 
 	write_tree_source_node(f, dti->dt, 0);
+
+	for_each_orphan(dti->orphanlist, orphan) {
+		fprintf(f, "\n");
+		write_tree_source_node(f, orphan, 0);
+	}
 }
Signature · 1 line
2.52.0
#123 lore raw

RFC PATCH 56/77 Add support for FDT_BEGIN_NODE_REF_SYM dtb tag

In reply to Herve Codina

The FDT_BEGIN_NODE_REF dtb tag is a meta-data tag defining a referenced node.

This kind of nodes can be present in addon dtbs and identifies a node external to the addon dtb but modified by the addon.

For instance, if an addon adds a sub-node a node existing in the device-tree the addon is applied to, the existing node needs to be referenced by the addon dtb. This is the purpose of FDT_BEGIN_NODE_REF.

This tag typically identifies what we call orphan nodes in dts.

The structure of FDT_BEGIN_NODE_REF is identical to the structure of FDT_BEGIN_NODE except that the node name is not present and it is replaced by the node symbol reference needed to reference the node in the base device-tree when the addon device-tree blob is applied.

The FDT_BEGIN_NODE_REF block is terminated by a FDT_END_NODE tag.

The FDT_BEGIN_NODE_REF tag is followed by:
- node symbol name (string including \0)
The symbol name used to reference the node in the base device-tree when the addon is applied.
- padding:

      Padding (0x00) added to have the next value aligned on 32bit.

- Node structure (see FDT_BEGIN_NODE):
Items provided by the addon to be merged in the referenced node when the addon is applied.
- FDT_END_NODE tag

Example:
FDT_BEGIN_NODE_REF 'foo1' 0x00 0x00 0x00 ... FDT_END_NODE

This means that the external node referenced by 'foo1' is modified by the addon. Items to merge when the addon is applied are represented by the '...' part.

  This is what is encoded in the dtb when the related dts has the
  following orphan node:
    &foo1 {
      ...
    };

If several external nodes are modified by the addon (several orphan nodes described in the addon), several FDT_BEGIN_NODE_REF are present. Each of them related to an external node. For instance, having 'foo1' and 'bar1' as external nodes leads to the following sequence:
FDT_BEGIN_NODE_REF 'foo1' 0x00 0x00 0x00 ... FDT_END_NODE FDT_BEGIN_NODE_REF 'bar1' 0x00 0x00 0x00 ... FDT_END_NODE

The FDT_BEGIN_NODE_REF can be present only for a top level node. Subnodes are identified by a FDT_BEGIN_NODE tag.

If FDT_BEGIN_NODE_REF tags are present in the dtb, they are present after the root node definition (i.e. after the first FDT_BEGIN_NODE / FDT_END_NODE block).

Add support for this new dtb tag.

---
 fdtdump.c    |  11 ++++++
 flattree.c   | 103 ++++++++++++++++++++++++++++++++++++++++++---------
 libfdt/fdt.c |  10 +++++
 libfdt/fdt.h |   2 +
 4 files changed, 108 insertions(+), 18 deletions(-)
fdtdump.c +11 -0
index 04e6e38..7d58e3d 100644
@@ -176,6 +176,17 @@ static void dump_blob(void *blob, bool debug)
 			continue;
 		}
 
+		if (tag == FDT_BEGIN_NODE_REF) {
+			last_prop_name = NULL;
+			s = p;
+			p = PALIGN(p + strlen(s) + 1, 4);
+
+			printf("%*s&%s {\n", depth * shift, "", s);
+
+			depth++;
+			continue;
+		}
+
 		if (tag == FDT_EXPORT_SYM) {
 			s = p;
 			p = PALIGN(p + strlen(s) + 1, 4);
flattree.c +85 -18

204 lines not on this page · raw message

libfdt/fdt.c +10 -0
index c169dd9..dc58d2d 100644
@@ -232,6 +232,15 @@ uint32_t fdt_next_tag_full(const void *fdt, int startoffset, int *nextoffset)
 			return FDT_END; /* premature end */
 		break;
 
+	case FDT_BEGIN_NODE_REF:
+		/* Skip ref */
+		do {
+			p = fdt_offset_ptr(fdt, offset++, 1);
+		} while (p && (*p != '\0'));
+		if (!can_assume(VALID_DTB) && !p)
+			return FDT_END; /* premature end */
+		break;
+
 	case FDT_EXPORT_SYM:
 		/* Skip name */
 		do {
@@ -342,6 +351,7 @@ uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
 			break;
 
 		case FDT_IMPORT_SYM:
+		case FDT_BEGIN_NODE_REF:
 			/* Those tags are available at the root level, after the
 			 * root node -> Skip everything until FDT_END
 			 */
libfdt/fdt.h +2 -0
index b6c23ef..8a39458 100644
@@ -63,6 +63,8 @@ struct fdt_property {
 #define FDT_REF_LOCAL   0x5		/* local phandle reference: offset */
 #define FDT_REF_PHANDLE 0x6		/* external phandle reference: offset,
 					   external label */
+#define FDT_BEGIN_NODE_REF 0x7		/* Same as FDT_BEGIN_NODE but with
+					   reference instead of name */
 #define FDT_END		0x9
 #define FDT_EXPORT_SYM	0xa		/* export symbol: name, phandle value */
 #define FDT_EXPORT_SYM_REF 0xb		/* export symbol: name, phandle value (maybe
Signature · 1 line
2.52.0
#124 lore raw

RFC PATCH 57/77 tests: metadata: Add basic test for addon orphan nodes

In reply to Herve Codina

Add tests related to addon orphan nodes (FDT_BEGIN_NODE_REF dtb tag).

---
 tests/metadata_addon_orphan1.dtb.dts.expect | 16 ++++++++++++++++
 tests/metadata_addon_orphan1.dtb.expect     | 13 +++++++++++++
 tests/metadata_addon_orphan1.dts            | 19 +++++++++++++++++++
 tests/metadata_addon_orphan1.dts.dts.expect | 16 ++++++++++++++++
 tests/run_tests.sh                          |  3 ++-
 5 files changed, 66 insertions(+), 1 deletion(-)
 create mode 100644 tests/metadata_addon_orphan1.dtb.dts.expect
 create mode 100644 tests/metadata_addon_orphan1.dtb.expect
 create mode 100644 tests/metadata_addon_orphan1.dts
 create mode 100644 tests/metadata_addon_orphan1.dts.dts.expect
tests/metadata_addon_orphan1.dtb.dts.expect new file +16 -0
new file mode 100644
index 0000000..c24a00f
@@ -0,0 +1,16 @@
+/dts-v1/;
+/addon/;
+
+/ {
+
+	node-a {
+		prop = <0x01>;
+	};
+};
+
+&base {
+
+	addon-node {
+		prop = <0x02>;
+	};
+};
tests/metadata_addon_orphan1.dtb.expect new file +13 -0
new file mode 100644
index 0000000..7058a2e
@@ -0,0 +1,13 @@
+/dts-v1/;
+/addon/;
+
+/ {
+    node-a {
+        prop = <0x00000001>;
+    };
+};
+&base {
+    addon-node {
+        prop = <0x00000002>;
+    };
+};
tests/metadata_addon_orphan1.dts new file +19 -0
new file mode 100644
index 0000000..f20d179
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
+/*
+ * Copyright (C) 2026 Bootlin
+ */
+
+/dts-v1/;
+/addon/;
+
+/ {
+	node-a {
+		prop = <1>;
+	};
+};
+
+&base {
+	addon-node {
+		prop = <2>;
+	};
+};
tests/metadata_addon_orphan1.dts.dts.expect new file +16 -0
new file mode 100644
index 0000000..c24a00f
@@ -0,0 +1,16 @@
+/dts-v1/;
+/addon/;
+
+/ {
+
+	node-a {
+		prop = <0x01>;
+	};
+};
+
+&base {
+
+	addon-node {
+		prop = <0x02>;
+	};
+};
tests/run_tests.sh +2 -1
index a5e31df..659b42b 100755
@@ -1127,7 +1127,8 @@ wrap_fdtdump () {
 metadata_tests() {
 	for dt in metadata_reflocal metadata_refphandle \
 		  metadata_addon_base metadata_exportsyms_local \
-		  metadata_exportsyms_ref metadata_importsyms; do
+		  metadata_exportsyms_ref metadata_importsyms \
+		  metadata_addon_orphan1; do
 		run_dtc_test -I dts -O dts -o $dt.dts.dts "$SRCDIR/$dt.dts"
 		base_run_test check_diff $dt.dts.dts "$SRCDIR/$dt.dts.dts.expect"
 		run_dtc_test -I dts -O dtb -o $dt.dtb "$SRCDIR/$dt.dts"
Signature · 1 line
2.52.0
#125 lore raw

RFC PATCH 58/77 dtc: Add support for missing root node in addon device-tree

In reply to Herve Codina

Addon can have orphan nodes fully described (dts) and encoded (dtb) without the need for a root device tree.

Contrary to plugin (overlay), addon doesn't need any specific root tree structure to described the orphans. Indeed, /fragment@n/__overlay__ doesn't exist for addons. Orphans are encoded in dtb using the FDT_BEGIN_NODE_REF tag without any impact on the root tree.

The following snippet is fully legit for addon:
--- 8< ---
/addon/;

   &foo {
      subnode {
        prop = <1>;
      };
   }
   --- 8< ---

This snippet doesn't contains a root device tree, and the related dtb doesn't need any root device tree to encode the snippet.

The root device is no more mandatory for addon.

Add support for addon without a root device-tree.

---
 checks.c     | 28 ++++++++++++++++++++++++++--
 dtc-parser.y | 18 ++++++++++++++----
 dtc.c        | 36 +++++++++++++++++++++++-------------
 flattree.c   | 42 +++++++++++++++++++++++++++++-------------
 livetree.c   | 22 +++++++++++++++++-----
 treesource.c |  3 ++-
 6 files changed, 111 insertions(+), 38 deletions(-)
checks.c +26 -2
index 83a0f6e..f98f153 100644
@@ -154,7 +154,6 @@ static bool is_multiple_of(int multiple, int divisor)
 
 static bool run_check(struct check *c, struct dt_info *dti)
 {
-	struct node *dt = dti->dt;
 	struct node *orphan;
 	bool error = false;
 	int i;
@@ -179,7 +178,8 @@ static bool run_check(struct check *c, struct dt_info *dti)
 	if (c->status != UNCHECKED)
 		goto out;
 
-	check_nodes_props(c, dti, dt);
+	if (dti->dt)
+		check_nodes_props(c, dti, dti->dt);
 
 	for_each_orphan(dti->orphanlist, orphan)
 		check_nodes_props(c, dti, orphan);
@@ -2079,6 +2079,30 @@ void process_checks(bool force, struct dt_info *dti)
 	unsigned int i;
 	int error = 0;
 
+	if (!dti->dt) {
+		/* No root node is only allowed for addons */
+		if (dti->dtsflags & DTSF_ADDON) {
+			if (!dti->orphanlist) {
+				/*
+				 * but addons without a root node and without
+				 * orphan nodes is really incorrect
+				 */
+				fprintf(stderr,
+					"ERROR: Input tree has no root or orphan nodes, aborting\n");
+				exit(2);
+			}
+		} else {
+			fprintf(stderr, "ERROR: Input tree has no root node, aborting\n");
+			exit(2);
+		}
+	}
+	if (!(dti->dtsflags & DTSF_ADDON)) {
+		if (dti->orphanlist) {
+			fprintf(stderr, "ERROR: Input tree has orphan nodes, aborting\n");
+			exit(2);
+		}
+	}
+
 	for (i = 0; i < ARRAY_SIZE(check_table); i++) {
 		struct check *c = check_table[i];
 
dtc-parser.y +14 -4
index 10ca6d4..cf5447a 100644
@@ -133,12 +133,18 @@ static struct node *parser_get_node_by_ref(struct node *dt, struct node *orphanl
 sourcefile:
 	  headers memreserves devicetree
 		{
+			if (!($1 & DTSF_ADDON) && !$3)
+				ERROR(&@3, "Only addon support missing root node");
+
 			parser_output = build_dt_info($1, $2, $3,
-			                              guess_boot_cpuid($3),
+			                              $3 ? guess_boot_cpuid($3) : 0,
 						      NULL, parser_orphanlist);
 		}
 	|  headers memreserves importlist devicetree
 		{
+			if (!($1 & DTSF_ADDON) && !$4)
+				ERROR(&@4, "Only addon support missing root node");
+
 			/*
 			 * importlist is created with chain_symbol() and so it
 			 * is created in reverse order. Reverse it now to have
@@ -241,7 +247,10 @@ devicetree:
 		}
 	| devicetree '/' nodedef
 		{
-			$$ = merge_nodes($1, $3);
+			if ($1)
+				$$ = merge_nodes($1, $3);
+			else
+				$$ = name_node($3, "");
 		}
 	| dt_ref nodedef
 		{
@@ -256,8 +265,9 @@ devicetree:
 							  ""),
 						$2, $1);
 			} else {
-				ERROR(&@2, "Orphan node %s without a root node not yet supported", $1);
-				YYERROR;
+				addon_add_orphan_node(&parser_orphanlist,
+						      orphan_node($2, $1));
+				$$ = NULL;
 			}
 		}
 	| devicetree DT_LABEL dt_ref nodedef
dtc.c +23 -13
index 5cf8f31..63725bf 100644
@@ -351,27 +351,37 @@ int main(int argc, char *argv[])
 	update_exports_ref(dti);
 	mark_local_exports(dti);
 
-	/*
-	 * With FDT_REF_PHANDLE added in dtbs, we need to identified
-	 * if some unresolved phandle references are allowed in the dtb
-	 * we have parsed (needed for process_check() to run properly).
-	 *
-	 * Identify plugin device-trees (overlays) based on specific node
-	 * presence.
-	 */
-	if (get_subnode(dti->dt, "__fixups__") ||
-	    get_subnode(dti->dt, "__local_fixups__"))
-		dti->dtsflags |= DTSF_PLUGIN;
+	if (dti->dt) {
+		/*
+		 * With FDT_REF_PHANDLE added in dtbs, we need to identified
+		 * if some unresolved phandle references are allowed in the dtb
+		 * we have parsed (needed for process_check() to run properly).
+		 *
+		 * Identify plugin device-trees (overlays) based on specific node
+		 * presence.
+		 */
+		if (get_subnode(dti->dt, "__fixups__") ||
+		    get_subnode(dti->dt, "__local_fixups__"))
+			dti->dtsflags |= DTSF_PLUGIN;
+	}
 
 	process_checks(force, dti);
 
-	if (auto_label_aliases)
+	if (auto_label_aliases) {
+		if (!dti->dt)
+			die("auto-alias not supported without a root node\n");
 		generate_label_tree(dti, "aliases", false);
+	}
 
-	if (generate_symbols)
+	if (generate_symbols) {
+		if (!dti->dt)
+			die("generation of symbols not supported without a root node\n");
 		generate_label_tree(dti, "__symbols__", true);
+	}
 
 	if (generate_fixups) {
+		if (!dti->dt)
+			die("generation of fixups not supported without a root node\n");
 		generate_fixups_tree(dti, "__fixups__");
 		generate_local_fixups_tree(dti, "__local_fixups__");
 	}
flattree.c +29 -13

76 lines not on this page · raw message

livetree.c +17 -5
index eaface5..00274c5 100644
@@ -1203,7 +1203,9 @@ void sort_tree(struct dt_info *dti)
 {
 	sort_reserve_entries(dti);
 	sort_importsyms(dti);
-	sort_node(dti->dt);
+
+	if (dti->dt)
+		sort_node(dti->dt);
 }
 
 /* utility helper to avoid code duplication */
@@ -1451,6 +1453,8 @@ static int generate_local_fixups_tree_internal(struct dt_info *dti,
 
 void generate_label_tree(struct dt_info *dti, const char *name, bool allocph)
 {
+	assert(dti->dt);
+
 	if (!any_label_tree(dti, dti->dt))
 		return;
 	generate_label_tree_internal(dti, build_root_node(dti->dt, name),
@@ -1459,6 +1463,8 @@ void generate_label_tree(struct dt_info *dti, const char *name, bool allocph)
 
 void generate_fixups_tree(struct dt_info *dti, const char *name)
 {
+	assert(dti->dt);
+
 	if (!any_fixup_tree(dti, dti->dt))
 		return;
 	if (generate_fixups_tree_internal(dti, build_root_node(dti->dt, name), dti->dt))
@@ -1469,6 +1475,8 @@ void generate_fixups_tree(struct dt_info *dti, const char *name)
 
 void generate_local_fixups_tree(struct dt_info *dti, const char *name)
 {
+	assert(dti->dt);
+
 	if (!any_local_fixup_tree(dti, dti->dt))
 		return;
 	if (generate_local_fixups_tree_internal(dti, build_root_node(dti->dt, name), dti->dt))
@@ -1514,7 +1522,8 @@ void update_phandles_ref(struct dt_info *dti)
 {
 	struct node *orphan;
 
-	update_phandles_ref_internal(dti, dti->dt);
+	if (dti->dt)
+		update_phandles_ref_internal(dti, dti->dt);
 
 	for_each_orphan(dti->orphanlist, orphan)
 		update_phandles_ref_internal(dti, orphan);
@@ -1545,7 +1554,8 @@ void mark_local_phandles(struct dt_info *dti)
 {
 	struct node *orphan;
 
-	mark_local_phandles_internal(dti, dti->dt);
+	if (dti->dt)
+		mark_local_phandles_internal(dti, dti->dt);
 
 	for_each_orphan(dti->orphanlist, orphan)
 		mark_local_phandles_internal(dti, orphan);
@@ -1580,7 +1590,8 @@ void update_exports_ref(struct dt_info *dti)
 {
 	struct node *orphan;
 
-	update_exports_ref_internal(dti, dti->dt);
+	if (dti->dt)
+		update_exports_ref_internal(dti, dti->dt);
 
 	for_each_orphan(dti->orphanlist, orphan)
 		update_exports_ref_internal(dti, orphan);
@@ -1607,7 +1618,8 @@ void mark_local_exports(struct dt_info *dti)
 {
 	struct node *orphan;
 
-	mark_local_exports_internal(dti, dti->dt);
+	if (dti->dt)
+		mark_local_exports_internal(dti, dti->dt);
 
 	for_each_orphan(dti->orphanlist, orphan)
 		mark_local_exports_internal(dti, orphan);
treesource.c +2 -1
index bc5d847..71dbd5f 100644
@@ -410,7 +410,8 @@ void dt_to_source(FILE *f, struct dt_info *dti)
 		fprintf(f, "\n");
 	}
 
-	write_tree_source_node(f, dti->dt, 0);
+	if (dti->dt)
+		write_tree_source_node(f, dti->dt, 0);
 
 	for_each_orphan(dti->orphanlist, orphan) {
 		fprintf(f, "\n");
Signature · 1 line
2.52.0