Simon Glass | bfb0bb2 | 2019-10-31 07:42:55 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 3 | # Copyright (c) 2012 The Chromium OS Authors. |
| 4 | # |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 5 | |
| 6 | """Tests for the dtb_platdata module |
| 7 | |
Simon Glass | 70cd0d7 | 2018-07-06 10:27:20 -0600 | [diff] [blame] | 8 | This includes unit tests for some functions and functional tests for the dtoc |
| 9 | tool. |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 10 | """ |
| 11 | |
| 12 | import collections |
Simon Glass | 768ff0a | 2021-02-03 06:00:51 -0700 | [diff] [blame] | 13 | import copy |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 14 | import glob |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 15 | import os |
| 16 | import struct |
| 17 | import unittest |
| 18 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 19 | from dtb_platdata import get_value |
| 20 | from dtb_platdata import tab_to |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 21 | from dtoc import dtb_platdata |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 22 | from dtoc import fdt |
| 23 | from dtoc import fdt_util |
Simon Glass | 768ff0a | 2021-02-03 06:00:51 -0700 | [diff] [blame] | 24 | from dtoc import src_scan |
Simon Glass | 9065bc9 | 2020-12-28 20:35:06 -0700 | [diff] [blame] | 25 | from dtoc.src_scan import conv_name_to_c |
| 26 | from dtoc.src_scan import get_compat_name |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 27 | from patman import test_util |
| 28 | from patman import tools |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 29 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 30 | OUR_PATH = os.path.dirname(os.path.realpath(__file__)) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 31 | |
| 32 | |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 33 | HEADER = '''/* |
| 34 | * DO NOT MODIFY |
| 35 | * |
Simon Glass | 6b20884 | 2020-12-28 20:35:00 -0700 | [diff] [blame] | 36 | * Defines the structs used to hold devicetree data. |
| 37 | * This was generated by dtoc from a .dtb (device tree binary) file. |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 38 | */ |
| 39 | |
| 40 | #include <stdbool.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 41 | #include <linux/libfdt.h>''' |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 42 | |
| 43 | C_HEADER = '''/* |
| 44 | * DO NOT MODIFY |
| 45 | * |
Simon Glass | 6b20884 | 2020-12-28 20:35:00 -0700 | [diff] [blame] | 46 | * Declares the U_BOOT_DRIVER() records and platform data. |
| 47 | * This was generated by dtoc from a .dtb (device tree binary) file. |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 48 | */ |
| 49 | |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 50 | /* Allow use of U_BOOT_DRVINFO() in this file */ |
Simon Glass | beddd7a | 2020-12-28 20:35:01 -0700 | [diff] [blame] | 51 | #define DT_PLAT_C |
Simon Glass | 4c73d7b | 2020-10-03 11:31:41 -0600 | [diff] [blame] | 52 | |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 53 | #include <common.h> |
| 54 | #include <dm.h> |
| 55 | #include <dt-structs.h> |
| 56 | ''' |
| 57 | |
Simon Glass | 768ff0a | 2021-02-03 06:00:51 -0700 | [diff] [blame] | 58 | # Scanner saved from a previous run of the tests (to speed things up) |
| 59 | saved_scan = None |
| 60 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 61 | # This is a test so is allowed to access private things in the module it is |
| 62 | # testing |
| 63 | # pylint: disable=W0212 |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 64 | |
| 65 | def get_dtb_file(dts_fname, capture_stderr=False): |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 66 | """Compile a .dts file to a .dtb |
| 67 | |
| 68 | Args: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 69 | dts_fname (str): Filename of .dts file in the current directory |
| 70 | capture_stderr (bool): True to capture and discard stderr output |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 71 | |
| 72 | Returns: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 73 | str: Filename of compiled file in output directory |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 74 | """ |
Simon Glass | 4f4b240 | 2021-02-03 06:00:56 -0700 | [diff] [blame] | 75 | return fdt_util.EnsureCompiled(os.path.join(OUR_PATH, 'test', dts_fname), |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 76 | capture_stderr=capture_stderr) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 77 | |
Simon Glass | 768ff0a | 2021-02-03 06:00:51 -0700 | [diff] [blame] | 78 | |
| 79 | def setup(): |
| 80 | global saved_scan |
| 81 | |
| 82 | # Disable warnings so that calls to get_normalized_compat_name() will not |
| 83 | # output things. |
| 84 | saved_scan = src_scan.Scanner(None, True, False) |
| 85 | saved_scan.scan_drivers() |
| 86 | |
| 87 | def copy_scan(): |
| 88 | """Get a copy of saved_scan so that each test can start clean""" |
| 89 | return copy.deepcopy(saved_scan) |
| 90 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 91 | |
| 92 | class TestDtoc(unittest.TestCase): |
| 93 | """Tests for dtoc""" |
| 94 | @classmethod |
| 95 | def setUpClass(cls): |
| 96 | tools.PrepareOutputDir(None) |
Simon Glass | 7f5e226 | 2020-07-07 21:32:06 -0600 | [diff] [blame] | 97 | cls.maxDiff = None |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 98 | |
| 99 | @classmethod |
| 100 | def tearDownClass(cls): |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 101 | tools.FinaliseOutputDir() |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 102 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 103 | @staticmethod |
| 104 | def _write_python_string(fname, data): |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 105 | """Write a string with tabs expanded as done in this Python file |
| 106 | |
| 107 | Args: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 108 | fname (str): Filename to write to |
| 109 | data (str): Raw string to convert |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 110 | """ |
| 111 | data = data.replace('\t', '\\t') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 112 | with open(fname, 'w') as fout: |
| 113 | fout.write(data) |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 114 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 115 | def _check_strings(self, expected, actual): |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 116 | """Check that a string matches its expected value |
| 117 | |
| 118 | If the strings do not match, they are written to the /tmp directory in |
| 119 | the same Python format as is used here in the test. This allows for |
| 120 | easy comparison and update of the tests. |
| 121 | |
| 122 | Args: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 123 | expected (str): Expected string |
| 124 | actual (str): Actual string |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 125 | """ |
| 126 | if expected != actual: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 127 | self._write_python_string('/tmp/binman.expected', expected) |
| 128 | self._write_python_string('/tmp/binman.actual', actual) |
Simon Glass | 61b88e5 | 2019-05-17 22:00:31 -0600 | [diff] [blame] | 129 | print('Failures written to /tmp/binman.{expected,actual}') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 130 | self.assertEqual(expected, actual) |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 131 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 132 | @staticmethod |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame^] | 133 | def run_test(args, dtb_file, output, instantiate=False): |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 134 | """Run a test using dtoc |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 135 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 136 | Args: |
| 137 | args (list of str): List of arguments for dtoc |
| 138 | dtb_file (str): Filename of .dtb file |
| 139 | output (str): Filename of output file |
Simon Glass | be88d2f | 2021-02-03 06:01:07 -0700 | [diff] [blame] | 140 | |
| 141 | Returns: |
| 142 | DtbPlatdata object |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 143 | """ |
Simon Glass | 80d782c4 | 2021-02-03 06:01:10 -0700 | [diff] [blame] | 144 | # Make a copy of the 'scan' object, since it includes uclasses and |
| 145 | # drivers, which get updated during execution. |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame^] | 146 | return dtb_platdata.run_steps( |
| 147 | args, dtb_file, False, output, [], None, instantiate, |
| 148 | warning_disabled=True, scan=copy_scan()) |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 149 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 150 | def test_name(self): |
| 151 | """Test conversion of device tree names to C identifiers""" |
| 152 | self.assertEqual('serial_at_0x12', conv_name_to_c('serial@0x12')) |
| 153 | self.assertEqual('vendor_clock_frequency', |
| 154 | conv_name_to_c('vendor,clock-frequency')) |
| 155 | self.assertEqual('rockchip_rk3399_sdhci_5_1', |
| 156 | conv_name_to_c('rockchip,rk3399-sdhci-5.1')) |
| 157 | |
| 158 | def test_tab_to(self): |
| 159 | """Test operation of tab_to() function""" |
| 160 | self.assertEqual('fred ', tab_to(0, 'fred')) |
| 161 | self.assertEqual('fred\t', tab_to(1, 'fred')) |
| 162 | self.assertEqual('fred was here ', tab_to(1, 'fred was here')) |
| 163 | self.assertEqual('fred was here\t\t', tab_to(3, 'fred was here')) |
| 164 | self.assertEqual('exactly8 ', tab_to(1, 'exactly8')) |
| 165 | self.assertEqual('exactly8\t', tab_to(2, 'exactly8')) |
| 166 | |
| 167 | def test_get_value(self): |
| 168 | """Test operation of get_value() function""" |
| 169 | self.assertEqual('0x45', |
Simon Glass | c9a032c | 2020-11-08 20:36:17 -0700 | [diff] [blame] | 170 | get_value(fdt.Type.INT, struct.pack('>I', 0x45))) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 171 | self.assertEqual('0x45', |
Simon Glass | c9a032c | 2020-11-08 20:36:17 -0700 | [diff] [blame] | 172 | get_value(fdt.Type.BYTE, struct.pack('<I', 0x45))) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 173 | self.assertEqual('0x0', |
Simon Glass | c9a032c | 2020-11-08 20:36:17 -0700 | [diff] [blame] | 174 | get_value(fdt.Type.BYTE, struct.pack('>I', 0x45))) |
| 175 | self.assertEqual('"test"', get_value(fdt.Type.STRING, 'test')) |
| 176 | self.assertEqual('true', get_value(fdt.Type.BOOL, None)) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 177 | |
| 178 | def test_get_compat_name(self): |
| 179 | """Test operation of get_compat_name() function""" |
| 180 | Prop = collections.namedtuple('Prop', ['value']) |
| 181 | Node = collections.namedtuple('Node', ['props']) |
| 182 | |
| 183 | prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1']) |
| 184 | node = Node({'compatible': prop}) |
Walter Lozano | 5fe734c | 2020-07-23 00:22:03 -0300 | [diff] [blame] | 185 | self.assertEqual((['rockchip_rk3399_sdhci_5_1', 'arasan_sdhci_5_1']), |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 186 | get_compat_name(node)) |
| 187 | |
| 188 | prop = Prop(['rockchip,rk3399-sdhci-5.1']) |
| 189 | node = Node({'compatible': prop}) |
Walter Lozano | 5fe734c | 2020-07-23 00:22:03 -0300 | [diff] [blame] | 190 | self.assertEqual((['rockchip_rk3399_sdhci_5_1']), |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 191 | get_compat_name(node)) |
| 192 | |
| 193 | prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1', 'third']) |
| 194 | node = Node({'compatible': prop}) |
Walter Lozano | 5fe734c | 2020-07-23 00:22:03 -0300 | [diff] [blame] | 195 | self.assertEqual((['rockchip_rk3399_sdhci_5_1', |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 196 | 'arasan_sdhci_5_1', 'third']), |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 197 | get_compat_name(node)) |
| 198 | |
| 199 | def test_empty_file(self): |
| 200 | """Test output from a device tree file with no nodes""" |
| 201 | dtb_file = get_dtb_file('dtoc_test_empty.dts') |
| 202 | output = tools.GetOutputFilename('output') |
Simon Glass | 768ff0a | 2021-02-03 06:00:51 -0700 | [diff] [blame] | 203 | |
| 204 | # Run this one without saved_scan to complete test coverage |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame^] | 205 | dtb_platdata.run_steps(['struct'], dtb_file, False, output, [], None, |
| 206 | False) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 207 | with open(output) as infile: |
| 208 | lines = infile.read().splitlines() |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 209 | self.assertEqual(HEADER.splitlines(), lines) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 210 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 211 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 212 | with open(output) as infile: |
| 213 | lines = infile.read().splitlines() |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 214 | self.assertEqual(C_HEADER.splitlines() + [''], lines) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 215 | |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 216 | struct_text = HEADER + ''' |
Simon Glass | 32a8d22 | 2021-02-03 06:00:57 -0700 | [diff] [blame] | 217 | struct dtd_sandbox_i2c { |
Simon Glass | 90e5f0a | 2017-08-29 14:15:51 -0600 | [diff] [blame] | 218 | }; |
Simon Glass | 32a8d22 | 2021-02-03 06:00:57 -0700 | [diff] [blame] | 219 | struct dtd_sandbox_pmic { |
Simon Glass | 90e5f0a | 2017-08-29 14:15:51 -0600 | [diff] [blame] | 220 | \tbool\t\tlow_power; |
| 221 | \tfdt64_t\t\treg[2]; |
| 222 | }; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 223 | struct dtd_sandbox_spl_test { |
Simon Glass | 7f5e226 | 2020-07-07 21:32:06 -0600 | [diff] [blame] | 224 | \tconst char * acpi_name; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 225 | \tbool\t\tboolval; |
| 226 | \tunsigned char\tbytearray[3]; |
| 227 | \tunsigned char\tbyteval; |
| 228 | \tfdt32_t\t\tintarray[4]; |
| 229 | \tfdt32_t\t\tintval; |
| 230 | \tunsigned char\tlongbytearray[9]; |
Simon Glass | 9c52633 | 2018-07-06 10:27:28 -0600 | [diff] [blame] | 231 | \tunsigned char\tnotstring[5]; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 232 | \tconst char *\tstringarray[3]; |
| 233 | \tconst char *\tstringval; |
| 234 | }; |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 235 | ''' |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 236 | |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 237 | platdata_text = C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 238 | /* Node /i2c@0 index 0 */ |
Simon Glass | 32a8d22 | 2021-02-03 06:00:57 -0700 | [diff] [blame] | 239 | static struct dtd_sandbox_i2c dtv_i2c_at_0 = { |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 240 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 241 | U_BOOT_DRVINFO(i2c_at_0) = { |
Simon Glass | 32a8d22 | 2021-02-03 06:00:57 -0700 | [diff] [blame] | 242 | \t.name\t\t= "sandbox_i2c", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 243 | \t.plat\t= &dtv_i2c_at_0, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 244 | \t.plat_size\t= sizeof(dtv_i2c_at_0), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 245 | \t.parent_idx\t= -1, |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | /* Node /i2c@0/pmic@9 index 1 */ |
Simon Glass | 32a8d22 | 2021-02-03 06:00:57 -0700 | [diff] [blame] | 249 | static struct dtd_sandbox_pmic dtv_pmic_at_9 = { |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 250 | \t.low_power\t\t= true, |
| 251 | \t.reg\t\t\t= {0x9, 0x0}, |
| 252 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 253 | U_BOOT_DRVINFO(pmic_at_9) = { |
Simon Glass | 32a8d22 | 2021-02-03 06:00:57 -0700 | [diff] [blame] | 254 | \t.name\t\t= "sandbox_pmic", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 255 | \t.plat\t= &dtv_pmic_at_9, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 256 | \t.plat_size\t= sizeof(dtv_pmic_at_9), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 257 | \t.parent_idx\t= 0, |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 258 | }; |
| 259 | |
| 260 | /* Node /spl-test index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 261 | static struct dtd_sandbox_spl_test dtv_spl_test = { |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 262 | \t.boolval\t\t= true, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 263 | \t.bytearray\t\t= {0x6, 0x0, 0x0}, |
| 264 | \t.byteval\t\t= 0x5, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 265 | \t.intarray\t\t= {0x2, 0x3, 0x4, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 266 | \t.intval\t\t\t= 0x1, |
Simon Glass | 131e0b0 | 2017-08-29 14:15:49 -0600 | [diff] [blame] | 267 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, |
| 268 | \t\t0x11}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 269 | \t.notstring\t\t= {0x20, 0x21, 0x22, 0x10, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 270 | \t.stringarray\t\t= {"multi-word", "message", ""}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 271 | \t.stringval\t\t= "message", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 272 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 273 | U_BOOT_DRVINFO(spl_test) = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 274 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 275 | \t.plat\t= &dtv_spl_test, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 276 | \t.plat_size\t= sizeof(dtv_spl_test), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 277 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 278 | }; |
| 279 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 280 | /* Node /spl-test2 index 3 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 281 | static struct dtd_sandbox_spl_test dtv_spl_test2 = { |
Simon Glass | 7f5e226 | 2020-07-07 21:32:06 -0600 | [diff] [blame] | 282 | \t.acpi_name\t\t= "\\\\_SB.GPO0", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 283 | \t.bytearray\t\t= {0x1, 0x23, 0x34}, |
| 284 | \t.byteval\t\t= 0x8, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 285 | \t.intarray\t\t= {0x5, 0x0, 0x0, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 286 | \t.intval\t\t\t= 0x3, |
Simon Glass | 8034e4d | 2020-10-03 11:31:27 -0600 | [diff] [blame] | 287 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0x0, 0x0, 0x0, 0x0, |
Simon Glass | 131e0b0 | 2017-08-29 14:15:49 -0600 | [diff] [blame] | 288 | \t\t0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 289 | \t.stringarray\t\t= {"another", "multi-word", "message"}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 290 | \t.stringval\t\t= "message2", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 291 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 292 | U_BOOT_DRVINFO(spl_test2) = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 293 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 294 | \t.plat\t= &dtv_spl_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 295 | \t.plat_size\t= sizeof(dtv_spl_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 296 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 297 | }; |
| 298 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 299 | /* Node /spl-test3 index 4 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 300 | static struct dtd_sandbox_spl_test dtv_spl_test3 = { |
Simon Glass | 8034e4d | 2020-10-03 11:31:27 -0600 | [diff] [blame] | 301 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, |
| 302 | \t\t0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 303 | \t.stringarray\t\t= {"one", "", ""}, |
| 304 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 305 | U_BOOT_DRVINFO(spl_test3) = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 306 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 307 | \t.plat\t= &dtv_spl_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 308 | \t.plat_size\t= sizeof(dtv_spl_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 309 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 310 | }; |
| 311 | |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 312 | ''' |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 313 | |
| 314 | def test_simple(self): |
| 315 | """Test output from some simple nodes with various types of data""" |
| 316 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 317 | output = tools.GetOutputFilename('output') |
| 318 | self.run_test(['struct'], dtb_file, output) |
| 319 | with open(output) as infile: |
| 320 | data = infile.read() |
| 321 | |
| 322 | self._check_strings(self.struct_text, data) |
| 323 | |
| 324 | self.run_test(['platdata'], dtb_file, output) |
| 325 | with open(output) as infile: |
| 326 | data = infile.read() |
| 327 | |
| 328 | self._check_strings(self.platdata_text, data) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 329 | |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 330 | # Try the 'all' command |
| 331 | self.run_test(['all'], dtb_file, output) |
| 332 | data = tools.ReadFile(output, binary=False) |
| 333 | self._check_strings(self.platdata_text + self.struct_text, data) |
| 334 | |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 335 | def test_driver_alias(self): |
| 336 | """Test output from a device tree file with a driver alias""" |
| 337 | dtb_file = get_dtb_file('dtoc_test_driver_alias.dts') |
| 338 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 339 | self.run_test(['struct'], dtb_file, output) |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 340 | with open(output) as infile: |
| 341 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 342 | self._check_strings(HEADER + ''' |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 343 | struct dtd_sandbox_gpio { |
| 344 | \tconst char *\tgpio_bank_name; |
| 345 | \tbool\t\tgpio_controller; |
| 346 | \tfdt32_t\t\tsandbox_gpio_count; |
| 347 | }; |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 348 | ''', data) |
| 349 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 350 | self.run_test(['platdata'], dtb_file, output) |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 351 | with open(output) as infile: |
| 352 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 353 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 354 | /* Node /gpios@0 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 355 | static struct dtd_sandbox_gpio dtv_gpios_at_0 = { |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 356 | \t.gpio_bank_name\t\t= "a", |
| 357 | \t.gpio_controller\t= true, |
| 358 | \t.sandbox_gpio_count\t= 0x14, |
| 359 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 360 | U_BOOT_DRVINFO(gpios_at_0) = { |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 361 | \t.name\t\t= "sandbox_gpio", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 362 | \t.plat\t= &dtv_gpios_at_0, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 363 | \t.plat_size\t= sizeof(dtv_gpios_at_0), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 364 | \t.parent_idx\t= -1, |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 365 | }; |
| 366 | |
| 367 | ''', data) |
| 368 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 369 | def test_invalid_driver(self): |
| 370 | """Test output from a device tree file with an invalid driver""" |
| 371 | dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts') |
| 372 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 373 | with test_util.capture_sys_output() as _: |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame^] | 374 | dtb_platdata.run_steps( |
| 375 | ['struct'], dtb_file, False, output, [], None, False, |
| 376 | scan=copy_scan()) |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 377 | with open(output) as infile: |
| 378 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 379 | self._check_strings(HEADER + ''' |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 380 | struct dtd_invalid { |
| 381 | }; |
| 382 | ''', data) |
| 383 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 384 | with test_util.capture_sys_output() as _: |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame^] | 385 | dtb_platdata.run_steps( |
| 386 | ['platdata'], dtb_file, False, output, [], None, False, |
| 387 | scan=copy_scan()) |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 388 | with open(output) as infile: |
| 389 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 390 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 391 | /* Node /spl-test index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 392 | static struct dtd_invalid dtv_spl_test = { |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 393 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 394 | U_BOOT_DRVINFO(spl_test) = { |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 395 | \t.name\t\t= "invalid", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 396 | \t.plat\t= &dtv_spl_test, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 397 | \t.plat_size\t= sizeof(dtv_spl_test), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 398 | \t.parent_idx\t= -1, |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 399 | }; |
| 400 | |
| 401 | ''', data) |
| 402 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 403 | def test_phandle(self): |
| 404 | """Test output from a node containing a phandle reference""" |
| 405 | dtb_file = get_dtb_file('dtoc_test_phandle.dts') |
| 406 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 407 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 408 | with open(output) as infile: |
| 409 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 410 | self._check_strings(HEADER + ''' |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 411 | struct dtd_source { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 412 | \tstruct phandle_2_arg clocks[4]; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 413 | }; |
| 414 | struct dtd_target { |
| 415 | \tfdt32_t\t\tintval; |
| 416 | }; |
| 417 | ''', data) |
| 418 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 419 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 420 | with open(output) as infile: |
| 421 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 422 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 423 | /* Node /phandle2-target index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 424 | static struct dtd_target dtv_phandle2_target = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 425 | \t.intval\t\t\t= 0x1, |
| 426 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 427 | U_BOOT_DRVINFO(phandle2_target) = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 428 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 429 | \t.plat\t= &dtv_phandle2_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 430 | \t.plat_size\t= sizeof(dtv_phandle2_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 431 | \t.parent_idx\t= -1, |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 432 | }; |
| 433 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 434 | /* Node /phandle3-target index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 435 | static struct dtd_target dtv_phandle3_target = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 436 | \t.intval\t\t\t= 0x2, |
| 437 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 438 | U_BOOT_DRVINFO(phandle3_target) = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 439 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 440 | \t.plat\t= &dtv_phandle3_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 441 | \t.plat_size\t= sizeof(dtv_phandle3_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 442 | \t.parent_idx\t= -1, |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 443 | }; |
| 444 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 445 | /* Node /phandle-source index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 446 | static struct dtd_source dtv_phandle_source = { |
Simon Glass | d0cd075 | 2017-08-29 14:15:57 -0600 | [diff] [blame] | 447 | \t.clocks\t\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 448 | \t\t\t{4, {}}, |
| 449 | \t\t\t{0, {11}}, |
| 450 | \t\t\t{1, {12, 13}}, |
| 451 | \t\t\t{4, {}},}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 452 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 453 | U_BOOT_DRVINFO(phandle_source) = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 454 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 455 | \t.plat\t= &dtv_phandle_source, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 456 | \t.plat_size\t= sizeof(dtv_phandle_source), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 457 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 458 | }; |
| 459 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 460 | /* Node /phandle-source2 index 3 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 461 | static struct dtd_source dtv_phandle_source2 = { |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 462 | \t.clocks\t\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 463 | \t\t\t{4, {}},}, |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 464 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 465 | U_BOOT_DRVINFO(phandle_source2) = { |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 466 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 467 | \t.plat\t= &dtv_phandle_source2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 468 | \t.plat_size\t= sizeof(dtv_phandle_source2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 469 | \t.parent_idx\t= -1, |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 470 | }; |
| 471 | |
Simon Glass | 16382ce | 2020-12-28 20:35:04 -0700 | [diff] [blame] | 472 | /* Node /phandle-target index 4 */ |
| 473 | static struct dtd_target dtv_phandle_target = { |
| 474 | \t.intval\t\t\t= 0x0, |
| 475 | }; |
| 476 | U_BOOT_DRVINFO(phandle_target) = { |
| 477 | \t.name\t\t= "target", |
| 478 | \t.plat\t= &dtv_phandle_target, |
| 479 | \t.plat_size\t= sizeof(dtv_phandle_target), |
| 480 | \t.parent_idx\t= -1, |
| 481 | }; |
| 482 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 483 | ''', data) |
| 484 | |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 485 | def test_phandle_single(self): |
| 486 | """Test output from a node containing a phandle reference""" |
| 487 | dtb_file = get_dtb_file('dtoc_test_phandle_single.dts') |
| 488 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 489 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 490 | with open(output) as infile: |
| 491 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 492 | self._check_strings(HEADER + ''' |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 493 | struct dtd_source { |
| 494 | \tstruct phandle_0_arg clocks[1]; |
| 495 | }; |
| 496 | struct dtd_target { |
| 497 | \tfdt32_t\t\tintval; |
| 498 | }; |
| 499 | ''', data) |
| 500 | |
| 501 | def test_phandle_reorder(self): |
| 502 | """Test that phandle targets are generated before their references""" |
| 503 | dtb_file = get_dtb_file('dtoc_test_phandle_reorder.dts') |
| 504 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 505 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 506 | with open(output) as infile: |
| 507 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 508 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 509 | /* Node /phandle-source2 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 510 | static struct dtd_source dtv_phandle_source2 = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 511 | \t.clocks\t\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 512 | \t\t\t{1, {}},}, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 513 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 514 | U_BOOT_DRVINFO(phandle_source2) = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 515 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 516 | \t.plat\t= &dtv_phandle_source2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 517 | \t.plat_size\t= sizeof(dtv_phandle_source2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 518 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 519 | }; |
| 520 | |
Simon Glass | 16382ce | 2020-12-28 20:35:04 -0700 | [diff] [blame] | 521 | /* Node /phandle-target index 1 */ |
| 522 | static struct dtd_target dtv_phandle_target = { |
| 523 | }; |
| 524 | U_BOOT_DRVINFO(phandle_target) = { |
| 525 | \t.name\t\t= "target", |
| 526 | \t.plat\t= &dtv_phandle_target, |
| 527 | \t.plat_size\t= sizeof(dtv_phandle_target), |
| 528 | \t.parent_idx\t= -1, |
| 529 | }; |
| 530 | |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 531 | ''', data) |
| 532 | |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 533 | def test_phandle_cd_gpio(self): |
| 534 | """Test that phandle targets are generated when unsing cd-gpios""" |
| 535 | dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts') |
| 536 | output = tools.GetOutputFilename('output') |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame^] | 537 | dtb_platdata.run_steps( |
| 538 | ['platdata'], dtb_file, False, output, [], None, False, |
| 539 | warning_disabled=True, scan=copy_scan()) |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 540 | with open(output) as infile: |
| 541 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 542 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 543 | /* Node /phandle2-target index 0 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 544 | static struct dtd_target dtv_phandle2_target = { |
| 545 | \t.intval\t\t\t= 0x1, |
| 546 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 547 | U_BOOT_DRVINFO(phandle2_target) = { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 548 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 549 | \t.plat\t= &dtv_phandle2_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 550 | \t.plat_size\t= sizeof(dtv_phandle2_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 551 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 552 | }; |
| 553 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 554 | /* Node /phandle3-target index 1 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 555 | static struct dtd_target dtv_phandle3_target = { |
| 556 | \t.intval\t\t\t= 0x2, |
| 557 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 558 | U_BOOT_DRVINFO(phandle3_target) = { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 559 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 560 | \t.plat\t= &dtv_phandle3_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 561 | \t.plat_size\t= sizeof(dtv_phandle3_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 562 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 563 | }; |
| 564 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 565 | /* Node /phandle-source index 2 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 566 | static struct dtd_source dtv_phandle_source = { |
| 567 | \t.cd_gpios\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 568 | \t\t\t{4, {}}, |
| 569 | \t\t\t{0, {11}}, |
| 570 | \t\t\t{1, {12, 13}}, |
| 571 | \t\t\t{4, {}},}, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 572 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 573 | U_BOOT_DRVINFO(phandle_source) = { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 574 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 575 | \t.plat\t= &dtv_phandle_source, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 576 | \t.plat_size\t= sizeof(dtv_phandle_source), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 577 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 578 | }; |
| 579 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 580 | /* Node /phandle-source2 index 3 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 581 | static struct dtd_source dtv_phandle_source2 = { |
| 582 | \t.cd_gpios\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 583 | \t\t\t{4, {}},}, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 584 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 585 | U_BOOT_DRVINFO(phandle_source2) = { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 586 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 587 | \t.plat\t= &dtv_phandle_source2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 588 | \t.plat_size\t= sizeof(dtv_phandle_source2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 589 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 590 | }; |
| 591 | |
Simon Glass | 16382ce | 2020-12-28 20:35:04 -0700 | [diff] [blame] | 592 | /* Node /phandle-target index 4 */ |
| 593 | static struct dtd_target dtv_phandle_target = { |
| 594 | \t.intval\t\t\t= 0x0, |
| 595 | }; |
| 596 | U_BOOT_DRVINFO(phandle_target) = { |
| 597 | \t.name\t\t= "target", |
| 598 | \t.plat\t= &dtv_phandle_target, |
| 599 | \t.plat_size\t= sizeof(dtv_phandle_target), |
| 600 | \t.parent_idx\t= -1, |
| 601 | }; |
| 602 | |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 603 | ''', data) |
| 604 | |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 605 | def test_phandle_bad(self): |
| 606 | """Test a node containing an invalid phandle fails""" |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 607 | dtb_file = get_dtb_file('dtoc_test_phandle_bad.dts', |
| 608 | capture_stderr=True) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 609 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 610 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 611 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 612 | self.assertIn("Cannot parse 'clocks' in node 'phandle-source'", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 613 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 614 | |
| 615 | def test_phandle_bad2(self): |
| 616 | """Test a phandle target missing its #*-cells property""" |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 617 | dtb_file = get_dtb_file('dtoc_test_phandle_bad2.dts', |
| 618 | capture_stderr=True) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 619 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 620 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 621 | self.run_test(['struct'], dtb_file, output) |
Walter Lozano | 179f0b6 | 2020-06-25 01:10:16 -0300 | [diff] [blame] | 622 | self.assertIn("Node 'phandle-target' has no cells property", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 623 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 624 | |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 625 | def test_addresses64(self): |
| 626 | """Test output from a node with a 'reg' property with na=2, ns=2""" |
| 627 | dtb_file = get_dtb_file('dtoc_test_addr64.dts') |
| 628 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 629 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 630 | with open(output) as infile: |
| 631 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 632 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 633 | struct dtd_test1 { |
| 634 | \tfdt64_t\t\treg[2]; |
| 635 | }; |
| 636 | struct dtd_test2 { |
| 637 | \tfdt64_t\t\treg[2]; |
| 638 | }; |
| 639 | struct dtd_test3 { |
| 640 | \tfdt64_t\t\treg[4]; |
| 641 | }; |
| 642 | ''', data) |
| 643 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 644 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 645 | with open(output) as infile: |
| 646 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 647 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 648 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 649 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 650 | \t.reg\t\t\t= {0x1234, 0x5678}, |
| 651 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 652 | U_BOOT_DRVINFO(test1) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 653 | \t.name\t\t= "test1", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 654 | \t.plat\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 655 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 656 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 657 | }; |
| 658 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 659 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 660 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 661 | \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654}, |
| 662 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 663 | U_BOOT_DRVINFO(test2) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 664 | \t.name\t\t= "test2", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 665 | \t.plat\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 666 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 667 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 668 | }; |
| 669 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 670 | /* Node /test3 index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 671 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 672 | \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3}, |
| 673 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 674 | U_BOOT_DRVINFO(test3) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 675 | \t.name\t\t= "test3", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 676 | \t.plat\t= &dtv_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 677 | \t.plat_size\t= sizeof(dtv_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 678 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 679 | }; |
| 680 | |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 681 | ''', data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 682 | |
| 683 | def test_addresses32(self): |
| 684 | """Test output from a node with a 'reg' property with na=1, ns=1""" |
| 685 | dtb_file = get_dtb_file('dtoc_test_addr32.dts') |
| 686 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 687 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 688 | with open(output) as infile: |
| 689 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 690 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 691 | struct dtd_test1 { |
| 692 | \tfdt32_t\t\treg[2]; |
| 693 | }; |
| 694 | struct dtd_test2 { |
| 695 | \tfdt32_t\t\treg[4]; |
| 696 | }; |
| 697 | ''', data) |
| 698 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 699 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 700 | with open(output) as infile: |
| 701 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 702 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 703 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 704 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 705 | \t.reg\t\t\t= {0x1234, 0x5678}, |
| 706 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 707 | U_BOOT_DRVINFO(test1) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 708 | \t.name\t\t= "test1", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 709 | \t.plat\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 710 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 711 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 712 | }; |
| 713 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 714 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 715 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 716 | \t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3}, |
| 717 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 718 | U_BOOT_DRVINFO(test2) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 719 | \t.name\t\t= "test2", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 720 | \t.plat\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 721 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 722 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 723 | }; |
| 724 | |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 725 | ''', data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 726 | |
| 727 | def test_addresses64_32(self): |
| 728 | """Test output from a node with a 'reg' property with na=2, ns=1""" |
| 729 | dtb_file = get_dtb_file('dtoc_test_addr64_32.dts') |
| 730 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 731 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 732 | with open(output) as infile: |
| 733 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 734 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 735 | struct dtd_test1 { |
| 736 | \tfdt64_t\t\treg[2]; |
| 737 | }; |
| 738 | struct dtd_test2 { |
| 739 | \tfdt64_t\t\treg[2]; |
| 740 | }; |
| 741 | struct dtd_test3 { |
| 742 | \tfdt64_t\t\treg[4]; |
| 743 | }; |
| 744 | ''', data) |
| 745 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 746 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 747 | with open(output) as infile: |
| 748 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 749 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 750 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 751 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 752 | \t.reg\t\t\t= {0x123400000000, 0x5678}, |
| 753 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 754 | U_BOOT_DRVINFO(test1) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 755 | \t.name\t\t= "test1", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 756 | \t.plat\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 757 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 758 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 759 | }; |
| 760 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 761 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 762 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 763 | \t.reg\t\t\t= {0x1234567890123456, 0x98765432}, |
| 764 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 765 | U_BOOT_DRVINFO(test2) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 766 | \t.name\t\t= "test2", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 767 | \t.plat\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 768 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 769 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 770 | }; |
| 771 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 772 | /* Node /test3 index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 773 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 774 | \t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3}, |
| 775 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 776 | U_BOOT_DRVINFO(test3) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 777 | \t.name\t\t= "test3", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 778 | \t.plat\t= &dtv_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 779 | \t.plat_size\t= sizeof(dtv_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 780 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 781 | }; |
| 782 | |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 783 | ''', data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 784 | |
| 785 | def test_addresses32_64(self): |
| 786 | """Test output from a node with a 'reg' property with na=1, ns=2""" |
| 787 | dtb_file = get_dtb_file('dtoc_test_addr32_64.dts') |
| 788 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 789 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 790 | with open(output) as infile: |
| 791 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 792 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 793 | struct dtd_test1 { |
| 794 | \tfdt64_t\t\treg[2]; |
| 795 | }; |
| 796 | struct dtd_test2 { |
| 797 | \tfdt64_t\t\treg[2]; |
| 798 | }; |
| 799 | struct dtd_test3 { |
| 800 | \tfdt64_t\t\treg[4]; |
| 801 | }; |
| 802 | ''', data) |
| 803 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 804 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 805 | with open(output) as infile: |
| 806 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 807 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 808 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 809 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 810 | \t.reg\t\t\t= {0x1234, 0x567800000000}, |
| 811 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 812 | U_BOOT_DRVINFO(test1) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 813 | \t.name\t\t= "test1", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 814 | \t.plat\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 815 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 816 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 817 | }; |
| 818 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 819 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 820 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 821 | \t.reg\t\t\t= {0x12345678, 0x9876543210987654}, |
| 822 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 823 | U_BOOT_DRVINFO(test2) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 824 | \t.name\t\t= "test2", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 825 | \t.plat\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 826 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 827 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 828 | }; |
| 829 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 830 | /* Node /test3 index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 831 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 832 | \t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3}, |
| 833 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 834 | U_BOOT_DRVINFO(test3) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 835 | \t.name\t\t= "test3", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 836 | \t.plat\t= &dtv_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 837 | \t.plat_size\t= sizeof(dtv_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 838 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 839 | }; |
| 840 | |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 841 | ''', data) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 842 | |
| 843 | def test_bad_reg(self): |
| 844 | """Test that a reg property with an invalid type generates an error""" |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 845 | # Capture stderr since dtc will emit warnings for this file |
| 846 | dtb_file = get_dtb_file('dtoc_test_bad_reg.dts', capture_stderr=True) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 847 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 848 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 849 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 850 | self.assertIn("Node 'spl-test' reg property is not an int", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 851 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 852 | |
| 853 | def test_bad_reg2(self): |
| 854 | """Test that a reg property with an invalid cell count is detected""" |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 855 | # Capture stderr since dtc will emit warnings for this file |
| 856 | dtb_file = get_dtb_file('dtoc_test_bad_reg2.dts', capture_stderr=True) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 857 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 858 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 859 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 860 | self.assertIn( |
| 861 | "Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)", |
| 862 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 863 | |
| 864 | def test_add_prop(self): |
| 865 | """Test that a subequent node can add a new property to a struct""" |
| 866 | dtb_file = get_dtb_file('dtoc_test_add_prop.dts') |
| 867 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 868 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 869 | with open(output) as infile: |
| 870 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 871 | self._check_strings(HEADER + ''' |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 872 | struct dtd_sandbox_spl_test { |
| 873 | \tfdt32_t\t\tintarray; |
| 874 | \tfdt32_t\t\tintval; |
| 875 | }; |
| 876 | ''', data) |
| 877 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 878 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 879 | with open(output) as infile: |
| 880 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 881 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 882 | /* Node /spl-test index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 883 | static struct dtd_sandbox_spl_test dtv_spl_test = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 884 | \t.intval\t\t\t= 0x1, |
| 885 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 886 | U_BOOT_DRVINFO(spl_test) = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 887 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 888 | \t.plat\t= &dtv_spl_test, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 889 | \t.plat_size\t= sizeof(dtv_spl_test), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 890 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 891 | }; |
| 892 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 893 | /* Node /spl-test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 894 | static struct dtd_sandbox_spl_test dtv_spl_test2 = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 895 | \t.intarray\t\t= 0x5, |
| 896 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 897 | U_BOOT_DRVINFO(spl_test2) = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 898 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 899 | \t.plat\t= &dtv_spl_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 900 | \t.plat_size\t= sizeof(dtv_spl_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 901 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 902 | }; |
| 903 | |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 904 | ''', data) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 905 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 906 | def test_stdout(self): |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 907 | """Test output to stdout""" |
| 908 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 909 | with test_util.capture_sys_output() as (stdout, _): |
Simon Glass | 6ca0c7a | 2020-12-28 20:34:48 -0700 | [diff] [blame] | 910 | self.run_test(['struct'], dtb_file, None) |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 911 | self._check_strings(self.struct_text, stdout.getvalue()) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 912 | |
Simon Glass | c3a310a8 | 2020-12-28 20:34:51 -0700 | [diff] [blame] | 913 | def test_multi_to_file(self): |
| 914 | """Test output of multiple pieces to a single file""" |
| 915 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 916 | output = tools.GetOutputFilename('output') |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 917 | self.run_test(['all'], dtb_file, output) |
Simon Glass | c3a310a8 | 2020-12-28 20:34:51 -0700 | [diff] [blame] | 918 | data = tools.ReadFile(output, binary=False) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 919 | self._check_strings(self.platdata_text + self.struct_text, data) |
Simon Glass | c3a310a8 | 2020-12-28 20:34:51 -0700 | [diff] [blame] | 920 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 921 | def test_no_command(self): |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 922 | """Test running dtoc without a command""" |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 923 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 924 | self.run_test([], '', '') |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 925 | self.assertIn("Please specify a command: struct, platdata", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 926 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 927 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 928 | def test_bad_command(self): |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 929 | """Test running dtoc with an invalid command""" |
| 930 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 931 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 932 | with self.assertRaises(ValueError) as exc: |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame^] | 933 | self.run_test(['invalid-cmd'], dtb_file, output, False) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 934 | self.assertIn("Unknown command 'invalid-cmd': (use: platdata, struct)", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 935 | str(exc.exception)) |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 936 | |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 937 | def test_output_conflict(self): |
| 938 | """Test a conflict between and output dirs and output file""" |
| 939 | with self.assertRaises(ValueError) as exc: |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame^] | 940 | dtb_platdata.run_steps( |
| 941 | ['all'], None, False, 'out', ['cdir'], None, False, |
| 942 | warning_disabled=True, scan=copy_scan()) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 943 | self.assertIn("Must specify either output or output_dirs, not both", |
| 944 | str(exc.exception)) |
| 945 | |
| 946 | def test_output_dirs(self): |
| 947 | """Test outputting files to a directory""" |
| 948 | # Remove the directory so that files from other tests are not there |
| 949 | tools._RemoveOutputDir() |
| 950 | tools.PrepareOutputDir(None) |
| 951 | |
| 952 | # This should create the .dts and .dtb in the output directory |
| 953 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 954 | outdir = tools.GetOutputDir() |
| 955 | fnames = glob.glob(outdir + '/*') |
| 956 | self.assertEqual(2, len(fnames)) |
| 957 | |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame^] | 958 | dtb_platdata.run_steps( |
| 959 | ['all'], dtb_file, False, None, [outdir], None, False, |
| 960 | warning_disabled=True, scan=copy_scan()) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 961 | fnames = glob.glob(outdir + '/*') |
| 962 | self.assertEqual(4, len(fnames)) |
| 963 | |
| 964 | leafs = set(os.path.basename(fname) for fname in fnames) |
| 965 | self.assertEqual( |
Simon Glass | beddd7a | 2020-12-28 20:35:01 -0700 | [diff] [blame] | 966 | {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb'}, |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 967 | leafs) |
Simon Glass | 047a480 | 2021-02-03 06:01:00 -0700 | [diff] [blame] | 968 | |
| 969 | def setup_process_test(self): |
| 970 | """Set up a test of process_nodes() |
| 971 | |
| 972 | This uses saved_scan but returns a deep copy of it, so it is safe to |
| 973 | modify it in these tests |
| 974 | |
| 975 | Returns: |
| 976 | tuple: |
| 977 | DtbPlatdata: object to test |
| 978 | Scanner: scanner to use |
| 979 | """ |
| 980 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 981 | output = tools.GetOutputFilename('output') |
| 982 | |
| 983 | # Take a copy before messing with it |
Simon Glass | c14fd0c | 2021-02-03 06:01:11 -0700 | [diff] [blame] | 984 | scan = copy_scan() |
Simon Glass | 047a480 | 2021-02-03 06:01:00 -0700 | [diff] [blame] | 985 | plat = dtb_platdata.DtbPlatdata(scan, dtb_file, False) |
| 986 | plat.scan_dtb() |
Simon Glass | c14fd0c | 2021-02-03 06:01:11 -0700 | [diff] [blame] | 987 | plat.scan_tree(False) |
Simon Glass | 047a480 | 2021-02-03 06:01:00 -0700 | [diff] [blame] | 988 | plat.prepare_nodes() |
| 989 | return plat, scan |
| 990 | |
| 991 | def test_process_nodes(self): |
| 992 | """Test processing nodes to add various info""" |
| 993 | plat, scan = self.setup_process_test() |
| 994 | plat.process_nodes(True) |
| 995 | |
| 996 | i2c_node = plat._fdt.GetNode('/i2c@0') |
| 997 | pmic_node = plat._fdt.GetNode('/i2c@0/pmic@9') |
| 998 | pmic = scan._drivers['sandbox_pmic'] |
| 999 | i2c = scan._drivers['sandbox_i2c'] |
| 1000 | self.assertEqual('DM_DEVICE_REF(pmic_at_9)', pmic_node.dev_ref) |
| 1001 | self.assertEqual(pmic, pmic_node.driver) |
| 1002 | self.assertEqual(i2c_node, pmic_node.parent) |
| 1003 | self.assertEqual(i2c, pmic_node.parent_driver) |
| 1004 | |
| 1005 | # The pmic is the only child |
| 1006 | self.assertEqual(pmic_node.parent_seq, 0) |
| 1007 | self.assertEqual([pmic_node], i2c_node.child_devs) |
| 1008 | |
| 1009 | # Start and end of the list should be the child_head |
| 1010 | ref = '&DM_DEVICE_REF(i2c_at_0)->child_head' |
| 1011 | self.assertEqual( |
| 1012 | {-1: ref, 0: '&DM_DEVICE_REF(pmic_at_9)->sibling_node', 1: ref}, |
| 1013 | i2c_node.child_refs) |
| 1014 | |
| 1015 | def test_process_nodes_bad_parent(self): |
| 1016 | # Pretend that i2c has a parent (the pmic) and delete that driver |
| 1017 | plat, scan = self.setup_process_test() |
| 1018 | |
| 1019 | i2c_node = plat._fdt.GetNode('/i2c@0') |
| 1020 | pmic_node = plat._fdt.GetNode('/i2c@0/pmic@9') |
| 1021 | del scan._drivers['sandbox_pmic'] |
| 1022 | i2c_node.parent = pmic_node |
| 1023 | |
| 1024 | # Process twice, the second time to generate an exception |
| 1025 | plat.process_nodes(False) |
| 1026 | with self.assertRaises(ValueError) as exc: |
| 1027 | plat.process_nodes(True) |
| 1028 | self.assertIn( |
| 1029 | "Cannot parse/find parent driver 'sandbox_pmic' for 'sandbox_i2c", |
| 1030 | str(exc.exception)) |
| 1031 | |
| 1032 | def test_process_nodes_bad_node(self): |
| 1033 | plat, scan = self.setup_process_test() |
| 1034 | |
| 1035 | # Now remove the pmic driver |
| 1036 | del scan._drivers['sandbox_pmic'] |
| 1037 | |
| 1038 | # Process twice, the second time to generate an exception |
| 1039 | plat.process_nodes(False) |
| 1040 | with self.assertRaises(ValueError) as exc: |
| 1041 | plat.process_nodes(True) |
| 1042 | self.assertIn("Cannot parse/find driver for 'sandbox_pmic", |
| 1043 | str(exc.exception)) |
Simon Glass | eb3c249 | 2021-02-03 06:01:01 -0700 | [diff] [blame] | 1044 | |
Simon Glass | 80d782c4 | 2021-02-03 06:01:10 -0700 | [diff] [blame] | 1045 | def test_process_nodes_bad_uclass(self): |
| 1046 | plat, scan = self.setup_process_test() |
| 1047 | |
| 1048 | self.assertIn('UCLASS_I2C', scan._uclass) |
| 1049 | del scan._uclass['UCLASS_I2C'] |
| 1050 | with self.assertRaises(ValueError) as exc: |
| 1051 | plat.process_nodes(True) |
| 1052 | self.assertIn("Cannot parse/find uclass 'UCLASS_I2C' for driver 'sandbox_i2c'", |
| 1053 | str(exc.exception)) |
| 1054 | |
Simon Glass | eb3c249 | 2021-02-03 06:01:01 -0700 | [diff] [blame] | 1055 | def test_process_nodes_used(self): |
| 1056 | """Test processing nodes to add various info""" |
| 1057 | plat, scan = self.setup_process_test() |
| 1058 | plat.process_nodes(True) |
| 1059 | |
| 1060 | pmic = scan._drivers['sandbox_pmic'] |
| 1061 | self.assertTrue(pmic.used) |
| 1062 | |
| 1063 | gpio = scan._drivers['sandbox_gpio'] |
| 1064 | self.assertFalse(gpio.used) |
Simon Glass | be88d2f | 2021-02-03 06:01:07 -0700 | [diff] [blame] | 1065 | |
| 1066 | def test_alias_read(self): |
| 1067 | """Test obtaining aliases""" |
| 1068 | dtb_file = get_dtb_file('dtoc_test_inst.dts') |
| 1069 | output = tools.GetOutputFilename('output') |
| 1070 | plat = self.run_test(['struct'], dtb_file, output) |
| 1071 | |
| 1072 | scan = plat._scan |
| 1073 | testfdt_node = plat._fdt.GetNode('/some-bus/test') |
Simon Glass | 80d782c4 | 2021-02-03 06:01:10 -0700 | [diff] [blame] | 1074 | test0_node = plat._fdt.GetNode('/some-bus/test0') |
Simon Glass | be88d2f | 2021-02-03 06:01:07 -0700 | [diff] [blame] | 1075 | self.assertIn('UCLASS_TEST_FDT', scan._uclass) |
| 1076 | uc = scan._uclass['UCLASS_TEST_FDT'] |
Simon Glass | 80d782c4 | 2021-02-03 06:01:10 -0700 | [diff] [blame] | 1077 | self.assertEqual({1: testfdt_node, 2: test0_node}, |
| 1078 | uc.alias_num_to_node) |
| 1079 | self.assertEqual({'/some-bus/test': 1, '/some-bus/test0': 2}, |
| 1080 | uc.alias_path_to_num) |
Simon Glass | be88d2f | 2021-02-03 06:01:07 -0700 | [diff] [blame] | 1081 | |
| 1082 | # Try adding an alias that doesn't exist |
| 1083 | self.assertFalse(scan.add_uclass_alias('fred', 3, None)) |
| 1084 | |
| 1085 | # Try adding an alias for a missing node |
| 1086 | self.assertIsNone(scan.add_uclass_alias('testfdt', 3, None)) |
| 1087 | |
| 1088 | def test_alias_read_bad(self): |
| 1089 | """Test invalid alias property name""" |
| 1090 | dtb_file = get_dtb_file('dtoc_test_alias_bad.dts') |
| 1091 | output = tools.GetOutputFilename('output') |
| 1092 | with self.assertRaises(ValueError) as exc: |
| 1093 | plat = self.run_test(['struct'], dtb_file, output) |
| 1094 | self.assertIn("Cannot decode alias 'i2c4-'", str(exc.exception)) |
| 1095 | |
| 1096 | def test_alias_read_bad_path(self): |
| 1097 | """Test alias pointing to a non-existent node""" |
| 1098 | # This line may produce a warning, so capture it: |
| 1099 | # Warning (alias_paths): /aliases:i2c4: aliases property is not a valid |
| 1100 | # node (/does/not/exist) |
| 1101 | dtb_file = get_dtb_file('dtoc_test_alias_bad_path.dts', True) |
| 1102 | |
| 1103 | output = tools.GetOutputFilename('output') |
| 1104 | with self.assertRaises(ValueError) as exc: |
| 1105 | plat = self.run_test(['struct'], dtb_file, output) |
| 1106 | self.assertIn("Alias 'i2c4' path '/does/not/exist' not found", |
| 1107 | str(exc.exception)) |
| 1108 | |
| 1109 | def test_alias_read_bad_uclass(self): |
| 1110 | """Test alias for a uclass that doesn't exist""" |
| 1111 | dtb_file = get_dtb_file('dtoc_test_alias_bad_uc.dts') |
| 1112 | output = tools.GetOutputFilename('output') |
| 1113 | with test_util.capture_sys_output() as (stdout, _): |
| 1114 | plat = self.run_test(['struct'], dtb_file, output) |
| 1115 | self.assertEqual("Could not find uclass for alias 'other1'", |
| 1116 | stdout.getvalue().strip()) |
Simon Glass | df56e0b | 2021-02-03 06:01:09 -0700 | [diff] [blame] | 1117 | |
| 1118 | def test_sequence(self): |
| 1119 | """Test assignment of sequence numnbers""" |
| 1120 | dtb_file = get_dtb_file('dtoc_test_inst.dts') |
| 1121 | output = tools.GetOutputFilename('output') |
| 1122 | plat = self.run_test(['struct'], dtb_file, output) |
Simon Glass | 80d782c4 | 2021-02-03 06:01:10 -0700 | [diff] [blame] | 1123 | |
| 1124 | scan = plat._scan |
| 1125 | testfdt = plat._fdt.GetNode('/some-bus/test') |
| 1126 | self.assertEqual(1, testfdt.seq) |
| 1127 | i2c = plat._fdt.GetNode('/i2c') |
| 1128 | |
| 1129 | # For now this uclass is not compiled in, so no sequence is assigned |
| 1130 | self.assertEqual(4, i2c.seq) |
| 1131 | spl = plat._fdt.GetNode('/spl-test') |
| 1132 | self.assertEqual(0, spl.seq) |
Simon Glass | c14fd0c | 2021-02-03 06:01:11 -0700 | [diff] [blame] | 1133 | |
| 1134 | def test_process_root(self): |
| 1135 | """Test assignment of sequence numnbers""" |
| 1136 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 1137 | output = tools.GetOutputFilename('output') |
| 1138 | |
| 1139 | # Take a copy before messing with it |
| 1140 | scan = copy_scan() |
| 1141 | plat = dtb_platdata.DtbPlatdata(scan, dtb_file, False) |
| 1142 | plat.scan_dtb() |
| 1143 | root = plat._fdt.GetRoot() |
| 1144 | |
| 1145 | plat.scan_tree(False) |
| 1146 | self.assertNotIn(root, plat._valid_nodes) |
| 1147 | |
| 1148 | plat.scan_tree(True) |
| 1149 | self.assertIn(root, plat._valid_nodes) |
| 1150 | self.assertEqual('root_driver', |
| 1151 | scan.get_normalized_compat_name(root)[0]) |