Adds ability to get properties from the /cpus group,
in the goal of retrieving timebase-frequency for CPU groups.
Signed-off-by: Camille BAUD <mail@massdriver.space>
On arrays DT_ENUM_HAS_VALUE() and DT_INST_ENUM_HAS_VALUE()
were only checking the first index, this changes it to check all indexes.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.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>
DT_ENUM_HAS_VALUE_BY_IDX states, that the value
must be lowercase-and-underscores, this makes sure,
that they can match.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
Extract the part of `dts.cmake` that invokes `gen_dts_cmake.py`, then
generalize it into a CMake extension, which can be reused by sysbuild.
The Python script itself is also updated, so that the generated CMake
file can accept an input variable DEVICETREE_TARGET, which comes from
the `zephyr_dt_import(TARGET ...)` argument.
Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
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>
The motivation for this patch was to improve the script's performance,
but some stylistic changes and cleanups are included as well.
The main optimization concerns the use of PyYAML, as it offers multiple
functions for interpreting YAML. The commonly used `load`/`safe_load`
converts a YAML stream to a dictionary. There are also `scan`, `parse`,
and `compose`, which return intermediate representations, the last one
being a graph. [1]
Since `gen_driver_kconfig_dts` scans DT bindings for compatible strings,
it only needs to look through top level keys in YAML. The intermediate
PyYAML graph is sufficient for this, and using it reduces the script's
execution time by about 30%, without making the code too complicated.
[1] - https://pyyaml.org/wiki/PyYAMLDocumentation
Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
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>
Remove deprecated _ENUM_TOKEN and _ENUM_UPPER_TOKEN. These are
deprecated for over three years by now.
Signed-off-by: Joel Hirsbrunner <jhirsbrunner@baumer.com>