RFC: devicetree: use stable path-based hashes in DT object names #77799
+136
−26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem statement
Currently Zephyr uses a simple but effective sequential numbering scheme for the various C identifiers associated with Devicetree nodes: each node is numbered incrementally and results in a
dts_ord_
nnn name and C-level identifier. Since these numbers are allocated at every build, any node added or removed in the DT will result in a different mapping between identifiers and devices.This is a problem for extensions that need to access devices and DT nodes, as these names would not be constant and the extension would have to be rebuilt along with the main application on any Devicetree change, even those not directly affecting the extension.
Proposed solution
This PR proposes to add a Kconfig option,
CONFIG_LLEXT_EXPORT_DEV_IDS_BY_HASH
, to use a stable hash computed at build time from the full DT path of the node for identifiers exported to exensions. The resulting symbol names are of the formdts_hash_
xxx with xxx being the full hash of the DT node (with SHA256, a 64-char hex string). The build fails if a hash collision is detected, but with 256-bit hashes of text strings it should be an exceedingly unlikely event.A new Twister test has been added to check this new functionality and ensure stability of the generated hashes.
Conclusion
Stable DT names, or some way to have a stable look-up, is going to be important for LLEXT moving forward. Looking for feedback on both the proposed solution and implementation!