169f2ed77SSimon Glass#!/usr/bin/python 269f2ed77SSimon Glass# 369f2ed77SSimon Glass# Copyright (C) 2016 Google, Inc 469f2ed77SSimon Glass# Written by Simon Glass <sjg@chromium.org> 569f2ed77SSimon Glass# 669f2ed77SSimon Glass# SPDX-License-Identifier: GPL-2.0+ 769f2ed77SSimon Glass# 869f2ed77SSimon Glass 969f2ed77SSimon Glassimport copy 1069f2ed77SSimon Glassfrom optparse import OptionError, OptionParser 1169f2ed77SSimon Glassimport os 1258593115SSimon Glassimport struct 1369f2ed77SSimon Glassimport sys 1469f2ed77SSimon Glass 1569f2ed77SSimon Glass# Bring in the patman libraries 1669f2ed77SSimon Glassour_path = os.path.dirname(os.path.realpath(__file__)) 1769f2ed77SSimon Glasssys.path.append(os.path.join(our_path, '../patman')) 1869f2ed77SSimon Glass 19bc1dea36SSimon Glassimport fdt 20ba482585SSimon Glassimport fdt_select 21ba482585SSimon Glassimport fdt_util 2269f2ed77SSimon Glass 2369f2ed77SSimon Glass# When we see these properties we ignore them - i.e. do not create a structure member 2469f2ed77SSimon GlassPROP_IGNORE_LIST = [ 2569f2ed77SSimon Glass '#address-cells', 2669f2ed77SSimon Glass '#gpio-cells', 2769f2ed77SSimon Glass '#size-cells', 2869f2ed77SSimon Glass 'compatible', 2969f2ed77SSimon Glass 'linux,phandle', 3069f2ed77SSimon Glass "status", 3169f2ed77SSimon Glass 'phandle', 32efefe122SSimon Glass 'u-boot,dm-pre-reloc', 3327326c7eSHeiko Stübner 'u-boot,dm-tpl', 3427326c7eSHeiko Stübner 'u-boot,dm-spl', 3569f2ed77SSimon Glass] 3669f2ed77SSimon Glass 3769f2ed77SSimon Glass# C type declarations for the tyues we support 3869f2ed77SSimon GlassTYPE_NAMES = { 39bc1dea36SSimon Glass fdt.TYPE_INT: 'fdt32_t', 40bc1dea36SSimon Glass fdt.TYPE_BYTE: 'unsigned char', 41bc1dea36SSimon Glass fdt.TYPE_STRING: 'const char *', 42bc1dea36SSimon Glass fdt.TYPE_BOOL: 'bool', 4369f2ed77SSimon Glass}; 4469f2ed77SSimon Glass 4569f2ed77SSimon GlassSTRUCT_PREFIX = 'dtd_' 4669f2ed77SSimon GlassVAL_PREFIX = 'dtv_' 4769f2ed77SSimon Glass 4869f2ed77SSimon Glassdef Conv_name_to_c(name): 4969f2ed77SSimon Glass """Convert a device-tree name to a C identifier 5069f2ed77SSimon Glass 5169f2ed77SSimon Glass Args: 5269f2ed77SSimon Glass name: Name to convert 5369f2ed77SSimon Glass Return: 5469f2ed77SSimon Glass String containing the C version of this name 5569f2ed77SSimon Glass """ 5669f2ed77SSimon Glass str = name.replace('@', '_at_') 5769f2ed77SSimon Glass str = str.replace('-', '_') 5869f2ed77SSimon Glass str = str.replace(',', '_') 596b6024a3SSimon Glass str = str.replace('.', '_') 6069f2ed77SSimon Glass str = str.replace('/', '__') 6169f2ed77SSimon Glass return str 6269f2ed77SSimon Glass 6369f2ed77SSimon Glassdef TabTo(num_tabs, str): 6469f2ed77SSimon Glass if len(str) >= num_tabs * 8: 6569f2ed77SSimon Glass return str + ' ' 6634c38896SPaul Burton return str + '\t' * (num_tabs - len(str) // 8) 6769f2ed77SSimon Glass 6869f2ed77SSimon Glassclass DtbPlatdata: 6969f2ed77SSimon Glass """Provide a means to convert device tree binary data to platform data 7069f2ed77SSimon Glass 7169f2ed77SSimon Glass The output of this process is C structures which can be used in space- 7269f2ed77SSimon Glass constrained encvironments where the ~3KB code overhead of device tree 7369f2ed77SSimon Glass code is not affordable. 7469f2ed77SSimon Glass 7569f2ed77SSimon Glass Properties: 7669f2ed77SSimon Glass fdt: Fdt object, referencing the device tree 7769f2ed77SSimon Glass _dtb_fname: Filename of the input device tree binary file 7869f2ed77SSimon Glass _valid_nodes: A list of Node object with compatible strings 7969f2ed77SSimon Glass _options: Command-line options 8069f2ed77SSimon Glass _phandle_node: A dict of nodes indexed by phandle number (1, 2...) 8169f2ed77SSimon Glass _outfile: The current output file (sys.stdout or a real file) 8269f2ed77SSimon Glass _lines: Stashed list of output lines for outputting in the future 8369f2ed77SSimon Glass _phandle_node: A dict of Nodes indexed by phandle (an integer) 8469f2ed77SSimon Glass """ 8569f2ed77SSimon Glass def __init__(self, dtb_fname, options): 8669f2ed77SSimon Glass self._dtb_fname = dtb_fname 8769f2ed77SSimon Glass self._valid_nodes = None 8869f2ed77SSimon Glass self._options = options 8969f2ed77SSimon Glass self._phandle_node = {} 9069f2ed77SSimon Glass self._outfile = None 9169f2ed77SSimon Glass self._lines = [] 9269f2ed77SSimon Glass 9369f2ed77SSimon Glass def SetupOutput(self, fname): 9469f2ed77SSimon Glass """Set up the output destination 9569f2ed77SSimon Glass 9669f2ed77SSimon Glass Once this is done, future calls to self.Out() will output to this 9769f2ed77SSimon Glass file. 9869f2ed77SSimon Glass 9969f2ed77SSimon Glass Args: 10069f2ed77SSimon Glass fname: Filename to send output to, or '-' for stdout 10169f2ed77SSimon Glass """ 10269f2ed77SSimon Glass if fname == '-': 10369f2ed77SSimon Glass self._outfile = sys.stdout 10469f2ed77SSimon Glass else: 10569f2ed77SSimon Glass self._outfile = open(fname, 'w') 10669f2ed77SSimon Glass 10769f2ed77SSimon Glass def Out(self, str): 10869f2ed77SSimon Glass """Output a string to the output file 10969f2ed77SSimon Glass 11069f2ed77SSimon Glass Args: 11169f2ed77SSimon Glass str: String to output 11269f2ed77SSimon Glass """ 11369f2ed77SSimon Glass self._outfile.write(str) 11469f2ed77SSimon Glass 11569f2ed77SSimon Glass def Buf(self, str): 11669f2ed77SSimon Glass """Buffer up a string to send later 11769f2ed77SSimon Glass 11869f2ed77SSimon Glass Args: 11969f2ed77SSimon Glass str: String to add to our 'buffer' list 12069f2ed77SSimon Glass """ 12169f2ed77SSimon Glass self._lines.append(str) 12269f2ed77SSimon Glass 12369f2ed77SSimon Glass def GetBuf(self): 12469f2ed77SSimon Glass """Get the contents of the output buffer, and clear it 12569f2ed77SSimon Glass 12669f2ed77SSimon Glass Returns: 12769f2ed77SSimon Glass The output buffer, which is then cleared for future use 12869f2ed77SSimon Glass """ 12969f2ed77SSimon Glass lines = self._lines 13069f2ed77SSimon Glass self._lines = [] 13169f2ed77SSimon Glass return lines 13269f2ed77SSimon Glass 13369f2ed77SSimon Glass def GetValue(self, type, value): 13469f2ed77SSimon Glass """Get a value as a C expression 13569f2ed77SSimon Glass 13669f2ed77SSimon Glass For integers this returns a byte-swapped (little-endian) hex string 13769f2ed77SSimon Glass For bytes this returns a hex string, e.g. 0x12 13869f2ed77SSimon Glass For strings this returns a literal string enclosed in quotes 13969f2ed77SSimon Glass For booleans this return 'true' 14069f2ed77SSimon Glass 14169f2ed77SSimon Glass Args: 14269f2ed77SSimon Glass type: Data type (fdt_util) 14369f2ed77SSimon Glass value: Data value, as a string of bytes 14469f2ed77SSimon Glass """ 145bc1dea36SSimon Glass if type == fdt.TYPE_INT: 14669f2ed77SSimon Glass return '%#x' % fdt_util.fdt32_to_cpu(value) 147bc1dea36SSimon Glass elif type == fdt.TYPE_BYTE: 14869f2ed77SSimon Glass return '%#x' % ord(value[0]) 149bc1dea36SSimon Glass elif type == fdt.TYPE_STRING: 15069f2ed77SSimon Glass return '"%s"' % value 151bc1dea36SSimon Glass elif type == fdt.TYPE_BOOL: 15269f2ed77SSimon Glass return 'true' 15369f2ed77SSimon Glass 15469f2ed77SSimon Glass def GetCompatName(self, node): 15569f2ed77SSimon Glass """Get a node's first compatible string as a C identifier 15669f2ed77SSimon Glass 15769f2ed77SSimon Glass Args: 15869f2ed77SSimon Glass node: Node object to check 15969f2ed77SSimon Glass Return: 16069f2ed77SSimon Glass C identifier for the first compatible string 16169f2ed77SSimon Glass """ 16269f2ed77SSimon Glass compat = node.props['compatible'].value 16369f2ed77SSimon Glass if type(compat) == list: 16469f2ed77SSimon Glass compat = compat[0] 16569f2ed77SSimon Glass return Conv_name_to_c(compat) 16669f2ed77SSimon Glass 16769f2ed77SSimon Glass def ScanDtb(self): 16869f2ed77SSimon Glass """Scan the device tree to obtain a tree of notes and properties 16969f2ed77SSimon Glass 17069f2ed77SSimon Glass Once this is done, self.fdt.GetRoot() can be called to obtain the 17169f2ed77SSimon Glass device tree root node, and progress from there. 17269f2ed77SSimon Glass """ 173ba482585SSimon Glass self.fdt = fdt_select.FdtScan(self._dtb_fname) 17469f2ed77SSimon Glass 17555bc080eSPhilipp Tomsich def ScanNode(self, root): 17655bc080eSPhilipp Tomsich for node in root.subnodes: 17755bc080eSPhilipp Tomsich if 'compatible' in node.props: 17855bc080eSPhilipp Tomsich status = node.props.get('status') 17955bc080eSPhilipp Tomsich if (not options.include_disabled and not status or 18055bc080eSPhilipp Tomsich status.value != 'disabled'): 18155bc080eSPhilipp Tomsich self._valid_nodes.append(node) 18255bc080eSPhilipp Tomsich phandle_prop = node.props.get('phandle') 18355bc080eSPhilipp Tomsich if phandle_prop: 18455bc080eSPhilipp Tomsich phandle = phandle_prop.GetPhandle() 18555bc080eSPhilipp Tomsich self._phandle_node[phandle] = node 18655bc080eSPhilipp Tomsich 18755bc080eSPhilipp Tomsich # recurse to handle any subnodes 18855bc080eSPhilipp Tomsich self.ScanNode(node); 18955bc080eSPhilipp Tomsich 19069f2ed77SSimon Glass def ScanTree(self): 19169f2ed77SSimon Glass """Scan the device tree for useful information 19269f2ed77SSimon Glass 19369f2ed77SSimon Glass This fills in the following properties: 19469f2ed77SSimon Glass _phandle_node: A dict of Nodes indexed by phandle (an integer) 19569f2ed77SSimon Glass _valid_nodes: A list of nodes we wish to consider include in the 19669f2ed77SSimon Glass platform data 19769f2ed77SSimon Glass """ 19869f2ed77SSimon Glass self._phandle_node = {} 19955bc080eSPhilipp Tomsich self._valid_nodes = [] 20055bc080eSPhilipp Tomsich return self.ScanNode(self.fdt.GetRoot()); 20155bc080eSPhilipp Tomsich 20269f2ed77SSimon Glass for node in self.fdt.GetRoot().subnodes: 20369f2ed77SSimon Glass if 'compatible' in node.props: 20469f2ed77SSimon Glass status = node.props.get('status') 20569f2ed77SSimon Glass if (not options.include_disabled and not status or 20669f2ed77SSimon Glass status.value != 'disabled'): 20769f2ed77SSimon Glass node_list.append(node) 20869f2ed77SSimon Glass phandle_prop = node.props.get('phandle') 20969f2ed77SSimon Glass if phandle_prop: 21069f2ed77SSimon Glass phandle = phandle_prop.GetPhandle() 21169f2ed77SSimon Glass self._phandle_node[phandle] = node 21269f2ed77SSimon Glass 21369f2ed77SSimon Glass self._valid_nodes = node_list 21469f2ed77SSimon Glass 21569f2ed77SSimon Glass def IsPhandle(self, prop): 21669f2ed77SSimon Glass """Check if a node contains phandles 21769f2ed77SSimon Glass 21869f2ed77SSimon Glass We have no reliable way of detecting whether a node uses a phandle 21969f2ed77SSimon Glass or not. As an interim measure, use a list of known property names. 22069f2ed77SSimon Glass 22169f2ed77SSimon Glass Args: 22269f2ed77SSimon Glass prop: Prop object to check 22369f2ed77SSimon Glass Return: 22469f2ed77SSimon Glass True if the object value contains phandles, else False 22569f2ed77SSimon Glass """ 22669f2ed77SSimon Glass if prop.name in ['clocks']: 22769f2ed77SSimon Glass return True 22869f2ed77SSimon Glass return False 22969f2ed77SSimon Glass 23069f2ed77SSimon Glass def ScanStructs(self): 23169f2ed77SSimon Glass """Scan the device tree building up the C structures we will use. 23269f2ed77SSimon Glass 23369f2ed77SSimon Glass Build a dict keyed by C struct name containing a dict of Prop 23469f2ed77SSimon Glass object for each struct field (keyed by property name). Where the 23569f2ed77SSimon Glass same struct appears multiple times, try to use the 'widest' 23669f2ed77SSimon Glass property, i.e. the one with a type which can express all others. 23769f2ed77SSimon Glass 23869f2ed77SSimon Glass Once the widest property is determined, all other properties are 23969f2ed77SSimon Glass updated to match that width. 24069f2ed77SSimon Glass """ 24169f2ed77SSimon Glass structs = {} 24269f2ed77SSimon Glass for node in self._valid_nodes: 24369f2ed77SSimon Glass node_name = self.GetCompatName(node) 24469f2ed77SSimon Glass fields = {} 24569f2ed77SSimon Glass 24669f2ed77SSimon Glass # Get a list of all the valid properties in this node. 2474ae6549fSPaul Burton for name, prop in node.props.items(): 24869f2ed77SSimon Glass if name not in PROP_IGNORE_LIST and name[0] != '#': 24969f2ed77SSimon Glass fields[name] = copy.deepcopy(prop) 25069f2ed77SSimon Glass 25169f2ed77SSimon Glass # If we've seen this node_name before, update the existing struct. 25269f2ed77SSimon Glass if node_name in structs: 25369f2ed77SSimon Glass struct = structs[node_name] 2544ae6549fSPaul Burton for name, prop in fields.items(): 25569f2ed77SSimon Glass oldprop = struct.get(name) 25669f2ed77SSimon Glass if oldprop: 25769f2ed77SSimon Glass oldprop.Widen(prop) 25869f2ed77SSimon Glass else: 25969f2ed77SSimon Glass struct[name] = prop 26069f2ed77SSimon Glass 26169f2ed77SSimon Glass # Otherwise store this as a new struct. 26269f2ed77SSimon Glass else: 26369f2ed77SSimon Glass structs[node_name] = fields 26469f2ed77SSimon Glass 26569f2ed77SSimon Glass upto = 0 26669f2ed77SSimon Glass for node in self._valid_nodes: 26769f2ed77SSimon Glass node_name = self.GetCompatName(node) 26869f2ed77SSimon Glass struct = structs[node_name] 2694ae6549fSPaul Burton for name, prop in node.props.items(): 27069f2ed77SSimon Glass if name not in PROP_IGNORE_LIST and name[0] != '#': 27169f2ed77SSimon Glass prop.Widen(struct[name]) 27269f2ed77SSimon Glass upto += 1 27369f2ed77SSimon Glass return structs 27469f2ed77SSimon Glass 27569f2ed77SSimon Glass def GenerateStructs(self, structs): 27669f2ed77SSimon Glass """Generate struct defintions for the platform data 27769f2ed77SSimon Glass 27869f2ed77SSimon Glass This writes out the body of a header file consisting of structure 27969f2ed77SSimon Glass definitions for node in self._valid_nodes. See the documentation in 28069f2ed77SSimon Glass README.of-plat for more information. 28169f2ed77SSimon Glass """ 28269f2ed77SSimon Glass self.Out('#include <stdbool.h>\n') 28369f2ed77SSimon Glass self.Out('#include <libfdt.h>\n') 28469f2ed77SSimon Glass 28569f2ed77SSimon Glass # Output the struct definition 28669f2ed77SSimon Glass for name in sorted(structs): 28769f2ed77SSimon Glass self.Out('struct %s%s {\n' % (STRUCT_PREFIX, name)); 28869f2ed77SSimon Glass for pname in sorted(structs[name]): 28969f2ed77SSimon Glass prop = structs[name][pname] 29069f2ed77SSimon Glass if self.IsPhandle(prop): 29169f2ed77SSimon Glass # For phandles, include a reference to the target 29269f2ed77SSimon Glass self.Out('\t%s%s[%d]' % (TabTo(2, 'struct phandle_2_cell'), 29369f2ed77SSimon Glass Conv_name_to_c(prop.name), 29469f2ed77SSimon Glass len(prop.value) / 2)) 29569f2ed77SSimon Glass else: 29669f2ed77SSimon Glass ptype = TYPE_NAMES[prop.type] 29769f2ed77SSimon Glass self.Out('\t%s%s' % (TabTo(2, ptype), 29869f2ed77SSimon Glass Conv_name_to_c(prop.name))) 29969f2ed77SSimon Glass if type(prop.value) == list: 30069f2ed77SSimon Glass self.Out('[%d]' % len(prop.value)) 30169f2ed77SSimon Glass self.Out(';\n') 30269f2ed77SSimon Glass self.Out('};\n') 30369f2ed77SSimon Glass 304*49eec8c7SSimon Glass def OutputNode(self, node): 305*49eec8c7SSimon Glass """Output the C code for a node 30669f2ed77SSimon Glass 307*49eec8c7SSimon Glass Args: 308*49eec8c7SSimon Glass node: node to output 30969f2ed77SSimon Glass """ 31069f2ed77SSimon Glass struct_name = self.GetCompatName(node) 31169f2ed77SSimon Glass var_name = Conv_name_to_c(node.name) 31269f2ed77SSimon Glass self.Buf('static struct %s%s %s%s = {\n' % 31369f2ed77SSimon Glass (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name)) 3144ae6549fSPaul Burton for pname, prop in node.props.items(): 31569f2ed77SSimon Glass if pname in PROP_IGNORE_LIST or pname[0] == '#': 31669f2ed77SSimon Glass continue 31769f2ed77SSimon Glass ptype = TYPE_NAMES[prop.type] 31869f2ed77SSimon Glass member_name = Conv_name_to_c(prop.name) 31969f2ed77SSimon Glass self.Buf('\t%s= ' % TabTo(3, '.' + member_name)) 32069f2ed77SSimon Glass 32169f2ed77SSimon Glass # Special handling for lists 32269f2ed77SSimon Glass if type(prop.value) == list: 32369f2ed77SSimon Glass self.Buf('{') 32469f2ed77SSimon Glass vals = [] 32569f2ed77SSimon Glass # For phandles, output a reference to the platform data 32669f2ed77SSimon Glass # of the target node. 32769f2ed77SSimon Glass if self.IsPhandle(prop): 32869f2ed77SSimon Glass # Process the list as pairs of (phandle, id) 32969f2ed77SSimon Glass it = iter(prop.value) 33069f2ed77SSimon Glass for phandle_cell, id_cell in zip(it, it): 33169f2ed77SSimon Glass phandle = fdt_util.fdt32_to_cpu(phandle_cell) 33269f2ed77SSimon Glass id = fdt_util.fdt32_to_cpu(id_cell) 33369f2ed77SSimon Glass target_node = self._phandle_node[phandle] 33469f2ed77SSimon Glass name = Conv_name_to_c(target_node.name) 33569f2ed77SSimon Glass vals.append('{&%s%s, %d}' % (VAL_PREFIX, name, id)) 33669f2ed77SSimon Glass else: 33769f2ed77SSimon Glass for val in prop.value: 33869f2ed77SSimon Glass vals.append(self.GetValue(prop.type, val)) 33969f2ed77SSimon Glass self.Buf(', '.join(vals)) 34069f2ed77SSimon Glass self.Buf('}') 34169f2ed77SSimon Glass else: 34269f2ed77SSimon Glass self.Buf(self.GetValue(prop.type, prop.value)) 34369f2ed77SSimon Glass self.Buf(',\n') 34469f2ed77SSimon Glass self.Buf('};\n') 34569f2ed77SSimon Glass 34669f2ed77SSimon Glass # Add a device declaration 34769f2ed77SSimon Glass self.Buf('U_BOOT_DEVICE(%s) = {\n' % var_name) 34869f2ed77SSimon Glass self.Buf('\t.name\t\t= "%s",\n' % struct_name) 34969f2ed77SSimon Glass self.Buf('\t.platdata\t= &%s%s,\n' % (VAL_PREFIX, var_name)) 3509fa28190SSimon Glass self.Buf('\t.platdata_size\t= sizeof(%s%s),\n' % 3519fa28190SSimon Glass (VAL_PREFIX, var_name)) 35269f2ed77SSimon Glass self.Buf('};\n') 35369f2ed77SSimon Glass self.Buf('\n') 35469f2ed77SSimon Glass 355*49eec8c7SSimon Glass def GenerateTables(self): 356*49eec8c7SSimon Glass """Generate device defintions for the platform data 357*49eec8c7SSimon Glass 358*49eec8c7SSimon Glass This writes out C platform data initialisation data and 359*49eec8c7SSimon Glass U_BOOT_DEVICE() declarations for each valid node. See the 360*49eec8c7SSimon Glass documentation in README.of-plat for more information. 361*49eec8c7SSimon Glass """ 362*49eec8c7SSimon Glass self.Out('#include <common.h>\n') 363*49eec8c7SSimon Glass self.Out('#include <dm.h>\n') 364*49eec8c7SSimon Glass self.Out('#include <dt-structs.h>\n') 365*49eec8c7SSimon Glass self.Out('\n') 366*49eec8c7SSimon Glass node_txt_list = [] 367*49eec8c7SSimon Glass for node in self._valid_nodes: 368*49eec8c7SSimon Glass self.OutputNode(node) 369*49eec8c7SSimon Glass 37069f2ed77SSimon Glass # Output phandle target nodes first, since they may be referenced 37169f2ed77SSimon Glass # by others 37269f2ed77SSimon Glass if 'phandle' in node.props: 37369f2ed77SSimon Glass self.Out(''.join(self.GetBuf())) 37469f2ed77SSimon Glass else: 37569f2ed77SSimon Glass node_txt_list.append(self.GetBuf()) 37669f2ed77SSimon Glass 37769f2ed77SSimon Glass # Output all the nodes which are not phandle targets themselves, but 37869f2ed77SSimon Glass # may reference them. This avoids the need for forward declarations. 37969f2ed77SSimon Glass for node_txt in node_txt_list: 38069f2ed77SSimon Glass self.Out(''.join(node_txt)) 38169f2ed77SSimon Glass 38269f2ed77SSimon Glass 38369f2ed77SSimon Glassif __name__ != "__main__": 38469f2ed77SSimon Glass pass 38569f2ed77SSimon Glass 38669f2ed77SSimon Glassparser = OptionParser() 38769f2ed77SSimon Glassparser.add_option('-d', '--dtb-file', action='store', 38869f2ed77SSimon Glass help='Specify the .dtb input file') 38969f2ed77SSimon Glassparser.add_option('--include-disabled', action='store_true', 39069f2ed77SSimon Glass help='Include disabled nodes') 39169f2ed77SSimon Glassparser.add_option('-o', '--output', action='store', default='-', 39269f2ed77SSimon Glass help='Select output filename') 39369f2ed77SSimon Glass(options, args) = parser.parse_args() 39469f2ed77SSimon Glass 39569f2ed77SSimon Glassif not args: 39669f2ed77SSimon Glass raise ValueError('Please specify a command: struct, platdata') 39769f2ed77SSimon Glass 39869f2ed77SSimon Glassplat = DtbPlatdata(options.dtb_file, options) 39969f2ed77SSimon Glassplat.ScanDtb() 40069f2ed77SSimon Glassplat.ScanTree() 40169f2ed77SSimon Glassplat.SetupOutput(options.output) 40269f2ed77SSimon Glassstructs = plat.ScanStructs() 40369f2ed77SSimon Glass 40469f2ed77SSimon Glassfor cmd in args[0].split(','): 40569f2ed77SSimon Glass if cmd == 'struct': 40669f2ed77SSimon Glass plat.GenerateStructs(structs) 40769f2ed77SSimon Glass elif cmd == 'platdata': 40869f2ed77SSimon Glass plat.GenerateTables() 40969f2ed77SSimon Glass else: 41069f2ed77SSimon Glass raise ValueError("Unknown command '%s': (use: struct, platdata)" % cmd) 411