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 | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame^] | 13 | import glob |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 14 | import os |
| 15 | import struct |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 16 | import tempfile |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 17 | import unittest |
| 18 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 19 | from dtb_platdata import conv_name_to_c |
| 20 | from dtb_platdata import get_compat_name |
| 21 | from dtb_platdata import get_value |
| 22 | from dtb_platdata import tab_to |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 23 | from dtoc import dtb_platdata |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 24 | from dtoc import fdt |
| 25 | from dtoc import fdt_util |
| 26 | from patman import test_util |
| 27 | from patman import tools |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 28 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 29 | OUR_PATH = os.path.dirname(os.path.realpath(__file__)) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 30 | |
| 31 | |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 32 | HEADER = '''/* |
| 33 | * DO NOT MODIFY |
| 34 | * |
| 35 | * This file was generated by dtoc from a .dtb (device tree binary) file. |
| 36 | */ |
| 37 | |
| 38 | #include <stdbool.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 39 | #include <linux/libfdt.h>''' |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 40 | |
| 41 | C_HEADER = '''/* |
| 42 | * DO NOT MODIFY |
| 43 | * |
| 44 | * This file was generated by dtoc from a .dtb (device tree binary) file. |
| 45 | */ |
| 46 | |
Simon Glass | 4c73d7b | 2020-10-03 11:31:41 -0600 | [diff] [blame] | 47 | /* Allow use of U_BOOT_DEVICE() in this file */ |
| 48 | #define DT_PLATDATA_C |
| 49 | |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 50 | #include <common.h> |
| 51 | #include <dm.h> |
| 52 | #include <dt-structs.h> |
| 53 | ''' |
| 54 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 55 | C_EMPTY_POPULATE_PHANDLE_DATA = '''void dm_populate_phandle_data(void) { |
| 56 | } |
| 57 | ''' |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 58 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 59 | # This is a test so is allowed to access private things in the module it is |
| 60 | # testing |
| 61 | # pylint: disable=W0212 |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 62 | |
| 63 | def get_dtb_file(dts_fname, capture_stderr=False): |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 64 | """Compile a .dts file to a .dtb |
| 65 | |
| 66 | Args: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 67 | dts_fname (str): Filename of .dts file in the current directory |
| 68 | capture_stderr (bool): True to capture and discard stderr output |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 69 | |
| 70 | Returns: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 71 | str: Filename of compiled file in output directory |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 72 | """ |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 73 | return fdt_util.EnsureCompiled(os.path.join(OUR_PATH, dts_fname), |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 74 | capture_stderr=capture_stderr) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 75 | |
| 76 | |
| 77 | class TestDtoc(unittest.TestCase): |
| 78 | """Tests for dtoc""" |
| 79 | @classmethod |
| 80 | def setUpClass(cls): |
| 81 | tools.PrepareOutputDir(None) |
Simon Glass | 7f5e226 | 2020-07-07 21:32:06 -0600 | [diff] [blame] | 82 | cls.maxDiff = None |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 83 | |
| 84 | @classmethod |
| 85 | def tearDownClass(cls): |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 86 | tools.FinaliseOutputDir() |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 87 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 88 | @staticmethod |
| 89 | def _write_python_string(fname, data): |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 90 | """Write a string with tabs expanded as done in this Python file |
| 91 | |
| 92 | Args: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 93 | fname (str): Filename to write to |
| 94 | data (str): Raw string to convert |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 95 | """ |
| 96 | data = data.replace('\t', '\\t') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 97 | with open(fname, 'w') as fout: |
| 98 | fout.write(data) |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 99 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 100 | def _check_strings(self, expected, actual): |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 101 | """Check that a string matches its expected value |
| 102 | |
| 103 | If the strings do not match, they are written to the /tmp directory in |
| 104 | the same Python format as is used here in the test. This allows for |
| 105 | easy comparison and update of the tests. |
| 106 | |
| 107 | Args: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 108 | expected (str): Expected string |
| 109 | actual (str): Actual string |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 110 | """ |
| 111 | if expected != actual: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 112 | self._write_python_string('/tmp/binman.expected', expected) |
| 113 | self._write_python_string('/tmp/binman.actual', actual) |
Simon Glass | 61b88e5 | 2019-05-17 22:00:31 -0600 | [diff] [blame] | 114 | print('Failures written to /tmp/binman.{expected,actual}') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 115 | self.assertEqual(expected, actual) |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 116 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 117 | @staticmethod |
| 118 | def run_test(args, dtb_file, output): |
| 119 | """Run a test using dtoc |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 120 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 121 | Args: |
| 122 | args (list of str): List of arguments for dtoc |
| 123 | dtb_file (str): Filename of .dtb file |
| 124 | output (str): Filename of output file |
| 125 | """ |
Simon Glass | 6a65d8a | 2020-12-28 20:34:50 -0700 | [diff] [blame] | 126 | dtb_platdata.run_steps(args, dtb_file, False, output, [], True) |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 127 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 128 | def test_name(self): |
| 129 | """Test conversion of device tree names to C identifiers""" |
| 130 | self.assertEqual('serial_at_0x12', conv_name_to_c('serial@0x12')) |
| 131 | self.assertEqual('vendor_clock_frequency', |
| 132 | conv_name_to_c('vendor,clock-frequency')) |
| 133 | self.assertEqual('rockchip_rk3399_sdhci_5_1', |
| 134 | conv_name_to_c('rockchip,rk3399-sdhci-5.1')) |
| 135 | |
| 136 | def test_tab_to(self): |
| 137 | """Test operation of tab_to() function""" |
| 138 | self.assertEqual('fred ', tab_to(0, 'fred')) |
| 139 | self.assertEqual('fred\t', tab_to(1, 'fred')) |
| 140 | self.assertEqual('fred was here ', tab_to(1, 'fred was here')) |
| 141 | self.assertEqual('fred was here\t\t', tab_to(3, 'fred was here')) |
| 142 | self.assertEqual('exactly8 ', tab_to(1, 'exactly8')) |
| 143 | self.assertEqual('exactly8\t', tab_to(2, 'exactly8')) |
| 144 | |
| 145 | def test_get_value(self): |
| 146 | """Test operation of get_value() function""" |
| 147 | self.assertEqual('0x45', |
Simon Glass | c9a032c | 2020-11-08 20:36:17 -0700 | [diff] [blame] | 148 | get_value(fdt.Type.INT, struct.pack('>I', 0x45))) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 149 | self.assertEqual('0x45', |
Simon Glass | c9a032c | 2020-11-08 20:36:17 -0700 | [diff] [blame] | 150 | get_value(fdt.Type.BYTE, struct.pack('<I', 0x45))) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 151 | self.assertEqual('0x0', |
Simon Glass | c9a032c | 2020-11-08 20:36:17 -0700 | [diff] [blame] | 152 | get_value(fdt.Type.BYTE, struct.pack('>I', 0x45))) |
| 153 | self.assertEqual('"test"', get_value(fdt.Type.STRING, 'test')) |
| 154 | self.assertEqual('true', get_value(fdt.Type.BOOL, None)) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 155 | |
| 156 | def test_get_compat_name(self): |
| 157 | """Test operation of get_compat_name() function""" |
| 158 | Prop = collections.namedtuple('Prop', ['value']) |
| 159 | Node = collections.namedtuple('Node', ['props']) |
| 160 | |
| 161 | prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1']) |
| 162 | node = Node({'compatible': prop}) |
Walter Lozano | 5fe734c | 2020-07-23 00:22:03 -0300 | [diff] [blame] | 163 | self.assertEqual((['rockchip_rk3399_sdhci_5_1', 'arasan_sdhci_5_1']), |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 164 | get_compat_name(node)) |
| 165 | |
| 166 | prop = Prop(['rockchip,rk3399-sdhci-5.1']) |
| 167 | node = Node({'compatible': prop}) |
Walter Lozano | 5fe734c | 2020-07-23 00:22:03 -0300 | [diff] [blame] | 168 | self.assertEqual((['rockchip_rk3399_sdhci_5_1']), |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 169 | get_compat_name(node)) |
| 170 | |
| 171 | prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1', 'third']) |
| 172 | node = Node({'compatible': prop}) |
Walter Lozano | 5fe734c | 2020-07-23 00:22:03 -0300 | [diff] [blame] | 173 | self.assertEqual((['rockchip_rk3399_sdhci_5_1', |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 174 | 'arasan_sdhci_5_1', 'third']), |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 175 | get_compat_name(node)) |
| 176 | |
| 177 | def test_empty_file(self): |
| 178 | """Test output from a device tree file with no nodes""" |
| 179 | dtb_file = get_dtb_file('dtoc_test_empty.dts') |
| 180 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 181 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 182 | with open(output) as infile: |
| 183 | lines = infile.read().splitlines() |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 184 | self.assertEqual(HEADER.splitlines(), lines) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 185 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 186 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 187 | with open(output) as infile: |
| 188 | lines = infile.read().splitlines() |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 189 | self.assertEqual(C_HEADER.splitlines() + [''] + |
| 190 | C_EMPTY_POPULATE_PHANDLE_DATA.splitlines(), lines) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 191 | |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 192 | struct_text = HEADER + ''' |
Simon Glass | 90e5f0a | 2017-08-29 14:15:51 -0600 | [diff] [blame] | 193 | struct dtd_sandbox_i2c_test { |
| 194 | }; |
| 195 | struct dtd_sandbox_pmic_test { |
| 196 | \tbool\t\tlow_power; |
| 197 | \tfdt64_t\t\treg[2]; |
| 198 | }; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 199 | struct dtd_sandbox_spl_test { |
Simon Glass | 7f5e226 | 2020-07-07 21:32:06 -0600 | [diff] [blame] | 200 | \tconst char * acpi_name; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 201 | \tbool\t\tboolval; |
| 202 | \tunsigned char\tbytearray[3]; |
| 203 | \tunsigned char\tbyteval; |
| 204 | \tfdt32_t\t\tintarray[4]; |
| 205 | \tfdt32_t\t\tintval; |
| 206 | \tunsigned char\tlongbytearray[9]; |
Simon Glass | 9c52633 | 2018-07-06 10:27:28 -0600 | [diff] [blame] | 207 | \tunsigned char\tnotstring[5]; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 208 | \tconst char *\tstringarray[3]; |
| 209 | \tconst char *\tstringval; |
| 210 | }; |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 211 | ''' |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 212 | |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 213 | platdata_text = C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 214 | /* Node /i2c@0 index 0 */ |
| 215 | static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = { |
| 216 | }; |
| 217 | U_BOOT_DEVICE(i2c_at_0) = { |
| 218 | \t.name\t\t= "sandbox_i2c_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 219 | \t.plat\t= &dtv_i2c_at_0, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 220 | \t.plat_size\t= sizeof(dtv_i2c_at_0), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 221 | \t.parent_idx\t= -1, |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 222 | }; |
| 223 | |
| 224 | /* Node /i2c@0/pmic@9 index 1 */ |
| 225 | static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = { |
| 226 | \t.low_power\t\t= true, |
| 227 | \t.reg\t\t\t= {0x9, 0x0}, |
| 228 | }; |
| 229 | U_BOOT_DEVICE(pmic_at_9) = { |
| 230 | \t.name\t\t= "sandbox_pmic_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 231 | \t.plat\t= &dtv_pmic_at_9, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 232 | \t.plat_size\t= sizeof(dtv_pmic_at_9), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 233 | \t.parent_idx\t= 0, |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | /* Node /spl-test index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 237 | static struct dtd_sandbox_spl_test dtv_spl_test = { |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 238 | \t.boolval\t\t= true, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 239 | \t.bytearray\t\t= {0x6, 0x0, 0x0}, |
| 240 | \t.byteval\t\t= 0x5, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 241 | \t.intarray\t\t= {0x2, 0x3, 0x4, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 242 | \t.intval\t\t\t= 0x1, |
Simon Glass | 131e0b0 | 2017-08-29 14:15:49 -0600 | [diff] [blame] | 243 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, |
| 244 | \t\t0x11}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 245 | \t.notstring\t\t= {0x20, 0x21, 0x22, 0x10, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 246 | \t.stringarray\t\t= {"multi-word", "message", ""}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 247 | \t.stringval\t\t= "message", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 248 | }; |
| 249 | U_BOOT_DEVICE(spl_test) = { |
| 250 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 251 | \t.plat\t= &dtv_spl_test, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 252 | \t.plat_size\t= sizeof(dtv_spl_test), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 253 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 254 | }; |
| 255 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 256 | /* Node /spl-test2 index 3 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 257 | static struct dtd_sandbox_spl_test dtv_spl_test2 = { |
Simon Glass | 7f5e226 | 2020-07-07 21:32:06 -0600 | [diff] [blame] | 258 | \t.acpi_name\t\t= "\\\\_SB.GPO0", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 259 | \t.bytearray\t\t= {0x1, 0x23, 0x34}, |
| 260 | \t.byteval\t\t= 0x8, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 261 | \t.intarray\t\t= {0x5, 0x0, 0x0, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 262 | \t.intval\t\t\t= 0x3, |
Simon Glass | 8034e4d | 2020-10-03 11:31:27 -0600 | [diff] [blame] | 263 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0x0, 0x0, 0x0, 0x0, |
Simon Glass | 131e0b0 | 2017-08-29 14:15:49 -0600 | [diff] [blame] | 264 | \t\t0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 265 | \t.stringarray\t\t= {"another", "multi-word", "message"}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 266 | \t.stringval\t\t= "message2", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 267 | }; |
| 268 | U_BOOT_DEVICE(spl_test2) = { |
| 269 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 270 | \t.plat\t= &dtv_spl_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 271 | \t.plat_size\t= sizeof(dtv_spl_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 272 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 273 | }; |
| 274 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 275 | /* Node /spl-test3 index 4 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 276 | static struct dtd_sandbox_spl_test dtv_spl_test3 = { |
Simon Glass | 8034e4d | 2020-10-03 11:31:27 -0600 | [diff] [blame] | 277 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, |
| 278 | \t\t0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 279 | \t.stringarray\t\t= {"one", "", ""}, |
| 280 | }; |
| 281 | U_BOOT_DEVICE(spl_test3) = { |
| 282 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 283 | \t.plat\t= &dtv_spl_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 284 | \t.plat_size\t= sizeof(dtv_spl_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 285 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 286 | }; |
| 287 | |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 288 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA |
| 289 | |
| 290 | def test_simple(self): |
| 291 | """Test output from some simple nodes with various types of data""" |
| 292 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 293 | output = tools.GetOutputFilename('output') |
| 294 | self.run_test(['struct'], dtb_file, output) |
| 295 | with open(output) as infile: |
| 296 | data = infile.read() |
| 297 | |
| 298 | self._check_strings(self.struct_text, data) |
| 299 | |
| 300 | self.run_test(['platdata'], dtb_file, output) |
| 301 | with open(output) as infile: |
| 302 | data = infile.read() |
| 303 | |
| 304 | self._check_strings(self.platdata_text, data) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 305 | |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame^] | 306 | # Try the 'all' command |
| 307 | self.run_test(['all'], dtb_file, output) |
| 308 | data = tools.ReadFile(output, binary=False) |
| 309 | self._check_strings(self.platdata_text + self.struct_text, data) |
| 310 | |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 311 | def test_driver_alias(self): |
| 312 | """Test output from a device tree file with a driver alias""" |
| 313 | dtb_file = get_dtb_file('dtoc_test_driver_alias.dts') |
| 314 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 315 | self.run_test(['struct'], dtb_file, output) |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 316 | with open(output) as infile: |
| 317 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 318 | self._check_strings(HEADER + ''' |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 319 | struct dtd_sandbox_gpio { |
| 320 | \tconst char *\tgpio_bank_name; |
| 321 | \tbool\t\tgpio_controller; |
| 322 | \tfdt32_t\t\tsandbox_gpio_count; |
| 323 | }; |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 324 | ''', data) |
| 325 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 326 | self.run_test(['platdata'], dtb_file, output) |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 327 | with open(output) as infile: |
| 328 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 329 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 330 | /* Node /gpios@0 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 331 | static struct dtd_sandbox_gpio dtv_gpios_at_0 = { |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 332 | \t.gpio_bank_name\t\t= "a", |
| 333 | \t.gpio_controller\t= true, |
| 334 | \t.sandbox_gpio_count\t= 0x14, |
| 335 | }; |
| 336 | U_BOOT_DEVICE(gpios_at_0) = { |
| 337 | \t.name\t\t= "sandbox_gpio", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 338 | \t.plat\t= &dtv_gpios_at_0, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 339 | \t.plat_size\t= sizeof(dtv_gpios_at_0), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 340 | \t.parent_idx\t= -1, |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 341 | }; |
| 342 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 343 | void dm_populate_phandle_data(void) { |
| 344 | } |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 345 | ''', data) |
| 346 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 347 | def test_invalid_driver(self): |
| 348 | """Test output from a device tree file with an invalid driver""" |
| 349 | dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts') |
| 350 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 351 | with test_util.capture_sys_output() as _: |
Simon Glass | 6a65d8a | 2020-12-28 20:34:50 -0700 | [diff] [blame] | 352 | dtb_platdata.run_steps(['struct'], dtb_file, False, output, []) |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 353 | with open(output) as infile: |
| 354 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 355 | self._check_strings(HEADER + ''' |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 356 | struct dtd_invalid { |
| 357 | }; |
| 358 | ''', data) |
| 359 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 360 | with test_util.capture_sys_output() as _: |
Simon Glass | 6a65d8a | 2020-12-28 20:34:50 -0700 | [diff] [blame] | 361 | dtb_platdata.run_steps(['platdata'], dtb_file, False, output, []) |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 362 | with open(output) as infile: |
| 363 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 364 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 365 | /* Node /spl-test index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 366 | static struct dtd_invalid dtv_spl_test = { |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 367 | }; |
| 368 | U_BOOT_DEVICE(spl_test) = { |
| 369 | \t.name\t\t= "invalid", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 370 | \t.plat\t= &dtv_spl_test, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 371 | \t.plat_size\t= sizeof(dtv_spl_test), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 372 | \t.parent_idx\t= -1, |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 373 | }; |
| 374 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 375 | void dm_populate_phandle_data(void) { |
| 376 | } |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 377 | ''', data) |
| 378 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 379 | def test_phandle(self): |
| 380 | """Test output from a node containing a phandle reference""" |
| 381 | dtb_file = get_dtb_file('dtoc_test_phandle.dts') |
| 382 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 383 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 384 | with open(output) as infile: |
| 385 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 386 | self._check_strings(HEADER + ''' |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 387 | struct dtd_source { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 388 | \tstruct phandle_2_arg clocks[4]; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 389 | }; |
| 390 | struct dtd_target { |
| 391 | \tfdt32_t\t\tintval; |
| 392 | }; |
| 393 | ''', data) |
| 394 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 395 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 396 | with open(output) as infile: |
| 397 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 398 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 399 | /* Node /phandle2-target index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 400 | static struct dtd_target dtv_phandle2_target = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 401 | \t.intval\t\t\t= 0x1, |
| 402 | }; |
| 403 | U_BOOT_DEVICE(phandle2_target) = { |
| 404 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 405 | \t.plat\t= &dtv_phandle2_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 406 | \t.plat_size\t= sizeof(dtv_phandle2_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 407 | \t.parent_idx\t= -1, |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 408 | }; |
| 409 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 410 | /* Node /phandle3-target index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 411 | static struct dtd_target dtv_phandle3_target = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 412 | \t.intval\t\t\t= 0x2, |
| 413 | }; |
| 414 | U_BOOT_DEVICE(phandle3_target) = { |
| 415 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 416 | \t.plat\t= &dtv_phandle3_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 417 | \t.plat_size\t= sizeof(dtv_phandle3_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 418 | \t.parent_idx\t= -1, |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 419 | }; |
| 420 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 421 | /* Node /phandle-target index 4 */ |
| 422 | static struct dtd_target dtv_phandle_target = { |
| 423 | \t.intval\t\t\t= 0x0, |
| 424 | }; |
| 425 | U_BOOT_DEVICE(phandle_target) = { |
| 426 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 427 | \t.plat\t= &dtv_phandle_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 428 | \t.plat_size\t= sizeof(dtv_phandle_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 429 | \t.parent_idx\t= -1, |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 430 | }; |
| 431 | |
| 432 | /* Node /phandle-source index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 433 | static struct dtd_source dtv_phandle_source = { |
Simon Glass | d0cd075 | 2017-08-29 14:15:57 -0600 | [diff] [blame] | 434 | \t.clocks\t\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 435 | \t\t\t{4, {}}, |
| 436 | \t\t\t{0, {11}}, |
| 437 | \t\t\t{1, {12, 13}}, |
| 438 | \t\t\t{4, {}},}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 439 | }; |
| 440 | U_BOOT_DEVICE(phandle_source) = { |
| 441 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 442 | \t.plat\t= &dtv_phandle_source, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 443 | \t.plat_size\t= sizeof(dtv_phandle_source), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 444 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 445 | }; |
| 446 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 447 | /* Node /phandle-source2 index 3 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 448 | static struct dtd_source dtv_phandle_source2 = { |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 449 | \t.clocks\t\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 450 | \t\t\t{4, {}},}, |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 451 | }; |
| 452 | U_BOOT_DEVICE(phandle_source2) = { |
| 453 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 454 | \t.plat\t= &dtv_phandle_source2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 455 | \t.plat_size\t= sizeof(dtv_phandle_source2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 456 | \t.parent_idx\t= -1, |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 457 | }; |
| 458 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 459 | void dm_populate_phandle_data(void) { |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 460 | } |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 461 | ''', data) |
| 462 | |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 463 | def test_phandle_single(self): |
| 464 | """Test output from a node containing a phandle reference""" |
| 465 | dtb_file = get_dtb_file('dtoc_test_phandle_single.dts') |
| 466 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 467 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 468 | with open(output) as infile: |
| 469 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 470 | self._check_strings(HEADER + ''' |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 471 | struct dtd_source { |
| 472 | \tstruct phandle_0_arg clocks[1]; |
| 473 | }; |
| 474 | struct dtd_target { |
| 475 | \tfdt32_t\t\tintval; |
| 476 | }; |
| 477 | ''', data) |
| 478 | |
| 479 | def test_phandle_reorder(self): |
| 480 | """Test that phandle targets are generated before their references""" |
| 481 | dtb_file = get_dtb_file('dtoc_test_phandle_reorder.dts') |
| 482 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 483 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 484 | with open(output) as infile: |
| 485 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 486 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 487 | /* Node /phandle-target index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 488 | static struct dtd_target dtv_phandle_target = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 489 | }; |
| 490 | U_BOOT_DEVICE(phandle_target) = { |
| 491 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 492 | \t.plat\t= &dtv_phandle_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 493 | \t.plat_size\t= sizeof(dtv_phandle_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 494 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 495 | }; |
| 496 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 497 | /* Node /phandle-source2 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 498 | static struct dtd_source dtv_phandle_source2 = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 499 | \t.clocks\t\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 500 | \t\t\t{1, {}},}, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 501 | }; |
| 502 | U_BOOT_DEVICE(phandle_source2) = { |
| 503 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 504 | \t.plat\t= &dtv_phandle_source2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 505 | \t.plat_size\t= sizeof(dtv_phandle_source2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 506 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 507 | }; |
| 508 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 509 | void dm_populate_phandle_data(void) { |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 510 | } |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 511 | ''', data) |
| 512 | |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 513 | def test_phandle_cd_gpio(self): |
| 514 | """Test that phandle targets are generated when unsing cd-gpios""" |
| 515 | dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts') |
| 516 | output = tools.GetOutputFilename('output') |
Simon Glass | 6a65d8a | 2020-12-28 20:34:50 -0700 | [diff] [blame] | 517 | dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [], True) |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 518 | with open(output) as infile: |
| 519 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 520 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 521 | /* Node /phandle2-target index 0 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 522 | static struct dtd_target dtv_phandle2_target = { |
| 523 | \t.intval\t\t\t= 0x1, |
| 524 | }; |
| 525 | U_BOOT_DEVICE(phandle2_target) = { |
| 526 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 527 | \t.plat\t= &dtv_phandle2_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 528 | \t.plat_size\t= sizeof(dtv_phandle2_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 529 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 530 | }; |
| 531 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 532 | /* Node /phandle3-target index 1 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 533 | static struct dtd_target dtv_phandle3_target = { |
| 534 | \t.intval\t\t\t= 0x2, |
| 535 | }; |
| 536 | U_BOOT_DEVICE(phandle3_target) = { |
| 537 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 538 | \t.plat\t= &dtv_phandle3_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 539 | \t.plat_size\t= sizeof(dtv_phandle3_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 540 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 541 | }; |
| 542 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 543 | /* Node /phandle-target index 4 */ |
| 544 | static struct dtd_target dtv_phandle_target = { |
| 545 | \t.intval\t\t\t= 0x0, |
| 546 | }; |
| 547 | U_BOOT_DEVICE(phandle_target) = { |
| 548 | \t.name\t\t= "target", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 549 | \t.plat\t= &dtv_phandle_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 550 | \t.plat_size\t= sizeof(dtv_phandle_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 551 | \t.parent_idx\t= -1, |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 552 | }; |
| 553 | |
| 554 | /* Node /phandle-source index 2 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 555 | static struct dtd_source dtv_phandle_source = { |
| 556 | \t.cd_gpios\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 557 | \t\t\t{4, {}}, |
| 558 | \t\t\t{0, {11}}, |
| 559 | \t\t\t{1, {12, 13}}, |
| 560 | \t\t\t{4, {}},}, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 561 | }; |
| 562 | U_BOOT_DEVICE(phandle_source) = { |
| 563 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 564 | \t.plat\t= &dtv_phandle_source, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 565 | \t.plat_size\t= sizeof(dtv_phandle_source), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 566 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 567 | }; |
| 568 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 569 | /* Node /phandle-source2 index 3 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 570 | static struct dtd_source dtv_phandle_source2 = { |
| 571 | \t.cd_gpios\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 572 | \t\t\t{4, {}},}, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 573 | }; |
| 574 | U_BOOT_DEVICE(phandle_source2) = { |
| 575 | \t.name\t\t= "source", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 576 | \t.plat\t= &dtv_phandle_source2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 577 | \t.plat_size\t= sizeof(dtv_phandle_source2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 578 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 579 | }; |
| 580 | |
| 581 | void dm_populate_phandle_data(void) { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 582 | } |
| 583 | ''', data) |
| 584 | |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 585 | def test_phandle_bad(self): |
| 586 | """Test a node containing an invalid phandle fails""" |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 587 | dtb_file = get_dtb_file('dtoc_test_phandle_bad.dts', |
| 588 | capture_stderr=True) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 589 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 590 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 591 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 592 | self.assertIn("Cannot parse 'clocks' in node 'phandle-source'", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 593 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 594 | |
| 595 | def test_phandle_bad2(self): |
| 596 | """Test a phandle target missing its #*-cells property""" |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 597 | dtb_file = get_dtb_file('dtoc_test_phandle_bad2.dts', |
| 598 | capture_stderr=True) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 599 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 600 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 601 | self.run_test(['struct'], dtb_file, output) |
Walter Lozano | 179f0b6 | 2020-06-25 01:10:16 -0300 | [diff] [blame] | 602 | self.assertIn("Node 'phandle-target' has no cells property", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 603 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 604 | |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 605 | def test_addresses64(self): |
| 606 | """Test output from a node with a 'reg' property with na=2, ns=2""" |
| 607 | dtb_file = get_dtb_file('dtoc_test_addr64.dts') |
| 608 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 609 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 610 | with open(output) as infile: |
| 611 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 612 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 613 | struct dtd_test1 { |
| 614 | \tfdt64_t\t\treg[2]; |
| 615 | }; |
| 616 | struct dtd_test2 { |
| 617 | \tfdt64_t\t\treg[2]; |
| 618 | }; |
| 619 | struct dtd_test3 { |
| 620 | \tfdt64_t\t\treg[4]; |
| 621 | }; |
| 622 | ''', data) |
| 623 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 624 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 625 | with open(output) as infile: |
| 626 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 627 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 628 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 629 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 630 | \t.reg\t\t\t= {0x1234, 0x5678}, |
| 631 | }; |
| 632 | U_BOOT_DEVICE(test1) = { |
| 633 | \t.name\t\t= "test1", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 634 | \t.plat\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 635 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 636 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 637 | }; |
| 638 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 639 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 640 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 641 | \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654}, |
| 642 | }; |
| 643 | U_BOOT_DEVICE(test2) = { |
| 644 | \t.name\t\t= "test2", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 645 | \t.plat\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 646 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 647 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 648 | }; |
| 649 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 650 | /* Node /test3 index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 651 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 652 | \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3}, |
| 653 | }; |
| 654 | U_BOOT_DEVICE(test3) = { |
| 655 | \t.name\t\t= "test3", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 656 | \t.plat\t= &dtv_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 657 | \t.plat_size\t= sizeof(dtv_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 658 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 659 | }; |
| 660 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 661 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 662 | |
| 663 | def test_addresses32(self): |
| 664 | """Test output from a node with a 'reg' property with na=1, ns=1""" |
| 665 | dtb_file = get_dtb_file('dtoc_test_addr32.dts') |
| 666 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 667 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 668 | with open(output) as infile: |
| 669 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 670 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 671 | struct dtd_test1 { |
| 672 | \tfdt32_t\t\treg[2]; |
| 673 | }; |
| 674 | struct dtd_test2 { |
| 675 | \tfdt32_t\t\treg[4]; |
| 676 | }; |
| 677 | ''', data) |
| 678 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 679 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 680 | with open(output) as infile: |
| 681 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 682 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 683 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 684 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 685 | \t.reg\t\t\t= {0x1234, 0x5678}, |
| 686 | }; |
| 687 | U_BOOT_DEVICE(test1) = { |
| 688 | \t.name\t\t= "test1", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 689 | \t.plat\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 690 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 691 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 692 | }; |
| 693 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 694 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 695 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 696 | \t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3}, |
| 697 | }; |
| 698 | U_BOOT_DEVICE(test2) = { |
| 699 | \t.name\t\t= "test2", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 700 | \t.plat\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 701 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 702 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 703 | }; |
| 704 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 705 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 706 | |
| 707 | def test_addresses64_32(self): |
| 708 | """Test output from a node with a 'reg' property with na=2, ns=1""" |
| 709 | dtb_file = get_dtb_file('dtoc_test_addr64_32.dts') |
| 710 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 711 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 712 | with open(output) as infile: |
| 713 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 714 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 715 | struct dtd_test1 { |
| 716 | \tfdt64_t\t\treg[2]; |
| 717 | }; |
| 718 | struct dtd_test2 { |
| 719 | \tfdt64_t\t\treg[2]; |
| 720 | }; |
| 721 | struct dtd_test3 { |
| 722 | \tfdt64_t\t\treg[4]; |
| 723 | }; |
| 724 | ''', data) |
| 725 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 726 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 727 | with open(output) as infile: |
| 728 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 729 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 730 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 731 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 732 | \t.reg\t\t\t= {0x123400000000, 0x5678}, |
| 733 | }; |
| 734 | U_BOOT_DEVICE(test1) = { |
| 735 | \t.name\t\t= "test1", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 736 | \t.plat\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 737 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 738 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 739 | }; |
| 740 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 741 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 742 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 743 | \t.reg\t\t\t= {0x1234567890123456, 0x98765432}, |
| 744 | }; |
| 745 | U_BOOT_DEVICE(test2) = { |
| 746 | \t.name\t\t= "test2", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 747 | \t.plat\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 748 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 749 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 750 | }; |
| 751 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 752 | /* Node /test3 index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 753 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 754 | \t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3}, |
| 755 | }; |
| 756 | U_BOOT_DEVICE(test3) = { |
| 757 | \t.name\t\t= "test3", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 758 | \t.plat\t= &dtv_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 759 | \t.plat_size\t= sizeof(dtv_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 760 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 761 | }; |
| 762 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 763 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 764 | |
| 765 | def test_addresses32_64(self): |
| 766 | """Test output from a node with a 'reg' property with na=1, ns=2""" |
| 767 | dtb_file = get_dtb_file('dtoc_test_addr32_64.dts') |
| 768 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 769 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 770 | with open(output) as infile: |
| 771 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 772 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 773 | struct dtd_test1 { |
| 774 | \tfdt64_t\t\treg[2]; |
| 775 | }; |
| 776 | struct dtd_test2 { |
| 777 | \tfdt64_t\t\treg[2]; |
| 778 | }; |
| 779 | struct dtd_test3 { |
| 780 | \tfdt64_t\t\treg[4]; |
| 781 | }; |
| 782 | ''', data) |
| 783 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 784 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 785 | with open(output) as infile: |
| 786 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 787 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 788 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 789 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 790 | \t.reg\t\t\t= {0x1234, 0x567800000000}, |
| 791 | }; |
| 792 | U_BOOT_DEVICE(test1) = { |
| 793 | \t.name\t\t= "test1", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 794 | \t.plat\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 795 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 796 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 797 | }; |
| 798 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 799 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 800 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 801 | \t.reg\t\t\t= {0x12345678, 0x9876543210987654}, |
| 802 | }; |
| 803 | U_BOOT_DEVICE(test2) = { |
| 804 | \t.name\t\t= "test2", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 805 | \t.plat\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 806 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 807 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 808 | }; |
| 809 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 810 | /* Node /test3 index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 811 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 812 | \t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3}, |
| 813 | }; |
| 814 | U_BOOT_DEVICE(test3) = { |
| 815 | \t.name\t\t= "test3", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 816 | \t.plat\t= &dtv_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 817 | \t.plat_size\t= sizeof(dtv_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 818 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 819 | }; |
| 820 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 821 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 822 | |
| 823 | def test_bad_reg(self): |
| 824 | """Test that a reg property with an invalid type generates an error""" |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 825 | # Capture stderr since dtc will emit warnings for this file |
| 826 | 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] | 827 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 828 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 829 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 830 | self.assertIn("Node 'spl-test' reg property is not an int", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 831 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 832 | |
| 833 | def test_bad_reg2(self): |
| 834 | """Test that a reg property with an invalid cell count is detected""" |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 835 | # Capture stderr since dtc will emit warnings for this file |
| 836 | 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] | 837 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 838 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 839 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 840 | self.assertIn( |
| 841 | "Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)", |
| 842 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 843 | |
| 844 | def test_add_prop(self): |
| 845 | """Test that a subequent node can add a new property to a struct""" |
| 846 | dtb_file = get_dtb_file('dtoc_test_add_prop.dts') |
| 847 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 848 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 849 | with open(output) as infile: |
| 850 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 851 | self._check_strings(HEADER + ''' |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 852 | struct dtd_sandbox_spl_test { |
| 853 | \tfdt32_t\t\tintarray; |
| 854 | \tfdt32_t\t\tintval; |
| 855 | }; |
| 856 | ''', data) |
| 857 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 858 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 859 | with open(output) as infile: |
| 860 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 861 | self._check_strings(C_HEADER + ''' |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 862 | /* Node /spl-test index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 863 | static struct dtd_sandbox_spl_test dtv_spl_test = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 864 | \t.intval\t\t\t= 0x1, |
| 865 | }; |
| 866 | U_BOOT_DEVICE(spl_test) = { |
| 867 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 868 | \t.plat\t= &dtv_spl_test, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 869 | \t.plat_size\t= sizeof(dtv_spl_test), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 870 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 871 | }; |
| 872 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 873 | /* Node /spl-test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 874 | static struct dtd_sandbox_spl_test dtv_spl_test2 = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 875 | \t.intarray\t\t= 0x5, |
| 876 | }; |
| 877 | U_BOOT_DEVICE(spl_test2) = { |
| 878 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 879 | \t.plat\t= &dtv_spl_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 880 | \t.plat_size\t= sizeof(dtv_spl_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 881 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 882 | }; |
| 883 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 884 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 885 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 886 | def test_stdout(self): |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 887 | """Test output to stdout""" |
| 888 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 889 | with test_util.capture_sys_output() as (stdout, _): |
Simon Glass | 6ca0c7a | 2020-12-28 20:34:48 -0700 | [diff] [blame] | 890 | self.run_test(['struct'], dtb_file, None) |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 891 | self._check_strings(self.struct_text, stdout.getvalue()) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 892 | |
Simon Glass | c3a310a8 | 2020-12-28 20:34:51 -0700 | [diff] [blame] | 893 | def test_multi_to_file(self): |
| 894 | """Test output of multiple pieces to a single file""" |
| 895 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 896 | output = tools.GetOutputFilename('output') |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame^] | 897 | self.run_test(['all'], dtb_file, output) |
Simon Glass | c3a310a8 | 2020-12-28 20:34:51 -0700 | [diff] [blame] | 898 | data = tools.ReadFile(output, binary=False) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame^] | 899 | self._check_strings(self.platdata_text + self.struct_text, data) |
Simon Glass | c3a310a8 | 2020-12-28 20:34:51 -0700 | [diff] [blame] | 900 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 901 | def test_no_command(self): |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 902 | """Test running dtoc without a command""" |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 903 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 904 | self.run_test([], '', '') |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 905 | self.assertIn("Please specify a command: struct, platdata", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 906 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 907 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 908 | def test_bad_command(self): |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 909 | """Test running dtoc with an invalid command""" |
| 910 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 911 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 912 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 913 | self.run_test(['invalid-cmd'], dtb_file, output) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame^] | 914 | self.assertIn("Unknown command 'invalid-cmd': (use: platdata, struct)", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 915 | str(exc.exception)) |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 916 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 917 | @staticmethod |
| 918 | def test_scan_drivers(): |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 919 | """Test running dtoc with additional drivers to scan""" |
| 920 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 921 | output = tools.GetOutputFilename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 922 | with test_util.capture_sys_output() as _: |
| 923 | dtb_platdata.run_steps( |
Simon Glass | 6a65d8a | 2020-12-28 20:34:50 -0700 | [diff] [blame] | 924 | ['struct'], dtb_file, False, output, [], True, |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 925 | [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx']) |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 926 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 927 | @staticmethod |
| 928 | def test_unicode_error(): |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 929 | """Test running dtoc with an invalid unicode file |
| 930 | |
| 931 | To be able to perform this test without adding a weird text file which |
| 932 | would produce issues when using checkpatch.pl or patman, generate the |
| 933 | file at runtime and then process it. |
| 934 | """ |
| 935 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 936 | output = tools.GetOutputFilename('output') |
| 937 | driver_fn = '/tmp/' + next(tempfile._get_candidate_names()) |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 938 | with open(driver_fn, 'wb+') as fout: |
| 939 | fout.write(b'\x81') |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 940 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 941 | with test_util.capture_sys_output() as _: |
Simon Glass | 6a65d8a | 2020-12-28 20:34:50 -0700 | [diff] [blame] | 942 | dtb_platdata.run_steps(['struct'], dtb_file, False, output, [], |
| 943 | True, [driver_fn]) |
Simon Glass | b42ed51 | 2020-12-23 08:11:23 -0700 | [diff] [blame] | 944 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 945 | def test_driver(self): |
Simon Glass | b42ed51 | 2020-12-23 08:11:23 -0700 | [diff] [blame] | 946 | """Test the Driver class""" |
| 947 | drv1 = dtb_platdata.Driver('fred') |
| 948 | drv2 = dtb_platdata.Driver('mary') |
| 949 | drv3 = dtb_platdata.Driver('fred') |
| 950 | self.assertEqual("Driver(name='fred')", str(drv1)) |
| 951 | self.assertEqual(drv1, drv3) |
| 952 | self.assertNotEqual(drv1, drv2) |
| 953 | self.assertNotEqual(drv2, drv3) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame^] | 954 | |
| 955 | def test_output_conflict(self): |
| 956 | """Test a conflict between and output dirs and output file""" |
| 957 | with self.assertRaises(ValueError) as exc: |
| 958 | dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], True) |
| 959 | self.assertIn("Must specify either output or output_dirs, not both", |
| 960 | str(exc.exception)) |
| 961 | |
| 962 | def test_output_dirs(self): |
| 963 | """Test outputting files to a directory""" |
| 964 | # Remove the directory so that files from other tests are not there |
| 965 | tools._RemoveOutputDir() |
| 966 | tools.PrepareOutputDir(None) |
| 967 | |
| 968 | # This should create the .dts and .dtb in the output directory |
| 969 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 970 | outdir = tools.GetOutputDir() |
| 971 | fnames = glob.glob(outdir + '/*') |
| 972 | self.assertEqual(2, len(fnames)) |
| 973 | |
| 974 | dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True) |
| 975 | fnames = glob.glob(outdir + '/*') |
| 976 | self.assertEqual(4, len(fnames)) |
| 977 | |
| 978 | leafs = set(os.path.basename(fname) for fname in fnames) |
| 979 | self.assertEqual( |
| 980 | {'dt-structs-gen.h', 'source.dts', 'dt-platdata.c', 'source.dtb'}, |
| 981 | leafs) |