From acf276f1df79462d454ce5f518b07684fccd162c Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Wed, 7 Aug 2019 19:33:45 +0200 Subject: [PATCH] edtlib: Check that 'status' has one of the values from the DT spec. dtlib is meant to be general and anything-goes re. property values, but edtlib can be pickier. Check that all 'status' properties have one of the values listed in the devicetree specification (https://www.devicetree.org/specifications/), and error out otherwise. This will get rid of the 'status = "ok"'s (should be "okay") that keep cropping up. Signed-off-by: Ulf Magnusson --- scripts/dts/edtlib.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/dts/edtlib.py b/scripts/dts/edtlib.py index 37c704a7bb0..901e918c420 100644 --- a/scripts/dts/edtlib.py +++ b/scripts/dts/edtlib.py @@ -108,6 +108,7 @@ class EDT: self.bindings_dirs = bindings_dirs self._dt = DT(dts) + _check_dt(self._dt) self._init_compat2binding(bindings_dirs) self._init_devices() @@ -1635,6 +1636,30 @@ def _slice(node, prop_name, size): return [raw[i:i + size] for i in range(0, len(raw), size)] +def _check_dt(dt): + # Does devicetree sanity checks. dtlib is meant to be general and + # anything-goes except for very special properties like phandle, but in + # edtlib we can be pickier. + + # Check that 'status' has one of the values given in the devicetree spec. + + ok_status = {"okay", "disabled", "reserved", "fail", "fail-sss"} + + for node in dt.node_iter(): + if "status" in node.props: + try: + status_val = node.props["status"].to_string() + except DTError as e: + # The error message gives the path + _err(str(e)) + + if status_val not in ok_status: + _err("unknown 'status' value \"{}\" in {} in {}, expected one " + "of {} (see the devicetree specification)" + .format(status_val, node.path, node.dt.filename, + ", ".join(ok_status))) + + def _err(msg): raise EDTError(msg)