]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dtoc: Make _output_list a top-level function
authorSimon Glass <sjg@chromium.org>
Wed, 23 Dec 2020 15:11:20 +0000 (08:11 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 5 Jan 2021 19:24:41 +0000 (12:24 -0700)
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@chromium.org>
tools/dtoc/dtb_platdata.py

index cc3e58a1cd66d22e0454b18a6abe5e464d3291c8..372f756037ee268d83e4a39602125859f0e24089 100644 (file)
@@ -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')