mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-08-06 21:55:18 +00:00
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> |
||
---|---|---|
.. | ||
child.yaml | ||
clock-1-cell.yaml | ||
clock-2-cell.yaml | ||
fixed-clock.yaml | ||
gpio-1-cell.yaml | ||
gpio-2-cell.yaml | ||
grandchild.yaml | ||
interrupt-1-cell.yaml | ||
interrupt-2-cell.yaml | ||
interrupt-3-cell.yaml | ||
io-channel.yaml | ||
multidir.yaml | ||
parent.yaml | ||
props.yaml | ||
pwm-1-cell.yaml | ||
pwm-0-cell.yaml | ||
sub-node-parent.yaml |