dts: scripts: Require properties to be declared in bindings

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>
This commit is contained in:
Ulf Magnusson 2019-08-30 03:49:43 +02:00 committed by Kumar Gala
commit b918e25921
2 changed files with 34 additions and 8 deletions

View file

@ -572,15 +572,20 @@ class Device:
return None
def _init_props(self):
# Creates self.props. See the class docstring.
# Creates self.props. See the class docstring. Also checks that all
# properties on the node are declared in its binding.
self.props = {}
if not self._binding or "properties" not in self._binding:
if not self._binding:
return
for name, options in self._binding["properties"].items():
self._init_prop(name, options)
# Initialize self.props
if "properties" in self._binding:
for name, options in self._binding["properties"].items():
self._init_prop(name, options)
self._check_undeclared_props()
def _init_prop(self, name, options):
# _init_props() helper for initializing a single property
@ -714,6 +719,31 @@ class Device:
# to have a 'type: ...'. No Property object is created for it.
return None
def _check_undeclared_props(self):
# Checks that all properties are declared in the binding
if "properties" in self._binding:
declared_props = self._binding["properties"].keys()
else:
declared_props = set()
for prop_name in self._node.props:
# Allow a few special properties to not be declared in the binding
if prop_name.endswith("-controller") or \
prop_name.startswith("#") or \
prop_name.startswith("pinctrl-") or \
prop_name in {
"compatible", "status", "ranges", "phandle",
"interrupt-parent", "interrupts-extended", "device_type"}:
continue
if prop_name not in declared_props:
_err("'{}' appears in {} in {}, but is not declared in "
"'properties:' in {}"
.format(prop_name, self._node.path, self.edt.dts_path,
self.binding_path))
def _init_regs(self):
# Initializes self.regs

View file

@ -300,9 +300,6 @@
phandle-ref = < &{/props/node} >;
phandle-refs = < &{/props/node} &{/props/node2} >;
phandle-refs-and-vals = < &{/props/node} 1 &{/props/node2} 2 >;
// Does not appear in the binding, so won't create an entry in
// Device.props
not-speced = <0>;
node {
};
@ -330,7 +327,6 @@
node {
foo = <1>;
bar = <2>;
not-speced = <0>;
};
};