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