scripts: dts: fix handling for phandle-arrays with *-cells=0

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>
This commit is contained in:
Martí Bolívar 2020-10-05 09:34:02 -07:00 committed by Kumar Gala
commit 1ea7bf0db0
4 changed files with 32 additions and 6 deletions

View file

@ -1230,11 +1230,11 @@ class Node:
# This type is a bit high-level for dtlib as it involves # This type is a bit high-level for dtlib as it involves
# information from bindings and *-names properties, so there's no # information from bindings and *-names properties, so there's no
# to_phandle_array() in dtlib. Do the type check ourselves. # to_phandle_array() in dtlib. Do the type check ourselves.
if prop.type not in (TYPE_PHANDLE, TYPE_PHANDLES_AND_NUMS): if prop.type not in (TYPE_PHANDLE, TYPE_PHANDLES, TYPE_PHANDLES_AND_NUMS):
_err("expected property '{0}' in {1} in {2} to be assigned " _err(f"expected property '{name}' in {node.path} in "
"with '{0} = < &foo 1 2 ... &bar 3 4 ... >' (a mix of " f"{node.dt.filename} to be assigned "
"phandles and numbers), not '{3}'" f"with '{name} = < &foo ... &bar 1 ... &baz 2 3 >' "
.format(name, node.path, node.dt.filename, prop)) f"(a mix of phandles and numbers), not '{prop}'")
return self._standard_phandle_val_list(prop) return self._standard_phandle_val_list(prop)

View file

@ -0,0 +1,7 @@
# SPDX-License-Identifier: BSD-3-Clause
description: Controller with zero data values
compatible: "phandle-array-controller-0"
phandle-array-foo-cells: []

View file

@ -261,6 +261,22 @@
#phandle-array-foo-cells = <2>; #phandle-array-foo-cells = <2>;
}; };
props-2 {
compatible = "props";
phandle-array-foos = < &{/ctrl-0-1} &{/ctrl-0-2} >;
};
ctrl-0-1 {
compatible = "phandle-array-controller-0";
#phandle-array-foo-cells = <0>;
};
ctrl-0-2 {
compatible = "phandle-array-controller-0";
#phandle-array-foo-cells = <0>;
};
// //
// Test <prefix>-map, via gpio-map // Test <prefix>-map, via gpio-map
// //

View file

@ -168,7 +168,7 @@ def test_props():
'''Test Node.props (derived from DT and 'properties:' in the binding)''' '''Test Node.props (derived from DT and 'properties:' in the binding)'''
edt = edtlib.EDT("test.dts", ["test-bindings"]) edt = edtlib.EDT("test.dts", ["test-bindings"])
filenames = {i: hpath(f'test-bindings/phandle-array-controller-{i}.yaml') filenames = {i: hpath(f'test-bindings/phandle-array-controller-{i}.yaml')
for i in range(1, 4)} for i in range(0, 4)}
assert str(edt.get_node("/props").props["int"]) == \ assert str(edt.get_node("/props").props["int"]) == \
"<Property, name: int, type: int, value: 1>" "<Property, name: int, type: int, value: 1>"
@ -200,6 +200,9 @@ def test_props():
assert str(edt.get_node("/props").props["phandle-array-foos"]) == \ assert str(edt.get_node("/props").props["phandle-array-foos"]) == \
f"<Property, name: phandle-array-foos, type: phandle-array, value: [<ControllerAndData, controller: <Node /ctrl-1 in 'test.dts', binding {filenames[1]}>, data: OrderedDict([('one', 1)])>, <ControllerAndData, controller: <Node /ctrl-2 in 'test.dts', binding {filenames[2]}>, data: OrderedDict([('one', 2), ('two', 3)])>]>" f"<Property, name: phandle-array-foos, type: phandle-array, value: [<ControllerAndData, controller: <Node /ctrl-1 in 'test.dts', binding {filenames[1]}>, data: OrderedDict([('one', 1)])>, <ControllerAndData, controller: <Node /ctrl-2 in 'test.dts', binding {filenames[2]}>, data: OrderedDict([('one', 2), ('two', 3)])>]>"
assert str(edt.get_node("/props-2").props["phandle-array-foos"]) == \
f"<Property, name: phandle-array-foos, type: phandle-array, value: [<ControllerAndData, controller: <Node /ctrl-0-1 in 'test.dts', binding {filenames[0]}>, data: OrderedDict()>, <ControllerAndData, controller: <Node /ctrl-0-2 in 'test.dts', binding {filenames[0]}>, data: OrderedDict()>]>"
assert str(edt.get_node("/props").props["foo-gpios"]) == \ assert str(edt.get_node("/props").props["foo-gpios"]) == \
f"<Property, name: foo-gpios, type: phandle-array, value: [<ControllerAndData, controller: <Node /ctrl-1 in 'test.dts', binding {filenames[1]}>, data: OrderedDict([('gpio-one', 1)])>]>" f"<Property, name: foo-gpios, type: phandle-array, value: [<ControllerAndData, controller: <Node /ctrl-1 in 'test.dts', binding {filenames[1]}>, data: OrderedDict([('gpio-one', 1)])>]>"