[PATCH v2 08/21] dtoc: Make _output_list a top-level function

Simon Glass sjg at chromium.org
Wed Dec 23 16:11:20 CET 2020


It is annoying to have this function inside its parent since it makes the
parent longer and hard to read. Move it to the top level.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v1)

 tools/dtoc/dtb_platdata.py | 80 +++++++++++++++++++-------------------
 1 file changed, 40 insertions(+), 40 deletions(-)

diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index cc3e58a1cd6..372f756037e 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -592,51 +592,51 @@ class DtbPlatdata():
                 self.out(';\n')
             self.out('};\n')
 
+    def _output_list(self, node, prop):
+        """Output the C code for a devicetree property that holds a list
+
+        Args:
+            node (fdt.Node): Node to output
+            prop (fdt.Prop): Prop to output
+        """
+        self.buf('{')
+        vals = []
+        # For phandles, output a reference to the platform data
+        # of the target node.
+        info = self.get_phandle_argc(prop, node.name)
+        if info:
+            # Process the list as pairs of (phandle, id)
+            pos = 0
+            for args in info.args:
+                phandle_cell = prop.value[pos]
+                phandle = fdt_util.fdt32_to_cpu(phandle_cell)
+                target_node = self._fdt.phandle_to_node[phandle]
+                arg_values = []
+                for i in range(args):
+                    arg_values.append(
+                        str(fdt_util.fdt32_to_cpu(prop.value[pos + 1 + i])))
+                pos += 1 + args
+                vals.append('\t{%d, {%s}}' % (target_node.idx,
+                                              ', '.join(arg_values)))
+            for val in vals:
+                self.buf('\n\t\t%s,' % val)
+        else:
+            for val in prop.value:
+                vals.append(get_value(prop.type, val))
+
+            # Put 8 values per line to avoid very long lines.
+            for i in range(0, len(vals), 8):
+                if i:
+                    self.buf(',\n\t\t')
+                self.buf(', '.join(vals[i:i + 8]))
+        self.buf('}')
+
     def output_node(self, node):
         """Output the C code for a node
 
         Args:
             node (fdt.Node): node to output
         """
-        def _output_list(node, prop):
-            """Output the C code for a devicetree property that holds a list
-
-            Args:
-                node (fdt.Node): Node to output
-                prop (fdt.Prop): Prop to output
-            """
-            self.buf('{')
-            vals = []
-            # For phandles, output a reference to the platform data
-            # of the target node.
-            info = self.get_phandle_argc(prop, node.name)
-            if info:
-                # Process the list as pairs of (phandle, id)
-                pos = 0
-                for args in info.args:
-                    phandle_cell = prop.value[pos]
-                    phandle = fdt_util.fdt32_to_cpu(phandle_cell)
-                    target_node = self._fdt.phandle_to_node[phandle]
-                    arg_values = []
-                    for i in range(args):
-                        arg_values.append(
-                            str(fdt_util.fdt32_to_cpu(prop.value[pos + 1 + i])))
-                    pos += 1 + args
-                    vals.append('\t{%d, {%s}}' % (target_node.idx,
-                                                  ', '.join(arg_values)))
-                for val in vals:
-                    self.buf('\n\t\t%s,' % val)
-            else:
-                for val in prop.value:
-                    vals.append(get_value(prop.type, val))
-
-                # Put 8 values per line to avoid very long lines.
-                for i in range(0, len(vals), 8):
-                    if i:
-                        self.buf(',\n\t\t')
-                    self.buf(', '.join(vals[i:i + 8]))
-            self.buf('}')
-
         struct_name, _ = self.get_normalized_compat_name(node)
         var_name = conv_name_to_c(node.name)
         self.buf('/* Node %s index %d */\n' % (node.path, node.idx))
@@ -651,7 +651,7 @@ class DtbPlatdata():
 
             # Special handling for lists
             if isinstance(prop.value, list):
-                _output_list(node, prop)
+                self._output_list(node, prop)
             else:
                 self.buf(get_value(prop.type, prop.value))
             self.buf(',\n')
-- 
2.29.2.729.g45daf8777d-goog



More information about the U-Boot mailing list