dtb_platdata.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. #!/usr/bin/python
  2. # SPDX-License-Identifier: GPL-2.0+
  3. #
  4. # Copyright (C) 2017 Google, Inc
  5. # Written by Simon Glass <sjg@chromium.org>
  6. #
  7. """Device tree to platform data class
  8. This supports converting device tree data to C structures definitions and
  9. static data.
  10. """
  11. import collections
  12. import copy
  13. import os
  14. import re
  15. import sys
  16. from dtoc import fdt
  17. from dtoc import fdt_util
  18. from patman import tools
  19. # When we see these properties we ignore them - i.e. do not create a structure member
  20. PROP_IGNORE_LIST = [
  21. '#address-cells',
  22. '#gpio-cells',
  23. '#size-cells',
  24. 'compatible',
  25. 'linux,phandle',
  26. "status",
  27. 'phandle',
  28. 'u-boot,dm-pre-reloc',
  29. 'u-boot,dm-tpl',
  30. 'u-boot,dm-spl',
  31. ]
  32. # C type declarations for the tyues we support
  33. TYPE_NAMES = {
  34. fdt.TYPE_INT: 'fdt32_t',
  35. fdt.TYPE_BYTE: 'unsigned char',
  36. fdt.TYPE_STRING: 'const char *',
  37. fdt.TYPE_BOOL: 'bool',
  38. fdt.TYPE_INT64: 'fdt64_t',
  39. }
  40. STRUCT_PREFIX = 'dtd_'
  41. VAL_PREFIX = 'dtv_'
  42. # This holds information about a property which includes phandles.
  43. #
  44. # max_args: integer: Maximum number or arguments that any phandle uses (int).
  45. # args: Number of args for each phandle in the property. The total number of
  46. # phandles is len(args). This is a list of integers.
  47. PhandleInfo = collections.namedtuple('PhandleInfo', ['max_args', 'args'])
  48. def conv_name_to_c(name):
  49. """Convert a device-tree name to a C identifier
  50. This uses multiple replace() calls instead of re.sub() since it is faster
  51. (400ms for 1m calls versus 1000ms for the 're' version).
  52. Args:
  53. name: Name to convert
  54. Return:
  55. String containing the C version of this name
  56. """
  57. new = name.replace('@', '_at_')
  58. new = new.replace('-', '_')
  59. new = new.replace(',', '_')
  60. new = new.replace('.', '_')
  61. return new
  62. def tab_to(num_tabs, line):
  63. """Append tabs to a line of text to reach a tab stop.
  64. Args:
  65. num_tabs: Tab stop to obtain (0 = column 0, 1 = column 8, etc.)
  66. line: Line of text to append to
  67. Returns:
  68. line with the correct number of tabs appeneded. If the line already
  69. extends past that tab stop then a single space is appended.
  70. """
  71. if len(line) >= num_tabs * 8:
  72. return line + ' '
  73. return line + '\t' * (num_tabs - len(line) // 8)
  74. def get_value(ftype, value):
  75. """Get a value as a C expression
  76. For integers this returns a byte-swapped (little-endian) hex string
  77. For bytes this returns a hex string, e.g. 0x12
  78. For strings this returns a literal string enclosed in quotes
  79. For booleans this return 'true'
  80. Args:
  81. type: Data type (fdt_util)
  82. value: Data value, as a string of bytes
  83. """
  84. if ftype == fdt.TYPE_INT:
  85. return '%#x' % fdt_util.fdt32_to_cpu(value)
  86. elif ftype == fdt.TYPE_BYTE:
  87. return '%#x' % tools.ToByte(value[0])
  88. elif ftype == fdt.TYPE_STRING:
  89. return '"%s"' % value
  90. elif ftype == fdt.TYPE_BOOL:
  91. return 'true'
  92. elif ftype == fdt.TYPE_INT64:
  93. return '%#x' % value
  94. def get_compat_name(node):
  95. """Get a node's first compatible string as a C identifier
  96. Args:
  97. node: Node object to check
  98. Return:
  99. Tuple:
  100. C identifier for the first compatible string
  101. List of C identifiers for all the other compatible strings
  102. (possibly empty)
  103. """
  104. compat = node.props['compatible'].value
  105. aliases = []
  106. if isinstance(compat, list):
  107. compat, aliases = compat[0], compat[1:]
  108. return conv_name_to_c(compat), [conv_name_to_c(a) for a in aliases]
  109. class DtbPlatdata(object):
  110. """Provide a means to convert device tree binary data to platform data
  111. The output of this process is C structures which can be used in space-
  112. constrained encvironments where the ~3KB code overhead of device tree
  113. code is not affordable.
  114. Properties:
  115. _fdt: Fdt object, referencing the device tree
  116. _dtb_fname: Filename of the input device tree binary file
  117. _valid_nodes: A list of Node object with compatible strings
  118. _include_disabled: true to include nodes marked status = "disabled"
  119. _outfile: The current output file (sys.stdout or a real file)
  120. _warning_disabled: true to disable warnings about driver names not found
  121. _lines: Stashed list of output lines for outputting in the future
  122. _aliases: Dict that hold aliases for compatible strings
  123. key: First compatible string declared in a node
  124. value: List of additional compatible strings declared in a node
  125. _drivers: List of valid driver names found in drivers/
  126. _driver_aliases: Dict that holds aliases for driver names
  127. key: Driver alias declared with
  128. U_BOOT_DRIVER_ALIAS(driver_alias, driver_name)
  129. value: Driver name declared with U_BOOT_DRIVER(driver_name)
  130. _links: List of links to be included in dm_populate_phandle_data()
  131. """
  132. def __init__(self, dtb_fname, include_disabled, warning_disabled):
  133. self._fdt = None
  134. self._dtb_fname = dtb_fname
  135. self._valid_nodes = None
  136. self._include_disabled = include_disabled
  137. self._outfile = None
  138. self._warning_disabled = warning_disabled
  139. self._lines = []
  140. self._aliases = {}
  141. self._drivers = []
  142. self._driver_aliases = {}
  143. self._links = []
  144. def get_normalized_compat_name(self, node):
  145. """Get a node's normalized compat name
  146. Returns a valid driver name by retrieving node's first compatible
  147. string as a C identifier and performing a check against _drivers
  148. and a lookup in driver_aliases printing a warning in case of failure.
  149. Args:
  150. node: Node object to check
  151. Return:
  152. Tuple:
  153. Driver name associated with the first compatible string
  154. List of C identifiers for all the other compatible strings
  155. (possibly empty)
  156. In case of no match found, the return will be the same as
  157. get_compat_name()
  158. """
  159. compat_c, aliases_c = get_compat_name(node)
  160. if compat_c not in self._drivers:
  161. compat_c_old = compat_c
  162. compat_c = self._driver_aliases.get(compat_c)
  163. if not compat_c:
  164. if not self._warning_disabled:
  165. print('WARNING: the driver %s was not found in the driver list'
  166. % (compat_c_old))
  167. compat_c = compat_c_old
  168. else:
  169. aliases_c = [compat_c_old] + aliases_c
  170. return compat_c, aliases_c
  171. def setup_output(self, fname):
  172. """Set up the output destination
  173. Once this is done, future calls to self.out() will output to this
  174. file.
  175. Args:
  176. fname: Filename to send output to, or '-' for stdout
  177. """
  178. if fname == '-':
  179. self._outfile = sys.stdout
  180. else:
  181. self._outfile = open(fname, 'w')
  182. def out(self, line):
  183. """Output a string to the output file
  184. Args:
  185. line: String to output
  186. """
  187. self._outfile.write(line)
  188. def buf(self, line):
  189. """Buffer up a string to send later
  190. Args:
  191. line: String to add to our 'buffer' list
  192. """
  193. self._lines.append(line)
  194. def get_buf(self):
  195. """Get the contents of the output buffer, and clear it
  196. Returns:
  197. The output buffer, which is then cleared for future use
  198. """
  199. lines = self._lines
  200. self._lines = []
  201. return lines
  202. def out_header(self):
  203. """Output a message indicating that this is an auto-generated file"""
  204. self.out('''/*
  205. * DO NOT MODIFY
  206. *
  207. * This file was generated by dtoc from a .dtb (device tree binary) file.
  208. */
  209. ''')
  210. def get_phandle_argc(self, prop, node_name):
  211. """Check if a node contains phandles
  212. We have no reliable way of detecting whether a node uses a phandle
  213. or not. As an interim measure, use a list of known property names.
  214. Args:
  215. prop: Prop object to check
  216. Return:
  217. Number of argument cells is this is a phandle, else None
  218. """
  219. if prop.name in ['clocks']:
  220. if not isinstance(prop.value, list):
  221. prop.value = [prop.value]
  222. val = prop.value
  223. i = 0
  224. max_args = 0
  225. args = []
  226. while i < len(val):
  227. phandle = fdt_util.fdt32_to_cpu(val[i])
  228. # If we get to the end of the list, stop. This can happen
  229. # since some nodes have more phandles in the list than others,
  230. # but we allocate enough space for the largest list. So those
  231. # nodes with shorter lists end up with zeroes at the end.
  232. if not phandle:
  233. break
  234. target = self._fdt.phandle_to_node.get(phandle)
  235. if not target:
  236. raise ValueError("Cannot parse '%s' in node '%s'" %
  237. (prop.name, node_name))
  238. prop_name = '#clock-cells'
  239. cells = target.props.get(prop_name)
  240. if not cells:
  241. raise ValueError("Node '%s' has no '%s' property" %
  242. (target.name, prop_name))
  243. num_args = fdt_util.fdt32_to_cpu(cells.value)
  244. max_args = max(max_args, num_args)
  245. args.append(num_args)
  246. i += 1 + num_args
  247. return PhandleInfo(max_args, args)
  248. return None
  249. def scan_driver(self, fn):
  250. """Scan a driver file to build a list of driver names and aliases
  251. This procedure will populate self._drivers and self._driver_aliases
  252. Args
  253. fn: Driver filename to scan
  254. """
  255. with open(fn, encoding='utf-8') as fd:
  256. try:
  257. buff = fd.read()
  258. except UnicodeDecodeError:
  259. # This seems to happen on older Python versions
  260. print("Skipping file '%s' due to unicode error" % fn)
  261. return
  262. # The following re will search for driver names declared as
  263. # U_BOOT_DRIVER(driver_name)
  264. drivers = re.findall('U_BOOT_DRIVER\((.*)\)', buff)
  265. for driver in drivers:
  266. self._drivers.append(driver)
  267. # The following re will search for driver aliases declared as
  268. # U_BOOT_DRIVER_ALIAS(alias, driver_name)
  269. driver_aliases = re.findall('U_BOOT_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)',
  270. buff)
  271. for alias in driver_aliases: # pragma: no cover
  272. if len(alias) != 2:
  273. continue
  274. self._driver_aliases[alias[1]] = alias[0]
  275. def scan_drivers(self):
  276. """Scan the driver folders to build a list of driver names and aliases
  277. This procedure will populate self._drivers and self._driver_aliases
  278. """
  279. basedir = sys.argv[0].replace('tools/dtoc/dtoc', '')
  280. if basedir == '':
  281. basedir = './'
  282. for (dirpath, dirnames, filenames) in os.walk(basedir):
  283. for fn in filenames:
  284. if not fn.endswith('.c'):
  285. continue
  286. self.scan_driver(dirpath + '/' + fn)
  287. def scan_dtb(self):
  288. """Scan the device tree to obtain a tree of nodes and properties
  289. Once this is done, self._fdt.GetRoot() can be called to obtain the
  290. device tree root node, and progress from there.
  291. """
  292. self._fdt = fdt.FdtScan(self._dtb_fname)
  293. def scan_node(self, root):
  294. """Scan a node and subnodes to build a tree of node and phandle info
  295. This adds each node to self._valid_nodes.
  296. Args:
  297. root: Root node for scan
  298. """
  299. for node in root.subnodes:
  300. if 'compatible' in node.props:
  301. status = node.props.get('status')
  302. if (not self._include_disabled and not status or
  303. status.value != 'disabled'):
  304. self._valid_nodes.append(node)
  305. # recurse to handle any subnodes
  306. self.scan_node(node)
  307. def scan_tree(self):
  308. """Scan the device tree for useful information
  309. This fills in the following properties:
  310. _valid_nodes: A list of nodes we wish to consider include in the
  311. platform data
  312. """
  313. self._valid_nodes = []
  314. return self.scan_node(self._fdt.GetRoot())
  315. @staticmethod
  316. def get_num_cells(node):
  317. """Get the number of cells in addresses and sizes for this node
  318. Args:
  319. node: Node to check
  320. Returns:
  321. Tuple:
  322. Number of address cells for this node
  323. Number of size cells for this node
  324. """
  325. parent = node.parent
  326. na, ns = 2, 2
  327. if parent:
  328. na_prop = parent.props.get('#address-cells')
  329. ns_prop = parent.props.get('#size-cells')
  330. if na_prop:
  331. na = fdt_util.fdt32_to_cpu(na_prop.value)
  332. if ns_prop:
  333. ns = fdt_util.fdt32_to_cpu(ns_prop.value)
  334. return na, ns
  335. def scan_reg_sizes(self):
  336. """Scan for 64-bit 'reg' properties and update the values
  337. This finds 'reg' properties with 64-bit data and converts the value to
  338. an array of 64-values. This allows it to be output in a way that the
  339. C code can read.
  340. """
  341. for node in self._valid_nodes:
  342. reg = node.props.get('reg')
  343. if not reg:
  344. continue
  345. na, ns = self.get_num_cells(node)
  346. total = na + ns
  347. if reg.type != fdt.TYPE_INT:
  348. raise ValueError("Node '%s' reg property is not an int" %
  349. node.name)
  350. if len(reg.value) % total:
  351. raise ValueError("Node '%s' reg property has %d cells "
  352. 'which is not a multiple of na + ns = %d + %d)' %
  353. (node.name, len(reg.value), na, ns))
  354. reg.na = na
  355. reg.ns = ns
  356. if na != 1 or ns != 1:
  357. reg.type = fdt.TYPE_INT64
  358. i = 0
  359. new_value = []
  360. val = reg.value
  361. if not isinstance(val, list):
  362. val = [val]
  363. while i < len(val):
  364. addr = fdt_util.fdt_cells_to_cpu(val[i:], reg.na)
  365. i += na
  366. size = fdt_util.fdt_cells_to_cpu(val[i:], reg.ns)
  367. i += ns
  368. new_value += [addr, size]
  369. reg.value = new_value
  370. def scan_structs(self):
  371. """Scan the device tree building up the C structures we will use.
  372. Build a dict keyed by C struct name containing a dict of Prop
  373. object for each struct field (keyed by property name). Where the
  374. same struct appears multiple times, try to use the 'widest'
  375. property, i.e. the one with a type which can express all others.
  376. Once the widest property is determined, all other properties are
  377. updated to match that width.
  378. """
  379. structs = {}
  380. for node in self._valid_nodes:
  381. node_name, _ = self.get_normalized_compat_name(node)
  382. fields = {}
  383. # Get a list of all the valid properties in this node.
  384. for name, prop in node.props.items():
  385. if name not in PROP_IGNORE_LIST and name[0] != '#':
  386. fields[name] = copy.deepcopy(prop)
  387. # If we've seen this node_name before, update the existing struct.
  388. if node_name in structs:
  389. struct = structs[node_name]
  390. for name, prop in fields.items():
  391. oldprop = struct.get(name)
  392. if oldprop:
  393. oldprop.Widen(prop)
  394. else:
  395. struct[name] = prop
  396. # Otherwise store this as a new struct.
  397. else:
  398. structs[node_name] = fields
  399. upto = 0
  400. for node in self._valid_nodes:
  401. node_name, _ = self.get_normalized_compat_name(node)
  402. struct = structs[node_name]
  403. for name, prop in node.props.items():
  404. if name not in PROP_IGNORE_LIST and name[0] != '#':
  405. prop.Widen(struct[name])
  406. upto += 1
  407. struct_name, aliases = self.get_normalized_compat_name(node)
  408. for alias in aliases:
  409. self._aliases[alias] = struct_name
  410. return structs
  411. def scan_phandles(self):
  412. """Figure out what phandles each node uses
  413. We need to be careful when outputing nodes that use phandles since
  414. they must come after the declaration of the phandles in the C file.
  415. Otherwise we get a compiler error since the phandle struct is not yet
  416. declared.
  417. This function adds to each node a list of phandle nodes that the node
  418. depends on. This allows us to output things in the right order.
  419. """
  420. for node in self._valid_nodes:
  421. node.phandles = set()
  422. for pname, prop in node.props.items():
  423. if pname in PROP_IGNORE_LIST or pname[0] == '#':
  424. continue
  425. info = self.get_phandle_argc(prop, node.name)
  426. if info:
  427. # Process the list as pairs of (phandle, id)
  428. pos = 0
  429. for args in info.args:
  430. phandle_cell = prop.value[pos]
  431. phandle = fdt_util.fdt32_to_cpu(phandle_cell)
  432. target_node = self._fdt.phandle_to_node[phandle]
  433. node.phandles.add(target_node)
  434. pos += 1 + args
  435. def generate_structs(self, structs):
  436. """Generate struct defintions for the platform data
  437. This writes out the body of a header file consisting of structure
  438. definitions for node in self._valid_nodes. See the documentation in
  439. doc/driver-model/of-plat.rst for more information.
  440. """
  441. self.out_header()
  442. self.out('#include <stdbool.h>\n')
  443. self.out('#include <linux/libfdt.h>\n')
  444. # Output the struct definition
  445. for name in sorted(structs):
  446. self.out('struct %s%s {\n' % (STRUCT_PREFIX, name))
  447. for pname in sorted(structs[name]):
  448. prop = structs[name][pname]
  449. info = self.get_phandle_argc(prop, structs[name])
  450. if info:
  451. # For phandles, include a reference to the target
  452. struct_name = 'struct phandle_%d_arg' % info.max_args
  453. self.out('\t%s%s[%d]' % (tab_to(2, struct_name),
  454. conv_name_to_c(prop.name),
  455. len(info.args)))
  456. else:
  457. ptype = TYPE_NAMES[prop.type]
  458. self.out('\t%s%s' % (tab_to(2, ptype),
  459. conv_name_to_c(prop.name)))
  460. if isinstance(prop.value, list):
  461. self.out('[%d]' % len(prop.value))
  462. self.out(';\n')
  463. self.out('};\n')
  464. for alias, struct_name in self._aliases.items():
  465. if alias not in sorted(structs):
  466. self.out('#define %s%s %s%s\n'% (STRUCT_PREFIX, alias,
  467. STRUCT_PREFIX, struct_name))
  468. def output_node(self, node):
  469. """Output the C code for a node
  470. Args:
  471. node: node to output
  472. """
  473. struct_name, _ = self.get_normalized_compat_name(node)
  474. var_name = conv_name_to_c(node.name)
  475. self.buf('static struct %s%s %s%s = {\n' %
  476. (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name))
  477. for pname in sorted(node.props):
  478. prop = node.props[pname]
  479. if pname in PROP_IGNORE_LIST or pname[0] == '#':
  480. continue
  481. member_name = conv_name_to_c(prop.name)
  482. self.buf('\t%s= ' % tab_to(3, '.' + member_name))
  483. # Special handling for lists
  484. if isinstance(prop.value, list):
  485. self.buf('{')
  486. vals = []
  487. # For phandles, output a reference to the platform data
  488. # of the target node.
  489. info = self.get_phandle_argc(prop, node.name)
  490. if info:
  491. # Process the list as pairs of (phandle, id)
  492. pos = 0
  493. item = 0
  494. for args in info.args:
  495. phandle_cell = prop.value[pos]
  496. phandle = fdt_util.fdt32_to_cpu(phandle_cell)
  497. target_node = self._fdt.phandle_to_node[phandle]
  498. name = conv_name_to_c(target_node.name)
  499. arg_values = []
  500. for i in range(args):
  501. arg_values.append(str(fdt_util.fdt32_to_cpu(prop.value[pos + 1 + i])))
  502. pos += 1 + args
  503. # node member is filled with NULL as the real value
  504. # will be update at run-time during dm_init_and_scan()
  505. # by dm_populate_phandle_data()
  506. vals.append('\t{NULL, {%s}}' % (', '.join(arg_values)))
  507. var_node = '%s%s.%s[%d].node' % \
  508. (VAL_PREFIX, var_name, member_name, item)
  509. # Save the the link information to be use to define
  510. # dm_populate_phandle_data()
  511. self._links.append({'var_node': var_node, 'dev_name': name})
  512. item += 1
  513. for val in vals:
  514. self.buf('\n\t\t%s,' % val)
  515. else:
  516. for val in prop.value:
  517. vals.append(get_value(prop.type, val))
  518. # Put 8 values per line to avoid very long lines.
  519. for i in range(0, len(vals), 8):
  520. if i:
  521. self.buf(',\n\t\t')
  522. self.buf(', '.join(vals[i:i + 8]))
  523. self.buf('}')
  524. else:
  525. self.buf(get_value(prop.type, prop.value))
  526. self.buf(',\n')
  527. self.buf('};\n')
  528. # Add a device declaration
  529. self.buf('U_BOOT_DEVICE(%s) = {\n' % var_name)
  530. self.buf('\t.name\t\t= "%s",\n' % struct_name)
  531. self.buf('\t.platdata\t= &%s%s,\n' % (VAL_PREFIX, var_name))
  532. self.buf('\t.platdata_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name))
  533. self.buf('};\n')
  534. self.buf('\n')
  535. self.out(''.join(self.get_buf()))
  536. def generate_tables(self):
  537. """Generate device defintions for the platform data
  538. This writes out C platform data initialisation data and
  539. U_BOOT_DEVICE() declarations for each valid node. Where a node has
  540. multiple compatible strings, a #define is used to make them equivalent.
  541. See the documentation in doc/driver-model/of-plat.rst for more
  542. information.
  543. """
  544. self.out_header()
  545. self.out('#include <common.h>\n')
  546. self.out('#include <dm.h>\n')
  547. self.out('#include <dt-structs.h>\n')
  548. self.out('\n')
  549. nodes_to_output = list(self._valid_nodes)
  550. # Keep outputing nodes until there is none left
  551. while nodes_to_output:
  552. node = nodes_to_output[0]
  553. # Output all the node's dependencies first
  554. for req_node in node.phandles:
  555. if req_node in nodes_to_output:
  556. self.output_node(req_node)
  557. nodes_to_output.remove(req_node)
  558. self.output_node(node)
  559. nodes_to_output.remove(node)
  560. # Define dm_populate_phandle_data() which will add the linking between
  561. # nodes using DM_GET_DEVICE
  562. # dtv_dmc_at_xxx.clocks[0].node = DM_GET_DEVICE(clock_controller_at_xxx)
  563. self.buf('void dm_populate_phandle_data(void) {\n')
  564. for l in self._links:
  565. self.buf('\t%s = DM_GET_DEVICE(%s);\n' % (l['var_node'], l['dev_name']))
  566. self.buf('}\n')
  567. self.out(''.join(self.get_buf()))
  568. def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False):
  569. """Run all the steps of the dtoc tool
  570. Args:
  571. args: List of non-option arguments provided to the problem
  572. dtb_file: Filename of dtb file to process
  573. include_disabled: True to include disabled nodes
  574. output: Name of output file
  575. """
  576. if not args:
  577. raise ValueError('Please specify a command: struct, platdata')
  578. plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled)
  579. plat.scan_drivers()
  580. plat.scan_dtb()
  581. plat.scan_tree()
  582. plat.scan_reg_sizes()
  583. plat.setup_output(output)
  584. structs = plat.scan_structs()
  585. plat.scan_phandles()
  586. for cmd in args[0].split(','):
  587. if cmd == 'struct':
  588. plat.generate_structs(structs)
  589. elif cmd == 'platdata':
  590. plat.generate_tables()
  591. else:
  592. raise ValueError("Unknown command '%s': (use: struct, platdata)" %
  593. cmd)