aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass2020-12-23 08:11:21 -0700
committerSimon Glass2021-01-05 12:24:41 -0700
commit221ddc11586fa29b6fcaeae5ea06379f5c62e5e4 (patch)
tree6b6fb7abe9f209ac82cce75af842341a81b053ed
parentabf0c80292d62121d0c28cda27a92a10406428de (diff)
dtoc: Output the device in a separate function
Reduce the length of output_node() by moving the device-output functionality into a separate function. Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--tools/dtoc/dtb_platdata.py33
1 files changed, 22 insertions, 11 deletions
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 372f756037e..2d701ac24da 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -631,6 +631,27 @@ class DtbPlatdata():
self.buf(', '.join(vals[i:i + 8]))
self.buf('}')
+ def _declare_device(self, var_name, struct_name, node_parent):
+ """Add a device declaration to the output
+
+ This declares a U_BOOT_DEVICE() for the device being processed
+
+ Args:
+ var_name (str): C name for the node
+ struct_name (str): Name for the dt struct associated with the node
+ node_parent (Node): Parent of the node (or None if none)
+ """
+ self.buf('U_BOOT_DEVICE(%s) = {\n' % var_name)
+ self.buf('\t.name\t\t= "%s",\n' % struct_name)
+ self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, var_name))
+ self.buf('\t.plat_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name))
+ idx = -1
+ if node_parent and node_parent in self._valid_nodes:
+ idx = node_parent.idx
+ self.buf('\t.parent_idx\t= %d,\n' % idx)
+ self.buf('};\n')
+ self.buf('\n')
+
def output_node(self, node):
"""Output the C code for a node
@@ -657,17 +678,7 @@ class DtbPlatdata():
self.buf(',\n')
self.buf('};\n')
- # Add a device declaration
- self.buf('U_BOOT_DEVICE(%s) = {\n' % var_name)
- self.buf('\t.name\t\t= "%s",\n' % struct_name)
- self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, var_name))
- self.buf('\t.plat_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name))
- idx = -1
- if node.parent and node.parent in self._valid_nodes:
- idx = node.parent.idx
- self.buf('\t.parent_idx\t= %d,\n' % idx)
- self.buf('};\n')
- self.buf('\n')
+ self._declare_device(var_name, struct_name, node.parent)
self.out(''.join(self.get_buf()))