dtb_platdata.py 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  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. See doc/driver-model/of-plat.rst for more informaiton
  11. """
  12. import collections
  13. import copy
  14. from enum import IntEnum
  15. import os
  16. import re
  17. import sys
  18. from dtoc import fdt
  19. from dtoc import fdt_util
  20. from dtoc import src_scan
  21. from dtoc.src_scan import conv_name_to_c
  22. # When we see these properties we ignore them - i.e. do not create a structure
  23. # member
  24. PROP_IGNORE_LIST = [
  25. '#address-cells',
  26. '#gpio-cells',
  27. '#size-cells',
  28. 'compatible',
  29. 'linux,phandle',
  30. "status",
  31. 'phandle',
  32. 'u-boot,dm-pre-reloc',
  33. 'u-boot,dm-tpl',
  34. 'u-boot,dm-spl',
  35. ]
  36. # C type declarations for the types we support
  37. TYPE_NAMES = {
  38. fdt.Type.INT: 'fdt32_t',
  39. fdt.Type.BYTE: 'unsigned char',
  40. fdt.Type.STRING: 'const char *',
  41. fdt.Type.BOOL: 'bool',
  42. fdt.Type.INT64: 'fdt64_t',
  43. }
  44. STRUCT_PREFIX = 'dtd_'
  45. VAL_PREFIX = 'dtv_'
  46. # Properties which are considered to be phandles
  47. # key: property name
  48. # value: name of associated #cells property in the target node
  49. #
  50. # New phandle properties must be added here; otherwise they will come through as
  51. # simple integers and finding devices by phandle will not work.
  52. # Any property that ends with one of these (e.g. 'cd-gpios') will be considered
  53. # a phandle property.
  54. PHANDLE_PROPS = {
  55. 'clocks': '#clock-cells',
  56. 'gpios': '#gpio-cells',
  57. 'sandbox,emul': '#emul-cells',
  58. }
  59. class Ftype(IntEnum):
  60. SOURCE, HEADER = range(2)
  61. # This holds information about each type of output file dtoc can create
  62. # type: Type of file (Ftype)
  63. # fname: Filename excluding directory, e.g. 'dt-plat.c'
  64. # hdr_comment: Comment explaining the purpose of the file
  65. OutputFile = collections.namedtuple('OutputFile',
  66. ['ftype', 'fname', 'method', 'hdr_comment'])
  67. # This holds information about a property which includes phandles.
  68. #
  69. # max_args: integer: Maximum number or arguments that any phandle uses (int).
  70. # args: Number of args for each phandle in the property. The total number of
  71. # phandles is len(args). This is a list of integers.
  72. PhandleInfo = collections.namedtuple('PhandleInfo', ['max_args', 'args'])
  73. # Holds a single phandle link, allowing a C struct value to be assigned to point
  74. # to a device
  75. #
  76. # var_node: C variable to assign (e.g. 'dtv_mmc.clocks[0].node')
  77. # dev_name: Name of device to assign to (e.g. 'clock')
  78. PhandleLink = collections.namedtuple('PhandleLink', ['var_node', 'dev_name'])
  79. def tab_to(num_tabs, line):
  80. """Append tabs to a line of text to reach a tab stop.
  81. Args:
  82. num_tabs (int): Tab stop to obtain (0 = column 0, 1 = column 8, etc.)
  83. line (str): Line of text to append to
  84. Returns:
  85. str: line with the correct number of tabs appeneded. If the line already
  86. extends past that tab stop then a single space is appended.
  87. """
  88. if len(line) >= num_tabs * 8:
  89. return line + ' '
  90. return line + '\t' * (num_tabs - len(line) // 8)
  91. def get_value(ftype, value):
  92. """Get a value as a C expression
  93. For integers this returns a byte-swapped (little-endian) hex string
  94. For bytes this returns a hex string, e.g. 0x12
  95. For strings this returns a literal string enclosed in quotes
  96. For booleans this return 'true'
  97. Args:
  98. ftype (fdt.Type): Data type (fdt_util)
  99. value (bytes): Data value, as a string of bytes
  100. Returns:
  101. str: String representation of the value
  102. """
  103. if ftype == fdt.Type.INT:
  104. val = '%#x' % fdt_util.fdt32_to_cpu(value)
  105. elif ftype == fdt.Type.BYTE:
  106. char = value[0]
  107. val = '%#x' % (ord(char) if isinstance(char, str) else char)
  108. elif ftype == fdt.Type.STRING:
  109. # Handle evil ACPI backslashes by adding another backslash before them.
  110. # So "\\_SB.GPO0" in the device tree effectively stays like that in C
  111. val = '"%s"' % value.replace('\\', '\\\\')
  112. elif ftype == fdt.Type.BOOL:
  113. val = 'true'
  114. else: # ftype == fdt.Type.INT64:
  115. val = '%#x' % value
  116. return val
  117. class DtbPlatdata():
  118. """Provide a means to convert device tree binary data to platform data
  119. The output of this process is C structures which can be used in space-
  120. constrained encvironments where the ~3KB code overhead of device tree
  121. code is not affordable.
  122. Properties:
  123. _scan: Scan object, for scanning and reporting on useful information
  124. from the U-Boot source code
  125. _fdt: Fdt object, referencing the device tree
  126. _dtb_fname: Filename of the input device tree binary file
  127. _valid_nodes_unsorted: A list of Node object with compatible strings,
  128. ordered by devicetree node order
  129. _valid_nodes: A list of Node object with compatible strings, ordered by
  130. conv_name_to_c(node.name)
  131. _include_disabled: true to include nodes marked status = "disabled"
  132. _outfile: The current output file (sys.stdout or a real file)
  133. _lines: Stashed list of output lines for outputting in the future
  134. _dirname: Directory to hold output files, or None for none (all files
  135. go to stdout)
  136. _struct_data (dict): OrderedDict of dtplat structures to output
  137. key (str): Node name, as a C identifier
  138. value: dict containing structure fields:
  139. key (str): Field name
  140. value: Prop object with field information
  141. _basedir (str): Base directory of source tree
  142. _valid_uclasses (list of src_scan.Uclass): List of uclasses needed for
  143. the selected devices (see _valid_node), in alphabetical order
  144. _instantiate: Instantiate devices so they don't need to be bound at
  145. run-time
  146. """
  147. def __init__(self, scan, dtb_fname, include_disabled, instantiate=False):
  148. self._scan = scan
  149. self._fdt = None
  150. self._dtb_fname = dtb_fname
  151. self._valid_nodes = None
  152. self._valid_nodes_unsorted = None
  153. self._include_disabled = include_disabled
  154. self._outfile = None
  155. self._lines = []
  156. self._dirnames = [None] * len(Ftype)
  157. self._struct_data = collections.OrderedDict()
  158. self._basedir = None
  159. self._valid_uclasses = None
  160. self._instantiate = instantiate
  161. def setup_output_dirs(self, output_dirs):
  162. """Set up the output directories
  163. This should be done before setup_output() is called
  164. Args:
  165. output_dirs (tuple of str):
  166. Directory to use for C output files.
  167. Use None to write files relative current directory
  168. Directory to use for H output files.
  169. Defaults to the C output dir
  170. """
  171. def process_dir(ftype, dirname):
  172. if dirname:
  173. os.makedirs(dirname, exist_ok=True)
  174. self._dirnames[ftype] = dirname
  175. if output_dirs:
  176. c_dirname = output_dirs[0]
  177. h_dirname = output_dirs[1] if len(output_dirs) > 1 else c_dirname
  178. process_dir(Ftype.SOURCE, c_dirname)
  179. process_dir(Ftype.HEADER, h_dirname)
  180. def setup_output(self, ftype, fname):
  181. """Set up the output destination
  182. Once this is done, future calls to self.out() will output to this
  183. file. The file used is as follows:
  184. self._dirnames[ftype] is None: output to fname, or stdout if None
  185. self._dirnames[ftype] is not None: output to fname in that directory
  186. Calling this function multiple times will close the old file and open
  187. the new one. If they are the same file, nothing happens and output will
  188. continue to the same file.
  189. Args:
  190. ftype (str): Type of file to create ('c' or 'h')
  191. fname (str): Filename to send output to. If there is a directory in
  192. self._dirnames for this file type, it will be put in that
  193. directory
  194. """
  195. dirname = self._dirnames[ftype]
  196. if dirname:
  197. pathname = os.path.join(dirname, fname)
  198. if self._outfile:
  199. self._outfile.close()
  200. self._outfile = open(pathname, 'w')
  201. elif fname:
  202. if not self._outfile:
  203. self._outfile = open(fname, 'w')
  204. else:
  205. self._outfile = sys.stdout
  206. def finish_output(self):
  207. """Finish outputing to a file
  208. This closes the output file, if one is in use
  209. """
  210. if self._outfile != sys.stdout:
  211. self._outfile.close()
  212. self._outfile = None
  213. def out(self, line):
  214. """Output a string to the output file
  215. Args:
  216. line (str): String to output
  217. """
  218. self._outfile.write(line)
  219. def buf(self, line):
  220. """Buffer up a string to send later
  221. Args:
  222. line (str): String to add to our 'buffer' list
  223. """
  224. self._lines.append(line)
  225. def get_buf(self):
  226. """Get the contents of the output buffer, and clear it
  227. Returns:
  228. list(str): The output buffer, which is then cleared for future use
  229. """
  230. lines = self._lines
  231. self._lines = []
  232. return lines
  233. def out_header(self, outfile):
  234. """Output a message indicating that this is an auto-generated file
  235. Args:
  236. outfile: OutputFile describing the file being generated
  237. """
  238. self.out('''/*
  239. * DO NOT MODIFY
  240. *
  241. * %s.
  242. * This was generated by dtoc from a .dtb (device tree binary) file.
  243. */
  244. ''' % outfile.hdr_comment)
  245. def get_phandle_argc(self, prop, node_name):
  246. """Check if a node contains phandles
  247. We have no reliable way of detecting whether a node uses a phandle
  248. or not. As an interim measure, use a list of known property names.
  249. Args:
  250. prop (fdt.Prop): Prop object to check
  251. node_name (str): Node name, only used for raising an error
  252. Returns:
  253. int or None: Number of argument cells is this is a phandle,
  254. else None
  255. Raises:
  256. ValueError: if the phandle cannot be parsed or the required property
  257. is not present
  258. """
  259. cells_prop = None
  260. for name, cprop in PHANDLE_PROPS.items():
  261. if prop.name.endswith(name):
  262. cells_prop = cprop
  263. if cells_prop:
  264. if not isinstance(prop.value, list):
  265. prop.value = [prop.value]
  266. val = prop.value
  267. i = 0
  268. max_args = 0
  269. args = []
  270. while i < len(val):
  271. phandle = fdt_util.fdt32_to_cpu(val[i])
  272. # If we get to the end of the list, stop. This can happen
  273. # since some nodes have more phandles in the list than others,
  274. # but we allocate enough space for the largest list. So those
  275. # nodes with shorter lists end up with zeroes at the end.
  276. if not phandle:
  277. break
  278. target = self._fdt.phandle_to_node.get(phandle)
  279. if not target:
  280. raise ValueError("Cannot parse '%s' in node '%s'" %
  281. (prop.name, node_name))
  282. cells = target.props.get(cells_prop)
  283. if not cells:
  284. raise ValueError("Node '%s' has no cells property" %
  285. target.name)
  286. num_args = fdt_util.fdt32_to_cpu(cells.value)
  287. max_args = max(max_args, num_args)
  288. args.append(num_args)
  289. i += 1 + num_args
  290. return PhandleInfo(max_args, args)
  291. return None
  292. def scan_dtb(self):
  293. """Scan the device tree to obtain a tree of nodes and properties
  294. Once this is done, self._fdt.GetRoot() can be called to obtain the
  295. device tree root node, and progress from there.
  296. """
  297. self._fdt = fdt.FdtScan(self._dtb_fname)
  298. def scan_node(self, node, valid_nodes):
  299. """Scan a node and subnodes to build a tree of node and phandle info
  300. This adds each subnode to self._valid_nodes if it is enabled and has a
  301. compatible string.
  302. Args:
  303. node (Node): Node for scan for subnodes
  304. valid_nodes (list of Node): List of Node objects to add to
  305. """
  306. for subnode in node.subnodes:
  307. if 'compatible' in subnode.props:
  308. status = subnode.props.get('status')
  309. if (not self._include_disabled and not status or
  310. status.value != 'disabled'):
  311. valid_nodes.append(subnode)
  312. # recurse to handle any subnodes
  313. self.scan_node(subnode, valid_nodes)
  314. def scan_tree(self, add_root):
  315. """Scan the device tree for useful information
  316. This fills in the following properties:
  317. _valid_nodes_unsorted: A list of nodes we wish to consider include
  318. in the platform data (in devicetree node order)
  319. _valid_nodes: Sorted version of _valid_nodes_unsorted
  320. Args:
  321. add_root: True to add the root node also (which wouldn't normally
  322. be added as it may not have a compatible string)
  323. """
  324. root = self._fdt.GetRoot()
  325. valid_nodes = []
  326. if add_root:
  327. valid_nodes.append(root)
  328. self.scan_node(root, valid_nodes)
  329. self._valid_nodes_unsorted = valid_nodes
  330. self._valid_nodes = sorted(valid_nodes,
  331. key=lambda x: conv_name_to_c(x.name))
  332. def prepare_nodes(self):
  333. """Add extra properties to the nodes we are using
  334. The following properties are added for use by dtoc:
  335. idx: Index number of this node (0=first, etc.)
  336. struct_name: Name of the struct dtd used by this node
  337. var_name: C name for this node
  338. child_devs: List of child devices for this node, each a None
  339. child_refs: Dict of references for each child:
  340. key: Position in child list (-1=head, 0=first, 1=second, ...
  341. n-1=last, n=head)
  342. seq: Sequence number of the device (unique within its uclass), or
  343. -1 not not known yet
  344. dev_ref: Reference to this device, e.g. 'DM_DEVICE_REF(serial)'
  345. driver: Driver record for this node, or None if not known
  346. uclass: Uclass record for this node, or None if not known
  347. uclass_seq: Position of this device within the uclass list (0=first,
  348. n-1=last)
  349. parent_seq: Position of this device within it siblings (0=first,
  350. n-1=last)
  351. parent_driver: Driver record of the node's parent, or None if none.
  352. We don't use node.parent.driver since node.parent may not be in
  353. the list of valid nodes
  354. """
  355. for idx, node in enumerate(self._valid_nodes):
  356. node.idx = idx
  357. node.struct_name, _ = self._scan.get_normalized_compat_name(node)
  358. node.var_name = conv_name_to_c(node.name)
  359. node.child_devs = []
  360. node.child_refs = {}
  361. node.seq = -1
  362. node.dev_ref = None
  363. node.driver = None
  364. node.uclass = None
  365. node.uclass_seq = None
  366. node.parent_seq = None
  367. node.parent_driver = None
  368. @staticmethod
  369. def get_num_cells(node):
  370. """Get the number of cells in addresses and sizes for this node
  371. Args:
  372. node (fdt.None): Node to check
  373. Returns:
  374. Tuple:
  375. Number of address cells for this node
  376. Number of size cells for this node
  377. """
  378. parent = node.parent
  379. if parent and not parent.props:
  380. raise ValueError("Parent node '%s' has no properties - do you need u-boot,dm-spl or similar?" %
  381. parent.path)
  382. num_addr, num_size = 2, 2
  383. if parent:
  384. addr_prop = parent.props.get('#address-cells')
  385. size_prop = parent.props.get('#size-cells')
  386. if addr_prop:
  387. num_addr = fdt_util.fdt32_to_cpu(addr_prop.value)
  388. if size_prop:
  389. num_size = fdt_util.fdt32_to_cpu(size_prop.value)
  390. return num_addr, num_size
  391. def scan_reg_sizes(self):
  392. """Scan for 64-bit 'reg' properties and update the values
  393. This finds 'reg' properties with 64-bit data and converts the value to
  394. an array of 64-values. This allows it to be output in a way that the
  395. C code can read.
  396. """
  397. for node in self._valid_nodes:
  398. reg = node.props.get('reg')
  399. if not reg:
  400. continue
  401. num_addr, num_size = self.get_num_cells(node)
  402. total = num_addr + num_size
  403. if reg.type != fdt.Type.INT:
  404. raise ValueError("Node '%s' reg property is not an int" %
  405. node.name)
  406. if not isinstance(reg.value, list):
  407. reg.value = [reg.value]
  408. if len(reg.value) % total:
  409. raise ValueError(
  410. "Node '%s' (parent '%s') reg property has %d cells "
  411. 'which is not a multiple of na + ns = %d + %d)' %
  412. (node.name, node.parent.name, len(reg.value), num_addr,
  413. num_size))
  414. reg.num_addr = num_addr
  415. reg.num_size = num_size
  416. if num_addr > 1 or num_size > 1:
  417. reg.type = fdt.Type.INT64
  418. i = 0
  419. new_value = []
  420. val = reg.value
  421. while i < len(val):
  422. addr = fdt_util.fdt_cells_to_cpu(val[i:], reg.num_addr)
  423. i += num_addr
  424. size = fdt_util.fdt_cells_to_cpu(val[i:], reg.num_size)
  425. i += num_size
  426. new_value += [addr, size]
  427. reg.value = new_value
  428. def scan_structs(self):
  429. """Scan the device tree building up the C structures we will use.
  430. Build a dict keyed by C struct name containing a dict of Prop
  431. object for each struct field (keyed by property name). Where the
  432. same struct appears multiple times, try to use the 'widest'
  433. property, i.e. the one with a type which can express all others.
  434. Once the widest property is determined, all other properties are
  435. updated to match that width.
  436. The results are written to self._struct_data
  437. """
  438. structs = self._struct_data
  439. for node in self._valid_nodes:
  440. fields = {}
  441. # Get a list of all the valid properties in this node.
  442. for name, prop in node.props.items():
  443. if name not in PROP_IGNORE_LIST and name[0] != '#':
  444. fields[name] = copy.deepcopy(prop)
  445. # If we've seen this struct_name before, update the existing struct
  446. if node.struct_name in structs:
  447. struct = structs[node.struct_name]
  448. for name, prop in fields.items():
  449. oldprop = struct.get(name)
  450. if oldprop:
  451. oldprop.Widen(prop)
  452. else:
  453. struct[name] = prop
  454. # Otherwise store this as a new struct.
  455. else:
  456. structs[node.struct_name] = fields
  457. for node in self._valid_nodes:
  458. struct = structs[node.struct_name]
  459. for name, prop in node.props.items():
  460. if name not in PROP_IGNORE_LIST and name[0] != '#':
  461. prop.Widen(struct[name])
  462. def scan_phandles(self):
  463. """Figure out what phandles each node uses
  464. We need to be careful when outputing nodes that use phandles since
  465. they must come after the declaration of the phandles in the C file.
  466. Otherwise we get a compiler error since the phandle struct is not yet
  467. declared.
  468. This function adds to each node a list of phandle nodes that the node
  469. depends on. This allows us to output things in the right order.
  470. """
  471. for node in self._valid_nodes:
  472. node.phandles = set()
  473. for pname, prop in node.props.items():
  474. if pname in PROP_IGNORE_LIST or pname[0] == '#':
  475. continue
  476. info = self.get_phandle_argc(prop, node.name)
  477. if info:
  478. # Process the list as pairs of (phandle, id)
  479. pos = 0
  480. for args in info.args:
  481. phandle_cell = prop.value[pos]
  482. phandle = fdt_util.fdt32_to_cpu(phandle_cell)
  483. target_node = self._fdt.phandle_to_node[phandle]
  484. node.phandles.add(target_node)
  485. pos += 1 + args
  486. def generate_structs(self):
  487. """Generate struct defintions for the platform data
  488. This writes out the body of a header file consisting of structure
  489. definitions for node in self._valid_nodes. See the documentation in
  490. doc/driver-model/of-plat.rst for more information.
  491. """
  492. structs = self._struct_data
  493. self.out('#include <stdbool.h>\n')
  494. self.out('#include <linux/libfdt.h>\n')
  495. # Output the struct definition
  496. for name in sorted(structs):
  497. self.out('struct %s%s {\n' % (STRUCT_PREFIX, name))
  498. for pname in sorted(structs[name]):
  499. prop = structs[name][pname]
  500. info = self.get_phandle_argc(prop, structs[name])
  501. if info:
  502. # For phandles, include a reference to the target
  503. struct_name = 'struct phandle_%d_arg' % info.max_args
  504. self.out('\t%s%s[%d]' % (tab_to(2, struct_name),
  505. conv_name_to_c(prop.name),
  506. len(info.args)))
  507. else:
  508. ptype = TYPE_NAMES[prop.type]
  509. self.out('\t%s%s' % (tab_to(2, ptype),
  510. conv_name_to_c(prop.name)))
  511. if isinstance(prop.value, list):
  512. self.out('[%d]' % len(prop.value))
  513. self.out(';\n')
  514. self.out('};\n')
  515. def _output_list(self, node, prop):
  516. """Output the C code for a devicetree property that holds a list
  517. Args:
  518. node (fdt.Node): Node to output
  519. prop (fdt.Prop): Prop to output
  520. """
  521. self.buf('{')
  522. vals = []
  523. # For phandles, output a reference to the platform data
  524. # of the target node.
  525. info = self.get_phandle_argc(prop, node.name)
  526. if info:
  527. # Process the list as pairs of (phandle, id)
  528. pos = 0
  529. for args in info.args:
  530. phandle_cell = prop.value[pos]
  531. phandle = fdt_util.fdt32_to_cpu(phandle_cell)
  532. target_node = self._fdt.phandle_to_node[phandle]
  533. arg_values = []
  534. for i in range(args):
  535. arg_values.append(
  536. str(fdt_util.fdt32_to_cpu(prop.value[pos + 1 + i])))
  537. pos += 1 + args
  538. vals.append('\t{%d, {%s}}' % (target_node.idx,
  539. ', '.join(arg_values)))
  540. for val in vals:
  541. self.buf('\n\t\t%s,' % val)
  542. else:
  543. for val in prop.value:
  544. vals.append(get_value(prop.type, val))
  545. # Put 8 values per line to avoid very long lines.
  546. for i in range(0, len(vals), 8):
  547. if i:
  548. self.buf(',\n\t\t')
  549. self.buf(', '.join(vals[i:i + 8]))
  550. self.buf('}')
  551. def _declare_device(self, node):
  552. """Add a device declaration to the output
  553. This declares a U_BOOT_DRVINFO() for the device being processed
  554. Args:
  555. node: Node to process
  556. """
  557. self.buf('U_BOOT_DRVINFO(%s) = {\n' % node.var_name)
  558. self.buf('\t.name\t\t= "%s",\n' % node.struct_name)
  559. self.buf('\t.plat\t\t= &%s%s,\n' % (VAL_PREFIX, node.var_name))
  560. self.buf('\t.plat_size\t= sizeof(%s%s),\n' %
  561. (VAL_PREFIX, node.var_name))
  562. idx = -1
  563. if node.parent and node.parent in self._valid_nodes:
  564. idx = node.parent.idx
  565. self.buf('\t.parent_idx\t= %d,\n' % idx)
  566. self.buf('};\n')
  567. self.buf('\n')
  568. def prep_priv(self, struc, name, suffix, section='.priv_data'):
  569. if not struc:
  570. return None
  571. var_name = '_%s%s' % (name, suffix)
  572. hdr = self._scan._structs.get(struc)
  573. if hdr:
  574. self.buf('#include <%s>\n' % hdr.fname)
  575. else:
  576. print('Warning: Cannot find header file for struct %s' % struc)
  577. attr = '__attribute__ ((section ("%s")))' % section
  578. return var_name, struc, attr
  579. def alloc_priv(self, info, name, extra, suffix='_priv'):
  580. result = self.prep_priv(info, name, suffix)
  581. if not result:
  582. return None
  583. var_name, struc, section = result
  584. self.buf('u8 %s_%s[sizeof(struct %s)]\n\t%s;\n' %
  585. (var_name, extra, struc.strip(), section))
  586. return '%s_%s' % (var_name, extra)
  587. def alloc_plat(self, info, name, extra, node):
  588. result = self.prep_priv(info, name, '_plat')
  589. if not result:
  590. return None
  591. var_name, struc, section = result
  592. self.buf('struct %s %s\n\t%s_%s = {\n' %
  593. (struc.strip(), section, var_name, extra))
  594. self.buf('\t.dtplat = {\n')
  595. for pname in sorted(node.props):
  596. self._output_prop(node, node.props[pname], 2)
  597. self.buf('\t},\n')
  598. self.buf('};\n')
  599. return '&%s_%s' % (var_name, extra)
  600. def _declare_device_inst(self, node, parent_driver):
  601. """Add a device instance declaration to the output
  602. This declares a DM_DEVICE_INST() for the device being processed
  603. Args:
  604. node: Node to output
  605. """
  606. driver = node.driver
  607. uclass = node.uclass
  608. self.buf('\n')
  609. num_lines = len(self._lines)
  610. plat_name = self.alloc_plat(driver.plat, driver.name, node.var_name,
  611. node)
  612. priv_name = self.alloc_priv(driver.priv, driver.name, node.var_name)
  613. parent_plat_name = None
  614. parent_priv_name = None
  615. if parent_driver:
  616. # TODO: deal with uclass providing these values
  617. parent_plat_name = self.alloc_priv(
  618. parent_driver.child_plat, driver.name, node.var_name,
  619. '_parent_plat')
  620. parent_priv_name = self.alloc_priv(
  621. parent_driver.child_priv, driver.name, node.var_name,
  622. '_parent_priv')
  623. uclass_plat_name = self.alloc_priv(
  624. uclass.per_dev_plat, driver.name + '_uc', node.var_name, 'plat')
  625. uclass_priv_name = self.alloc_priv(uclass.per_dev_priv,
  626. driver.name + '_uc', node.var_name)
  627. for hdr in driver.headers:
  628. self.buf('#include %s\n' % hdr)
  629. # Add a blank line if we emitted any stuff above, for readability
  630. if num_lines != len(self._lines):
  631. self.buf('\n')
  632. self.buf('DM_DEVICE_INST(%s) = {\n' % node.var_name)
  633. self.buf('\t.driver\t\t= DM_DRIVER_REF(%s),\n' % node.struct_name)
  634. self.buf('\t.name\t\t= "%s",\n' % node.struct_name)
  635. if plat_name:
  636. self.buf('\t.plat_\t\t= %s,\n' % plat_name)
  637. else:
  638. self.buf('\t.plat_\t\t= &%s%s,\n' % (VAL_PREFIX, node.var_name))
  639. if parent_plat_name:
  640. self.buf('\t.parent_plat_\t= %s,\n' % parent_plat_name)
  641. if uclass_plat_name:
  642. self.buf('\t.uclass_plat_\t= %s,\n' % uclass_plat_name)
  643. driver_date = None
  644. if node != self._fdt.GetRoot():
  645. compat_list = node.props['compatible'].value
  646. if not isinstance(compat_list, list):
  647. compat_list = [compat_list]
  648. for compat in compat_list:
  649. driver_data = driver.compat.get(compat)
  650. if driver_data:
  651. self.buf('\t.driver_data\t= %s,\n' % driver_data)
  652. break
  653. if node.parent and node.parent.parent:
  654. if node.parent not in self._valid_nodes:
  655. # This might indicate that the parent node is not in the
  656. # SPL/TPL devicetree but the child is. For example if we are
  657. # dealing with of-platdata in TPL, the parent has a
  658. # u-boot,dm-tpl tag but the child has u-boot,dm-pre-reloc. In
  659. # this case the child node exists in TPL but the parent does
  660. # not.
  661. raise ValueError("Node '%s' requires parent node '%s' but it is not in the valid list" %
  662. (node.path, node.parent.path))
  663. self.buf('\t.parent\t\t= DM_DEVICE_REF(%s),\n' %
  664. node.parent.var_name)
  665. if priv_name:
  666. self.buf('\t.priv_\t\t= %s,\n' % priv_name)
  667. self.buf('\t.uclass\t\t= DM_UCLASS_REF(%s),\n' % uclass.name)
  668. if uclass_priv_name:
  669. self.buf('\t.uclass_priv_ = %s,\n' % uclass_priv_name)
  670. if parent_priv_name:
  671. self.buf('\t.parent_priv_\t= %s,\n' % parent_priv_name)
  672. self.list_node('uclass_node', uclass.node_refs, node.uclass_seq)
  673. self.list_head('child_head', 'sibling_node', node.child_devs, node.var_name)
  674. if node.parent in self._valid_nodes:
  675. self.list_node('sibling_node', node.parent.child_refs,
  676. node.parent_seq)
  677. # flags is left as 0
  678. self.buf('\t.seq_ = %d,\n' % node.seq)
  679. self.buf('};\n')
  680. self.buf('\n')
  681. return parent_plat_name
  682. def _output_prop(self, node, prop, tabs=1):
  683. """Output a line containing the value of a struct member
  684. Args:
  685. node (Node): Node being output
  686. prop (Prop): Prop object to output
  687. """
  688. if prop.name in PROP_IGNORE_LIST or prop.name[0] == '#':
  689. return
  690. member_name = conv_name_to_c(prop.name)
  691. self.buf('%s%s= ' % ('\t' * tabs, tab_to(3, '.' + member_name)))
  692. # Special handling for lists
  693. if isinstance(prop.value, list):
  694. self._output_list(node, prop)
  695. else:
  696. self.buf(get_value(prop.type, prop.value))
  697. self.buf(',\n')
  698. def _output_values(self, node):
  699. """Output the definition of a device's struct values
  700. Args:
  701. node (Node): Node to output
  702. """
  703. self.buf('static struct %s%s %s%s = {\n' %
  704. (STRUCT_PREFIX, node.struct_name, VAL_PREFIX, node.var_name))
  705. for pname in sorted(node.props):
  706. self._output_prop(node, node.props[pname])
  707. self.buf('};\n')
  708. def list_head(self, head_member, node_member, node_refs, var_name):
  709. self.buf('\t.%s\t= {\n' % head_member)
  710. if node_refs:
  711. last = node_refs[-1].dev_ref
  712. first = node_refs[0].dev_ref
  713. member = node_member
  714. else:
  715. last = 'DM_DEVICE_REF(%s)' % var_name
  716. first = last
  717. member = head_member
  718. self.buf('\t\t.prev = &%s->%s,\n' % (last, member))
  719. self.buf('\t\t.next = &%s->%s,\n' % (first, member))
  720. self.buf('\t},\n')
  721. def list_node(self, member, node_refs, seq):
  722. self.buf('\t.%s\t= {\n' % member)
  723. self.buf('\t\t.prev = %s,\n' % node_refs[seq - 1])
  724. self.buf('\t\t.next = %s,\n' % node_refs[seq + 1])
  725. self.buf('\t},\n')
  726. def generate_uclasses(self):
  727. self.out('\n')
  728. self.out('#include <common.h>\n')
  729. self.out('#include <dm.h>\n')
  730. self.out('#include <dt-structs.h>\n')
  731. self.out('\n')
  732. self.buf('/*\n')
  733. self.buf(
  734. " * uclass declarations, ordered by 'struct uclass' linker_list idx:\n")
  735. uclass_list = self._valid_uclasses
  736. for seq, uclass in enumerate(uclass_list):
  737. self.buf(' * %3d: %s\n' % (seq, uclass.name))
  738. self.buf(' *\n')
  739. self.buf(' * Sequence numbers allocated in each uclass:\n')
  740. for uclass in uclass_list:
  741. if uclass.alias_num_to_node:
  742. self.buf(' * %s: %s\n' % (uclass.name, uclass.uclass_id))
  743. for seq, node in uclass.alias_num_to_node.items():
  744. self.buf(' * %d: %s\n' % (seq, node.path))
  745. self.buf(' */\n')
  746. uclass_node = {}
  747. for seq, uclass in enumerate(uclass_list):
  748. uclass_node[seq] = ('&DM_UCLASS_REF(%s)->sibling_node' %
  749. uclass.name)
  750. uclass_node[-1] = '&uclass_head'
  751. uclass_node[len(uclass_list)] = '&uclass_head'
  752. self.buf('\n')
  753. self.buf('struct list_head %s = {\n' % 'uclass_head')
  754. self.buf('\t.prev = %s,\n' % uclass_node[len(uclass_list) -1])
  755. self.buf('\t.next = %s,\n' % uclass_node[0])
  756. self.buf('};\n')
  757. self.buf('\n')
  758. for seq, uclass in enumerate(uclass_list):
  759. uc_drv = self._scan._uclass.get(uclass.uclass_id)
  760. priv_name = self.alloc_priv(uc_drv.priv, uc_drv.name, '')
  761. self.buf('DM_UCLASS_INST(%s) = {\n' % uclass.name)
  762. if priv_name:
  763. self.buf('\t.priv_\t\t= %s,\n' % priv_name)
  764. self.buf('\t.uc_drv\t\t= DM_UCLASS_DRIVER_REF(%s),\n' % uclass.name)
  765. self.list_node('sibling_node', uclass_node, seq)
  766. self.list_head('dev_head', 'uclass_node', uc_drv.devs, None)
  767. self.buf('};\n')
  768. self.buf('\n')
  769. self.out(''.join(self.get_buf()))
  770. def read_aliases(self):
  771. """Read the aliases and attach the information to self._alias
  772. Raises:
  773. ValueError: The alias path is not found
  774. """
  775. alias_node = self._fdt.GetNode('/aliases')
  776. if not alias_node:
  777. return
  778. re_num = re.compile('(^[a-z0-9-]+[a-z]+)([0-9]+)$')
  779. for prop in alias_node.props.values():
  780. m_alias = re_num.match(prop.name)
  781. if not m_alias:
  782. raise ValueError("Cannot decode alias '%s'" % prop.name)
  783. name, num = m_alias.groups()
  784. node = self._fdt.GetNode(prop.value)
  785. result = self._scan.add_uclass_alias(name, num, node)
  786. if result is None:
  787. raise ValueError("Alias '%s' path '%s' not found" %
  788. (prop.name, prop.value))
  789. elif result is False:
  790. print("Could not find uclass for alias '%s'" % prop.name)
  791. def generate_decl(self):
  792. nodes_to_output = list(self._valid_nodes)
  793. self.buf('#include <dm/device-internal.h>\n')
  794. self.buf('#include <dm/uclass-internal.h>\n')
  795. self.buf('\n')
  796. self.buf(
  797. '/* driver declarations - these allow DM_DRIVER_GET() to be used */\n')
  798. for node in nodes_to_output:
  799. self.buf('extern U_BOOT_DRIVER(%s);\n' % node.struct_name);
  800. self.buf('\n')
  801. if self._instantiate:
  802. self.buf(
  803. '/* device declarations - these allow DM_DEVICE_REF() to be used */\n')
  804. for node in nodes_to_output:
  805. self.buf('extern DM_DEVICE_INST(%s);\n' % node.var_name)
  806. self.buf('\n')
  807. uclass_list = self._valid_uclasses
  808. self.buf(
  809. '/* uclass driver declarations - needed for DM_UCLASS_DRIVER_REF() */\n')
  810. for uclass in uclass_list:
  811. self.buf('extern UCLASS_DRIVER(%s);\n' % uclass.name)
  812. if self._instantiate:
  813. self.buf('\n')
  814. self.buf('/* uclass declarations - needed for DM_UCLASS_REF() */\n')
  815. for uclass in uclass_list:
  816. self.buf('extern DM_UCLASS_INST(%s);\n' % uclass.name)
  817. self.out(''.join(self.get_buf()))
  818. def assign_seqs(self):
  819. """Assign a sequence number to each node"""
  820. for node in self._valid_nodes_unsorted:
  821. seq = self._scan.assign_seq(node)
  822. if seq is not None:
  823. node.seq = seq
  824. def process_nodes(self, need_drivers):
  825. nodes_to_output = list(self._valid_nodes)
  826. # Figure out which drivers we actually use
  827. self._scan.mark_used(nodes_to_output)
  828. for node in nodes_to_output:
  829. node.dev_ref = 'DM_DEVICE_REF(%s)' % node.var_name
  830. driver = self._scan.get_driver(node.struct_name)
  831. if not driver:
  832. if not need_drivers:
  833. continue
  834. raise ValueError("Cannot parse/find driver for '%s'" %
  835. node.struct_name)
  836. node.driver = driver
  837. uclass = self._scan._uclass.get(driver.uclass_id)
  838. if not uclass:
  839. raise ValueError("Cannot parse/find uclass '%s' for driver '%s'" %
  840. (driver.uclass_id, node.struct_name))
  841. node.uclass = uclass
  842. node.uclass_seq = len(node.uclass.devs)
  843. node.uclass.devs.append(node)
  844. uclass.node_refs[node.uclass_seq] = \
  845. '&%s->uclass_node' % node.dev_ref
  846. parent_driver = None
  847. if node.parent in self._valid_nodes:
  848. parent_driver = self._scan.get_driver(node.parent.struct_name)
  849. if not parent_driver:
  850. if not need_drivers:
  851. continue
  852. raise ValueError(
  853. "Cannot parse/find parent driver '%s' for '%s'" %
  854. (node.parent.struct_name, node.struct_name))
  855. node.parent_seq = len(node.parent.child_devs)
  856. node.parent.child_devs.append(node)
  857. node.parent.child_refs[node.parent_seq] = \
  858. '&%s->sibling_node' % node.dev_ref
  859. node.parent_driver = parent_driver
  860. for node in nodes_to_output:
  861. ref = '&%s->child_head' % node.dev_ref
  862. node.child_refs[-1] = ref
  863. node.child_refs[len(node.child_devs)] = ref
  864. uclass_set = set()
  865. for driver in self._scan._drivers.values():
  866. if driver.used and driver.uclass:
  867. uclass_set.add(driver.uclass)
  868. self._valid_uclasses = sorted(list(uclass_set),
  869. key=lambda uc: uc.uclass_id)
  870. for seq, uclass in enumerate(uclass_set):
  871. ref = '&DM_UCLASS_REF(%s)->dev_head' % uclass.name
  872. uclass.node_refs[-1] = ref
  873. uclass.node_refs[len(uclass.devs)] = ref
  874. def output_node_plat(self, node):
  875. """Output the C code for a node
  876. Args:
  877. node (fdt.Node): node to output
  878. """
  879. driver = node.driver
  880. parent_driver = node.parent_driver
  881. line1 = 'Node %s index %d' % (node.path, node.idx)
  882. if driver:
  883. self.buf('/*\n')
  884. self.buf(' * %s\n' % line1)
  885. self.buf(' * driver %s parent %s\n' % (driver.name,
  886. parent_driver.name if parent_driver else 'None'))
  887. self.buf(' */\n')
  888. else:
  889. self.buf('/* %s */\n' % line1)
  890. self._output_values(node)
  891. self._declare_device(node)
  892. self.out(''.join(self.get_buf()))
  893. def output_node_instance(self, node):
  894. """Output the C code for a node
  895. Args:
  896. node (fdt.Node): node to output
  897. """
  898. parent_driver = node.parent_driver
  899. self.buf('/*\n')
  900. self.buf(' * Node %s index %d\n' % (node.path, node.idx))
  901. self.buf(' * driver %s parent %s\n' % (node.driver.name,
  902. parent_driver.name if parent_driver else 'None'))
  903. self.buf('*/\n')
  904. if not node.driver.plat:
  905. self._output_values(node)
  906. self._declare_device_inst(node, parent_driver)
  907. self.out(''.join(self.get_buf()))
  908. def generate_plat(self):
  909. """Generate device defintions for the platform data
  910. This writes out C platform data initialisation data and
  911. U_BOOT_DRVINFO() declarations for each valid node. Where a node has
  912. multiple compatible strings, a #define is used to make them equivalent.
  913. See the documentation in doc/driver-model/of-plat.rst for more
  914. information.
  915. """
  916. self.out('/* Allow use of U_BOOT_DRVINFO() in this file */\n')
  917. self.out('#define DT_PLAT_C\n')
  918. self.out('\n')
  919. self.out('#include <common.h>\n')
  920. self.out('#include <dm.h>\n')
  921. self.out('#include <dt-structs.h>\n')
  922. self.out('\n')
  923. if self._valid_nodes:
  924. self.out('/*\n')
  925. self.out(
  926. " * driver_info declarations, ordered by 'struct driver_info' linker_list idx:\n")
  927. self.out(' *\n')
  928. self.out(' * idx %-20s %-s\n' % ('driver_info', 'driver'))
  929. self.out(' * --- %-20s %-s\n' % ('-' * 20, '-' * 20))
  930. for node in self._valid_nodes:
  931. self.out(' * %3d: %-20s %-s\n' %
  932. (node.idx, node.var_name, node.struct_name))
  933. self.out(' * --- %-20s %-s\n' % ('-' * 20, '-' * 20))
  934. self.out(' */\n')
  935. self.out('\n')
  936. for node in self._valid_nodes:
  937. self.output_node_plat(node)
  938. self.out(''.join(self.get_buf()))
  939. def generate_device(self):
  940. """Generate device instances
  941. This writes out DM_DEVICE_INST() records for each device in the
  942. build.
  943. See the documentation in doc/driver-model/of-plat.rst for more
  944. information.
  945. """
  946. self.out('#include <common.h>\n')
  947. self.out('#include <dm.h>\n')
  948. self.out('#include <dt-structs.h>\n')
  949. self.out('\n')
  950. if self._valid_nodes:
  951. self.out('/*\n')
  952. self.out(
  953. " * udevice declarations, ordered by 'struct udevice' linker_list position:\n")
  954. self.out(' *\n')
  955. self.out(' * idx %-20s %-s\n' % ('udevice', 'driver'))
  956. self.out(' * --- %-20s %-s\n' % ('-' * 20, '-' * 20))
  957. for node in self._valid_nodes:
  958. self.out(' * %3d: %-20s %-s\n' %
  959. (node.idx, node.var_name, node.struct_name))
  960. self.out(' * --- %-20s %-s\n' % ('-' * 20, '-' * 20))
  961. self.out(' */\n')
  962. self.out('\n')
  963. for node in self._valid_nodes:
  964. self.output_node_instance(node)
  965. self.out(''.join(self.get_buf()))
  966. # Types of output file we understand
  967. # key: Command used to generate this file
  968. # value: OutputFile for this command
  969. OUTPUT_FILES_COMMON = {
  970. 'decl':
  971. OutputFile(Ftype.HEADER, 'dt-decl.h', DtbPlatdata.generate_decl,
  972. 'Declares externs for all device/uclass instances'),
  973. 'struct':
  974. OutputFile(Ftype.HEADER, 'dt-structs-gen.h',
  975. DtbPlatdata.generate_structs,
  976. 'Defines the structs used to hold devicetree data'),
  977. }
  978. # File generated without instantiate
  979. OUTPUT_FILES_NOINST = {
  980. 'platdata':
  981. OutputFile(Ftype.SOURCE, 'dt-plat.c', DtbPlatdata.generate_plat,
  982. 'Declares the U_BOOT_DRIVER() records and platform data'),
  983. }
  984. # File generated with instantiate
  985. OUTPUT_FILES_INST = {
  986. 'device':
  987. OutputFile(Ftype.SOURCE, 'dt-device.c', DtbPlatdata.generate_device,
  988. 'Declares the DM_DEVICE_INST() records'),
  989. 'uclass':
  990. OutputFile(Ftype.SOURCE, 'dt-uclass.c', DtbPlatdata.generate_uclasses,
  991. 'Declares the uclass instances (struct uclass)'),
  992. }
  993. def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase,
  994. instantiate, warning_disabled=False, drivers_additional=None,
  995. basedir=None, scan=None):
  996. """Run all the steps of the dtoc tool
  997. Args:
  998. args (list): List of non-option arguments provided to the problem
  999. dtb_file (str): Filename of dtb file to process
  1000. include_disabled (bool): True to include disabled nodes
  1001. output (str): Name of output file (None for stdout)
  1002. output_dirs (tuple of str):
  1003. Directory to put C output files
  1004. Directory to put H output files
  1005. phase: The phase of U-Boot that we are generating data for, e.g. 'spl'
  1006. or 'tpl'. None if not known
  1007. instantiate: Instantiate devices so they don't need to be bound at
  1008. run-time
  1009. warning_disabled (bool): True to avoid showing warnings about missing
  1010. drivers
  1011. drivers_additional (list): List of additional drivers to use during
  1012. scanning
  1013. basedir (str): Base directory of U-Boot source code. Defaults to the
  1014. grandparent of this file's directory
  1015. scan (src_src.Scanner): Scanner from a previous run. This can help speed
  1016. up tests. Use None for normal operation
  1017. Returns:
  1018. DtbPlatdata object
  1019. Raises:
  1020. ValueError: if args has no command, or an unknown command
  1021. """
  1022. if not args:
  1023. raise ValueError('Please specify a command: struct, platdata, all')
  1024. if output and output_dirs and any(output_dirs):
  1025. raise ValueError('Must specify either output or output_dirs, not both')
  1026. if not scan:
  1027. scan = src_scan.Scanner(basedir, drivers_additional, phase)
  1028. scan.scan_drivers()
  1029. do_process = True
  1030. else:
  1031. do_process = False
  1032. plat = DtbPlatdata(scan, dtb_file, include_disabled, instantiate)
  1033. plat.scan_dtb()
  1034. plat.scan_tree(add_root=instantiate)
  1035. plat.prepare_nodes()
  1036. plat.scan_reg_sizes()
  1037. plat.setup_output_dirs(output_dirs)
  1038. plat.scan_structs()
  1039. plat.scan_phandles()
  1040. plat.process_nodes(instantiate)
  1041. plat.read_aliases()
  1042. plat.assign_seqs()
  1043. # Figure out what output files we plan to generate
  1044. output_files = dict(OUTPUT_FILES_COMMON)
  1045. if instantiate:
  1046. output_files.update(OUTPUT_FILES_INST)
  1047. else:
  1048. output_files.update(OUTPUT_FILES_NOINST)
  1049. cmds = args[0].split(',')
  1050. if 'all' in cmds:
  1051. cmds = sorted(output_files.keys())
  1052. for cmd in cmds:
  1053. outfile = output_files.get(cmd)
  1054. if not outfile:
  1055. raise ValueError("Unknown command '%s': (use: %s)" %
  1056. (cmd, ', '.join(sorted(output_files.keys()))))
  1057. plat.setup_output(outfile.ftype,
  1058. outfile.fname if output_dirs else output)
  1059. plat.out_header(outfile)
  1060. outfile.method(plat)
  1061. plat.finish_output()
  1062. if not warning_disabled:
  1063. scan.show_warnings()
  1064. return plat