Skip to content

dts: edtlib: Turn Node.instance_no into more flexible EDT.compat2nodes #21592

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

Closed
wants to merge 1 commit into from

Conversation

ulfalizer
Copy link
Collaborator

Add a dictionary EDT.compat2nodes that maps each compatible that appears
on some enabled node to a list of enabled nodes that implement the
compatible. For example, EDT.compat2nodes["foo"] is a list of all
enabled nodes whose 'compatible' includes "foo".

The old Node.instance_no functionality can easily be implemented in
terms of EDT.compat2nodes, so get rid of Node.instance_no.
EDT.compat2nodes is more powerful and easier to understand.

Simplify main() in gen_defines.py a bit by using EDT.compat2nodes to
generate the DT_COMPAT_ existence macros. The behavior is
slightly different now, as DT_COMPAT_ is generated for
enabled nodes that don't have a binding as well, but that might be an
improvement overall, and probably doesn't hurt.

EDT.compat2nodes will make the implementation of the new
$(dt_compat_get_str) preprocessor function in
#21560 cleaner and
simpler. That was the original motivation.

@ulfalizer
Copy link
Collaborator Author

CC @nandojve

@ulfalizer
Copy link
Collaborator Author

Bit arbitrary that EDT.compat2nodes only includes enabled nodes, though it's the only thing that's needed at the moment. I based it on Node.instance_no.

@nandojve
Copy link
Member

Nice! This is a missing common point for gen_defines.py and Kconfig.
I already tested and for me it's ok.

Now it will be nice to have a dt_compat_count at gen_defines.py with the total instances to start replace things like that on drivers:

#if DT_INST_0_<compatible>
...
#endif
#if DT_INST_1_<compatible>
...
#endif
#if DT_INST_N_<compatible>
...
#endif

to

#if DT_<compatible>_COUNT > 0
REPEAT(DT_<compatible>_COUNT)
#endif

It's just a dream!

Add a dictionary EDT.compat2nodes that maps each compatible that appears
on some enabled node to a list of enabled nodes that implement the
compatible. For example, EDT.compat2nodes["foo"] is a list of all
enabled nodes whose 'compatible' includes "foo".

The old Node.instance_no functionality can easily be implemented in
terms of EDT.compat2nodes, so get rid of Node.instance_no.
EDT.compat2nodes is more powerful and easier to understand.

Simplify main() in gen_defines.py a bit by using EDT.compat2nodes to
generate the DT_COMPAT_<compatible> existence macros. The behavior is
slightly different now, as DT_COMPAT_<compatible> is generated for
enabled nodes that don't have a binding as well, but that might be an
improvement overall, and probably doesn't hurt.

EDT.compat2nodes will make the implementation of the new
$(dt_compat_get_str) preprocessor function in
zephyrproject-rtos#21560 cleaner and
simpler. That was the original motivation.

Signed-off-by: Ulf Magnusson <[email protected]>
@zephyrbot
Copy link
Collaborator

All checks passed.

checkpatch (informational only, not a failure)

-:169: WARNING:UNDOCUMENTED_DT_STRING: DT compatible string "compat2nodes" appears un-documented -- check ./dts/bindings/
#169: FILE: scripts/dts/test.dts:303:
+			compatible = "compat2nodes";

-:173: WARNING:UNDOCUMENTED_DT_STRING: DT compatible string "compat2nodes" appears un-documented -- check ./dts/bindings/
#173: FILE: scripts/dts/test.dts:307:
+			compatible = "compat2nodes";

-:177: WARNING:UNDOCUMENTED_DT_STRING: DT compatible string "compat2nodes" appears un-documented -- check ./dts/bindings/
#177: FILE: scripts/dts/test.dts:311:
+			compatible = "compat2nodes";

-:183: WARNING:UNDOCUMENTED_DT_STRING: DT compatible string "compat2nodes-disabled" appears un-documented -- check ./dts/bindings/
#183: FILE: scripts/dts/test.dts:317:
+			compatible = "compat2nodes-disabled";

- total: 0 errors, 4 warnings, 187 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

Your patch has style problems, please review.

NOTE: Ignored message types: AVOID_EXTERNS BRACES CONFIG_EXPERIMENTAL CONST_STRUCT DATE_TIME FILE_PATH_CHANGES MINMAX NETWORKING_BLOCK_COMMENT_STYLE PRINTK_WITHOUT_KERN_LEVEL SPLIT_STRING VOLATILE

NOTE: If any of the errors are false positives, please report
      them to the maintainers.

Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages.

@ulfalizer
Copy link
Collaborator Author

Rebased and improved version: #22250

@ulfalizer ulfalizer closed this Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants