From 0de9a08e94e9cfc08ba252e05848161b70dfcca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Wed, 11 Mar 2020 16:10:16 -0700 Subject: [PATCH] scripts: dts: edtlib: add EDT.chosen_nodes property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This returns the entire logical {name: Node} dictionary which is currently being accessed element by element via chosen_node(name). It will be used in a new gen_defines.py for moving the handling of chosen nodes into C from Python. Signed-off-by: Martí Bolívar --- scripts/dts/edtlib.py | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/scripts/dts/edtlib.py b/scripts/dts/edtlib.py index fd943b7a2c7..3eb8521b846 100644 --- a/scripts/dts/edtlib.py +++ b/scripts/dts/edtlib.py @@ -120,6 +120,12 @@ class EDT: ... }; + chosen_nodes: + A collections.OrderedDict that maps the properties defined on the + devicetree's /chosen node to their values. 'chosen' is indexed by + property name (a string), and values are converted to Node objects. + Note that properties of the /chosen node which can't be converted + to a Node are not included in the value. dts_path: The .dts path passed to __init__() @@ -179,22 +185,32 @@ class EDT: except DTError as e: _err(e) + @property + def chosen_nodes(self): + ret = OrderedDict() + + try: + chosen = self._dt.get_node("/chosen") + except DTError: + return ret + + for name, prop in chosen.props.items(): + try: + node = prop.to_path() + except DTError: + # DTS value is not phandle or string, or path doesn't exist + continue + + ret[name] = self._node2enode[node] + + return ret + def chosen_node(self, name): """ Returns the Node pointed at by the property named 'name' in /chosen, or None if the property is missing """ - try: - chosen = self._dt.get_node("/chosen") - except DTError: - # No /chosen node - return None - - if name not in chosen.props: - return None - - # to_path() checks that the node exists - return self._node2enode[chosen.props[name].to_path()] + return self.chosen_nodes.get(name) @property def dts_source(self):