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>
Sanity-checking each !included file separately was inherited from the
old scripts. It makes it messy to check that combinations of fields make
sense, e.g. to check 'const:' or 'default:' against 'type:', since those
fields might come from different files (this is handy, since it makes
sense to just add/change a 'const:' value, for example).
Drop the requirement that each !included file is a complete binding in
itself, and treat them as binding fragments instead. Only check the
final merged binding.
This also means that !included files no longer need to have a
'description:' or 'title:' (those have always been unused for !included
files), so remove those, and add comments that explain what the
fragments are for instead. That should demystify bindings a bit.
Also fix the descriptions of i2c.yaml, i2s.yaml, spi.yaml, and
uart.yaml. They're for controllers, not devices. These are copy-paste
error from the corresponding device .yaml files.
Piggyback some indentation consistency nits in binding-template.yaml.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Similar to edtlib._err(). Just saves a bunch of 'raise DTError'.
Also add tests for some errors from the global to_num() and to_nums()
functions that were untested.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
The public DT.get_node() function was used during parsing to look up
paths in references like &{/foo/bar}, along with an ugly
'DT._is_parsing' flag to adapt its behavior (to not mention aliases in
error messages).
Split out common node lookup code needed during parsing and by
get_node() instead, and stop using get_node() during parsing. This
allows '_is_parsing' to be removed and untangles things a bit.
Piggyback some other small reference-related cleanups, and fix an issue
with the filename/linenr being given twice in some error messages.
This commit also removes the index of path components from error
messages, but just the string is probably good enough.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Require either type TYPE_EMPTY ('ranges;') or TYPE_NUMS
('ranges = < 1 2 ... >;').
Putting the check in _check_dt() means it will run for all nodes,
including nodes without bindings, which is handy.
The _split() function already gives a decent error message if 'ranges'
has unexpected length, so skip checking the length.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Deriving the type from looking at Property.val gets awkward e.g. when
there are many types that make Property.val a list. Instead, save the
type as given in the binding in Property.type.
Let Property.type just be a string. This has typo potential, but is nice
and flexible (and easy to print), and errors will probably be pretty
obvious.
Show the type in Property.__repr__() as well. This automatically gives
some test coverage.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Add two new type-checked property types 'phandles' and 'phandle-array'
to edtlib.
'phandles' is for pure lists of phandles, with no other data, like
foo = < &bar &baz ... >
'phandle-array' is for lists of phandles and (possibly) numbers, like
foo = < &bar 1 2 &baz 3 4 ... >
dt-schema also has the 'phandle-array' type.
Property.val (in edtlib) is set to an array of Device objects for the
'phandles' type.
For the 'phandle-array' type, no Property object is created. This type
is only used for type checking.
Also refactor how types that do not create a Property object
('phandle-array' and 'compound') are handled. Have _prop_val() return
None for them.
The new types are implemented with two new TYPE_PHANDLES and
TYPE_PHANDLES_AND_NUMS types at the dtlib level. There is also a new
Property.to_nodes() functions for fetching the Nodes for an array of
phandles, with type checking.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Previously, Property.to_node() would allow assignments like
x = < 1 >;
as long as 1 happened to be a valid phandle. This was deliberate, but
might hide errors, and would make the planned 'phandles' (list of
phandles) and 'phandle-array' (list of phandles and numbers) types a bit
too similar to 'type: array'.
Change Property.to_node() to only accept
x = < &foo >;
This is probably all we need, and if you really need to accept manually
specified phandles, it can be worked around in other ways.
Piggyback some consistency nits in error messages from the
Property.to_*() functions.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
The contents of 'sub-node:' was assigned as-is as the binding, bypassing
_check_binding(). This also hid an error in
test-bindings/sub-node-parent.yaml.
Require 'sub-node:' to just have 'properties:' in it, and sanity-check
the properties like for regular bindings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
We don't want any defines generated for 'status', 'interrupt-parent',
and 'interrupts-extended' properties. So skip them in write_props if
we see them.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Add a 'const' property to bindings for any properties that are expected
to have a specifi known value. For example, #address-cells for an I2C
bus should always be '1'. So we can do something like the following in
the I2C bus binding:
"#address-cells":
type: int
category: required
const: 1
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Move the enum checking before we early out for '#' and '-map' properties
so they can benefit from it. Also make the error messages for failed
'enum' check more informative by including the paths to the .dts file
and the binding for the node.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
dtlib.py and guiconfig.py do some hackery to build token and image
variable names, which triggers spurious pylint warnings like
scripts/dts/dtlib.py:243:28: E0602: Undefined variable '_T_LABEL'
(undefined-variable)
Suppress the warning for those files. The generated names get used in
lots of places.
Also suppress some warnings in doc/conf.py ('tags' is from Sphinx), and
fix a legitimate issue in scripts/dts/testdtlib.py.
This pylint check is useful enough to want enabled in the upcoming CI
check.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
If there is more than one IO Channel than generate a define with a
trailing index for the IO Channel. This matches what we do for GPIOs
and PWMs.
So something like:
DT_FOOBAR_IO_CHANNELS_CONTROLLER_0
DT_FOOBAR_IO_CHANNELS_CONTROLLER_1
...
DT_FOOBAR_IO_CHANNELS_CONTROLLER_<N>
Fixes#18352
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This was allowed due to a misunderstanding:
foo = 'x';
In reality, 'x' works like an integer literal, and is used like this:
foo = < 'x' >;
Fix character literal parsing to match the C tools.
Also fix backslash escape parsing to match the C tools exactly
(get_escape_char() in util.c): \<char> should be turned into <char> if
<char> isn't recognized as a special escape character, instead of being
left alone. This fixes parsing of e.g. '\'' (a character literal with a
single quote in it).
Piggyback some more tests for weird property/node names.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Property type-checking has been pretty rudimentary until now, only
checking things like the length being divisible by 4 for 'type: array',
and strings being null-terminated. In particular, no checking was done
for 'type: uint8-array', letting
jedec-id = < 0xc8 0x28 0x17 >;
slip through when
jedec-id = [ 0xc8 0x28 0x17 ];
was intended.
Fix it by adding a syntax-based type checker:
1. Add Property.type, which gives a high-level type for the property,
derived from the markers added in the previous commit.
This includes types like TYPE_EMPTY ('foo;'),
TYPE_NUM ('foo = < 3 >;'), TYPE_BYTES ('foo = [ 01 02 ];'),
TYPE_STRINGS ('foo = "bar", "baz"'),
TYPE_PHANDLE ('foo = < &bar >;'), and TYPE_COMPOUND (everything not
recognized).
See the Property.type docstring in dtlib for more info.
2. Use the high-level type in
Property.to_num()/to_string()/to_node()/etc. to verify that the
property was assigned in an expected way for the type.
If the assignment looks bad, give a helpful error:
expected property 'nums' on /foo/bar in some.dts to be assigned
with 'nums = < (number) (number) ... >', not 'nums = "oops";'
Some other related changes are included as well:
- There's a new Property.to_bytes() function that works like accessing
Property.bytes, except with an added check for the value being
assigned like 'foo = [ ... ]'.
This function solves problems like the jedec-id one.
- There's a new Property.to_path() function for fetching the
referenced node for assignments like 'foo = &node;', with type
checking. (Strings are accepted too, as long as they give the path
to an existing node.)
This function is used for /chosen and /aliases.
- A new 'type: phandle' type can now be given in bindings, for
properties that are assigned like 'foo = < &node >;'.
- Property.__str__() now displays phandles and path references as they
were written (e.g. '< &foo >' instead of '< 0x1 >', if the
allocated phandle happened to be 1).
- Property.to_num() and Property.to_nums() no longer take a 'length'
parameter, because it makes no sense with the type checking.
- The global dtlib.to_string() and dtlib.to_strings() functions were
removed, because they're not that useful.
- More tests were added, along with misc. minor cleanup in various
places.
- Probably other stuff I forgot.
The more strict type checking in dtlib indirectly makes some parts of
edtlib more strict as well (wherever Property.to_*() is used).
Fixes: #18131
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Previously, dtlib just stored the raw 'bytes' value for each property,
along with some markers in Property._markers for phandle and path
references.
Extend Property._markers to also remember where different data blocks
start, so that e.g.
foo = <1 2 3>, "bar", [00 01];
can be reproduced as written.
Use the new information to reproduce properties as written in
Property.__str__(). This gives good test coverage as well, since the
test suite checks literal __str__() output.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
If there is more than one PWM than generate a define with a trailing
index for the PWM. This matches what we do for GPIOs.
So something like:
DT_PWM_LEDS_RED_PWM_LED_PWMS_CONTROLLER_0
DT_PWM_LEDS_RED_PWM_LED_PWMS_CONTROLLER_1
...
DT_PWM_LEDS_RED_PWM_LED_PWMS_CONTROLLER_<N>
Fixes#18171
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
We don't want any defines generated for the boolean
'gpio-controller'. So skip it in write_props if we see it.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
We don't want any defines generated for the boolean
'interrupt-controller'. So skip it in write_props if we see it.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This is a direct search-and-replace copy of the PWM code.
The name is chosen to match Linux's iio-bindings.txt.
Signed-off-by: Jim Paris <jim@jtan.com>
Move when we early out for properties that start with # like
"#address-cells" or end with -map like "interrupt-map" to after we do
some error checking. This allows us to check those properties at least
exist if they are required.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
'keys' is really a dictionary of options (like {"type": "int", ...}) for
a property. Calling it 'options' makes it clearer.
Also s/prop/prop_name/.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>