Some of these are also tripping up a python 2 / python 3 warning
in mypy in the way that '{}'.format(b'foo') works, which we silence by
explicitly requesting the python 3 behavior.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The way that _init_tokens() is manipulating globals() defeats static
analyses of the file that are trying to infer a type for the 'tok_id'
variable in assignment expressions like 'tok_id = _T_INCLUDE'.
To make it easier on the analyser, define the token types as an
enum.IntEnum named _T. This means we can write e.g. '_T.INCLUDE'
instead of '_T_INCLUDE', avoiding line length increases in the lexing
code.
While we're here, use '==' and '!=' instead of 'is' and 'is not'
when comparing a tok_id that is obtained from an re.Match.lastindex
with a _T.FOO value.
This is now necessary since an int object and a _T object definitely
don't point to the same memory. It worked previously because CPython
interns all integer instances from -5 to 256, but that's an
implementation detail and not a language feature. Since we're getting
the ints from an re.Match.lastindex instead of putting the exact
_T_FOO values into some list, this code probably should not strictly
speaking have been using 'is'.
Explicitly initialize the global _token_re also, to make it more
visible for static analysis.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Continue annotating the module. In some cases mypy will miss that
_err() calls means the function will not return, so we return an
unnecessary local variable to appease it.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Add a _MarkerType enum. A subsequent commit will use it for type
annotations in the Property class.
Fix an incorrect type in a comment while we're here.
We continue to use 'marker_type is _MarkerType.FOO' instead of
'marker_type == _MarkerType.FOO' because we are adding those actual
_MarkerType.FOO objects to each property, so 'is' comparison
is legitimate.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
A step along the way towards typing the whole module.
Fix an incorrect (or at best misleading) comment while we're here,
which was noticed by the type checker when I originally annotated
'props' as a Dict[str, bytes].
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Marking this NoReturn helps the type checker figure out that functions
which call it are only returning valid values or failing to
return. (It unfortunately doesn't always work as mypy's control flow
analysis seems to treat a direct 'raise DTError(...)' differently than
calling _err() in some situations, but it helps.)
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Move the DTError, Node, Type, and Property definitions to the top.
This way, class definitions occur before methods which use those
classes. This will be useful to avoid string literals in type
annotations that will be added later. Some can't be avoided due to
circular dependencies, but this will help.
Adjust whitespace.
No functional changes expected.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
It can be convenient to "iterate" over the elements of a property, in
the same way it is convenient to "iterate" over enabled instances.
Add a new macro for doing this, along with a DT_INST_FOREACH_PROP_ELEM
variant.
This is likely to be more convenient than UTIL_LISTIFY or FOR_EACH in
some situations because:
- it handles inputs of any length
- compiler error messages will be shorter and more self-contained
- it is easier to use with phandle-array type properties, which
require more complicated macro boilerplate when used with
util_macro.h APIs
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
We already have support for handling the Zephyr binding "path" type in
edtlib.Node._prop_val(), but the binding inference code isn't making
use of that. Handle this type as well, as it is just as convenient as
Type.PHANDLE and can be more idiomatic depending on the situation.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Instead of hard-coding constants, use an IntEnum.
These is still a subclass of 'int', but is both easier to import and
easier to read during debugging.
For example, compare:
>>> Type.BYTES
<Type.BYTES: 1>
with:
>>> TYPE_BYTES
1
However, 'Type.BYTES == 1' is still True, and the enum values
otherwise behave like you would expect.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Add the ability to filter which properties get imported when we do an
include. We add a new YAML form for this:
include:
- name: other.yaml
property-blocklist:
- prop-to-block
or
include:
- name: other.yaml
property-allowlist:
- prop-to-allow
These lists can intermix simple file names with maps, like:
include:
- foo.yaml
- name: bar.yaml
property-allowlist:
- prop-to-allow
And you can filter from child bindings like this:
include:
- name: bar.yaml
child-binding:
property-allowlist:
- child-prop-to-allow
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
We are now in the process of extracting edtlib and dtlib into a
standalone source code library that we intend to share with other
projects.
Links related to the work making this standalone:
https://pypi.org/project/devicetree/https://python-devicetree.readthedocs.io/en/latest/https://github.com/zephyrproject-rtos/python-devicetree
This standalone repo includes the same features as what we have in
Zephyr, but in its own 'devicetree' python package with PyPI
integration, etc.
To avoid making this a hard fork, move the code that's being made
standalone around in Zephyr into a new scripts/dts/python-devicetree
subdirectory, and handle the package and sys.path changes in the
various places in the tree that use it.
From now on, it will be possible to update the standalone repository
by just recursively copying scripts/dts/python-devicetree's contents
into it and committing the results.
This is an interim step; do NOT 'pip install devicetree' yet.
The code in the zephyr repository is still the canonical location.
(In the long term, people will get the devicetree package from PyPI
just like they do the 'yaml' package today, but that won't happen for
the foreseeable future.)
This commit is purely intended to avoid a hard fork for the standalone
code, and no functional changes besides the package structure and
location of the code itself are expected.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Whenever a child-binding: dict has a compatible, we ought to make
that available in EDT._compat2binding. If we don't, we can't look it
up later.
This has adverse effects like missing child bindings which describe
buses.
Fixes: #32071
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Commit 0d4dca10b2 ("scripts: edtlib:
child binding compatibles match parents") was a hack meant to keep the
edtlib.Binding class in place without modifying some twister behavior
that needed further changes to work properly with first-class binding
objects.
This is a hack and is no longer necessary, so back out of this change.
Child Binding objects now have None compatible properties unless the
binding YAML explicitly sets a compatible.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Allow users to set the new EDT constructor argument which errors out
on deprecated properties via a command line argument.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
We'd like to start eliminating deprecated properties from upstream
Zephyr devicetrees. To make that possible in the build system, add an
EDT kwarg that does just that.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Commit 6bf761fc0a ("dts: Remove support
for deprecated DTS binding syntax") removed most of the support for
the 'legacy' bindings syntax.
A few straggler keys are still around in the bindings check code,
though. This allows some legacy keys which should cause errors to pass
silently instead.
Fix the error handling and print good errors for cases which are
removed, just in case someone is still using them somewhere.
Clean up some other error messages in the same function while we're
here.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This macro returns a node's name with unit-adddress, given its node
identifier.
The node name is useful information for the user to utilize for debug
information, similar to DT_NODE_PATH, or DT_LABEL.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Change the use of a f-string to a normal string as there is nothing
that needs formatting in the particular instance.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
While using the encoded path to a device tree node guarantees a unique
identifier for the corresponding device there is a limit on the number
of characters of that name that can be captured when looking up a
device by name from user mode, and the path can exceed that limit.
Synthesize a unique name from the node dependency ordinal instead, and
update the gen_defines script to record the name associated with the
full path in the extern declaration.
Add a build-time check that no device is created with a name that
violates the user mode requirement.
Also update the network device DTS helper functions to use the same
inference for dev_name and label that the real one does, since they
bypass the real one.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Before we had a bindings index in the documentation, the generated
header file was (somewhat unfortunately) often our best reference for
what a particular binding or property within a binding ends up doing,
so it made good sense to put the description in the generated file.
Now that we have HTML documentation that's a bit more digestible than
the generated file, though, we can just point users at that. Do that
and remove the inline description from the generated file.
This makes it possible to put C-style multiline comments in the
descriptions themselves, which will be done in subsequent patches.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This macro returns a node's full path, given its node identifier.
The entire path to a node is useful information for the user which can
be added to build-time error messages.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Generate a header (device_extern.h) that handles extern of possible
device structs that would come from devicetree. This removes the need
for DEVICE_DT_DECLARE and DEVICE_DT_INST_DECLARE which we can remove.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
There are some drivers in the tree that support devices on multiple
different buses, although so far this has not been represented in
device tree using the bus concept. In order to convert these drivers &
bindings to refer to a formal bus in device tree we need to be able to
match bindings which lack an explicit "on-bus: ..." value against any
parent bus. This will also be needed for any external bindings, since
those would not be aware of on-bus (as it's a Zephyhr-specific
extension).
The two drivers I'm particularly targeting is the ns16550 UART driver
(drivers/serial/uart_ns16550.c) and the DW I2C driver
(drivers/i2c/i2c_dw.c). They both support devices with a fixed MMIO
address as well as devices connected and discovered over PCIe. The
only issue is that instead of encoding the bus information the proper
DT way these bindings use a special "pcie" property in the DT node
entries to indicate whether the node is on the PCIe bus or not.
Being able to convert the above two drivers to use the DT bus concept
allow the removal of "hacks" like this:
if DT_INST_PROP(0, pcie) || \
DT_INST_PROP(1, pcie) || \
DT_INST_PROP(2, pcie) || \
DT_INST_PROP(3, pcie)
to the more intuitive:
if DT_ANY_INST_ON_BUS_STATUS_OKAY(pcie)
This also has the benefit that the driver doesn't need to make any
arbitrary assumptions of how many matching devices there may be but
works for any number of matches. This is already a problem now since
e.g. the ns16550 driver assumes a maximum of 4 nodes, whereas
dts/x86/elkhart_lake.dtsi defines up to 9 different ns16550 nodes.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
The DTS language permits zeroing out phandles in a phandle array to
say "there's nothing at this index", and dtlib manages that correctly,
but edtlib and gen_defines.py aren't equipped to do so.
Fix this by allowing None elements in the lists of ControllerAndData
values returned by edtlib for such properties.
Handle that in gen_defines.py by setting the generated
DT_N_<node>_P_<prop>_IDX_<i>_EXISTS macro to 0 in such cases.
The DT_N_<node>_P_<prop>_LEN macro still accounts for the entire
length of the phandle-array; it's just that some indexes may be
missing data.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
These are likely enough defined by mistake to emit a warning for.
Adjust tests to match, tweaking the test_warnings() setup: now that
we've got several test cases, it's a bit cleaner not to have to
copy/paste the ('edtlib', WARNING, ...) part of every expected log
record tuple.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The edtlib strategy for emitting warnings is to print directly to
standard error. This in turn requires hacks to drop stored references
to stderr in various _warn_file attributes so the EDT objects can be
pickled.
In general, I think it's not really appropriate for library modules
like edtlib to be printing to stderr directly. The user should be able
to configure logging for general utility data munging modules like
this as they please, and not just deciding what file to print to.
Move this around so the standard logging module is used instead. We
can preserve backwards compatibility in gen_defines by customizing the
'edtlib' logging module behavior so it prints the exact same thing it
always has.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Whenever a devicetree binding defines a string property whose
enumerated values are all tokenizable, generate C macros for each
property value that are the corresponding tokens.
Note that "token" is distinct from "identifier": both 'foo' and '123'
are valid tokens, but only 'foo' is a valid identifier. We permit some
strings which are not valid identifiers in anticipation that the
generalization may be useful, e.g. when defining macros that paste the
token onto a prefix that makes the whole thing an identifier.
Fixes: #21273
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Add enum_tokenizable and enum_upper_tokenizable to PropertySpec. These
allow a PropertySpec to declare that it both has an enumeration of
values and all of them are strings which are "tokenizable". Don't
bother extending Property with these; the user can access the
information through Property.spec now, so the extra delegation is
unnecessary.
See the docstrings for details on what "tokenizable" means. The basic
idea is that we should be able to use the DT binding's enum values as
C 'enum' enumerators in a "reasonable way".
Add val_as_token to Property. This produces a canonical token for the
property value.
Add tests for this feature in particular and property enumerations in
general.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
In the 'normal' case of a property whose definition is taken from a
binding YAML file, a fair number (three at present) of the attributes
available on Property objects are directly taken from the
corresponding PropertySpec object.
Refactor the internals of how a Property gets initialized so that it
has a direct reference to its PropertySpec, and make those attributes
properties which just delegate to the PropertySpec (which in turn just
delegate to the binding). Additionally, expose the PropertySpec
directly.
This will make it easier to extend the Property class with additional
attributes that normally come from the PropertySpec without having to
touch all the locations where Property.__init__ is called.
In the case of the 'default' properties, we handle this by dummying
out some PropertySpec objects. These dummy PropertySpecs in turn
require a dummy Binding.
This change has the advantage that it improves the degree to which
these defaults are checked, e.g. it makes sure that 'status' is one of
the permitted values.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
We have a use case for checking the results of a DT_PROP_HAS_IDX()
call with COND_CODE_1(). That won't work because its expansion is an
integer comparison; COND_CODE_1() expects a literal 1 or 0.
Adjust the macro implementation so it expands to a literal 1 or 0.
Make this work even when the index argument needs an expansion while
we're at it.
Fixes: #29833
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Fixes: #29758
Commit 7165b77a81 ("scripts: edtlib:
refactor for first class bindings") introduced a Binding class.
Its child_binding instance attribute has a compatible which can be
None. Adjust this behavior so the child Binding object has the same
compatible as the parent binding which ultimately has a compatible.
Without this, sanitycheck's expr_parser is doing some matching on
compatibles in child nodes that is producing unexpected results.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The child_binding object should default to having a path and
compatible that matches the parent's. Mark it as xfail because the
compatible part is failing.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This is a convenience function for creating a bunch of Binding objects
from files in a directory.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Add the ability to mark a property as 'deprecated' to get a warning that
it will be removed in the future.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
_prop_val comment referred to one of the arguments called "optional"
however the code has changed to call that argument "required" now. Fix
up the comment block to use the correct argument name and semantics of
that argument.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Add two new types: Binding and PropertySpec.
- Binding is a first-class abstraction for a devicetree binding
file as defined by a YAML file in the Zephyr syntax.
- PropertySpec is a helper type which represents a property
definition within a Binding.
Make the Binding constructor a new entry point to the library. This
enables users to deal with bindings as standalone entities, apart from
how they characterize a particular devicetree.
Rework the EDT and Node internals that deal with bindings as dict
values to use the Binding type instead. To make this less ambiguous,
use the variable name 'raw' when we're dealing with a binding as it's
parsed from YAML, and 'binding' when we're dealing with a Python
Binding object.
This commit drops support for the following legacy bindings keys
- '#cells': use '*-cells' instead (e.g. 'gpio-cells', 'pwm-cells')
- "child-bus: foo" and "child: bus: foo": use "bus:" instead
- "parent-bus" and "parent: bus: ": use "on-bus:" instead
Officially, legacy bindings have been gone since
6bf761fc0a ("dts: Remove support for deprecated DTS binding
syntax"), so this is vestigial code, and I couldn't find any in-tree
users.
It also drops the convention in this file that ""-strings are
preferred.
I honestly don't understand why this was ever enforced; the file
itself admits single quotes are common in Python and we use them
elsewhere in Zephyr's Python code.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Add the first API functions that directly deal with node dependency
ordinals as determined by edtlib:
- DT_DEP_ORD(node_id): node_id's ordinal
- DT_REQUIRES_DEP_ORDS(node_id): list of dep ordinals for node_id's
direct dependencies
- DT_SUPPORTS_DEP_ORDS(node_id): list of dep ordinals for nodes
depending directly on node_id
- DT_INST_ equivalents
This is not meant to be an exhaustive set of macros related to
dependency ordinals; rather, it's a starting out point meant to enable
initial struct device dependency tracking work. We can add more if
needed.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The legacy macros were first deprecated in Zephyr v2.3. Now that
Zephyr v2.4 has been released, that makes two releases where these
macros have been deprecated, so it's OK to remove them.
This leaves support for legacy binding syntax in place. Removing that
is left to future work.
We need to update various pieces of documentation related to flash
partitions that never got updated when the new API was introduced.
Consolidate this information in the flash_map.h API reference page,
since that's really where users will run into it. This also gives us
the opportunity to improve this documentation.
Adjust a couple of kconfigfunctions.py and sanitycheck bits to use
non-legacy edtlib APIs.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Each controller node in a phandle-array may set the number of cells in
a specifier as any nonnegative integer. Currently, we don't allow
this in edtlib in the case where there are multiple controllers in a
phandle-array property all of which have 0 cells in the relevant
specifier, which is not correct. Fix this, add a regression test, and
improve the error message while we are here.
Fixes: #28709
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Add a lookup table for finding a node by its dependency ordinal.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Make the scc_order method a property instead. This is in keeping with
the "General biased advice" at the top of file.
The actual order is therefore lazily initialized in this commit and
the order is not computed by the time __init__() returns. The next
commit will invoke scc_order by the time the constructor returns.
This is preparation work for adding a lookup table from dependency
ordinals to nodes. The combination of these two changes will make
intializing that lookup table a bit easier.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
We don't want to support cyclic dependency structures, because it
means that Node objects cannot have dep_ordinal attributes as they are
currently documented to possess unconditionally.
Nevertheless, we have some in our tests. Remove them by extracting the
/props/ctrl-X nodes to the same level as the /props nodes. This breaks
a cycle caused by:
- /props/ctrl-X nodes depend on /props because of the parent/child
relationship
- /props depends on /props/ctrl-X because it refers to them by phandle
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Use the pytest test framework in the dtlib.py and edtlib.py test
suites (testdtlib.py and testedtlib.py respectively).
The goal here is not to change what is being tested. The existing test
suite is excellent and very thorough.
However, it is made up of executable scripts where all of the tests
are run using a hand-rolled framework in a single function per file.
This is a bit all-or-nothing and prevents various nice features
available in the de-facto standard pytest test framework from being
used.
In particular, pytest can:
- drop into a debugger (pdb) when there is a problem
- accept a pattern which specifies a subset of tests to run
- print very detailed error messages about the actual and expected
results in various traceback formats from brief to very verbose
- gather coverage data for the python scripts being tested (via plugin)
- run tests in parallel (via plugin)
- It's easy in pytest to run tests with temporary directories
using the tmp_path and other fixtures. This us avoid
temporarily dirtying the working tree as is done now.
Moving to pytest lets us leverage all of these things without any loss
in ease of use (in fact, some things are nicer in pytest):
- Any function that starts with "test_" is automatically picked up and
run. No need for rolling up lists of functions into a test suite.
- Tests are written using ordinary Python 'assert'
statements.
- Pytest magic unpacks the AST of failed asserts to print details on
what went wrong in really nice ways. For example, it will show you
exactly what parts of two strings that are expected to be equal
differ.
For the most part, this is a pretty mechanical conversion:
- extract helpers and test cases into separate functions
- insert temporary paths and adjust tests accordingly to not match
file names exactly
- use 'assert CONDITION' instead of 'if not CONDITION: fail()'
There are a few cases where making this happen required slightly
larger changes than that, but they are limited.
Move the checks from check_compliance.py to a new GitHub workflow,
removing hacks that are no longer needed.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Tell the EDT instance that properties of the /zephyr,user node should
be generated based on the binding types inferred from the property
content.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Clean up of devicetree tooling removed generation of information
present in devicetree in nodes that have no compatible, or for extra
properties not defined by a binding. Discussion proposed that these
properties should be allowed, but only in a defined node /zephyr,user.
For that node infer bindings based on the presence of properties.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
Consolidate creation of edtlib.EDT objects from a build directory's
devicetree into one place by loading it from build/zephyr/edt.pickle
everywhere. A previous commit creates edt.pickle from gen_defines.py.
In addition to probably speeding things up slightly by not reparsing
the devicetree, the main benefit of this approach is creating a single
point of truth for the bindings directories and warnings
configuration, meaning we don't have to worry about them getting out
of sync while being passed around between devicetree creation and
usage time.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
We only have one use of _binding_compat and it doesn't need self, so
just fold it into _init_compat2binding.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
We deprecated a number of aspects of the DTS binding syntax in Zephyr
2.1. Remove the support for the deprecated syntax. Remove from docs
about the deprecated syntax as well.
Removed reference in release-notes-2.1.rst to legacy_binding_syntax
since that anchor doesn't exist anymore.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
We need to save and restore the devicetree data to generate optimized
dependency information later on in the build, in particular during the
final application link.
Make this happen by pickling the EDT object in BUILD_DIR/edt.pickle.
The existence of this file is an implementation detail, so do not add
it to the documentation.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
We have a use case for saving the EDT object to be able to open it up
again later. It would be convenient to be able to do this with the
pickle module from stdlib.
The only thing stopping us from doing that appears to be the open
reference to sys.stderr that's held the edt object even after
EDT.__init__ exits. However, there doesn't seem to be a need to keep
holding on to this object, and in fact it would be a little bit nicer
to drop the reference in case something else (even in the same Python
process that created it originally) wants the EDT object around, but
might want the warn file closed if its refcount zeroes out.
Just drop the reference at the end of __init__ and make EDT._warn()
throw an exception if it's attempted to be used after the constructor
exits.
Make pickle-ability an API guarantee so we can treat any regressions
as bugs going forward.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
I can't see a good reason to be doing this in the Node class's
unit_addr accessor. Move it up to the edtlib initialization so it only
happens once.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Add test cases that verify various bits and pieces of the legacy
devicetree macros match the new APIs.
Writing these test cases without giving rise to deprecated macro
warnings which might break people's CI if they build with -Werror
requires turning off the __WARN() generation in
devicetree_legacy_unfixed.h. The entire file is deprecated at this
point and must be explicitly enabled with an opt-in Kconfig option, so
there isn't any harm in doing this.
Nevertheless, take a minimally invasive approach to avoiding __WARN()
generation in gen_legacy_defines.py, to avoid the possibility of
breakage. This code is basically frozen anyway, so hacks like this
won't cause maintainability problems since it isn't being actively
maintained.
Use the new tests as fodder for a migration guide from the old API in
the documentation.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Some updates to the reference page for the "core" APIs, and associated
follow-ups in the guides:
- centralize documentation of chosen zephyr nodes in a non-legacy
file, provide a reference to them from the intro page in the guide
- review doxygen docstrings and correct errors for generic APIs
- add introductory text to each section in the API reference
- add missing hardware-specific pages
Documentation for layers built on top of these is mostly left to future
commits, but I do have a smattering of fixes in the guides that I
noticed while I was doing this.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Add DT_NODE_BY_FIXED_PARTITION_LABEL that given a "label" in any
fixed-partitions map will return the node_id for that partition node.
Add DT_NODE_HAS_FIXED_PARTITION_LABEL that will test if a given
fixed-partitions "label" is valid.
Add DT_FIXED_PARTITION_ID that will return an unique ordinal value for
the partition give a node_id to the partition.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
If we have a fixed-partition on a flash device that is for example on
a spi controller we will not get a binding match currently. This is
because we expect a match between both the compatible and the fact that
fixed-partition node is a decendant of the spi bus.
To address this we treat fixed-partitions as if they are on no bus.
This has the effect of causing a binding match as well as ensuring that
when we process the fixed-partition node we will do anything special to
it because of the bus it happens to be under (for example SPI CS_GPIO
processing).
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Setup node.compats right after we create the Node. This allows access
to the compats information in _bus_node.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Usually, we want to operate only on "available" device
nodes ("available" means "status is okay and a matching binding is
found"), but that's not true in all cases.
Sometimes we want to operate on special nodes without matching
bindings, such as those describing memory.
To handle the distinction, change various additional devicetree APIs
making it clear that they operate only on available device nodes,
adjusting gen_defines and devicetree.h implementation details
accordingly:
- emit macros for all existing nodes in gen_defines.py, regardless
of status or matching binding
- rename DT_NUM_INST to DT_NUM_INST_STATUS_OKAY
- rename DT_NODE_HAS_COMPAT to DT_NODE_HAS_COMPAT_STATUS_OKAY
- rename DT_INST_FOREACH to DT_INST_FOREACH_STATUS_OKAY
- rename DT_ANY_INST_ON_BUS to DT_ANY_INST_ON_BUS_STATUS_OKAY
- rewrite DT_HAS_NODE_STATUS_OKAY in terms of a new DT_NODE_HAS_STATUS
- resurrect DT_HAS_NODE in the form of DT_NODE_EXISTS
- remove DT_COMPAT_ON_BUS as a public API
- use the new default_prop_types edtlib parameter
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Even though it is about to be done for sound technical reasons, a
subsequent patch adding access to all device nodes at the last minute
in the 2.3 release is going to be playing a bit of a fast one on
the Zephyr community, especially users of DT_INST APIs.
In particular, instance numbers are currently allocated only to
enabled nodes, but that will not be true soon: *every* node of a
compatible will be allocated an instance number, even disabled ones.
This is especially unfortunate for drivers and applications that
expect singletons of their compatibles, and use DT_INST(0, ...) to
mean "the one enabled instance of my compatible".
To avoid gratuitous breakage, let's prepare for that by sorting each
edt.compat2nodes sub-list so that enabled instances always come before
disabled ones.
This doesn't break any API guarantees, because there basically *are*
no ordering guarantees, in part precisely to give us the flexibility
to do things like this. And it does help patterns that use instances 0
through N-1, including the important singleton case.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The macro iterates through the list of child nodes and invokes provided
macro for each node.
Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Remove semicolon between instance invocations of DT_FOREACH_IMPL_ and
thus DT_INST_FOREACH. This provides more flexibility to the user. This
requires we fixup in tree users to add semicolon where needed.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
These look up tables generalize the compat2enabled map in a way we
will need to make the API more flexible in Zephyr.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Let's get the actual node status, instead of relying on enabled.
Leave enabled in place for gen_legacy_defines.py's sake.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
If a devicetree node doesn't have a matching binding we will at least
populate a common standard set of properties for that node. The list of
standard properties is:
compatible
status
reg
reg-names
label
interrupt
interrupts-extended
interrupt-names
interrupt-controller
This allows us to handle cases like memory nodes that don't have any
compatible property, we can still generate the reg values.
We limit this to known properties as for any other property we can not
fully determine the property type without a binding and thus we can't
ensure the generation for that property is correct or may not change.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
It's a common operation to want to find a node based on its label. Add
a lookup table to make this easier.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Add a __WARN("Macro is deprecated") to all DT_<COMPAT>_BUS_<BUS> macros
now that all in tree users should have been converted to the new macros.
This is intended to make sure any PRs don't introduce new usages of
these macros.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Add a __WARN("Macro is deprecated") to all DT_INST macros now that all
in tree users should have been converted to the new macros.
This is intended to make sure any PRs don't introduce new usages of
these macros.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Always generate the comment text specifying a node's path identifier.
Add the DT_ prefix so it matches the actual macro usable from C. This
will make a following patch which adds support for accessing a node's
parent result in a generated header file which is easier to read.
Put the node's path right after "Devicetree node:" in the comment.
This makes the section for that node easier to grep for.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The root node's z_path_id value for the duration of this script
doesn't match the value DT_ROOT is defined to in devicetree.h.
I didn't notice this because the root node's compatible doesn't have a
matching binding in practice, so no macros are generated for it, but
we're about to start looking at node parents explicitly and this is an
issue for that. Fix it so the root node's z_path_id is "N", since
DT_ROOT is the token "DT_N".
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Add generation of the following macros:
DT_N_<node-id>_REG_IDX_<idx>_EXISTS 1
DT_N_<node-id>_IRQ_IDX_<idx>_EXISTS 1
This will allow us to use IS_ENABLED() in DT_REG_HAS_IDX and
DT_IRQ_HAS_IDX which matches behavior of other DT_*_HAS_* macros as
well as lets use these with COND_CODE_1.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Add generation of the following macros:
DT_N_<node-id>_P_<prop-id>_NAME_<NAME>_EXISTS
DT_N_<node-id>_P_<prop-id>_IDX_<idx>_EXISTS
This will be useful to check availability of named or indexed
property like dmas/dma-names.
Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
The last user of the .conf file format DTS data has been removed. We
can now remove the generation and associated support for the .conf file.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Due to the use of UTIL_EVAL*() macros, the UTIL_LISTIFY() macro used
by DT_INST_FOREACH(foo) can cause long build errors when there is a
build error in the expansion for "foo". More than a thousand lines of
build error output have been observed for an error in a single line of
faulty C.
To improve the situation, re-work the implementation details so the
errors are a bit shorter and easier to read. The use of COND_CODE_1
still makes the error messages quite long, due to GCC generating notes
for various intermediate expansions (__DEBRACKET,
__GET_ARG_2_DEBRACKET, __COND_CODE, Z_COND_CODE_1, COND_CODE1), but
it's better than the long list of UTIL_EVAL notes.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
And implement DT_ANY_INST_ON_BUS() in terms of it.
This makes some error messages quite a bit shorter by avoiding
UTIL_LISTIFY(), which has a nasty temper and tends to explode if not
treated gently.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
We get the following error:
ValueError: max() arg is an empty sequence
if the compatiable section of the device tree is empty or doesn't exist.
Fix this by havingin max_len get a default value of 0.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This is joint work with Kumar Gala (see signed-off-by).
This supports a new devicetree macro syntax coming. It's not really
worth mixing up the old and the new generation scripts into one file,
because:
- we aim to remove support for the old macros at some point, so it
will be cleaner to start fresh with a new script based on the old one
that only generates the new syntax
- it will avoid regressions to leave the existing code alone while
we're moving users to the new names
Keep the existing script by moving it to gen_legacy_defines.py and
changing a few comments and strings around. It's responsible for
generating:
- devicetree.conf: only needed by deprecated kconfigfunctions
- devicetree_legacy_unfixed.h: "old" devicetree_unfixed.h macros
Put a new gen_defines.py in its place. It generates:
- zephyr.dts
- devicetree_unfixed.h in the new syntax
Include devicetree_legacy_unfixed.h from devicetree.h so no DT users
are affected by this change.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
If the #address-cells property for a register is 0 than we set the addr
value of the reg to None. Similar, if #size-cells is 0 than we set the
size value to None for the reg.
Fixup kconfigfunctions.py to handle reg.size and reg.addr being None.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This rename is mostly to easy git managment and review so any changes or
the addition of the new gen_defines.py doesn't look like a diff against
the old code if you look at just that commit.
We keep changes to a minimum to just keep things building with the
renamed gen_legacy_defines.py.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This returns the entire logical {name: Node} dictionary which is
currently being accessed element by element via chosen_node(name).
It will be used in a new gen_defines.py for moving the handling of
chosen nodes into C from Python.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Pad node identifiers to 60 characters. This results in better
alignment in practice than the current value of 40, which is a bit
low.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This too is an attempt to reimplement the previous behavior exactly,
modulo the order in which things are defined.
This is the last function which is calling into the previous
implementation's out_node and node_*_alias() functions, so these can
be removed now.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This is similar to the work already done for regs.
Other than the order in which they appear and comments, the output
before and after this patch should be exactly the same.
We're intentionally leaving some of the helpers in module scope here
to use some of the subroutines elsewhere later on when reworking
write_spi_dev().
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Mirror the change already done to write_regs().
Other than the order in which they appear and comments, the output
before and after this patch should be exactly the same.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Use augmented nodes to print macros grouped by namespace.
Other than the order in which they appear and comments, the output
before and after this patch should be exactly the same.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Group the macros together by namespace rather than putting all the
BASE_ADDRESS macros together and all the SIZE macros together. E.g.,
all the DT_INST_<x> namespace macros for each node now appear
consecutively.
Add a comment making it clear that this output comes from "regs",
since "BASE_ADDRESS" and "SIZE" are not property names.
Other than the order in which they appear and comments, the output
before and after this patch should be exactly the same.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Add additional attributes to each edtlib.Node we process, before
calling into the write_foo() routines.
This includes the identifier returned by node_ident(), which is used
as the primary identifier for the node, as well as lists for instance
and aliases nodes, and a catchall list that contains all the other
identifiers in addition to the primary one.
Use this information in a new for_each_ident(node, ident) def that
will be put to use in the various write_foo() routines.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
spi_dev_cs_gpio() takes a Node and returns the chip select GPIO for it.
Having that information available directly from Node is neater, so turn
it into a Node.spi_cs_gpio property instead.
That gets rid of the only public global function in edtlib, which might
make the API design clearer too.
Tested with the sensortile_box board, which uses SPI chip select.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
It's better to allow per-instance EDT configuration than to set a global
variable on the edtlib module. Enable/disable the warning for reg/unit
address mismatches via a flag to EDT.__init__(), instead of via a global
variable. That makes it consistent too.
Another option would be to pass the 'dtc' flags to EDT.__init__(), but
it makes the interface a bit ugly. Maybe if it needs to emulate lots of
other flags later.
Clarify that edtlib itself isn't meant to have any state in the comment
at the top of the module.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Add a 'deprecation_msg' string/flag to out_dev(). When 'deprecation_msg'
is passed, all generated macros include
__WARN(<deprecation_msg>)
which prints a custom warning if the macro is used.
Meant to be used when improving the output format.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Single-bus warning in python parsing of device tree is suppressed if
this is also suppresed in the device tree compiler.
Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
Change the key function used to sort nodes so that unit addresses, if
present, break ties between sibling nodes. This orders siblings in
increasing order by unit-address in any gen_defines output that is
sorted by ordinal.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This makes the results easier to read, since node output appears in
the same order as the top level comment summarizing the tree.
Reorganize how flash partitions are emitted so they also appear in
dependency order, allowing us to extend the comment at the top of the
file to say that nodes are emitted in that order, along with other
useful information.
Print comments even for nodes that are disabled or have no binding,
to make it clearer that the script considered them and decided not to
output anything for them.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Change the output during CMake configure from
Devicetree configuration written to .../devicetree.conf
Parsing /home/ulf/z/z/Kconfig
Loaded configuration '.../frdm_kw41z_defconfig'
Merged configuration '.../prj.conf'
Configuration saved to '.../.config'
to
Devicetree header saved to '.../devicetree_unfixed.h'
Parsing /home/ulf/z/z/Kconfig
Loaded configuration '.../frdm_kw41z_defconfig'
Merged configuration '.../prj.conf'
Configuration saved to '.../.config'
Kconfig header saved to '.../autoconf.h'
devicetree_unfixed.h is more useful to be aware of than devicetree.conf
(still hoping we can get rid of it at some point), and seeing the
Kconfig header clarifies things to.
"Saved" instead of "written" for consistency. Maybe it could say
"Kconfig configuration" instead of "configuration" too, though it gets a
bit spammy in other contexts where the message shows up.
Updates Kconfiglib (and menuconfig/guiconfig, just to sync) to upstream
revision 061e71f7d7, to get this commit in, which is used to print the
header path:
Return a message from Kconfig.write_autoconf()
Like for Kconfig.write_config() and Kconfig.write_min_config(),
return a string from Kconfig.write_autoconf() with a message saying
that the header got saved, or that there were no changes to it. Can
be handy in tools.
Also make the "no change" message for the various files more
specific, by mentioning what type of file it is (configuration,
header, etc.)
Return True/False from Kconfig._write_if_changed() to indicate if
the file was updated. This also allows it to be reused in
Kconfig.write_min_config().
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Add a '--dts-out <file>' flag to gen_defines.py that saves the final
devicetree to <file>, in DTS format, using the new EDT.dts_source
attribute.
Handy to have available as a debugging aid. Unused otherwise.
Also write a dummy <BOARD>.dts_compiled file that tells people to look
at zephyr.dts, for people that might be used to that file. It was
removed in commit 8d8b06978c ("dts: Remove generation of
<BOARD>.dts_compiled").
Fixes: #22272
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
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
https://github.com/zephyrproject-rtos/zephyr/pull/21560. That was the
original motivation.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
'type: path' was added to edtlib for completeness in commit 23a5b4963b
("dts: edtlib: Add 'type: path' for path references"). gen_defines.py
crashes if it's ever used though, because it gets confused for a
'type: phandle-array'.
Ignore 'type: path' properties in gen_defines.py, like how
'type: phandle' and 'type: phandles' are currently ignored too.
(Note that gen_defines.py is only one possible user of edtlib.)
Fixes: #22197
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Use f-strings instead of .format() to makes all the macro identifier and
multiline comment building easier to read.
f-strings were added in Python 3.6, which is required by Zephyr now.
Convert some
... + "_" + ...
string building to f-strings as well.
f-strings are a bit faster too (because they avoid format()/str()
lookups), though it's not likely to be noticeable here.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
out_dev(), etc., as a name is a holdover from before commit 73ac1466fb
("scripts: edtlib: Call nodes "nodes" instead of "devices""). It's
confusing for the same reasons as mentioned in that commit.
Renamings:
- dev_ident() -> node_ident()
- out_dev() -> out_node()
- out_dev_s() -> out_node_s()
- dev_aliases() -> node_aliases()
- dev_path_aliases() -> node_path_aliases()
- dev_instance_aliases() -> node_instance_aliases()
Also clean up comments to talk about nodes instead of devices where it
makes sense.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
should_write() returns False for properties that are skipped in
write_properties(). Shortens write_properties() a bit.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
The
"{" + ", ".join(...) + "}"
pattern is in a bunch of places now. Add an out_dev_init() helper for
it, with the same parameters as out_dev().
Also makes "{" vs. "{ " consistent, picking the first one.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Add a helper function verify_error() to testedtlib.py that takes a DTS
source and verifies that it generates a particular EDTError.
Use it to test the hints that the previous commit added to errors
generated by _slice().
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Show how the element size was calculated in the error message when a
'reg', 'ranges', or 'interrupts' property has the wrong size. This
should help with debugging. Also mention that #*-cells properties come
from the parent node, which can be subtle.
Came up in https://github.com/zephyrproject-rtos/zephyr/issues/21607
(though it seems the comment disappeared).
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Add binding support for a 'path' property type, for properties that are
assigned node paths. Usually, paths are assigned with path references
like 'foo = &label' (common in /chosen), but plain strings are accepted
as well as long as they're valid paths.
The 'path' type is mostly for completeness at this point, but might be
useful for https://github.com/zephyrproject-rtos/zephyr/issues/21623.
The support is there already in dtlib.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
In some cases, we've seen the output files be truncated when the
python script has been rebuilt into a .pex before running it --
likely due to buffering.
Closing files explicitly is the right thing to do anyway, so let's
do it.
Signed-off-by: Olof Johansson <olof@lixom.net>
The SRAM address and size are currently available as both
DT_SRAM_{BASE_ADDRESS,SIZE} and as CONFIG_SRAM_{BASE_ADDRESS,SIZE} (via
the Kconfig preprocessor).
Use the CONFIG_SRAM_* versions everywhere, and remove generation of the
DT_SRAM_* versions from gen_defines.py.
The Kconfig symbols currently depend on 'ARC || ARM || NIOS2 || X86'.
Not sure why, so I removed it.
It looks like no configuration files set CONFIG_SRAM_* at the moment, so
another option might be to use the DT_* symbols everywhere instead. Some
Kconfig.defconfig.series files add defaults to them though.
Also improve the help texts for CONFIG_SRAM_* to say that they normally
come from devicetree rather than configuration files.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Reorganize write_regs() to reuse more code for *_BASE_ADDRESS and
*_SIZE, and get rid of reg_addr_ident() and reg_size_ident().
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
For the following devicetree, view 'nested' as being on the bus.
Previously, only 'node' was considered to be on the bus.
some-bus {
compatible = "foo,bus-controller";
node {
nested {
compatible = "foo,device-on-bus";
};
};
};
In practice, this means that a 'bus:' key in the binding for
'foo,bus-controller' will now get matched up to an 'on-bus:' key in the
binding for 'foo,device-on-bus'.
Change the meaning of Node.bus and add two new attributes Node.on_bus
and Node.bus_node, with these meanings:
Node.bus:
The bus type (as a string) if the node is a bus controller, and
None otherwise
Node.on_bus:
The bus type (as a string) if the node appears on a bus, and None
otherwise. The bus type is determined from the closest parent
that's a bus controller.
Node.bus_node:
The node for the bus controller if the node appears on a bus, and
None otherwise
It's a bit redundant to have both Node.bus_node and Node.on_bus, since
Node.on_bus is the same as Node.bus_node.bus, but Node.on_bus is pretty
handy to save some None checks.
Also update gen_defines.py to use Node.on_bus and Node.bus_node instead
of Node.parent wherever the code deals with buses.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
I keep mixing these up, so that's probably a sign that the names are
bad. The root of the problem is that "parent-bus" can be read as both
"this is the parent bus" and as "the parent bus is this".
Use 'bus:' for the bus "provider" and 'on-bus:' for nodes on the bus
instead, which is less confusing.
Support the old keys for backwards compatibility, along with a
deprecation warning.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Most bindings look something like this:
title: Foo
description: This binding provides a base representation of Foo
That kind of description doesn't add any useful information, as it's
just the title along with some copy-pasted text. I'm not sure what "base
representation" was supposed to mean originally either.
Many bindings also put something that's closer to a description in the
title, because it's not clear what's expected or how the title is used.
In reality, the title isn't used anywhere. 'description:' on the other
hand shows up as a comment in the generated header.
Deprecate 'title:' and generate a long informative warning if it shows
up in a binding.
Next commits will clean up the 'description:' strings (bringing them
closer to 'title:' in most cases) and remove 'title:' from all bindings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
A property may be optional with a default in a base yaml, then
overridden to be required in a subordinate file. Don't prevent this
by complaining about having a default on a required property.
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The ARM Generic Interrupt Controller (GIC) supports multiple interrupt
types whose linear IRQ numbers are offset by a type-specific base
number.
This commit adds a function to automatically fix up ARM GIC interrupts
in order to output a linear IRQ number that is offset by the interrupt
type-specific base number.
For more details, refer to the issue #19860.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
Shortens main() a bit and makes it easier to read.
Rename write_flash() to write_flash_node(), and let write_flash() be the
top-level function. Also move the looking-up of the /chosen properties
into the the various helper functions themselves, and shorten some names
that are clear in context.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Make the node/ordinal list a part of the header comment to make the
output prettier.
Before:
/*
* Generated by gen_defines.py
*
* DTS input file:
* rv32m1_vega_ri5cy.dts.pre.tmp
*
* Directories with bindings:
* $ZEPHYR_BASE/dts/bindings
*/
/* Nodes in dependency order (ordinal : path): */
/* 0 : / */
/* 1 : /aliases */
/* 2 : /chosen */
/* 3 : /connector */
/* 4 : /cpus */
/* 5 : /cpus/cpu@0 */
/* 6 : /gpio_keys */
/* 7 : /soc */
...
After:
/*
* Generated by gen_defines.py
*
* DTS input file:
* rv32m1_vega_ri5cy.dts.pre.tmp
*
* Directories with bindings:
* $ZEPHYR_BASE/dts/bindings
*
* Nodes in dependency order (ordinal and path):
* 0 /
* 1 /aliases
* 2 /chosen
* 3 /connector
* 4 /cpus
* 5 /cpus/cpu@0
* 6 /gpio_keys
* 7 /soc
* ...
*/
Also move the writing of the top comment and the node comments into
separate functions, to shorten main() and make it easier to follow.
Piggyback some minor comment-related simplifications.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
We now use EDTS and gen_defines.py to generate DTS defines. We
deprecated the old script and defines several releases ago, so lets now
remove them.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Erroring out for 'status = "ok"' broke backwards compatibility for a
downstream project. Accept it instead.
Maybe the error could be selectively re-enabled later.
The rest of the code only checks for 'status = "disabled"' (like the old
scripts), so no other updates are needed.
(It's a bit weird that we duplicate the property check in base.yaml.
Thinking of including base.yaml implicitly. Could clean things up then.)
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
The interprocessor communication can be based on shared memory.
Allow to declare this memory as with a generic name derived from
chosen declaration.
Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@st.com>
Python 3.5 and earlier do not preserve dictionary insertion order when
iterating over dictionaries, and do not give the same order between
runs. This broke the dtlib and edtlib test suites and made the output
jump around randomly between runs. It also made device INST_<n> numbers
non-deterministic, which broke some code on Python 3.5 (though
hardcoding device instance numbers in the code might be a bit shaky).
Fix it by using collections.OrderedDict instead of plain dict wherever
order matters. This makes the output identical on all supported Python
versions. It also allows testdtlib.py and testedtlib.py to run in CI,
which uses Python 3.5.
Fixes: #20571
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
edtlib is a library, and modifying yaml.(C)Loader directly interferes
with any binding loading in edtlib clients. To avoid that, add a custom
loader for bindings.
Internally, PyYAML does this, which is why defining a separate class
works:
@classmethod
def add_constructor(cls, tag, constructor):
if not 'yaml_constructors' in cls.__dict__:
cls.yaml_constructors = cls.yaml_constructors.copy()
cls.yaml_constructors[tag] = constructor
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Turns
edt.required_by(node)
edt.depends_on(node)
into
node.required_by
node.depends_on
which might be a bit more readable.
One drawback is that @property hides that there's some slight overhead
in accessing them, but I suspect it won't be meaningful. Caching could
be added if it ever turns out to be.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
(pinctrl-<index> is documented in
Documentation/devicetree/bindings/pinctrl/pinctrl-bindings.txt in
Linux.)
Add a new Node.pin_states property, derived from any pinctrl-<index>
properties on the node. Node.pin_states holds a list of PinState
objects, where each PinState represents a single pinctrl-<index>
property.
For example, Node.pin_states will have two elements for the 'device'
node below:
device {
pinctrl-0 = <&state_0>;
pinctrl-1 = <&state_1 &state_2>;
pinctrl-names = "default", "sleep";
};
pincontroller {
state_0: state_0 {
...
};
state_1: state_1 {
...
};
state_2: state_2 {
...
};
};
Each PinState holds the list of configurations nodes in
PinState.conf_nodes. For the node above, node.pin_states[1].conf_nodes
will contain the pincontroller/state_1 and pincontroller/state_2 nodes,
for example.
The new functionality isn't used by gen_defines.py yet, so this change
is a no-op in itself, except it adds some error checking for
pinctrl-<index> properties.
If needed, support for #pinctrl-cells and 'pinmux' (not the same thing
as the 'pinmux' properties in Zephyr I think) could be added separately
later. Not sure what belongs in edtlib.py there yet.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
If we have something like dma-names we should ended up generating
something like:
DT_ST_STM32_I2S_40015000_RX_DMAS_CONTROLLER_1
This isn't quite what we expect. We should instead get:
DT_ST_STM32_I2S_40015000_RX_DMAS_CONTROLLER
DT_ST_STM32_I2S_40015000_DMAS_CONTROLLER_1
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Device tree nodes have a dependency on their parents, as well as other
nodes. To ensure driver instances are initialized in the proper we
need to identify these dependencies and construct a total order on
nodes that ensures no node is initialized before something it depends
on.
Add a Graph class that calculates a partial order on nodes, taking
into account the potential for cycles in the dependency graph.
When generating devicetree value headers calculate the dependency
graph and document the order and dependencies in the derived files.
In the future these dependencies may be expressed in binding data.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Multi-line comments were stuck as-is between /* and */ in the generated
header, which looks ugly and confusing e.g. for multi-line
binding/property descriptions.
Use this format for multi-line comments in the header instead:
/*
* First line
* Second line
*
* Line after blank line
*/
Also clean up the output a bit by turning some things that were separate
comments into a single multi-line comment. Add some air and reduce line
lengths too.
Before:
/* Generated by gen_defines.py */
/* DTS input file: hifive1.dts.pre.tmp */
/* Directories with bindings: $ZEPHYR_BASE/dts/bindings */
/* Devicetree node: /cpus/cpu@0/interrupt-controller */
/* Binding (compatible = riscv,cpu-intc): $ZEPHYR_BASE/... */
/* Binding description: This binding describes the RISC-V ...
Some extra lines
for testing */
#define DT_INST_0_RISCV_CPU_INTC 1
After:
/*
* Generated by gen_defines.py
*
* DTS input file:
* hifive1.dts.pre.tmp
*
* Directories with bindings:
* $ZEPHYR_BASE/dts/bindings
*/
/*
* Devicetree node:
* /cpus/cpu@0/interrupt-controller
*
* Binding (compatible = riscv,cpu-intc):
* $ZEPHYR_BASE/dts/bindings/interrupt-controller/...
*
* Description:
* This binding describes the RISC-V CPU Interrupt Controller
*
* Some extra lines
* for testing
*/
#define DT_INST_0_RISCV_CPU_INTC 1
Also tweak Node.description and Property.description in edtlib to be
strip()ed instead of rstrip()ed. There's probably no reason to
preserving leading whitespace in them either.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Use the LibYAML-based yaml.CLoader if available instead of yaml.Loader,
which is written in Python and slow. See
https://pyyaml.org/wiki/PyYAMLDocumentation.
This speeds up gen_defines.py from 0.2s to 0.07s on my system, for
-DBOARD=hifive1. It should also make scripts/kconfig/kconfig.py faster,
because it indirectly uses edtlib via
scripts/kconfig/kconfigfunctions.py.
yaml.CLoader seems to be available out of the box when installing with
pip on Ubuntu at least.
Helps with https://github.com/zephyrproject-rtos/zephyr/issues/20104.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Simplify use of property values that have multiple elements by
providing all of them in an initializer list, in addition to each one
as an enumerated value.
For example if a driver requires a sequence of operations with
instance-specific delays between stages the durations can be specified
with:
delays = <30000 20 45000>;
and the driver can use:
static u32_t delays[] = DT_INST_0_COMPAT_DELAYS;
rather than enumerating the instances. This is particularly useful
when the number of entries in the array varies per instance, in which
case such an initialization is not easily expressed in code.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Previously, if two bindings had the same 'compatible:'/'parent-bus:'
values, the binding that happened to be loaded last would get used.
Turn it into an error instead. This avoids tricking people into thinking
that bindings get loaded in a defined order.
Maybe overriding bindings could be allowed later, if we need it.
Fixes: #19536
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Simplifies the code a bit.
Looks like the description wasn't rstrip()ed when it came from a
'child-binding:' either. This also indirectly fixes that.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Node._prop_val() returned too early for non-existent booleans, letting
missing 'required: true' booleans slip through without an error.
Fix it by rearranging the code to always do the 'required' check before
returning.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Requested by Marc Herbert. Makes the output deterministic as long as all
binding directories are within $ZEPHYR_BASE (and a bit less spammy too).
Example output for header:
Before:
/* Directories with bindings: /home/ulf/z/z/dts/bindings */
...
/* Binding (...): /home/ulf/.../arm,v7m-nvic.yaml */
After:
/* Directories with bindings: $ZEPHYR_BASE/dts/bindings */
...
/* Binding (...): $ZEPHYR_BASE/dts/.../arm,v7m-nvic.yaml */
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
verify_eq() can be used instead of verify_streq(), since
warnings.getvalue() already returns a string.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Add a 'warn_file' parameter to EDT.__init__() that gives a 'file' object
to write warnings to. Use it to capture and verify warnings generated
for deprecated features in testedtlib.py. This indirectly gets rid of
possibly broken-looking output when running it.
Because any function that writes warnings now needs to use EDT._warn()
(as self._warn()), some functions were moved into the EDT class.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Implement a nice generalization suggested by Bobby Noelte.
Instead of having a generic #cells key in bindings, have source-specific
*-cells keys. Some examples:
interrupt-cells:
- irq
- priority
- flags
gpio-cells:
- pin
- flags
pwm-cells:
- channel
- period
This makes bindings a bit easier to read, and allows a node to be a
controller for many different 'phandle-array' properties.
The prefix before *-cells is derived from the property name, meaning
there's no fixed set of *-cells keys. This is possible because of the
earlier 'phandle-array' generalization.
The older #cells key is supported for backwards compatibility, but
generates a deprecation warning.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Generating generic information for 'type: phandle-array' properties in
edtlib was difficult due to defining phandle-array as just a list of
phandles and numbers. To make sense of a phandle-array property like
'pwms', you have to know that #pwm-cells is expected to appear on
each referenced controller, and that the binding for the controller has
a #cells.
Because of this, handling of various 'type: phandle-array' properties
was previously hardcoded in edtlib and exposed through properties like
Node.pwms, instead of through the generic Node.props (though with a lot
of shared code).
In practice, it turns out that all 'type: phandle-array' properties in
Zephyr work exactly the same way: They all have names that end in -s,
the 's' is removed to derive the name of related properties, and they
all look up #cells in the binding for the controller, which gives names
to the data values.
Strengthen the definition of 'type: phandle-array' to mean a property
that works exactly like the existing phandle-array properties (which
also means requiring that the name ends in -s). This removes a ton of
hardcoding from edtlib and allows new 'type: phandle-array' properties
to be added without making any code changes.
If we ever need a property type that's a list of phandles and numbers
but that doesn't follow this scheme, then we could add a separate type
for it. We should check if the standard scheme is fine first though.
The only property type for which no information is generated is now
'compound'.
There's some inconsistency in how we generate identifiers for clocks
compared to other 'type: phandle-array' properties, so keep
special-casing them for now in gen_defines.py (see the comment in
write_clocks()).
This change also enabled a bunch of other simplifications, like reusing
the ControllerAndData class for interrupts.
Piggyback generalization of *-map properties so that they work for any
phandle-array properties. It's now possible to have things like
'io-channel-map', if you need to.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
'Specifier' is devicetree specalese for data associated with interrupts,
GPIOs, etc., e.g. <1 2> and <3 4> in
pwms = <&ctrl-1 1 2 &ctrl-2 3 4>;
It's probably unnecessarily confusing to call it that. Call it 'data'
instead, which is a bit more straightforward.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
edtlib.Device is just a devicetree node augmented with binding
information and some interpretation of properties. Rename it to
edtlib.Node to make that clearer. That also avoids calling things like
flash partition nodes "devices", which is a bit confusing.
I called it edtlib.Device instead of edtlib.Node originally to avoid
confusion with dtlib.Node, but in retrospect it probably makes it more
confusing on the whole. Something like edtlib.ENode might work too, but
it's probably overkill. Clients of edtlib.py only interact with
edtlib.Node, so the only potential for confusion is within edtlib.py
itself, and it doesn't get too bad there either.
Piggyback some documentation nits, and consistently write it
"devicetree" instead of "device tree", to match the spec.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
As a slightly hairy but important optimization inherited from the old
scripts, the binding loading code only looks at binding files whose raw
text contains one of the compatible strings from the devicetree. For
such files, a second pass parses the file as YAML and tries to extract a
compatible string, and skips the file if it fails (e.g. due to spurious
text matches in 'include'd binding fragments).
Until now, the binding would always get fully loaded (have 'include'd
files merged in, checks run, etc.) if the second pass managed to extract
a compatible.
Do slightly better by only fully loading the binding if the extracted
compatible from the second pass appears in the devicetree. This gets rid
of unnecessary binding loading in rare cases.
Discovered by test-bindings/deprecated.yaml getting loaded even when
everything that referenced it in test.dts was commented out, because it
happened to mention 'child-binding' in a comment.
Also add a check for YAML errors in the second pass, to be slightly more
robust. Print a warning if a file that isn't valid YAML is found.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
API oversight. This was meant to be there all along together with
Device.parent, for navigating the devicetree, but since a need for it
never came up in gen_defines.py, it got overlooked.
Devices are just devicetree nodes augmented with binding information and
some interpretation of devicetree properties. I wonder if the name
should be changed to something like edtlib.Node to make that clearer.
Calling something like a flash partition a "device" is a bit weird, as
Galak pointed out.
I think I went with Device originally to avoid confusion with
dtlib.Node, but since edtlib users don't directly interact with dtlib,
it might not be that confusing in practice.
Piggyback some documentation clarifications.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
The devicetree check in check_compliance.py in ci-tools expects the
dtlib/edtlib test suites to exit with sys.exit() (which raises
SystemExit) on test failures, and interprets Exception as an internal
error in the test suite.
testedtlib.py accidentally raised Exception on test failures, making
check_compliance.py error out and skipping the rest of the tests when
there were failures. Fix it.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Deprecate 'sub-node:' and add a more general 'child-binding:' mechanism
to bindings. Keep supporting 'sub-node:', but print a deprecation
warning when it's used.
Like 'sub-node:', 'child-binding:' gives a binding to child nodes, but
the binding is required to be a complete binding, and is treated (and
checked) like a normal binding.
'child-binding:' can in turn contain another 'child-binding:', up to any
number of levels. This is automatic from treating it like a normal
binding, and from the code initializing parent Devices before child
Devices.
This lets nodes give bindings to grandchildren.
For example, take this devicetree fragment:
parent {
compatible = "foo";
child-1 {
grandchild-1 {
...
};
grandchild-2 {
...
};
};
child-2 {
grandchild-3 {
...
};
};
};
The binding for 'foo' could provide bindings for grandchild-1/2/3 like
this:
compatible: "foo"
# Binding for children
child-binding:
title: ...
description: ...
...
# Binding for grandchildren
child-binding:
title: ...
description: ...
properties:
...
Due to implementation issues with the old devicetree scripts, only two
levels of 'child-binding:' is supported for now. This limitation will go
away in Zephyr 2.2.
Piggyback shortening 'description:' and 'title:' in some bindings that
provide child bindings. This makes the generated header a bit neater.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Instead of
child:
bus: foo
parent:
bus: bar
, have
child-bus: foo
parent-bus: bar
'bus' is the only key that ever appears under 'child' and 'parent'.
Support the old keys for backwards compatibility, with a deprecation
warning if they're used.
Also add 'child/parent-bus' tests to the edtlib test suite. It was
untested before.
I also considered putting more stuff under 'child' and 'parent', but
there's not much point when there's just a few keys I think. Top-level
stuff is cleaner and easier to read.
I'm planning to add a 'child-binding' key a bit later (like 'sub-node',
but more flexible), and child-* is consistent with that.
Also add an unrelated test-bindings/grandchild-3.yaml that was
accidentally left out earlier.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Convert how we get the various chosen properties like "zephyr,console"
to use the new kconfig functions like dt_chosen_to_label.
Because of how kconfig parses things we define a set of variables of the
form DT_CHOSEN_Z_<PROP> since comma's are parsed as field seperators in
macros.
This conversion allows us to remove code in gen_defines.py for the
following chosen properties:
zephyr,console
zephyr,shell-uart
zephyr,bt-uart
zephyr,uart-pipe
zephyr,bt-mon-uart
zephyr,uart-mcumgr
zephyr,bt-c2h-uart
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Things that parse generated_dts_board.conf can't deal with entries
like:
DT_GPIO_KEYS_BUTTON_1_GPIOS={"GPIO_0", 14, 256}
so keep them from being added there.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
When a phandle-array (compound) has multiple members generate a define
that says how many there are; generate an initializer for each
individual member; and generate an initializer for the sequence of
members.
This allows drivers that expect multiple values in a compound to process
them without horrendous conditional compilation code attempting to
detect the number of elements in the compound.
It also eliminates the need to repeat the long prefix when initializing
a structure with the fields of a single compound.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
The lowest level output function is the one that determines the full
name of the macro, including DT_ prefix. Return the name of the macro
that provides the value for an identifier so that it can be used in
higher layers of the generator.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Add str2str to make the conversion of a string into a C literal with all
necessary escapes and enclosing double quotes available outside a
function that emits a define.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
When foo.yaml set some property 'required: true' and bar.yaml set the
same property 'required: false', the check for changing
'required: false' to 'required: true' would raise an error for
include: [bar.yaml, foo.yaml]
(with that particular order due to implementation details).
The order files are included in shouldn't matter. To fix it, change the
logic so that 'required' values are ORed together between included files
(so that 'required: true' is always respected), and remove the
'required' true-to-false check when merging included files.
Keep the true-to-false check when merging the (merged) included files
into the main binding (the binding with the 'include:' in it). This
might give a good organization, and the old scripts do it too.
Piggyback two fixes/cleanups:
- 'compatible' should be allowed to appear in included files
- No need to allow an 'inherits' key in _check_binding(), because
it has been removed before then, when merging bindings
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
The 'fname' parameter to merge_included_bindings(), giving the path to
the top-level binding file, was accidentally shadowed in the
'for fname in fnames:' loop. This could lead to the wrong filename being
used in error messages.
Discovered via this pylint warning:
scripts/dts/extract_dts_includes.py:225:12: R1704: Redefining
argument with the local name 'fname' (redefined-argument-from-local)
Improve naming a bit to fix it.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Except for a few special properties like 'interrupts' and '#size-cells',
require all devicetree properties on nodes with bindings to be declared
in the binding.
This will help catch misspellings, and makes refactoring and cleanups
safer.
Suggested by Peter A. Bigot.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
When we have multi-level (ie chained interrupt controllers) Zephyr has a
schemee to encode the multi-level and IRQ values along the level's into
a single 32-bit value. This is the "IRQ" value expected by Zephyr APIs.
The encoding scheme is documented here:
doc/reference/kernel/other/interrupts.rst
Update the device tree generation to walk the interrupt levels and
generate the expected encoded value for the IRQ.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Put a type check in the offending method.
Now any scalar will be put in a list for
compatibility with following code.
Signed-off-by: Olle Norelius <norelius.olle@gmail.com>
For missing optional properties, it can be handy to generate a default
value instead of no value, to cut down on #ifdefs.
Allow a default value to be specified in the binding, via a new
'default: <default value>' setting for properties in bindings.
Defaults are supported for both scalar and array types. YAML arrays are
used to specify the value for array types.
'default:' also appears in json-schema, with the same meaning.
Include misc. sanity checks, like the 'default' value matching 'type'.
The documentation changes in binding-template.yaml explain the syntax.
Suggested by Peter A. Bigot in
https://github.com/zephyrproject-rtos/zephyr/issues/17829.
Fixes: #17829
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Instead of
properties:
compatible:
constraint: "foo"
, just have
compatible: "foo"
at the top level of the binding.
For backwards compatibility, the old 'properties: compatible: ...' form
is still accepted for now, and is treated the same as a single-element
'compatible:'.
The old syntax was inspired by dt-schema (though it isn't
dt-schema-compatible), which is in turn a thin wrapper around
json-schema (the idea is to transform .dts files into YAML and then
verify them).
Maybe the idea was to gradually switch the syntax over to dt-schema and
then be able to use unmodified dt-schema bindings, but dt-schema is
really a different kind of tool (a completely standalone linter), and
works very differently from our stuff (see schemas/dt-core.yaml in the
dt-schema repo to get an idea of just how differently).
Better to keep it simple.
This commit also piggybacks some clarifications to the binding template
re. '#cells:'.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
A bare 'except:' can do some annoying stuff like eat Ctrl-C (because it
catches KeyboardInterrupt). Better to use 'except Exception:' as a
catch-all.
Even better might be to catch some more specific exception, because even
'except Exception:' eats stuff like misspelled identifiers.
Fixes this pylint warning:
W0702: No exception type(s) specified (bare-except)
Fixing pylint warnings for a CI check.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Doesn't use 'self'. Fixes this pylint warning:
scripts/dts/edtlib.py:272:4: R0201: Method could be a function
(no-self-use)
Fixing pylint warnings for a CI check.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Having backwards compatibility for !include and 'constraint:' is silly
without also having backwards compatibility for 'category:', because
that forces a binding change anyway.
Add backwards compatibility for 'category:', and just print a
deprecation warning when it's used.
Also move tests for deprecated features into a dedicated
test-bindings/deprecated.yaml binding, instead of piggybacking on other
tests.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Suppress this pylint warning so that it can be enabled in the upcoming
CI check. The code is safe.
scripts/dts/dtlib.py:1904:13: W0631: Using possibly undefined loop
variable 'i' (undefined-loop-variable)
Also add some more comments to clarify _init_tokens().
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
"\w" gives a two-character string, but is iffy, because it relies on \w
not being defined as an escape sequence. r"\w" is better.
Fixes this pylint warning:
scripts/dts/devicetree.py:134:0: W1401: Anomalous backslash in
string: '\w'. String constant might be missing an r prefix.
(anomalous-backslash-in-string)
Wondering if I should exclude the old DTS scripts from the pylint CI
check, but doesn't hurt to fix it at least.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Move some property fetching and node deletion code from the DT class
over to the Node class. Reads pretty nicely, and indirectly gets rid of
two unused 'self' arguments.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Fix pylint warnings for bad indent, redundant len()s in conditionals,
tests that could be improved with 'in', methods that don't use 'self',
and type()s where isinstance() is more common.
Preparation for adding a CI check.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Have
include: foo.dts
include: [foo.dts, bar.dts]
instead of
inherits:
!include foo.dts
inherits:
!include [foo.dts, bar.dts]
This is a nicer and shorter and less cryptic syntax, and will make it
possible to get rid of the custom PyYAML constructor for '!include'
later.
'inherits: !include ...' is still supported for backwards compatibility
for now. Later on, I'm planning to mass-replace it, add a deprecation
warning if it's used, and document 'include:'. Then the '!include'
implementation can be removed a bit later.
'!include' has caused issues in the past (see the comment above the
add_constructor() call), gets iffy with multiple EDT instances, and
makes the code harder to follow.
I'm guessing '!include' might've been intended to be useful outside of
'inherits:' originally, but that's the only place where it's used. It's
undocumented that it's possible to put it elsewhere.
To implement the backwards compatibility, the code just transforms
inherits:
!include foo.dts
into
inherits:
- foo.dts
and treats 'inherits:' similarly to 'include:'. Previously, !include
inserted the contents of the included file instead.
Some more sanity checks for 'include:'/'inherits:' are included as well.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
The 'category: required/optional' setting for properties is just a
yes/no thing. Using a boolean makes it clearer, so have
'required: true/false' instead.
Print a clear error when 'category:' is used:
edtlib.EDTError: please put 'required: true' instead of 'category:
required' in 'properties: foo: ...' in
test-bindings/sub-node-parent.yaml - 'category' has been removed
The old scripts in scripts/dts/ ignore this setting, and only print a
warning if 'category: required' in an inherited binding is changed to
'category: optional'. Remove that code, since the new scripts already
have the same check.
The replacement was done with
git ls-files 'dts/bindings/*.yaml' | xargs sed -i \
-e 's/category:\s*required/required: true/' \
-e 's/category:\s*optional/required: false/'
dts/binding-template.yaml is updated as well.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Add a write_phandle_val_list() function for handling GPIOs, PWMs, and IO
channels. The logic is the same in all cases.
This also indirectly makes pwm-names and io-channel-names work the same
as gpio-names. Previously, they were ignored.
Also add a long explanation with example output.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Use Galak's idea from
https://github.com/zephyrproject-rtos/zephyr/pull/18313 to read the
'properties: compatible: constraint: "foo"' string from bindings in a
more robust way.
First, check if any of the compatible strings are in the file (needed as
an optimization). If any of them are, do a more careful check for the
'properties: compatible: constraint: ...' value matching a compatible,
to filter out false positives from comments and the like.
This commit a no-op in itself besides making things a bit more robust,
but it'll make later work easier (supporting multiple compatibles for a
binding, in a dt-schema-like way).
Co-authored-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>