zephyr/scripts/dts/test-bindings
Ulf Magnusson 06b746cc58 dts: dtlib/edtlib: Add a syntax-based type-checking system
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>
2019-08-13 07:41:45 -05:00
..
child.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00
clock-1-cell.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00
clock-2-cell.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00
fixed-clock.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00
gpio-1-cell.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00
gpio-2-cell.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00
grandchild.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00
interrupt-1-cell.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00
interrupt-2-cell.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00
interrupt-3-cell.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00
io-channel.yaml scripts/dts: add basic test for IO channel property 2019-08-09 13:16:09 -05:00
multidir.yaml scripts: dts: Add test for multiple binding directories 2019-08-03 14:17:49 -04:00
parent.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00
props.yaml dts: dtlib/edtlib: Add a syntax-based type-checking system 2019-08-13 07:41:45 -05:00
pwm-1-cell.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00
pwm-0-cell.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00
sub-node-parent.yaml dts: edtlib: Shorten some license headers 2019-08-09 00:03:19 -05:00