Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: devicetree: use stable path-based hashes in DT object names #77799

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pillo79
Copy link
Collaborator

@pillo79 pillo79 commented Aug 30, 2024

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 adts_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 form dts_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!

@pillo79 pillo79 added area: Devicetree RFC Request For Comments: want input from the community area: llext Linkable Loadable Extensions labels Aug 30, 2024
@pillo79
Copy link
Collaborator Author

pillo79 commented Aug 30, 2024

Compliance check found a leftover continue introduced by commit d25e5c2, 3 years ago.
It seems not many people dare to venture here! 🙂

@pillo79 pillo79 force-pushed the pr-stable-dt-hash branch 3 times, most recently from c0a7a54 to 067dd65 Compare September 17, 2024 07:22
@pillo79 pillo79 force-pushed the pr-stable-dt-hash branch 2 times, most recently from cf49b3d to f8b8c3f Compare September 25, 2024 09:35
Add a new "hash" attribute to all Devicetree EDT nodes. The hash is
calculated on the full path of the node; this means that its value
remains stable across rebuilds.
The hash is checked for uniqueness among nodes in the same EDT.

This computed token is then added to `devicetree_generated.h` and made
accessible to Zephyr code via a new DT_HASH(node_id) macro.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Add a new set of macros that allow customizing the symbol name when
exporting symbols. This is useful when the symbol name that extensions
need to look up is different from the identifier used in the base image.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
This new option allows to generate device names from the hash of the
devicetree node path, instead of the device's ordinal number. The
resulting names are stable across rebuilds.

Add a new test case to test this new option.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
@pillo79
Copy link
Collaborator Author

pillo79 commented Sep 25, 2024

v2:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree area: llext Linkable Loadable Extensions RFC Request For Comments: want input from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant