Add tests to check the correctness of '#address-cells' usage.
The missing tests have allowed bug #77890 to persist for years.
Signed-off-by: Andrey VOLKOV <andrey.volkov@munic.io>
The '_raw_unit_addr()' function was incorrectly written a long time ago.
It tries to look up and use the '#address-cells' of the node containing
the 'interrupts' property itself, instead of using the '#address-cells' of
the interrupt controller's node (or its parent).
As a result, the mapping is successful only if the '#address-cells' value
is the same in both the node and the interrupt controller, all other cases
lead to random errors being generated by the 'gen_defines.py' script.
Also, the function was trying to use the '#address-cells' value as a
little-endian one, which led to unpredictable results as well.
This problem has been fixed too.
Fixes#77890, and probably #78020
Signed-off-by: Andrey VOLKOV <andrey.volkov@munic.io>
Signed-off-by: Ioannis Damigos <ioannis.damigos.uj@renesas.com>
According to the following comment on github
https://github.com/zephyrproject-rtos/zephyr/pull/77900/files#r1750393745
edtlib implementation is partially correct and it is missing two things:
1. If an ancestor has an interrupt-controller or interrupt-map property,
the walk must terminate.
2. If an interrupt-parent property is found, the linked node must be a
valid interrupt controller or nexus.
This commit add these checks.
Signed-off-by: Ioannis Damigos <ioannis.damigos.uj@renesas.com>
Ensure that the order of properties in the output DTS file matches the
order in which they are defined in the DTS source files by moving props
to the end of the dictionary when they are accessed.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Split long arrays into multiple lines to improve readability of the
output DTS file. A new line is started when the array data exceeds
80 characters.
Add a few test entries to verify the new behavior.
Note: the F821 linter suppression prevents flagging 'array_start' and
'array_newline' as undefined variables. This is because these variables
are initialized when an opening brace is output, which is necessarily
before any element in a byte or prop array. A sequence of markers not
following this pattern would indicate a bug in the DTS parsing code.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Tweak the existing filename_and_lineno test to also check the generated
comments in the string representation of the devicetree match expected
contents and alignment.
Using tmpdir as the base directory simplifies the comparison by avoiding
directory separator issues.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
This commit allows comments to reference files with paths that are relative
to the Zephyr workspace root. This is done by adding a new argument
'--workspace-dir' to the 'gen_edt.py' script, which is passed to the
'EDT' and 'DT' classes and used instead of the current working directory.
The workspace directory is set to WEST_TOPDIR if West is in use,
otherwise it is set to the parent directory of ZEPHYR_BASE so that
Zephyr files have a 'zephyr/' prefix.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
The root node is the first node in the DTS string representation, and is
currently separated from the headers by two empty lines.
Adjust the spacing so that only one line is printed in all situations. A
small adjustment is added to the test suite to keep the current expected
outputs unchanged.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Output lineno/filename as comments in the string representation of a DT
to help with debugging DT issues. Also, remove the added comments when
comparing the string representation of a DT to a reference string in the
DT testsuite.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
List each element of a property array in a different line to improve
the readability of the generated DTS file.
Update the test suite's expected outputs accordingly.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
The phandle property is auto-generated when parsing the DTS, so there is
no 'source information'. This commit sets the filename and line number
of the phandle property to be the same as the first reference to the
target node.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Make the binding title available from the node the same way
the binding description is propagated.
Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
Replaced nested loops with a list comprehension
to improve performance. Execution time improved
from 0.0046203136444s to 0.0040774345397s
Signed-off-by: James Roy <rruuaanng@outlook.com>
Add a 'title' keyword to the binding to provide a short
description of the binding, while 'description' serves as
the long description.
Signed-off-by: James Roy <rruuaanng@outlook.com>
Remove the redundant keys method when using the
in statement on a dict to fix the Ruff SIM118
warning.
Signed-off-by: James Roy <rruuaanng@outlook.com>
This change enhances the devicetree library by adding support for tracking
the source filename and line number for nodes and properties.
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Node properties are not created for all properties defined
by the node's binding (Binding.prop2specs),
only for those that actually have a value.
Signed-off-by: Christophe Dufaza <chris@openmarl.org>
PropertySpec.path does NOT tell "the file where the property
was last modified", but instead the binding file specifying
the devicetree node of which this is a property.
See: #65135
Signed-off-by: Christophe Dufaza <chris@openmarl.org>
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_NODE_HASH(node_id) macro.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Add a series of unit tests which try to cover somewhat systematically
the possible inputs and what we finally get at the exit
of the Binding constructor.
Running the assumption that any (valid) YAML binding file is
something we can make a Binding instance with:
- check which properties are defined at which level (binding,
child-binding, grandchild-binding, etc) and their specifications
once the binding is initialized
- check how including bindings are permitted to specialize
the specifications of inherited properties
- check the rules applied when overwriting a binding's description
or compatible string (at the binding, child-binding, etc, levels)
Some tests covering known issues are disabled by default:
- this permits to document these issues
- while not causing CI errors (when running the python-devicetree
unit tests)
- enabling these tests without causing errors should allow us
to consider the related issues are fixed
Signed-off-by: Christophe Dufaza <chris@openmarl.org>
This simplifies the code and makes it clearer that both properties are
defined in terms of the Binding object matched to a given DT node.
Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
Moves several node-specific operations inside the Node class to improve
its encapsulation, remove a monkey patch and access to internal methods
and fields.
Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
[1] was introduced to get more valuable answers from
the PropertySpec.path API, which is supposed to tell
in which file the property's specification was "last modfied".
Further work on related issues [2] showed that the
approach chosen in [1] is dead end: we need to first rethink
how bindings (and especially child-bindings) are initialized.
[1] edtlib: fix last modified semantic in included property specs
[2] edtlib: Preserve paths of properties from included child bindings
See also: #65221, #78095
This reverts commit b3b5ad8156.
Signed-off-by: Christophe Dufaza <chris@openmarl.org>
Use-case "B includes I includes X":
- X is a base binding file, specifying common properties
- I is an intermediary binding file, which includes X
without modification nor filter
- B includes I, filtering the properties it chooses
to inherit with an allowlist or a blocklist
Check that the properties inherited from X via I
are actually filtered as B intends to,
up to the grandchild-binding level.
Signed-off-by: Christophe Dufaza <chris@openmarl.org>
This unit test was added to cover the change introduced by [1].
Further work on related issues [2] showed that the chosen approach
is dead end.
We're reverting all changes made in [1].
[1] edtlib: fix last modified semantic in included property specs
[2] edtlib: Preserve paths of properties from included child bindings
See also: #65221, #78095
This reverts commit 70eaa61cb0.
Signed-off-by: Christophe Dufaza <chris@openmarl.org>
This unit test was added specifically to cover a regression
reported by the CI while working on [1].
Further work on related issues [2] showed that:
- [1] and [2] are dead end: we need to first rethink
how bindings (and especially child-bindings) are initialized
- the inclusion mechanism supported by Zephyr deserves more systematic
testing in edtlib if we want to work with confidence
The approach we choose is to:
- revert all changes made in [1]
- from there, systematically add unit tests as we address
the issues we identified (or the additional features we need)
one after the other
[1] edtlib: fix last modified semantic in included property specs
[2] edtlib: Preserve paths of properties from included child bindings
See also: #65221, #78095
This reverts commit 33bb3b60d9.
Signed-off-by: Christophe Dufaza <chris@openmarl.org>
Adjust existing tests to support the changes and add new tests to test
the newly added feature.
Signed-off-by: Joel Hirsbrunner <jhirsbrunner@baumer.com>
It is currently impossible to use enum with any array like type (i.e.
string-array and array, these are the only ones that make sense) in the
devicetree and dt-bindings.
However, there is no such remark in the dt-bindings section of the docs.
Since this is a feature that comes in very handy and is implemented
fairly easily, I adjusted the scripts for this.
It is now possible to do something like this.
```yaml
compatible = "enums"
properties:
array-enum:
type: string-array
enum:
- bar
- foo
- baz
- zoo
```
```dts
/ {
enums {
compatible = "enums";
array-enum = "foo", "bar";
};
};
```
Signed-off-by: Joel Hirsbrunner <jhirsbrunner@baumer.com>