diff options
Diffstat (limited to 'tools/dtoc')
-rw-r--r-- | tools/dtoc/dtb_platdata.py | 185 | ||||
-rw-r--r-- | tools/dtoc/fdt.py | 58 | ||||
-rwxr-xr-x | tools/dtoc/test_dtoc.py | 142 | ||||
-rwxr-xr-x | tools/dtoc/test_fdt.py | 34 |
4 files changed, 226 insertions, 193 deletions
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 9b27aecc14..82671138a9 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -9,6 +9,8 @@ This supports converting device tree data to C structures definitions and static data. + +See doc/driver-model/of-plat.rst for more informaiton """ import collections @@ -19,9 +21,9 @@ import sys from dtoc import fdt from dtoc import fdt_util -from patman import tools -# When we see these properties we ignore them - i.e. do not create a structure member +# When we see these properties we ignore them - i.e. do not create a structure +# member PROP_IGNORE_LIST = [ '#address-cells', '#gpio-cells', @@ -35,13 +37,13 @@ PROP_IGNORE_LIST = [ 'u-boot,dm-spl', ] -# C type declarations for the tyues we support +# C type declarations for the types we support TYPE_NAMES = { - fdt.TYPE_INT: 'fdt32_t', - fdt.TYPE_BYTE: 'unsigned char', - fdt.TYPE_STRING: 'const char *', - fdt.TYPE_BOOL: 'bool', - fdt.TYPE_INT64: 'fdt64_t', + fdt.Type.INT: 'fdt32_t', + fdt.Type.BYTE: 'unsigned char', + fdt.Type.STRING: 'const char *', + fdt.Type.BOOL: 'bool', + fdt.Type.INT64: 'fdt64_t', } STRUCT_PREFIX = 'dtd_' @@ -69,9 +71,9 @@ def conv_name_to_c(name): (400ms for 1m calls versus 1000ms for the 're' version). Args: - name: Name to convert + name (str): Name to convert Return: - String containing the C version of this name + str: String containing the C version of this name """ new = name.replace('@', '_at_') new = new.replace('-', '_') @@ -83,11 +85,11 @@ def tab_to(num_tabs, line): """Append tabs to a line of text to reach a tab stop. Args: - num_tabs: Tab stop to obtain (0 = column 0, 1 = column 8, etc.) - line: Line of text to append to + num_tabs (int): Tab stop to obtain (0 = column 0, 1 = column 8, etc.) + line (str): Line of text to append to Returns: - line with the correct number of tabs appeneded. If the line already + str: line with the correct number of tabs appeneded. If the line already extends past that tab stop then a single space is appended. """ if len(line) >= num_tabs * 8: @@ -103,27 +105,31 @@ def get_value(ftype, value): For booleans this return 'true' Args: - type: Data type (fdt_util) - value: Data value, as a string of bytes + ftype (fdt.Type): Data type (fdt_util) + value (bytes): Data value, as a string of bytes + + Returns: + str: String representation of the value """ - if ftype == fdt.TYPE_INT: + if ftype == fdt.Type.INT: return '%#x' % fdt_util.fdt32_to_cpu(value) - elif ftype == fdt.TYPE_BYTE: - return '%#x' % tools.ToByte(value[0]) - elif ftype == fdt.TYPE_STRING: + elif ftype == fdt.Type.BYTE: + char = value[0] + return '%#x' % (ord(char) if isinstance(char, str) else char) + elif ftype == fdt.Type.STRING: # Handle evil ACPI backslashes by adding another backslash before them. # So "\\_SB.GPO0" in the device tree effectively stays like that in C return '"%s"' % value.replace('\\', '\\\\') - elif ftype == fdt.TYPE_BOOL: + elif ftype == fdt.Type.BOOL: return 'true' - elif ftype == fdt.TYPE_INT64: + else: # ftype == fdt.Type.INT64: return '%#x' % value def get_compat_name(node): """Get the node's list of compatible string as a C identifiers Args: - node: Node object to check + node (fdt.Node): Node object to check Return: List of C identifiers for all the compatible strings """ @@ -157,7 +163,7 @@ class DtbPlatdata(object): _drivers_additional: List of additional drivers to use during scanning """ def __init__(self, dtb_fname, include_disabled, warning_disabled, - drivers_additional=[]): + drivers_additional=None): self._fdt = None self._dtb_fname = dtb_fname self._valid_nodes = None @@ -167,7 +173,7 @@ class DtbPlatdata(object): self._lines = [] self._drivers = [] self._driver_aliases = {} - self._drivers_additional = drivers_additional + self._drivers_additional = drivers_additional or [] def get_normalized_compat_name(self, node): """Get a node's normalized compat name @@ -212,7 +218,7 @@ class DtbPlatdata(object): file. Args: - fname: Filename to send output to, or '-' for stdout + fname (str): Filename to send output to, or '-' for stdout """ if fname == '-': self._outfile = sys.stdout @@ -223,7 +229,7 @@ class DtbPlatdata(object): """Output a string to the output file Args: - line: String to output + line (str): String to output """ self._outfile.write(line) @@ -231,7 +237,7 @@ class DtbPlatdata(object): """Buffer up a string to send later Args: - line: String to add to our 'buffer' list + line (str): String to add to our 'buffer' list """ self._lines.append(line) @@ -239,7 +245,7 @@ class DtbPlatdata(object): """Get the contents of the output buffer, and clear it Returns: - The output buffer, which is then cleared for future use + list(str): The output buffer, which is then cleared for future use """ lines = self._lines self._lines = [] @@ -262,9 +268,14 @@ class DtbPlatdata(object): or not. As an interim measure, use a list of known property names. Args: - prop: Prop object to check - Return: - Number of argument cells is this is a phandle, else None + prop (fdt.Prop): Prop object to check + node_name (str): Node name, only used for raising an error + Returns: + int or None: Number of argument cells is this is a phandle, + else None + Raises: + ValueError: if the phandle cannot be parsed or the required property + is not present """ if prop.name in ['clocks', 'cd-gpios']: if not isinstance(prop.value, list): @@ -293,7 +304,7 @@ class DtbPlatdata(object): break if not cells: raise ValueError("Node '%s' has no cells property" % - (target.name)) + (target.name)) num_args = fdt_util.fdt32_to_cpu(cells.value) max_args = max(max_args, num_args) args.append(num_args) @@ -301,20 +312,20 @@ class DtbPlatdata(object): return PhandleInfo(max_args, args) return None - def scan_driver(self, fn): + def scan_driver(self, fname): """Scan a driver file to build a list of driver names and aliases This procedure will populate self._drivers and self._driver_aliases Args - fn: Driver filename to scan + fname: Driver filename to scan """ - with open(fn, encoding='utf-8') as fd: + with open(fname, encoding='utf-8') as inf: try: - buff = fd.read() + buff = inf.read() except UnicodeDecodeError: # This seems to happen on older Python versions - print("Skipping file '%s' due to unicode error" % fn) + print("Skipping file '%s' due to unicode error" % fname) return # The following re will search for driver names declared as @@ -326,8 +337,9 @@ class DtbPlatdata(object): # The following re will search for driver aliases declared as # U_BOOT_DRIVER_ALIAS(alias, driver_name) - driver_aliases = re.findall('U_BOOT_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)', - buff) + driver_aliases = re.findall( + 'U_BOOT_DRIVER_ALIAS\(\s*(\w+)\s*,\s*(\w+)\s*\)', + buff) for alias in driver_aliases: # pragma: no cover if len(alias) != 2: @@ -343,19 +355,19 @@ class DtbPlatdata(object): basedir = sys.argv[0].replace('tools/dtoc/dtoc', '') if basedir == '': basedir = './' - for (dirpath, dirnames, filenames) in os.walk(basedir): - for fn in filenames: - if not fn.endswith('.c'): + for (dirpath, _, filenames) in os.walk(basedir): + for fname in filenames: + if not fname.endswith('.c'): continue - self.scan_driver(dirpath + '/' + fn) + self.scan_driver(dirpath + '/' + fname) - for fn in self._drivers_additional: - if not isinstance(fn, str) or len(fn) == 0: + for fname in self._drivers_additional: + if not isinstance(fname, str) or len(fname) == 0: continue - if fn[0] == '/': - self.scan_driver(fn) + if fname[0] == '/': + self.scan_driver(fname) else: - self.scan_driver(basedir + '/' + fn) + self.scan_driver(basedir + '/' + fname) def scan_dtb(self): """Scan the device tree to obtain a tree of nodes and properties @@ -403,7 +415,7 @@ class DtbPlatdata(object): """Get the number of cells in addresses and sizes for this node Args: - node: Node to check + node (fdt.None): Node to check Returns: Tuple: @@ -411,15 +423,15 @@ class DtbPlatdata(object): Number of size cells for this node """ parent = node.parent - na, ns = 2, 2 + num_addr, num_size = 2, 2 if parent: - na_prop = parent.props.get('#address-cells') - ns_prop = parent.props.get('#size-cells') - if na_prop: - na = fdt_util.fdt32_to_cpu(na_prop.value) - if ns_prop: - ns = fdt_util.fdt32_to_cpu(ns_prop.value) - return na, ns + addr_prop = parent.props.get('#address-cells') + size_prop = parent.props.get('#size-cells') + if addr_prop: + num_addr = fdt_util.fdt32_to_cpu(addr_prop.value) + if size_prop: + num_size = fdt_util.fdt32_to_cpu(size_prop.value) + return num_addr, num_size def scan_reg_sizes(self): """Scan for 64-bit 'reg' properties and update the values @@ -432,30 +444,31 @@ class DtbPlatdata(object): reg = node.props.get('reg') if not reg: continue - na, ns = self.get_num_cells(node) - total = na + ns + num_addr, num_size = self.get_num_cells(node) + total = num_addr + num_size - if reg.type != fdt.TYPE_INT: + if reg.type != fdt.Type.INT: raise ValueError("Node '%s' reg property is not an int" % node.name) if len(reg.value) % total: - raise ValueError("Node '%s' reg property has %d cells " - 'which is not a multiple of na + ns = %d + %d)' % - (node.name, len(reg.value), na, ns)) - reg.na = na - reg.ns = ns - if na != 1 or ns != 1: - reg.type = fdt.TYPE_INT64 + raise ValueError( + "Node '%s' reg property has %d cells " + 'which is not a multiple of na + ns = %d + %d)' % + (node.name, len(reg.value), num_addr, num_size)) + reg.num_addr = num_addr + reg.num_size = num_size + if num_addr != 1 or num_size != 1: + reg.type = fdt.Type.INT64 i = 0 new_value = [] val = reg.value if not isinstance(val, list): val = [val] while i < len(val): - addr = fdt_util.fdt_cells_to_cpu(val[i:], reg.na) - i += na - size = fdt_util.fdt_cells_to_cpu(val[i:], reg.ns) - i += ns + addr = fdt_util.fdt_cells_to_cpu(val[i:], reg.num_addr) + i += num_addr + size = fdt_util.fdt_cells_to_cpu(val[i:], reg.num_size) + i += num_size new_value += [addr, size] reg.value = new_value @@ -501,14 +514,12 @@ class DtbPlatdata(object): else: structs[node_name] = fields - upto = 0 for node in self._valid_nodes: node_name, _ = self.get_normalized_compat_name(node) struct = structs[node_name] for name, prop in node.props.items(): if name not in PROP_IGNORE_LIST and name[0] != '#': prop.Widen(struct[name]) - upto += 1 return structs @@ -584,7 +595,7 @@ class DtbPlatdata(object): """Output the C code for a node Args: - node: node to output + node (fdt.Node): node to output """ def _output_list(node, prop): """Output the C code for a devicetree property that holds a list @@ -601,12 +612,10 @@ class DtbPlatdata(object): if info: # Process the list as pairs of (phandle, id) pos = 0 - item = 0 for args in info.args: phandle_cell = prop.value[pos] phandle = fdt_util.fdt32_to_cpu(phandle_cell) target_node = self._fdt.phandle_to_node[phandle] - name = conv_name_to_c(target_node.name) arg_values = [] for i in range(args): arg_values.append( @@ -614,7 +623,6 @@ class DtbPlatdata(object): pos += 1 + args vals.append('\t{%d, {%s}}' % (target_node.idx, ', '.join(arg_values))) - item += 1 for val in vals: self.buf('\n\t\t%s,' % val) else: @@ -651,8 +659,8 @@ class DtbPlatdata(object): # Add a device declaration self.buf('U_BOOT_DEVICE(%s) = {\n' % var_name) self.buf('\t.name\t\t= "%s",\n' % struct_name) - self.buf('\t.platdata\t= &%s%s,\n' % (VAL_PREFIX, var_name)) - self.buf('\t.platdata_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name)) + self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, var_name)) + self.buf('\t.plat_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name)) idx = -1 if node.parent and node.parent in self._valid_nodes: idx = node.parent.idx @@ -702,19 +710,26 @@ class DtbPlatdata(object): self.out(''.join(self.get_buf())) def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False, - drivers_additional=[]): + drivers_additional=None): """Run all the steps of the dtoc tool Args: - args: List of non-option arguments provided to the problem - dtb_file: Filename of dtb file to process - include_disabled: True to include disabled nodes - output: Name of output file + args (list): List of non-option arguments provided to the problem + dtb_file (str): Filename of dtb file to process + include_disabled (bool): True to include disabled nodes + output (str): Name of output file + warning_disabled (bool): True to avoid showing warnings about missing + drivers + _drivers_additional (list): List of additional drivers to use during + scanning + Raises: + ValueError: if args has no command, or an unknown command """ if not args: raise ValueError('Please specify a command: struct, platdata') - plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled, drivers_additional) + plat = DtbPlatdata(dtb_file, include_disabled, warning_disabled, + drivers_additional) plat.scan_drivers() plat.scan_dtb() plat.scan_tree() diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index 03b86773d5..4a78c73725 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -5,6 +5,7 @@ # Written by Simon Glass <sjg@chromium.org> # +from enum import IntEnum import struct import sys @@ -22,7 +23,25 @@ from patman import tools # so it is fairly efficient. # A list of types we support -(TYPE_BYTE, TYPE_INT, TYPE_STRING, TYPE_BOOL, TYPE_INT64) = range(5) +class Type(IntEnum): + (BYTE, INT, STRING, BOOL, INT64) = range(5) + + def is_wider_than(self, other): + """Check if another type is 'wider' than this one + + A wider type is one that holds more information than an earlier one, + similar to the concept of type-widening in C. + + This uses a simple arithmetic comparison, since type values are in order + from narrowest (BYTE) to widest (INT64). + + Args: + other: Other type to compare against + + Return: + True if the other type is wider + """ + return self.value > other.value def CheckErr(errnum, msg): if errnum: @@ -41,9 +60,9 @@ def BytesToValue(data): Type of data Data, either a single element or a list of elements. Each element is one of: - TYPE_STRING: str/bytes value from the property - TYPE_INT: a byte-swapped integer stored as a 4-byte str/bytes - TYPE_BYTE: a byte stored as a single-byte str/bytes + Type.STRING: str/bytes value from the property + Type.INT: a byte-swapped integer stored as a 4-byte str/bytes + Type.BYTE: a byte stored as a single-byte str/bytes """ data = bytes(data) size = len(data) @@ -63,21 +82,21 @@ def BytesToValue(data): is_string = False if is_string: if count == 1: - return TYPE_STRING, strings[0].decode() + return Type.STRING, strings[0].decode() else: - return TYPE_STRING, [s.decode() for s in strings[:-1]] + return Type.STRING, [s.decode() for s in strings[:-1]] if size % 4: if size == 1: - return TYPE_BYTE, tools.ToChar(data[0]) + return Type.BYTE, chr(data[0]) else: - return TYPE_BYTE, [tools.ToChar(ch) for ch in list(data)] + return Type.BYTE, [chr(ch) for ch in list(data)] val = [] for i in range(0, size, 4): val.append(data[i:i + 4]) if size == 4: - return TYPE_INT, val[0] + return Type.INT, val[0] else: - return TYPE_INT, val + return Type.INT, val class Prop: @@ -97,7 +116,7 @@ class Prop: self.bytes = bytes(data) self.dirty = False if not data: - self.type = TYPE_BOOL + self.type = Type.BOOL self.value = True return self.type, self.value = BytesToValue(bytes(data)) @@ -128,15 +147,14 @@ class Prop: update the current property to be like the second, since it is less specific. """ - if newprop.type < self.type: - # Special handling to convert an int into bytes - if self.type == TYPE_INT and newprop.type == TYPE_BYTE: + if self.type.is_wider_than(newprop.type): + if self.type == Type.INT and newprop.type == Type.BYTE: if type(self.value) == list: new_value = [] for val in self.value: - new_value += [tools.ToChar(by) for by in val] + new_value += [chr(by) for by in val] else: - new_value = [tools.ToChar(by) for by in self.value] + new_value = [chr(by) for by in self.value] self.value = new_value self.type = newprop.type @@ -155,11 +173,11 @@ class Prop: Returns: A single value of the given type """ - if type == TYPE_BYTE: + if type == Type.BYTE: return chr(0) - elif type == TYPE_INT: + elif type == Type.INT: return struct.pack('>I', 0); - elif type == TYPE_STRING: + elif type == Type.STRING: return '' else: return True @@ -184,7 +202,7 @@ class Prop: """ self.bytes = struct.pack('>I', val); self.value = self.bytes - self.type = TYPE_INT + self.type = Type.INT self.dirty = True def SetData(self, bytes): diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index a5836e04b7..4913d95021 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -134,13 +134,13 @@ class TestDtoc(unittest.TestCase): def test_get_value(self): """Test operation of get_value() function""" self.assertEqual('0x45', - get_value(fdt.TYPE_INT, struct.pack('>I', 0x45))) + get_value(fdt.Type.INT, struct.pack('>I', 0x45))) self.assertEqual('0x45', - get_value(fdt.TYPE_BYTE, struct.pack('<I', 0x45))) + get_value(fdt.Type.BYTE, struct.pack('<I', 0x45))) self.assertEqual('0x0', - get_value(fdt.TYPE_BYTE, struct.pack('>I', 0x45))) - self.assertEqual('"test"', get_value(fdt.TYPE_STRING, 'test')) - self.assertEqual('true', get_value(fdt.TYPE_BOOL, None)) + get_value(fdt.Type.BYTE, struct.pack('>I', 0x45))) + self.assertEqual('"test"', get_value(fdt.Type.STRING, 'test')) + self.assertEqual('true', get_value(fdt.Type.BOOL, None)) def test_get_compat_name(self): """Test operation of get_compat_name() function""" @@ -217,8 +217,8 @@ static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = { }; U_BOOT_DEVICE(i2c_at_0) = { \t.name\t\t= "sandbox_i2c_test", -\t.platdata\t= &dtv_i2c_at_0, -\t.platdata_size\t= sizeof(dtv_i2c_at_0), +\t.plat\t= &dtv_i2c_at_0, +\t.plat_size\t= sizeof(dtv_i2c_at_0), \t.parent_idx\t= -1, }; @@ -229,8 +229,8 @@ static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = { }; U_BOOT_DEVICE(pmic_at_9) = { \t.name\t\t= "sandbox_pmic_test", -\t.platdata\t= &dtv_pmic_at_9, -\t.platdata_size\t= sizeof(dtv_pmic_at_9), +\t.plat\t= &dtv_pmic_at_9, +\t.plat_size\t= sizeof(dtv_pmic_at_9), \t.parent_idx\t= 0, }; @@ -249,8 +249,8 @@ static struct dtd_sandbox_spl_test dtv_spl_test = { }; U_BOOT_DEVICE(spl_test) = { \t.name\t\t= "sandbox_spl_test", -\t.platdata\t= &dtv_spl_test, -\t.platdata_size\t= sizeof(dtv_spl_test), +\t.plat\t= &dtv_spl_test, +\t.plat_size\t= sizeof(dtv_spl_test), \t.parent_idx\t= -1, }; @@ -268,8 +268,8 @@ static struct dtd_sandbox_spl_test dtv_spl_test2 = { }; U_BOOT_DEVICE(spl_test2) = { \t.name\t\t= "sandbox_spl_test", -\t.platdata\t= &dtv_spl_test2, -\t.platdata_size\t= sizeof(dtv_spl_test2), +\t.plat\t= &dtv_spl_test2, +\t.plat_size\t= sizeof(dtv_spl_test2), \t.parent_idx\t= -1, }; @@ -281,8 +281,8 @@ static struct dtd_sandbox_spl_test dtv_spl_test3 = { }; U_BOOT_DEVICE(spl_test3) = { \t.name\t\t= "sandbox_spl_test", -\t.platdata\t= &dtv_spl_test3, -\t.platdata_size\t= sizeof(dtv_spl_test3), +\t.plat\t= &dtv_spl_test3, +\t.plat_size\t= sizeof(dtv_spl_test3), \t.parent_idx\t= -1, }; @@ -291,8 +291,8 @@ static struct dtd_sandbox_spl_test_2 dtv_spl_test4 = { }; U_BOOT_DEVICE(spl_test4) = { \t.name\t\t= "sandbox_spl_test_2", -\t.platdata\t= &dtv_spl_test4, -\t.platdata_size\t= sizeof(dtv_spl_test4), +\t.plat\t= &dtv_spl_test4, +\t.plat_size\t= sizeof(dtv_spl_test4), \t.parent_idx\t= -1, }; @@ -325,8 +325,8 @@ static struct dtd_sandbox_gpio dtv_gpios_at_0 = { }; U_BOOT_DEVICE(gpios_at_0) = { \t.name\t\t= "sandbox_gpio", -\t.platdata\t= &dtv_gpios_at_0, -\t.platdata_size\t= sizeof(dtv_gpios_at_0), +\t.plat\t= &dtv_gpios_at_0, +\t.plat_size\t= sizeof(dtv_gpios_at_0), \t.parent_idx\t= -1, }; @@ -357,8 +357,8 @@ static struct dtd_invalid dtv_spl_test = { }; U_BOOT_DEVICE(spl_test) = { \t.name\t\t= "invalid", -\t.platdata\t= &dtv_spl_test, -\t.platdata_size\t= sizeof(dtv_spl_test), +\t.plat\t= &dtv_spl_test, +\t.plat_size\t= sizeof(dtv_spl_test), \t.parent_idx\t= -1, }; @@ -392,8 +392,8 @@ static struct dtd_target dtv_phandle2_target = { }; U_BOOT_DEVICE(phandle2_target) = { \t.name\t\t= "target", -\t.platdata\t= &dtv_phandle2_target, -\t.platdata_size\t= sizeof(dtv_phandle2_target), +\t.plat\t= &dtv_phandle2_target, +\t.plat_size\t= sizeof(dtv_phandle2_target), \t.parent_idx\t= -1, }; @@ -403,8 +403,8 @@ static struct dtd_target dtv_phandle3_target = { }; U_BOOT_DEVICE(phandle3_target) = { \t.name\t\t= "target", -\t.platdata\t= &dtv_phandle3_target, -\t.platdata_size\t= sizeof(dtv_phandle3_target), +\t.plat\t= &dtv_phandle3_target, +\t.plat_size\t= sizeof(dtv_phandle3_target), \t.parent_idx\t= -1, }; @@ -414,8 +414,8 @@ static struct dtd_target dtv_phandle_target = { }; U_BOOT_DEVICE(phandle_target) = { \t.name\t\t= "target", -\t.platdata\t= &dtv_phandle_target, -\t.platdata_size\t= sizeof(dtv_phandle_target), +\t.plat\t= &dtv_phandle_target, +\t.plat_size\t= sizeof(dtv_phandle_target), \t.parent_idx\t= -1, }; @@ -429,8 +429,8 @@ static struct dtd_source dtv_phandle_source = { }; U_BOOT_DEVICE(phandle_source) = { \t.name\t\t= "source", -\t.platdata\t= &dtv_phandle_source, -\t.platdata_size\t= sizeof(dtv_phandle_source), +\t.plat\t= &dtv_phandle_source, +\t.plat_size\t= sizeof(dtv_phandle_source), \t.parent_idx\t= -1, }; @@ -441,8 +441,8 @@ static struct dtd_source dtv_phandle_source2 = { }; U_BOOT_DEVICE(phandle_source2) = { \t.name\t\t= "source", -\t.platdata\t= &dtv_phandle_source2, -\t.platdata_size\t= sizeof(dtv_phandle_source2), +\t.plat\t= &dtv_phandle_source2, +\t.plat_size\t= sizeof(dtv_phandle_source2), \t.parent_idx\t= -1, }; @@ -479,8 +479,8 @@ static struct dtd_target dtv_phandle_target = { }; U_BOOT_DEVICE(phandle_target) = { \t.name\t\t= "target", -\t.platdata\t= &dtv_phandle_target, -\t.platdata_size\t= sizeof(dtv_phandle_target), +\t.plat\t= &dtv_phandle_target, +\t.plat_size\t= sizeof(dtv_phandle_target), \t.parent_idx\t= -1, }; @@ -491,8 +491,8 @@ static struct dtd_source dtv_phandle_source2 = { }; U_BOOT_DEVICE(phandle_source2) = { \t.name\t\t= "source", -\t.platdata\t= &dtv_phandle_source2, -\t.platdata_size\t= sizeof(dtv_phandle_source2), +\t.plat\t= &dtv_phandle_source2, +\t.plat_size\t= sizeof(dtv_phandle_source2), \t.parent_idx\t= -1, }; @@ -514,8 +514,8 @@ static struct dtd_target dtv_phandle2_target = { }; U_BOOT_DEVICE(phandle2_target) = { \t.name\t\t= "target", -\t.platdata\t= &dtv_phandle2_target, -\t.platdata_size\t= sizeof(dtv_phandle2_target), +\t.plat\t= &dtv_phandle2_target, +\t.plat_size\t= sizeof(dtv_phandle2_target), \t.parent_idx\t= -1, }; @@ -525,8 +525,8 @@ static struct dtd_target dtv_phandle3_target = { }; U_BOOT_DEVICE(phandle3_target) = { \t.name\t\t= "target", -\t.platdata\t= &dtv_phandle3_target, -\t.platdata_size\t= sizeof(dtv_phandle3_target), +\t.plat\t= &dtv_phandle3_target, +\t.plat_size\t= sizeof(dtv_phandle3_target), \t.parent_idx\t= -1, }; @@ -536,8 +536,8 @@ static struct dtd_target dtv_phandle_target = { }; U_BOOT_DEVICE(phandle_target) = { \t.name\t\t= "target", -\t.platdata\t= &dtv_phandle_target, -\t.platdata_size\t= sizeof(dtv_phandle_target), +\t.plat\t= &dtv_phandle_target, +\t.plat_size\t= sizeof(dtv_phandle_target), \t.parent_idx\t= -1, }; @@ -551,8 +551,8 @@ static struct dtd_source dtv_phandle_source = { }; U_BOOT_DEVICE(phandle_source) = { \t.name\t\t= "source", -\t.platdata\t= &dtv_phandle_source, -\t.platdata_size\t= sizeof(dtv_phandle_source), +\t.plat\t= &dtv_phandle_source, +\t.plat_size\t= sizeof(dtv_phandle_source), \t.parent_idx\t= -1, }; @@ -563,8 +563,8 @@ static struct dtd_source dtv_phandle_source2 = { }; U_BOOT_DEVICE(phandle_source2) = { \t.name\t\t= "source", -\t.platdata\t= &dtv_phandle_source2, -\t.platdata_size\t= sizeof(dtv_phandle_source2), +\t.plat\t= &dtv_phandle_source2, +\t.plat_size\t= sizeof(dtv_phandle_source2), \t.parent_idx\t= -1, }; @@ -621,8 +621,8 @@ static struct dtd_test1 dtv_test1 = { }; U_BOOT_DEVICE(test1) = { \t.name\t\t= "test1", -\t.platdata\t= &dtv_test1, -\t.platdata_size\t= sizeof(dtv_test1), +\t.plat\t= &dtv_test1, +\t.plat_size\t= sizeof(dtv_test1), \t.parent_idx\t= -1, }; @@ -632,8 +632,8 @@ static struct dtd_test2 dtv_test2 = { }; U_BOOT_DEVICE(test2) = { \t.name\t\t= "test2", -\t.platdata\t= &dtv_test2, -\t.platdata_size\t= sizeof(dtv_test2), +\t.plat\t= &dtv_test2, +\t.plat_size\t= sizeof(dtv_test2), \t.parent_idx\t= -1, }; @@ -643,8 +643,8 @@ static struct dtd_test3 dtv_test3 = { }; U_BOOT_DEVICE(test3) = { \t.name\t\t= "test3", -\t.platdata\t= &dtv_test3, -\t.platdata_size\t= sizeof(dtv_test3), +\t.plat\t= &dtv_test3, +\t.plat_size\t= sizeof(dtv_test3), \t.parent_idx\t= -1, }; @@ -676,8 +676,8 @@ static struct dtd_test1 dtv_test1 = { }; U_BOOT_DEVICE(test1) = { \t.name\t\t= "test1", -\t.platdata\t= &dtv_test1, -\t.platdata_size\t= sizeof(dtv_test1), +\t.plat\t= &dtv_test1, +\t.plat_size\t= sizeof(dtv_test1), \t.parent_idx\t= -1, }; @@ -687,8 +687,8 @@ static struct dtd_test2 dtv_test2 = { }; U_BOOT_DEVICE(test2) = { \t.name\t\t= "test2", -\t.platdata\t= &dtv_test2, -\t.platdata_size\t= sizeof(dtv_test2), +\t.plat\t= &dtv_test2, +\t.plat_size\t= sizeof(dtv_test2), \t.parent_idx\t= -1, }; @@ -723,8 +723,8 @@ static struct dtd_test1 dtv_test1 = { }; U_BOOT_DEVICE(test1) = { \t.name\t\t= "test1", -\t.platdata\t= &dtv_test1, -\t.platdata_size\t= sizeof(dtv_test1), +\t.plat\t= &dtv_test1, +\t.plat_size\t= sizeof(dtv_test1), \t.parent_idx\t= -1, }; @@ -734,8 +734,8 @@ static struct dtd_test2 dtv_test2 = { }; U_BOOT_DEVICE(test2) = { \t.name\t\t= "test2", -\t.platdata\t= &dtv_test2, -\t.platdata_size\t= sizeof(dtv_test2), +\t.plat\t= &dtv_test2, +\t.plat_size\t= sizeof(dtv_test2), \t.parent_idx\t= -1, }; @@ -745,8 +745,8 @@ static struct dtd_test3 dtv_test3 = { }; U_BOOT_DEVICE(test3) = { \t.name\t\t= "test3", -\t.platdata\t= &dtv_test3, -\t.platdata_size\t= sizeof(dtv_test3), +\t.plat\t= &dtv_test3, +\t.plat_size\t= sizeof(dtv_test3), \t.parent_idx\t= -1, }; @@ -781,8 +781,8 @@ static struct dtd_test1 dtv_test1 = { }; U_BOOT_DEVICE(test1) = { \t.name\t\t= "test1", -\t.platdata\t= &dtv_test1, -\t.platdata_size\t= sizeof(dtv_test1), +\t.plat\t= &dtv_test1, +\t.plat_size\t= sizeof(dtv_test1), \t.parent_idx\t= -1, }; @@ -792,8 +792,8 @@ static struct dtd_test2 dtv_test2 = { }; U_BOOT_DEVICE(test2) = { \t.name\t\t= "test2", -\t.platdata\t= &dtv_test2, -\t.platdata_size\t= sizeof(dtv_test2), +\t.plat\t= &dtv_test2, +\t.plat_size\t= sizeof(dtv_test2), \t.parent_idx\t= -1, }; @@ -803,8 +803,8 @@ static struct dtd_test3 dtv_test3 = { }; U_BOOT_DEVICE(test3) = { \t.name\t\t= "test3", -\t.platdata\t= &dtv_test3, -\t.platdata_size\t= sizeof(dtv_test3), +\t.plat\t= &dtv_test3, +\t.plat_size\t= sizeof(dtv_test3), \t.parent_idx\t= -1, }; @@ -854,8 +854,8 @@ static struct dtd_sandbox_spl_test dtv_spl_test = { }; U_BOOT_DEVICE(spl_test) = { \t.name\t\t= "sandbox_spl_test", -\t.platdata\t= &dtv_spl_test, -\t.platdata_size\t= sizeof(dtv_spl_test), +\t.plat\t= &dtv_spl_test, +\t.plat_size\t= sizeof(dtv_spl_test), \t.parent_idx\t= -1, }; @@ -865,8 +865,8 @@ static struct dtd_sandbox_spl_test dtv_spl_test2 = { }; U_BOOT_DEVICE(spl_test2) = { \t.name\t\t= "sandbox_spl_test", -\t.platdata\t= &dtv_spl_test2, -\t.platdata_size\t= sizeof(dtv_spl_test2), +\t.plat\t= &dtv_spl_test2, +\t.plat_size\t= sizeof(dtv_spl_test2), \t.parent_idx\t= -1, }; diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index cfe3e04c7a..dc6943f733 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -19,7 +19,7 @@ sys.path.insert(1, os.path.join(our_path, '..')) from dtoc import fdt from dtoc import fdt_util from dtoc.fdt_util import fdt32_to_cpu -from fdt import TYPE_BYTE, TYPE_INT, TYPE_STRING, TYPE_BOOL, BytesToValue +from fdt import Type, BytesToValue import libfdt from patman import command from patman import test_util @@ -46,7 +46,7 @@ def _GetPropertyValue(dtb, node, prop_name): # Add 12, which is sizeof(struct fdt_property), to get to start of data offset = prop.GetOffset() + 12 data = dtb.GetContents()[offset:offset + len(prop.value)] - return prop, [tools.ToChar(x) for x in data] + return prop, [chr(x) for x in data] class TestFdt(unittest.TestCase): @@ -127,7 +127,7 @@ class TestFdt(unittest.TestCase): def testBytesToValue(self): self.assertEqual(BytesToValue(b'this\0is\0'), - (TYPE_STRING, ['this', 'is'])) + (Type.STRING, ['this', 'is'])) class TestNode(unittest.TestCase): """Test operation of the Node class""" @@ -249,46 +249,46 @@ class TestProp(unittest.TestCase): def testMakeProp(self): """Test we can convert all the the types that are supported""" prop = self._ConvertProp('boolval') - self.assertEqual(fdt.TYPE_BOOL, prop.type) + self.assertEqual(Type.BOOL, prop.type) self.assertEqual(True, prop.value) prop = self._ConvertProp('intval') - self.assertEqual(fdt.TYPE_INT, prop.type) + self.assertEqual(Type.INT, prop.type) self.assertEqual(1, fdt32_to_cpu(prop.value)) prop = self._ConvertProp('intarray') - self.assertEqual(fdt.TYPE_INT, prop.type) + self.assertEqual(Type.INT, prop.type) val = [fdt32_to_cpu(val) for val in prop.value] self.assertEqual([2, 3, 4], val) prop = self._ConvertProp('byteval') - self.assertEqual(fdt.TYPE_BYTE, prop.type) + self.assertEqual(Type.BYTE, prop.type) self.assertEqual(5, ord(prop.value)) prop = self._ConvertProp('longbytearray') - self.assertEqual(fdt.TYPE_BYTE, prop.type) + self.assertEqual(Type.BYTE, prop.type) val = [ord(val) for val in prop.value] self.assertEqual([9, 10, 11, 12, 13, 14, 15, 16, 17], val) prop = self._ConvertProp('stringval') - self.assertEqual(fdt.TYPE_STRING, prop.type) + self.assertEqual(Type.STRING, prop.type) self.assertEqual('message', prop.value) prop = self._ConvertProp('stringarray') - self.assertEqual(fdt.TYPE_STRING, prop.type) + self.assertEqual(Type.STRING, prop.type) self.assertEqual(['multi-word', 'message'], prop.value) prop = self._ConvertProp('notstring') - self.assertEqual(fdt.TYPE_BYTE, prop.type) + self.assertEqual(Type.BYTE, prop.type) val = [ord(val) for val in prop.value] self.assertEqual([0x20, 0x21, 0x22, 0x10, 0], val) def testGetEmpty(self): """Tests the GetEmpty() function for the various supported types""" - self.assertEqual(True, fdt.Prop.GetEmpty(fdt.TYPE_BOOL)) - self.assertEqual(chr(0), fdt.Prop.GetEmpty(fdt.TYPE_BYTE)) - self.assertEqual(tools.GetBytes(0, 4), fdt.Prop.GetEmpty(fdt.TYPE_INT)) - self.assertEqual('', fdt.Prop.GetEmpty(fdt.TYPE_STRING)) + self.assertEqual(True, fdt.Prop.GetEmpty(Type.BOOL)) + self.assertEqual(chr(0), fdt.Prop.GetEmpty(Type.BYTE)) + self.assertEqual(tools.GetBytes(0, 4), fdt.Prop.GetEmpty(Type.INT)) + self.assertEqual('', fdt.Prop.GetEmpty(Type.STRING)) def testGetOffset(self): """Test we can get the offset of a property""" @@ -304,13 +304,13 @@ class TestProp(unittest.TestCase): # No action prop2 = node2.props['intval'] prop.Widen(prop2) - self.assertEqual(fdt.TYPE_INT, prop.type) + self.assertEqual(Type.INT, prop.type) self.assertEqual(1, fdt32_to_cpu(prop.value)) # Convert singla value to array prop2 = self.node.props['intarray'] prop.Widen(prop2) - self.assertEqual(fdt.TYPE_INT, prop.type) + self.assertEqual(Type.INT, prop.type) self.assertTrue(isinstance(prop.value, list)) # A 4-byte array looks like a single integer. When widened by a longer |