-
Notifications
You must be signed in to change notification settings - Fork 7.4k
scripts: kconfig: Add dt_compat_get_inst_prop method #21560
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
scripts: kconfig: Add dt_compat_get_inst_prop method #21560
Conversation
536b9ab
to
ba17e04
Compare
Rebase and Fix 364 line.
to
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits and random thoughts.
Having some generic property lookup functions like these seems nice.
ba17e04
to
d0a3c95
Compare
I assumed that instance_no will be enough to check but testing in deep I saw inconsistencies.
On this example the first instance should be /../foo1/bar@0 and must be the only one. The current version returns /../foo0/bar@0. At generated_dts_board.conf file I saw two instances /../foo0/bar@1 and /../foo1/bar@0. Added scripts: dts: edtlib.py: Fix DT enabled node property to address the issue and fix unnecessary instances at generated_dts_board.conf |
d0a3c95
to
1b88247
Compare
1b88247
to
411eca2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having status = "disabled"
disable all the child nodes as well makes sense to me. Thanks for that.
I wonder how common it is to have nested status
properties, but if they show up, it probably makes sense for the parent status
to take precedence.
Feels like the old _set_instance_no()
code could be cleaned up a bit. It's pretty subtle how it works (depends on edt.nodes
only including the "previous" nodes when the function is called).
I'm thinking it might be nice to have an edt.compat2nodes
property, where e.g. edt.compat2nodes["foo"]
would be a list with all enabled nodes that have compatible = ..., "foo", ...
. That would simplify dt_compat_get_str()
as well.
I'll make a separate PR for that.
PR that turns |
411eca2
to
f51ec92
Compare
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]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems alright to me. Nice to have a function like that. Could be simplified a bit once #21592 is in too. Suspect most people are vacation at the moment.
Wonder if the function could just be called dt_compat_get
too, since it also works for integers. Maybe there could be a dt_compat_get_array
later if needed, that also takes an array index.
f51ec92
to
0f71741
Compare
I agreed with you, make sense. |
0f71741
to
9719f22
Compare
Rebase on top of |
9719f22
to
efa06b0
Compare
All checks passed. Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages. |
efa06b0
to
799e1ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixing up DTS into Kconfig is, imo, a mistake.
After almost 3 years we have been using DTS, we are still not yet where we want to be (too many instance-centric options are still in Kconfig, etc..)
And that PR makes it worse by mixing both. Definitely not a good idea.
799e1ee
to
a7d2561
Compare
The initial motivation of this PR was an open discussion at #21402. I agreed with you after weeks looking around DT, fixups, Kconfig etc. I believe any driver definition/configuration must be on that place and not around. I would like mention that there are DT improvements on #21592 and bug fix at 'scripts: dts: edtlib.py: Fix DT enabled node property' that probably need move forward. |
a7d2561
to
17bc8d2
Compare
Created "scripts: dts: edtlib.py: Fix DT enabled node property" #22215 dependency to separate DT fix from the current PR. |
Add an EDT.compat2enabled attribute that maps compatibles to enabled devicetree nodes that implement them. For example, EDT.compat2enabled["foo"] is a list of all enabled nodes with "foo" in the 'compatible' property. The old Node.instance_no functionality can be implemented in terms of EDT.compat2enabled, so remove Node.instance_no. EDT.compat2enabled is more flexible and easier to understand. Simplify main() in gen_defines.py by using EDT.compat2enabled 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. It probably doesn't hurt at least. EDT.compat2enabled simplifies the implementation of the new $(dt_compat_get_str) preprocessor function in zephyrproject-rtos#21560. That was the original motivation. Signed-off-by: Ulf Magnusson <[email protected]>
Add an EDT.compat2enabled attribute that maps compatibles to enabled devicetree nodes that implement them. For example, EDT.compat2enabled["foo"] is a list of all enabled nodes with "foo" in the 'compatible' property. The old Node.instance_no functionality can be implemented in terms of EDT.compat2enabled, so remove Node.instance_no. EDT.compat2enabled is more flexible and easier to understand. Simplify main() in gen_defines.py by using EDT.compat2enabled 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. It probably doesn't hurt at least. EDT.compat2enabled simplifies the implementation of the new $(dt_compat_get_str) preprocessor function in #21560. That was the original motivation. Signed-off-by: Ulf Magnusson <[email protected]>
I think the problem is mostly Kconfig options that allow you to change stuff that's already known from selecting the board. Think of Kconfig like an options menu in a game. You wouldn't show an option for selecting the operating system there, since it's already known. Kconfig is supposed to be simple like that, but the concepts got lost. Having devicetree information available to Kconfig is something else though. It allows you to tweak the options based on what the devicetree says (e.g. to only show Windows-specific options if the game runs on Windows, just to extend that example). This PR might help with getting rid of |
a62b4a5
to
1726408
Compare
The current version evaluate the node status and not the parent status. That define unnecessary symbols at 'devicetree.conf' which can increases total code size. This fix adding a new initialization method that evaluate all parents from a node and disable when appropriated. This fixes 'instance_no' set adding 'compat' only if node is enabled. Signed-off-by: Gerson Fernando Budke <[email protected]>
The 'dt_str_val' method has been deprecated. This add an alternative that uses 'compatible' and 'instance index' to find a node and than return the string representation or a passed default value. The instance is indexed by occurences of a compatible node with property 'status=okay'. This is necessary because 'path' is valid only at SoC directory. For instance, a driver for a SPI bus need search for a 'compatible' based on the 'instance' to determine the proper configuration. Example: how determine the right interface name from the device tree node label for the first instance? at DT: &foo0 { compatible = "manufacturer,device" status = "disabled"; label = "FOO_0"; }; &foo1 { compatible = "manufacturer,device" status = "okay"; label = "FOO_1"; }; at Kconfig: DT_FOO := manufacturer,device DT_FOO_INST := 0 DT_FOO_DEF := "default string on not match/error - optional empty" config FOO string "text" # Fetch 'label' property from instance INST, defaulting to DEF default "$(dt_compat_get_inst_prop, \ label, \ $(DT_FOO), \ $(DT_FOO_INST), \ $(DT_FOO_DEF))" The result is CONFIG_FOO="FOO_1". 'dt_compat_get_inst_prop' an be used to fetch properties that store string or integer values. Signed-off-by: Gerson Fernando Budke <[email protected]>
The IEEE 802.15.4 examples uses NET_CONFIG_IEEE802154_DEV_NAME config to determine the default device name to bind. This allows user define at DT node label the iface name. The default for all examples will be the first interface instance. This ensure on a multi band board with 2.4G and Sub-Giga radios that the first defined radio will be used. User can switch to the second radio definition by simply disabling the first one. Since this configuration is applied at Kconfig, changes obligate user to rebuild all the application. This ensure that cache will not affect expected behaviour. Signed-off-by: Gerson Fernando Budke <[email protected]>
1726408
to
e40a2f4
Compare
Since there isn't movement here I'm closing. |
The dt_str_val method has been deprecated. This add an alternative
that uses compat and instance number to find a node and than
return the string representation or a passed default value.
This is necessary becase path is valid only at SoC directory. For
instance, a driver for a SPI bus need search for a compat based on
the instance to determine the proper configuration.
depends on: #22215
Example: how determine the right interface name from the device tree
node label.
An example of use was delivered too.