zephyr/dts/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
..
arc dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
arm dts/bindings: Add base clock controller to dts bindings 2019-08-09 14:10:40 -05:00
audio dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
base dts/bindings: Change clock type to compound 2019-08-07 13:15:51 -04:00
bluetooth dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
can dts/bindings: Fix build issues with bindings 2019-08-13 07:04:46 -05:00
clock dts/bindings: Add base clock controller to dts bindings 2019-08-09 14:10:40 -05:00
cpu dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
crypto dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
display display: Add support for an ST7789V based LCD 2019-08-08 10:11:47 -05:00
espi dts: bindings: Clean up microchip,xec-espi.yaml and espi.yaml 2019-07-26 09:44:35 -04:00
ethernet dts/bindings: Fix build issues with bindings 2019-08-13 07:04:46 -05:00
flash_controller dts: bindings: Remove some YAML document separators 2019-07-23 04:08:16 -04:00
gpio dts/bindings: Add gpio-nexus base binding 2019-08-09 14:10:40 -05:00
i2c dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
i2s dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
ieee802154 dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
iio/adc dts/bindings: add '#cells' to nrf-saadc 2019-08-09 13:16:09 -05:00
interrupt-controller boards: hsdk: add initial support of ARC HS Development Kit 2019-08-10 20:11:29 +02:00
ipm dts/bindings: Cleanup st,stm32-ipm-mailbox binding 2019-07-26 10:37:19 -04:00
led dts/bindings: Make pwm-leds label optional 2019-07-23 04:09:19 -04:00
led_strip dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
memory-controllers dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
mhu dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
misc dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
mmc dts: bindings: Remove some YAML document separators 2019-07-23 04:08:16 -04:00
mmu_mpu dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
modem drivers: modem: ublox-sara-r4: Support SARA-U2 modems, sense VINT 2019-08-10 00:03:39 +02:00
mtd dts/bindings: cleanup partition binding 2019-08-09 14:56:20 -05:00
phy dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
pinctrl dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
power dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
pwm dts/bindings: Update pwm base binding 2019-08-09 14:10:40 -05:00
riscv dts/bindings: Add base clock controller to dts bindings 2019-08-09 14:10:40 -05:00
rng dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
rtc dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
sensor drivers: sensors: Remove 'version:' field in Si7006 binding 2019-08-07 18:46:21 +02:00
serial serial: Add Xilinx ZynqMP PS uart driver 2019-08-09 22:50:50 +02:00
spi dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
sram dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
timer timer: Add Xilinx ZynqMP PS ttc timer 2019-08-09 22:50:50 +02:00
usb dts: dtlib/edtlib: Add a syntax-based type-checking system 2019-08-13 07:41:45 -05:00
watchdog dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
wifi dts: bindings: Remove unused 'version' field 2019-07-22 09:28:07 -04:00
binding-template.yaml dts: dtlib/edtlib: Add a syntax-based type-checking system 2019-08-13 07:41:45 -05:00
vendor-prefixes.txt dts: Restructure xtensa dts directory 2019-06-27 07:21:11 -04:00