]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dtoc: Extract inner loop from output_node()
authorSimon Glass <sjg@chromium.org>
Sat, 3 Oct 2020 15:25:18 +0000 (09:25 -0600)
committerSimon Glass <sjg@chromium.org>
Thu, 29 Oct 2020 20:42:17 +0000 (14:42 -0600)
This function is very long. Put the inner loop in a separate function
to enhance readability.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/dtoc/dtb_platdata.py

index 579a6749c40c4dbd1f4a29bda809edaf0010591f..bd1daa4379aed1bed0356205a3ea11f87ccaaa96 100644 (file)
@@ -560,6 +560,54 @@ class DtbPlatdata(object):
         Args:
             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
+                item = 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]
+                    name = conv_name_to_c(target_node.name)
+                    arg_values = []
+                    for i in range(args):
+                        arg_values.append(str(fdt_util.fdt32_to_cpu(prop.value[pos + 1 + i])))
+                    pos += 1 + args
+                    # node member is filled with NULL as the real value
+                    # will be update at run-time during dm_init_and_scan()
+                    # by dm_populate_phandle_data()
+                    vals.append('\t{NULL, {%s}}' % (', '.join(arg_values)))
+                    var_node = '%s%s.%s[%d].node' % \
+                                (VAL_PREFIX, var_name, member_name, item)
+                    # Save the the link information to be use to define
+                    # dm_populate_phandle_data()
+                    self._links.append({'var_node': var_node, 'dev_name': name})
+                    item += 1
+                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('static struct %s%s %s%s = {\n' %
@@ -573,46 +621,7 @@ class DtbPlatdata(object):
 
             # Special handling for lists
             if isinstance(prop.value, list):
-                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
-                    item = 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]
-                        name = conv_name_to_c(target_node.name)
-                        arg_values = []
-                        for i in range(args):
-                            arg_values.append(str(fdt_util.fdt32_to_cpu(prop.value[pos + 1 + i])))
-                        pos += 1 + args
-                        # node member is filled with NULL as the real value
-                        # will be update at run-time during dm_init_and_scan()
-                        # by dm_populate_phandle_data()
-                        vals.append('\t{NULL, {%s}}' % (', '.join(arg_values)))
-                        var_node = '%s%s.%s[%d].node' % \
-                                    (VAL_PREFIX, var_name, member_name, item)
-                        # Save the the link information to be use to define
-                        # dm_populate_phandle_data()
-                        self._links.append({'var_node': var_node, 'dev_name': name})
-                        item += 1
-                    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('}')
+                _output_list(node, prop)
             else:
                 self.buf(get_value(prop.type, prop.value))
             self.buf(',\n')