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 |
| 13 | import os |
| 14 | import struct |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 15 | import sys |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 16 | import unittest |
| 17 | |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 18 | from dtoc import dtb_platdata |
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 | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 23 | from dtoc import fdt |
| 24 | from dtoc import fdt_util |
| 25 | from patman import test_util |
| 26 | from patman import tools |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 27 | |
| 28 | our_path = os.path.dirname(os.path.realpath(__file__)) |
| 29 | |
| 30 | |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 31 | HEADER = '''/* |
| 32 | * DO NOT MODIFY |
| 33 | * |
| 34 | * This file was generated by dtoc from a .dtb (device tree binary) file. |
| 35 | */ |
| 36 | |
| 37 | #include <stdbool.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 38 | #include <linux/libfdt.h>''' |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 39 | |
| 40 | C_HEADER = '''/* |
| 41 | * DO NOT MODIFY |
| 42 | * |
| 43 | * This file was generated by dtoc from a .dtb (device tree binary) file. |
| 44 | */ |
| 45 | |
| 46 | #include <common.h> |
| 47 | #include <dm.h> |
| 48 | #include <dt-structs.h> |
| 49 | ''' |
| 50 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 51 | C_EMPTY_POPULATE_PHANDLE_DATA = '''void dm_populate_phandle_data(void) { |
| 52 | } |
| 53 | ''' |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 54 | |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 55 | |
| 56 | def get_dtb_file(dts_fname, capture_stderr=False): |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 57 | """Compile a .dts file to a .dtb |
| 58 | |
| 59 | Args: |
| 60 | dts_fname: Filename of .dts file in the current directory |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 61 | capture_stderr: True to capture and discard stderr output |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 62 | |
| 63 | Returns: |
| 64 | Filename of compiled file in output directory |
| 65 | """ |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 66 | return fdt_util.EnsureCompiled(os.path.join(our_path, dts_fname), |
| 67 | capture_stderr=capture_stderr) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 68 | |
| 69 | |
| 70 | class TestDtoc(unittest.TestCase): |
| 71 | """Tests for dtoc""" |
| 72 | @classmethod |
| 73 | def setUpClass(cls): |
| 74 | tools.PrepareOutputDir(None) |
| 75 | |
| 76 | @classmethod |
| 77 | def tearDownClass(cls): |
| 78 | tools._RemoveOutputDir() |
| 79 | |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 80 | def _WritePythonString(self, fname, data): |
| 81 | """Write a string with tabs expanded as done in this Python file |
| 82 | |
| 83 | Args: |
| 84 | fname: Filename to write to |
| 85 | data: Raw string to convert |
| 86 | """ |
| 87 | data = data.replace('\t', '\\t') |
| 88 | with open(fname, 'w') as fd: |
| 89 | fd.write(data) |
| 90 | |
| 91 | def _CheckStrings(self, expected, actual): |
| 92 | """Check that a string matches its expected value |
| 93 | |
| 94 | If the strings do not match, they are written to the /tmp directory in |
| 95 | the same Python format as is used here in the test. This allows for |
| 96 | easy comparison and update of the tests. |
| 97 | |
| 98 | Args: |
| 99 | expected: Expected string |
| 100 | actual: Actual string |
| 101 | """ |
| 102 | if expected != actual: |
| 103 | self._WritePythonString('/tmp/binman.expected', expected) |
| 104 | self._WritePythonString('/tmp/binman.actual', actual) |
Simon Glass | 61b88e5 | 2019-05-17 22:00:31 -0600 | [diff] [blame] | 105 | print('Failures written to /tmp/binman.{expected,actual}') |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 106 | self.assertEquals(expected, actual) |
| 107 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 108 | |
| 109 | def run_test(self, args, dtb_file, output): |
| 110 | dtb_platdata.run_steps(args, dtb_file, False, output, True) |
| 111 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 112 | def test_name(self): |
| 113 | """Test conversion of device tree names to C identifiers""" |
| 114 | self.assertEqual('serial_at_0x12', conv_name_to_c('serial@0x12')) |
| 115 | self.assertEqual('vendor_clock_frequency', |
| 116 | conv_name_to_c('vendor,clock-frequency')) |
| 117 | self.assertEqual('rockchip_rk3399_sdhci_5_1', |
| 118 | conv_name_to_c('rockchip,rk3399-sdhci-5.1')) |
| 119 | |
| 120 | def test_tab_to(self): |
| 121 | """Test operation of tab_to() function""" |
| 122 | self.assertEqual('fred ', tab_to(0, 'fred')) |
| 123 | self.assertEqual('fred\t', tab_to(1, 'fred')) |
| 124 | self.assertEqual('fred was here ', tab_to(1, 'fred was here')) |
| 125 | self.assertEqual('fred was here\t\t', tab_to(3, 'fred was here')) |
| 126 | self.assertEqual('exactly8 ', tab_to(1, 'exactly8')) |
| 127 | self.assertEqual('exactly8\t', tab_to(2, 'exactly8')) |
| 128 | |
| 129 | def test_get_value(self): |
| 130 | """Test operation of get_value() function""" |
| 131 | self.assertEqual('0x45', |
| 132 | get_value(fdt.TYPE_INT, struct.pack('>I', 0x45))) |
| 133 | self.assertEqual('0x45', |
| 134 | get_value(fdt.TYPE_BYTE, struct.pack('<I', 0x45))) |
| 135 | self.assertEqual('0x0', |
| 136 | get_value(fdt.TYPE_BYTE, struct.pack('>I', 0x45))) |
| 137 | self.assertEqual('"test"', get_value(fdt.TYPE_STRING, 'test')) |
| 138 | self.assertEqual('true', get_value(fdt.TYPE_BOOL, None)) |
| 139 | |
| 140 | def test_get_compat_name(self): |
| 141 | """Test operation of get_compat_name() function""" |
| 142 | Prop = collections.namedtuple('Prop', ['value']) |
| 143 | Node = collections.namedtuple('Node', ['props']) |
| 144 | |
| 145 | prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1']) |
| 146 | node = Node({'compatible': prop}) |
| 147 | self.assertEqual(('rockchip_rk3399_sdhci_5_1', ['arasan_sdhci_5_1']), |
| 148 | get_compat_name(node)) |
| 149 | |
| 150 | prop = Prop(['rockchip,rk3399-sdhci-5.1']) |
| 151 | node = Node({'compatible': prop}) |
| 152 | self.assertEqual(('rockchip_rk3399_sdhci_5_1', []), |
| 153 | get_compat_name(node)) |
| 154 | |
| 155 | prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1', 'third']) |
| 156 | node = Node({'compatible': prop}) |
| 157 | self.assertEqual(('rockchip_rk3399_sdhci_5_1', |
| 158 | ['arasan_sdhci_5_1', 'third']), |
| 159 | get_compat_name(node)) |
| 160 | |
| 161 | def test_empty_file(self): |
| 162 | """Test output from a device tree file with no nodes""" |
| 163 | dtb_file = get_dtb_file('dtoc_test_empty.dts') |
| 164 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 165 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 166 | with open(output) as infile: |
| 167 | lines = infile.read().splitlines() |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 168 | self.assertEqual(HEADER.splitlines(), lines) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 169 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 170 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 171 | with open(output) as infile: |
| 172 | lines = infile.read().splitlines() |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 173 | self.assertEqual(C_HEADER.splitlines() + [''] + |
| 174 | C_EMPTY_POPULATE_PHANDLE_DATA.splitlines(), lines) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 175 | |
| 176 | def test_simple(self): |
| 177 | """Test output from some simple nodes with various types of data""" |
| 178 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 179 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 180 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 181 | with open(output) as infile: |
| 182 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 183 | self._CheckStrings(HEADER + ''' |
Simon Glass | 90e5f0a | 2017-08-29 14:15:51 -0600 | [diff] [blame] | 184 | struct dtd_sandbox_i2c_test { |
| 185 | }; |
| 186 | struct dtd_sandbox_pmic_test { |
| 187 | \tbool\t\tlow_power; |
| 188 | \tfdt64_t\t\treg[2]; |
| 189 | }; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 190 | struct dtd_sandbox_spl_test { |
| 191 | \tbool\t\tboolval; |
| 192 | \tunsigned char\tbytearray[3]; |
| 193 | \tunsigned char\tbyteval; |
| 194 | \tfdt32_t\t\tintarray[4]; |
| 195 | \tfdt32_t\t\tintval; |
| 196 | \tunsigned char\tlongbytearray[9]; |
Simon Glass | 9c52633 | 2018-07-06 10:27:28 -0600 | [diff] [blame] | 197 | \tunsigned char\tnotstring[5]; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 198 | \tconst char *\tstringarray[3]; |
| 199 | \tconst char *\tstringval; |
| 200 | }; |
| 201 | struct dtd_sandbox_spl_test_2 { |
| 202 | }; |
| 203 | ''', data) |
| 204 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 205 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 206 | with open(output) as infile: |
| 207 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 208 | self._CheckStrings(C_HEADER + ''' |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 209 | static struct dtd_sandbox_spl_test dtv_spl_test = { |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 210 | \t.boolval\t\t= true, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 211 | \t.bytearray\t\t= {0x6, 0x0, 0x0}, |
| 212 | \t.byteval\t\t= 0x5, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 213 | \t.intarray\t\t= {0x2, 0x3, 0x4, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 214 | \t.intval\t\t\t= 0x1, |
Simon Glass | 131e0b0 | 2017-08-29 14:15:49 -0600 | [diff] [blame] | 215 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, |
| 216 | \t\t0x11}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 217 | \t.notstring\t\t= {0x20, 0x21, 0x22, 0x10, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 218 | \t.stringarray\t\t= {"multi-word", "message", ""}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 219 | \t.stringval\t\t= "message", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 220 | }; |
| 221 | U_BOOT_DEVICE(spl_test) = { |
| 222 | \t.name\t\t= "sandbox_spl_test", |
| 223 | \t.platdata\t= &dtv_spl_test, |
| 224 | \t.platdata_size\t= sizeof(dtv_spl_test), |
| 225 | }; |
| 226 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 227 | static struct dtd_sandbox_spl_test dtv_spl_test2 = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 228 | \t.bytearray\t\t= {0x1, 0x23, 0x34}, |
| 229 | \t.byteval\t\t= 0x8, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 230 | \t.intarray\t\t= {0x5, 0x0, 0x0, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 231 | \t.intval\t\t\t= 0x3, |
Simon Glass | 131e0b0 | 2017-08-29 14:15:49 -0600 | [diff] [blame] | 232 | \t.longbytearray\t\t= {0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
| 233 | \t\t0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 234 | \t.stringarray\t\t= {"another", "multi-word", "message"}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 235 | \t.stringval\t\t= "message2", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 236 | }; |
| 237 | U_BOOT_DEVICE(spl_test2) = { |
| 238 | \t.name\t\t= "sandbox_spl_test", |
| 239 | \t.platdata\t= &dtv_spl_test2, |
| 240 | \t.platdata_size\t= sizeof(dtv_spl_test2), |
| 241 | }; |
| 242 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 243 | static struct dtd_sandbox_spl_test dtv_spl_test3 = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 244 | \t.stringarray\t\t= {"one", "", ""}, |
| 245 | }; |
| 246 | U_BOOT_DEVICE(spl_test3) = { |
| 247 | \t.name\t\t= "sandbox_spl_test", |
| 248 | \t.platdata\t= &dtv_spl_test3, |
| 249 | \t.platdata_size\t= sizeof(dtv_spl_test3), |
| 250 | }; |
| 251 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 252 | static struct dtd_sandbox_spl_test_2 dtv_spl_test4 = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 253 | }; |
| 254 | U_BOOT_DEVICE(spl_test4) = { |
| 255 | \t.name\t\t= "sandbox_spl_test_2", |
| 256 | \t.platdata\t= &dtv_spl_test4, |
| 257 | \t.platdata_size\t= sizeof(dtv_spl_test4), |
| 258 | }; |
| 259 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 260 | static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = { |
Simon Glass | 90e5f0a | 2017-08-29 14:15:51 -0600 | [diff] [blame] | 261 | }; |
| 262 | U_BOOT_DEVICE(i2c_at_0) = { |
| 263 | \t.name\t\t= "sandbox_i2c_test", |
| 264 | \t.platdata\t= &dtv_i2c_at_0, |
| 265 | \t.platdata_size\t= sizeof(dtv_i2c_at_0), |
| 266 | }; |
| 267 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 268 | static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = { |
Simon Glass | 90e5f0a | 2017-08-29 14:15:51 -0600 | [diff] [blame] | 269 | \t.low_power\t\t= true, |
| 270 | \t.reg\t\t\t= {0x9, 0x0}, |
| 271 | }; |
| 272 | U_BOOT_DEVICE(pmic_at_9) = { |
| 273 | \t.name\t\t= "sandbox_pmic_test", |
| 274 | \t.platdata\t= &dtv_pmic_at_9, |
| 275 | \t.platdata_size\t= sizeof(dtv_pmic_at_9), |
| 276 | }; |
| 277 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 278 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 279 | |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 280 | def test_driver_alias(self): |
| 281 | """Test output from a device tree file with a driver alias""" |
| 282 | dtb_file = get_dtb_file('dtoc_test_driver_alias.dts') |
| 283 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 284 | self.run_test(['struct'], dtb_file, output) |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 285 | with open(output) as infile: |
| 286 | data = infile.read() |
| 287 | self._CheckStrings(HEADER + ''' |
| 288 | struct dtd_sandbox_gpio { |
| 289 | \tconst char *\tgpio_bank_name; |
| 290 | \tbool\t\tgpio_controller; |
| 291 | \tfdt32_t\t\tsandbox_gpio_count; |
| 292 | }; |
| 293 | #define dtd_sandbox_gpio_alias dtd_sandbox_gpio |
| 294 | ''', data) |
| 295 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 296 | self.run_test(['platdata'], dtb_file, output) |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 297 | with open(output) as infile: |
| 298 | data = infile.read() |
| 299 | self._CheckStrings(C_HEADER + ''' |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 300 | static struct dtd_sandbox_gpio dtv_gpios_at_0 = { |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 301 | \t.gpio_bank_name\t\t= "a", |
| 302 | \t.gpio_controller\t= true, |
| 303 | \t.sandbox_gpio_count\t= 0x14, |
| 304 | }; |
| 305 | U_BOOT_DEVICE(gpios_at_0) = { |
| 306 | \t.name\t\t= "sandbox_gpio", |
| 307 | \t.platdata\t= &dtv_gpios_at_0, |
| 308 | \t.platdata_size\t= sizeof(dtv_gpios_at_0), |
| 309 | }; |
| 310 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 311 | void dm_populate_phandle_data(void) { |
| 312 | } |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 313 | ''', data) |
| 314 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 315 | def test_invalid_driver(self): |
| 316 | """Test output from a device tree file with an invalid driver""" |
| 317 | dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts') |
| 318 | output = tools.GetOutputFilename('output') |
| 319 | with test_util.capture_sys_output() as (stdout, stderr): |
| 320 | dtb_platdata.run_steps(['struct'], dtb_file, False, output) |
| 321 | with open(output) as infile: |
| 322 | data = infile.read() |
| 323 | self._CheckStrings(HEADER + ''' |
| 324 | struct dtd_invalid { |
| 325 | }; |
| 326 | ''', data) |
| 327 | |
| 328 | with test_util.capture_sys_output() as (stdout, stderr): |
| 329 | dtb_platdata.run_steps(['platdata'], dtb_file, False, output) |
| 330 | with open(output) as infile: |
| 331 | data = infile.read() |
| 332 | self._CheckStrings(C_HEADER + ''' |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 333 | static struct dtd_invalid dtv_spl_test = { |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 334 | }; |
| 335 | U_BOOT_DEVICE(spl_test) = { |
| 336 | \t.name\t\t= "invalid", |
| 337 | \t.platdata\t= &dtv_spl_test, |
| 338 | \t.platdata_size\t= sizeof(dtv_spl_test), |
| 339 | }; |
| 340 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 341 | void dm_populate_phandle_data(void) { |
| 342 | } |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 343 | ''', data) |
| 344 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 345 | def test_phandle(self): |
| 346 | """Test output from a node containing a phandle reference""" |
| 347 | dtb_file = get_dtb_file('dtoc_test_phandle.dts') |
| 348 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 349 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 350 | with open(output) as infile: |
| 351 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 352 | self._CheckStrings(HEADER + ''' |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 353 | struct dtd_source { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 354 | \tstruct phandle_2_arg clocks[4]; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 355 | }; |
| 356 | struct dtd_target { |
| 357 | \tfdt32_t\t\tintval; |
| 358 | }; |
| 359 | ''', data) |
| 360 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 361 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 362 | with open(output) as infile: |
| 363 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 364 | self._CheckStrings(C_HEADER + ''' |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 365 | static struct dtd_target dtv_phandle_target = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 366 | \t.intval\t\t\t= 0x0, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 367 | }; |
| 368 | U_BOOT_DEVICE(phandle_target) = { |
| 369 | \t.name\t\t= "target", |
| 370 | \t.platdata\t= &dtv_phandle_target, |
| 371 | \t.platdata_size\t= sizeof(dtv_phandle_target), |
| 372 | }; |
| 373 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 374 | static struct dtd_target dtv_phandle2_target = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 375 | \t.intval\t\t\t= 0x1, |
| 376 | }; |
| 377 | U_BOOT_DEVICE(phandle2_target) = { |
| 378 | \t.name\t\t= "target", |
| 379 | \t.platdata\t= &dtv_phandle2_target, |
| 380 | \t.platdata_size\t= sizeof(dtv_phandle2_target), |
| 381 | }; |
| 382 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 383 | static struct dtd_target dtv_phandle3_target = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 384 | \t.intval\t\t\t= 0x2, |
| 385 | }; |
| 386 | U_BOOT_DEVICE(phandle3_target) = { |
| 387 | \t.name\t\t= "target", |
| 388 | \t.platdata\t= &dtv_phandle3_target, |
| 389 | \t.platdata_size\t= sizeof(dtv_phandle3_target), |
| 390 | }; |
| 391 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 392 | static struct dtd_source dtv_phandle_source = { |
Simon Glass | d0cd075 | 2017-08-29 14:15:57 -0600 | [diff] [blame] | 393 | \t.clocks\t\t\t= { |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 394 | \t\t\t{NULL, {}}, |
| 395 | \t\t\t{NULL, {11}}, |
| 396 | \t\t\t{NULL, {12, 13}}, |
| 397 | \t\t\t{NULL, {}},}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 398 | }; |
| 399 | U_BOOT_DEVICE(phandle_source) = { |
| 400 | \t.name\t\t= "source", |
| 401 | \t.platdata\t= &dtv_phandle_source, |
| 402 | \t.platdata_size\t= sizeof(dtv_phandle_source), |
| 403 | }; |
| 404 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 405 | static struct dtd_source dtv_phandle_source2 = { |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 406 | \t.clocks\t\t\t= { |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 407 | \t\t\t{NULL, {}},}, |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 408 | }; |
| 409 | U_BOOT_DEVICE(phandle_source2) = { |
| 410 | \t.name\t\t= "source", |
| 411 | \t.platdata\t= &dtv_phandle_source2, |
| 412 | \t.platdata_size\t= sizeof(dtv_phandle_source2), |
| 413 | }; |
| 414 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 415 | void dm_populate_phandle_data(void) { |
| 416 | \tdtv_phandle_source.clocks[0].node = DM_GET_DEVICE(phandle_target); |
| 417 | \tdtv_phandle_source.clocks[1].node = DM_GET_DEVICE(phandle2_target); |
| 418 | \tdtv_phandle_source.clocks[2].node = DM_GET_DEVICE(phandle3_target); |
| 419 | \tdtv_phandle_source.clocks[3].node = DM_GET_DEVICE(phandle_target); |
| 420 | \tdtv_phandle_source2.clocks[0].node = DM_GET_DEVICE(phandle_target); |
| 421 | } |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 422 | ''', data) |
| 423 | |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 424 | def test_phandle_single(self): |
| 425 | """Test output from a node containing a phandle reference""" |
| 426 | dtb_file = get_dtb_file('dtoc_test_phandle_single.dts') |
| 427 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 428 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 429 | with open(output) as infile: |
| 430 | data = infile.read() |
| 431 | self._CheckStrings(HEADER + ''' |
| 432 | struct dtd_source { |
| 433 | \tstruct phandle_0_arg clocks[1]; |
| 434 | }; |
| 435 | struct dtd_target { |
| 436 | \tfdt32_t\t\tintval; |
| 437 | }; |
| 438 | ''', data) |
| 439 | |
| 440 | def test_phandle_reorder(self): |
| 441 | """Test that phandle targets are generated before their references""" |
| 442 | dtb_file = get_dtb_file('dtoc_test_phandle_reorder.dts') |
| 443 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 444 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 445 | with open(output) as infile: |
| 446 | data = infile.read() |
| 447 | self._CheckStrings(C_HEADER + ''' |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 448 | static struct dtd_target dtv_phandle_target = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 449 | }; |
| 450 | U_BOOT_DEVICE(phandle_target) = { |
| 451 | \t.name\t\t= "target", |
| 452 | \t.platdata\t= &dtv_phandle_target, |
| 453 | \t.platdata_size\t= sizeof(dtv_phandle_target), |
| 454 | }; |
| 455 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 456 | static struct dtd_source dtv_phandle_source2 = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 457 | \t.clocks\t\t\t= { |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 458 | \t\t\t{NULL, {}},}, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 459 | }; |
| 460 | U_BOOT_DEVICE(phandle_source2) = { |
| 461 | \t.name\t\t= "source", |
| 462 | \t.platdata\t= &dtv_phandle_source2, |
| 463 | \t.platdata_size\t= sizeof(dtv_phandle_source2), |
| 464 | }; |
| 465 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 466 | void dm_populate_phandle_data(void) { |
| 467 | \tdtv_phandle_source2.clocks[0].node = DM_GET_DEVICE(phandle_target); |
| 468 | } |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 469 | ''', data) |
| 470 | |
| 471 | def test_phandle_bad(self): |
| 472 | """Test a node containing an invalid phandle fails""" |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 473 | dtb_file = get_dtb_file('dtoc_test_phandle_bad.dts', |
| 474 | capture_stderr=True) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 475 | output = tools.GetOutputFilename('output') |
| 476 | with self.assertRaises(ValueError) as e: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 477 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 478 | self.assertIn("Cannot parse 'clocks' in node 'phandle-source'", |
| 479 | str(e.exception)) |
| 480 | |
| 481 | def test_phandle_bad2(self): |
| 482 | """Test a phandle target missing its #*-cells property""" |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 483 | dtb_file = get_dtb_file('dtoc_test_phandle_bad2.dts', |
| 484 | capture_stderr=True) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 485 | output = tools.GetOutputFilename('output') |
| 486 | with self.assertRaises(ValueError) as e: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 487 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 488 | self.assertIn("Node 'phandle-target' has no '#clock-cells' property", |
| 489 | str(e.exception)) |
| 490 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 491 | def test_aliases(self): |
| 492 | """Test output from a node with multiple compatible strings""" |
| 493 | dtb_file = get_dtb_file('dtoc_test_aliases.dts') |
| 494 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 495 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 496 | with open(output) as infile: |
| 497 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 498 | self._CheckStrings(HEADER + ''' |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 499 | struct dtd_compat1 { |
| 500 | \tfdt32_t\t\tintval; |
| 501 | }; |
| 502 | #define dtd_compat2_1_fred dtd_compat1 |
| 503 | #define dtd_compat3 dtd_compat1 |
| 504 | ''', data) |
| 505 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 506 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 507 | with open(output) as infile: |
| 508 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 509 | self._CheckStrings(C_HEADER + ''' |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 510 | static struct dtd_compat1 dtv_spl_test = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 511 | \t.intval\t\t\t= 0x1, |
| 512 | }; |
| 513 | U_BOOT_DEVICE(spl_test) = { |
| 514 | \t.name\t\t= "compat1", |
| 515 | \t.platdata\t= &dtv_spl_test, |
| 516 | \t.platdata_size\t= sizeof(dtv_spl_test), |
| 517 | }; |
| 518 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 519 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 520 | |
| 521 | def test_addresses64(self): |
| 522 | """Test output from a node with a 'reg' property with na=2, ns=2""" |
| 523 | dtb_file = get_dtb_file('dtoc_test_addr64.dts') |
| 524 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 525 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 526 | with open(output) as infile: |
| 527 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 528 | self._CheckStrings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 529 | struct dtd_test1 { |
| 530 | \tfdt64_t\t\treg[2]; |
| 531 | }; |
| 532 | struct dtd_test2 { |
| 533 | \tfdt64_t\t\treg[2]; |
| 534 | }; |
| 535 | struct dtd_test3 { |
| 536 | \tfdt64_t\t\treg[4]; |
| 537 | }; |
| 538 | ''', data) |
| 539 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 540 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 541 | with open(output) as infile: |
| 542 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 543 | self._CheckStrings(C_HEADER + ''' |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 544 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 545 | \t.reg\t\t\t= {0x1234, 0x5678}, |
| 546 | }; |
| 547 | U_BOOT_DEVICE(test1) = { |
| 548 | \t.name\t\t= "test1", |
| 549 | \t.platdata\t= &dtv_test1, |
| 550 | \t.platdata_size\t= sizeof(dtv_test1), |
| 551 | }; |
| 552 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 553 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 554 | \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654}, |
| 555 | }; |
| 556 | U_BOOT_DEVICE(test2) = { |
| 557 | \t.name\t\t= "test2", |
| 558 | \t.platdata\t= &dtv_test2, |
| 559 | \t.platdata_size\t= sizeof(dtv_test2), |
| 560 | }; |
| 561 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 562 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 563 | \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3}, |
| 564 | }; |
| 565 | U_BOOT_DEVICE(test3) = { |
| 566 | \t.name\t\t= "test3", |
| 567 | \t.platdata\t= &dtv_test3, |
| 568 | \t.platdata_size\t= sizeof(dtv_test3), |
| 569 | }; |
| 570 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 571 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 572 | |
| 573 | def test_addresses32(self): |
| 574 | """Test output from a node with a 'reg' property with na=1, ns=1""" |
| 575 | dtb_file = get_dtb_file('dtoc_test_addr32.dts') |
| 576 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 577 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 578 | with open(output) as infile: |
| 579 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 580 | self._CheckStrings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 581 | struct dtd_test1 { |
| 582 | \tfdt32_t\t\treg[2]; |
| 583 | }; |
| 584 | struct dtd_test2 { |
| 585 | \tfdt32_t\t\treg[4]; |
| 586 | }; |
| 587 | ''', data) |
| 588 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 589 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 590 | with open(output) as infile: |
| 591 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 592 | self._CheckStrings(C_HEADER + ''' |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 593 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 594 | \t.reg\t\t\t= {0x1234, 0x5678}, |
| 595 | }; |
| 596 | U_BOOT_DEVICE(test1) = { |
| 597 | \t.name\t\t= "test1", |
| 598 | \t.platdata\t= &dtv_test1, |
| 599 | \t.platdata_size\t= sizeof(dtv_test1), |
| 600 | }; |
| 601 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 602 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 603 | \t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3}, |
| 604 | }; |
| 605 | U_BOOT_DEVICE(test2) = { |
| 606 | \t.name\t\t= "test2", |
| 607 | \t.platdata\t= &dtv_test2, |
| 608 | \t.platdata_size\t= sizeof(dtv_test2), |
| 609 | }; |
| 610 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 611 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 612 | |
| 613 | def test_addresses64_32(self): |
| 614 | """Test output from a node with a 'reg' property with na=2, ns=1""" |
| 615 | dtb_file = get_dtb_file('dtoc_test_addr64_32.dts') |
| 616 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 617 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 618 | with open(output) as infile: |
| 619 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 620 | self._CheckStrings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 621 | struct dtd_test1 { |
| 622 | \tfdt64_t\t\treg[2]; |
| 623 | }; |
| 624 | struct dtd_test2 { |
| 625 | \tfdt64_t\t\treg[2]; |
| 626 | }; |
| 627 | struct dtd_test3 { |
| 628 | \tfdt64_t\t\treg[4]; |
| 629 | }; |
| 630 | ''', data) |
| 631 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 632 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 633 | with open(output) as infile: |
| 634 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 635 | self._CheckStrings(C_HEADER + ''' |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 636 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 637 | \t.reg\t\t\t= {0x123400000000, 0x5678}, |
| 638 | }; |
| 639 | U_BOOT_DEVICE(test1) = { |
| 640 | \t.name\t\t= "test1", |
| 641 | \t.platdata\t= &dtv_test1, |
| 642 | \t.platdata_size\t= sizeof(dtv_test1), |
| 643 | }; |
| 644 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 645 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 646 | \t.reg\t\t\t= {0x1234567890123456, 0x98765432}, |
| 647 | }; |
| 648 | U_BOOT_DEVICE(test2) = { |
| 649 | \t.name\t\t= "test2", |
| 650 | \t.platdata\t= &dtv_test2, |
| 651 | \t.platdata_size\t= sizeof(dtv_test2), |
| 652 | }; |
| 653 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 654 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 655 | \t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3}, |
| 656 | }; |
| 657 | U_BOOT_DEVICE(test3) = { |
| 658 | \t.name\t\t= "test3", |
| 659 | \t.platdata\t= &dtv_test3, |
| 660 | \t.platdata_size\t= sizeof(dtv_test3), |
| 661 | }; |
| 662 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 663 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 664 | |
| 665 | def test_addresses32_64(self): |
| 666 | """Test output from a node with a 'reg' property with na=1, ns=2""" |
| 667 | dtb_file = get_dtb_file('dtoc_test_addr32_64.dts') |
| 668 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 669 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 670 | with open(output) as infile: |
| 671 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 672 | self._CheckStrings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 673 | struct dtd_test1 { |
| 674 | \tfdt64_t\t\treg[2]; |
| 675 | }; |
| 676 | struct dtd_test2 { |
| 677 | \tfdt64_t\t\treg[2]; |
| 678 | }; |
| 679 | struct dtd_test3 { |
| 680 | \tfdt64_t\t\treg[4]; |
| 681 | }; |
| 682 | ''', data) |
| 683 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 684 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 685 | with open(output) as infile: |
| 686 | data = infile.read() |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 687 | self._CheckStrings(C_HEADER + ''' |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 688 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 689 | \t.reg\t\t\t= {0x1234, 0x567800000000}, |
| 690 | }; |
| 691 | U_BOOT_DEVICE(test1) = { |
| 692 | \t.name\t\t= "test1", |
| 693 | \t.platdata\t= &dtv_test1, |
| 694 | \t.platdata_size\t= sizeof(dtv_test1), |
| 695 | }; |
| 696 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 697 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 698 | \t.reg\t\t\t= {0x12345678, 0x9876543210987654}, |
| 699 | }; |
| 700 | U_BOOT_DEVICE(test2) = { |
| 701 | \t.name\t\t= "test2", |
| 702 | \t.platdata\t= &dtv_test2, |
| 703 | \t.platdata_size\t= sizeof(dtv_test2), |
| 704 | }; |
| 705 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 706 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 707 | \t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3}, |
| 708 | }; |
| 709 | U_BOOT_DEVICE(test3) = { |
| 710 | \t.name\t\t= "test3", |
| 711 | \t.platdata\t= &dtv_test3, |
| 712 | \t.platdata_size\t= sizeof(dtv_test3), |
| 713 | }; |
| 714 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 715 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 716 | |
| 717 | def test_bad_reg(self): |
| 718 | """Test that a reg property with an invalid type generates an error""" |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 719 | # Capture stderr since dtc will emit warnings for this file |
| 720 | 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] | 721 | output = tools.GetOutputFilename('output') |
| 722 | with self.assertRaises(ValueError) as e: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 723 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 724 | self.assertIn("Node 'spl-test' reg property is not an int", |
| 725 | str(e.exception)) |
| 726 | |
| 727 | def test_bad_reg2(self): |
| 728 | """Test that a reg property with an invalid cell count is detected""" |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 729 | # Capture stderr since dtc will emit warnings for this file |
| 730 | 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] | 731 | output = tools.GetOutputFilename('output') |
| 732 | with self.assertRaises(ValueError) as e: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 733 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 734 | self.assertIn("Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)", |
| 735 | str(e.exception)) |
| 736 | |
| 737 | def test_add_prop(self): |
| 738 | """Test that a subequent node can add a new property to a struct""" |
| 739 | dtb_file = get_dtb_file('dtoc_test_add_prop.dts') |
| 740 | output = tools.GetOutputFilename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 741 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 742 | with open(output) as infile: |
| 743 | data = infile.read() |
| 744 | self._CheckStrings(HEADER + ''' |
| 745 | struct dtd_sandbox_spl_test { |
| 746 | \tfdt32_t\t\tintarray; |
| 747 | \tfdt32_t\t\tintval; |
| 748 | }; |
| 749 | ''', data) |
| 750 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 751 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 752 | with open(output) as infile: |
| 753 | data = infile.read() |
| 754 | self._CheckStrings(C_HEADER + ''' |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 755 | static struct dtd_sandbox_spl_test dtv_spl_test = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 756 | \t.intval\t\t\t= 0x1, |
| 757 | }; |
| 758 | U_BOOT_DEVICE(spl_test) = { |
| 759 | \t.name\t\t= "sandbox_spl_test", |
| 760 | \t.platdata\t= &dtv_spl_test, |
| 761 | \t.platdata_size\t= sizeof(dtv_spl_test), |
| 762 | }; |
| 763 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 764 | static struct dtd_sandbox_spl_test dtv_spl_test2 = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 765 | \t.intarray\t\t= 0x5, |
| 766 | }; |
| 767 | U_BOOT_DEVICE(spl_test2) = { |
| 768 | \t.name\t\t= "sandbox_spl_test", |
| 769 | \t.platdata\t= &dtv_spl_test2, |
| 770 | \t.platdata_size\t= sizeof(dtv_spl_test2), |
| 771 | }; |
| 772 | |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 773 | ''' + C_EMPTY_POPULATE_PHANDLE_DATA, data) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 774 | |
| 775 | def testStdout(self): |
| 776 | """Test output to stdout""" |
| 777 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 778 | with test_util.capture_sys_output() as (stdout, stderr): |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 779 | self.run_test(['struct'], dtb_file, '-') |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 780 | |
| 781 | def testNoCommand(self): |
| 782 | """Test running dtoc without a command""" |
| 783 | with self.assertRaises(ValueError) as e: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 784 | self.run_test([], '', '') |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 785 | self.assertIn("Please specify a command: struct, platdata", |
| 786 | str(e.exception)) |
| 787 | |
| 788 | def testBadCommand(self): |
| 789 | """Test running dtoc with an invalid command""" |
| 790 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 791 | output = tools.GetOutputFilename('output') |
| 792 | with self.assertRaises(ValueError) as e: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 793 | self.run_test(['invalid-cmd'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 794 | self.assertIn("Unknown command 'invalid-cmd': (use: struct, platdata)", |
| 795 | str(e.exception)) |