dtoc: Make use of node properties

Now that we have these available, use them instead of recalculating
things each time.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2021-02-03 06:00:59 -07:00
parent 51d5d051fa
commit e525fea211

View file

@ -470,7 +470,6 @@ class DtbPlatdata():
""" """
structs = self._struct_data structs = self._struct_data
for node in self._valid_nodes: for node in self._valid_nodes:
node_name, _ = self._scan.get_normalized_compat_name(node)
fields = {} fields = {}
# Get a list of all the valid properties in this node. # Get a list of all the valid properties in this node.
@ -478,9 +477,9 @@ class DtbPlatdata():
if name not in PROP_IGNORE_LIST and name[0] != '#': if name not in PROP_IGNORE_LIST and name[0] != '#':
fields[name] = copy.deepcopy(prop) fields[name] = copy.deepcopy(prop)
# If we've seen this node_name before, update the existing struct. # If we've seen this struct_name before, update the existing struct
if node_name in structs: if node.struct_name in structs:
struct = structs[node_name] struct = structs[node.struct_name]
for name, prop in fields.items(): for name, prop in fields.items():
oldprop = struct.get(name) oldprop = struct.get(name)
if oldprop: if oldprop:
@ -490,11 +489,10 @@ class DtbPlatdata():
# Otherwise store this as a new struct. # Otherwise store this as a new struct.
else: else:
structs[node_name] = fields structs[node.struct_name] = fields
for node in self._valid_nodes: for node in self._valid_nodes:
node_name, _ = self._scan.get_normalized_compat_name(node) struct = structs[node.struct_name]
struct = structs[node_name]
for name, prop in node.props.items(): for name, prop in node.props.items():
if name not in PROP_IGNORE_LIST and name[0] != '#': if name not in PROP_IGNORE_LIST and name[0] != '#':
prop.Widen(struct[name]) prop.Widen(struct[name])
@ -598,23 +596,22 @@ class DtbPlatdata():
self.buf(', '.join(vals[i:i + 8])) self.buf(', '.join(vals[i:i + 8]))
self.buf('}') self.buf('}')
def _declare_device(self, var_name, struct_name, node_parent): def _declare_device(self, node):
"""Add a device declaration to the output """Add a device declaration to the output
This declares a U_BOOT_DRVINFO() for the device being processed This declares a U_BOOT_DRVINFO() for the device being processed
Args: Args:
var_name (str): C name for the node node: Node to process
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_DRVINFO(%s) = {\n' % var_name) self.buf('U_BOOT_DRVINFO(%s) = {\n' % node.var_name)
self.buf('\t.name\t\t= "%s",\n' % struct_name) self.buf('\t.name\t\t= "%s",\n' % node.struct_name)
self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, var_name)) self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, node.var_name))
self.buf('\t.plat_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name)) self.buf('\t.plat_size\t= sizeof(%s%s),\n' %
(VAL_PREFIX, node.var_name))
idx = -1 idx = -1
if node_parent and node_parent in self._valid_nodes: if node.parent and node.parent in self._valid_nodes:
idx = node_parent.idx idx = node.parent.idx
self.buf('\t.parent_idx\t= %d,\n' % idx) self.buf('\t.parent_idx\t= %d,\n' % idx)
self.buf('};\n') self.buf('};\n')
self.buf('\n') self.buf('\n')
@ -638,16 +635,14 @@ class DtbPlatdata():
self.buf(get_value(prop.type, prop.value)) self.buf(get_value(prop.type, prop.value))
self.buf(',\n') self.buf(',\n')
def _output_values(self, var_name, struct_name, node): def _output_values(self, node):
"""Output the definition of a device's struct values """Output the definition of a device's struct values
Args: Args:
var_name (str): C name for the node node (Node): Node to output
struct_name (str): Name for the dt struct associated with the node
node (Node): Node being output
""" """
self.buf('static struct %s%s %s%s = {\n' % self.buf('static struct %s%s %s%s = {\n' %
(STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name)) (STRUCT_PREFIX, node.struct_name, VAL_PREFIX, node.var_name))
for pname in sorted(node.props): for pname in sorted(node.props):
self._output_prop(node, node.props[pname]) self._output_prop(node, node.props[pname])
self.buf('};\n') self.buf('};\n')
@ -658,12 +653,10 @@ class DtbPlatdata():
Args: Args:
node (fdt.Node): node to output node (fdt.Node): node to output
""" """
struct_name, _ = self._scan.get_normalized_compat_name(node)
var_name = conv_name_to_c(node.name)
self.buf('/* Node %s index %d */\n' % (node.path, node.idx)) self.buf('/* Node %s index %d */\n' % (node.path, node.idx))
self._output_values(var_name, struct_name, node) self._output_values(node)
self._declare_device(var_name, struct_name, node.parent) self._declare_device(node)
self.out(''.join(self.get_buf())) self.out(''.join(self.get_buf()))