Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium OS Authors. |
| 3 | # |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 4 | |
| 5 | """Tests for the dtb_platdata module |
| 6 | |
Simon Glass | 3def0cf | 2018-07-06 10:27:20 -0600 | [diff] [blame] | 7 | This includes unit tests for some functions and functional tests for the dtoc |
| 8 | tool. |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 9 | """ |
| 10 | |
| 11 | import collections |
| 12 | import os |
| 13 | import struct |
| 14 | import unittest |
| 15 | |
| 16 | import dtb_platdata |
| 17 | from dtb_platdata import conv_name_to_c |
| 18 | from dtb_platdata import get_compat_name |
| 19 | from dtb_platdata import get_value |
| 20 | from dtb_platdata import tab_to |
| 21 | import fdt |
| 22 | import fdt_util |
| 23 | import tools |
| 24 | |
| 25 | our_path = os.path.dirname(os.path.realpath(__file__)) |
| 26 | |
| 27 | |
Simon Glass | aab660f | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 28 | HEADER = '''/* |
| 29 | * DO NOT MODIFY |
| 30 | * |
| 31 | * This file was generated by dtoc from a .dtb (device tree binary) file. |
| 32 | */ |
| 33 | |
| 34 | #include <stdbool.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 35 | #include <linux/libfdt.h>''' |
Simon Glass | aab660f | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 36 | |
| 37 | C_HEADER = '''/* |
| 38 | * DO NOT MODIFY |
| 39 | * |
| 40 | * This file was generated by dtoc from a .dtb (device tree binary) file. |
| 41 | */ |
| 42 | |
| 43 | #include <common.h> |
| 44 | #include <dm.h> |
| 45 | #include <dt-structs.h> |
| 46 | ''' |
| 47 | |
| 48 | |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 49 | def get_dtb_file(dts_fname): |
| 50 | """Compile a .dts file to a .dtb |
| 51 | |
| 52 | Args: |
| 53 | dts_fname: Filename of .dts file in the current directory |
| 54 | |
| 55 | Returns: |
| 56 | Filename of compiled file in output directory |
| 57 | """ |
| 58 | return fdt_util.EnsureCompiled(os.path.join(our_path, dts_fname)) |
| 59 | |
| 60 | |
| 61 | class TestDtoc(unittest.TestCase): |
| 62 | """Tests for dtoc""" |
| 63 | @classmethod |
| 64 | def setUpClass(cls): |
| 65 | tools.PrepareOutputDir(None) |
| 66 | |
| 67 | @classmethod |
| 68 | def tearDownClass(cls): |
| 69 | tools._RemoveOutputDir() |
| 70 | |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 71 | def _WritePythonString(self, fname, data): |
| 72 | """Write a string with tabs expanded as done in this Python file |
| 73 | |
| 74 | Args: |
| 75 | fname: Filename to write to |
| 76 | data: Raw string to convert |
| 77 | """ |
| 78 | data = data.replace('\t', '\\t') |
| 79 | with open(fname, 'w') as fd: |
| 80 | fd.write(data) |
| 81 | |
| 82 | def _CheckStrings(self, expected, actual): |
| 83 | """Check that a string matches its expected value |
| 84 | |
| 85 | If the strings do not match, they are written to the /tmp directory in |
| 86 | the same Python format as is used here in the test. This allows for |
| 87 | easy comparison and update of the tests. |
| 88 | |
| 89 | Args: |
| 90 | expected: Expected string |
| 91 | actual: Actual string |
| 92 | """ |
| 93 | if expected != actual: |
| 94 | self._WritePythonString('/tmp/binman.expected', expected) |
| 95 | self._WritePythonString('/tmp/binman.actual', actual) |
| 96 | print 'Failures written to /tmp/binman.{expected,actual}' |
| 97 | self.assertEquals(expected, actual) |
| 98 | |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 99 | def test_name(self): |
| 100 | """Test conversion of device tree names to C identifiers""" |
| 101 | self.assertEqual('serial_at_0x12', conv_name_to_c('serial@0x12')) |
| 102 | self.assertEqual('vendor_clock_frequency', |
| 103 | conv_name_to_c('vendor,clock-frequency')) |
| 104 | self.assertEqual('rockchip_rk3399_sdhci_5_1', |
| 105 | conv_name_to_c('rockchip,rk3399-sdhci-5.1')) |
| 106 | |
| 107 | def test_tab_to(self): |
| 108 | """Test operation of tab_to() function""" |
| 109 | self.assertEqual('fred ', tab_to(0, 'fred')) |
| 110 | self.assertEqual('fred\t', tab_to(1, 'fred')) |
| 111 | self.assertEqual('fred was here ', tab_to(1, 'fred was here')) |
| 112 | self.assertEqual('fred was here\t\t', tab_to(3, 'fred was here')) |
| 113 | self.assertEqual('exactly8 ', tab_to(1, 'exactly8')) |
| 114 | self.assertEqual('exactly8\t', tab_to(2, 'exactly8')) |
| 115 | |
| 116 | def test_get_value(self): |
| 117 | """Test operation of get_value() function""" |
| 118 | self.assertEqual('0x45', |
| 119 | get_value(fdt.TYPE_INT, struct.pack('>I', 0x45))) |
| 120 | self.assertEqual('0x45', |
| 121 | get_value(fdt.TYPE_BYTE, struct.pack('<I', 0x45))) |
| 122 | self.assertEqual('0x0', |
| 123 | get_value(fdt.TYPE_BYTE, struct.pack('>I', 0x45))) |
| 124 | self.assertEqual('"test"', get_value(fdt.TYPE_STRING, 'test')) |
| 125 | self.assertEqual('true', get_value(fdt.TYPE_BOOL, None)) |
| 126 | |
| 127 | def test_get_compat_name(self): |
| 128 | """Test operation of get_compat_name() function""" |
| 129 | Prop = collections.namedtuple('Prop', ['value']) |
| 130 | Node = collections.namedtuple('Node', ['props']) |
| 131 | |
| 132 | prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1']) |
| 133 | node = Node({'compatible': prop}) |
| 134 | self.assertEqual(('rockchip_rk3399_sdhci_5_1', ['arasan_sdhci_5_1']), |
| 135 | get_compat_name(node)) |
| 136 | |
| 137 | prop = Prop(['rockchip,rk3399-sdhci-5.1']) |
| 138 | node = Node({'compatible': prop}) |
| 139 | self.assertEqual(('rockchip_rk3399_sdhci_5_1', []), |
| 140 | get_compat_name(node)) |
| 141 | |
| 142 | prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1', 'third']) |
| 143 | node = Node({'compatible': prop}) |
| 144 | self.assertEqual(('rockchip_rk3399_sdhci_5_1', |
| 145 | ['arasan_sdhci_5_1', 'third']), |
| 146 | get_compat_name(node)) |
| 147 | |
| 148 | def test_empty_file(self): |
| 149 | """Test output from a device tree file with no nodes""" |
| 150 | dtb_file = get_dtb_file('dtoc_test_empty.dts') |
| 151 | output = tools.GetOutputFilename('output') |
| 152 | dtb_platdata.run_steps(['struct'], dtb_file, False, output) |
| 153 | with open(output) as infile: |
| 154 | lines = infile.read().splitlines() |
Simon Glass | aab660f | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 155 | self.assertEqual(HEADER.splitlines(), lines) |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 156 | |
| 157 | dtb_platdata.run_steps(['platdata'], dtb_file, False, output) |
| 158 | with open(output) as infile: |
| 159 | lines = infile.read().splitlines() |
Simon Glass | aab660f | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 160 | self.assertEqual(C_HEADER.splitlines() + [''], lines) |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 161 | |
| 162 | def test_simple(self): |
| 163 | """Test output from some simple nodes with various types of data""" |
| 164 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
| 165 | output = tools.GetOutputFilename('output') |
| 166 | dtb_platdata.run_steps(['struct'], dtb_file, False, output) |
| 167 | with open(output) as infile: |
| 168 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 169 | self._CheckStrings(HEADER + ''' |
Simon Glass | 5ec741f | 2017-08-29 14:15:51 -0600 | [diff] [blame] | 170 | struct dtd_sandbox_i2c_test { |
| 171 | }; |
| 172 | struct dtd_sandbox_pmic_test { |
| 173 | \tbool\t\tlow_power; |
| 174 | \tfdt64_t\t\treg[2]; |
| 175 | }; |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 176 | struct dtd_sandbox_spl_test { |
| 177 | \tbool\t\tboolval; |
| 178 | \tunsigned char\tbytearray[3]; |
| 179 | \tunsigned char\tbyteval; |
| 180 | \tfdt32_t\t\tintarray[4]; |
| 181 | \tfdt32_t\t\tintval; |
| 182 | \tunsigned char\tlongbytearray[9]; |
Simon Glass | 2a2d91d | 2018-07-06 10:27:28 -0600 | [diff] [blame] | 183 | \tunsigned char\tnotstring[5]; |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 184 | \tconst char *\tstringarray[3]; |
| 185 | \tconst char *\tstringval; |
| 186 | }; |
| 187 | struct dtd_sandbox_spl_test_2 { |
| 188 | }; |
| 189 | ''', data) |
| 190 | |
| 191 | dtb_platdata.run_steps(['platdata'], dtb_file, False, output) |
| 192 | with open(output) as infile: |
| 193 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 194 | self._CheckStrings(C_HEADER + ''' |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 195 | static struct dtd_sandbox_spl_test dtv_spl_test = { |
| 196 | \t.bytearray\t\t= {0x6, 0x0, 0x0}, |
| 197 | \t.byteval\t\t= 0x5, |
| 198 | \t.intval\t\t\t= 0x1, |
Simon Glass | 2a2d91d | 2018-07-06 10:27:28 -0600 | [diff] [blame] | 199 | \t.notstring\t\t= {0x20, 0x21, 0x22, 0x10, 0x0}, |
Simon Glass | 21d54ac | 2017-08-29 14:15:49 -0600 | [diff] [blame] | 200 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, |
| 201 | \t\t0x11}, |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 202 | \t.stringval\t\t= "message", |
| 203 | \t.boolval\t\t= true, |
| 204 | \t.intarray\t\t= {0x2, 0x3, 0x4, 0x0}, |
| 205 | \t.stringarray\t\t= {"multi-word", "message", ""}, |
| 206 | }; |
| 207 | U_BOOT_DEVICE(spl_test) = { |
| 208 | \t.name\t\t= "sandbox_spl_test", |
| 209 | \t.platdata\t= &dtv_spl_test, |
| 210 | \t.platdata_size\t= sizeof(dtv_spl_test), |
| 211 | }; |
| 212 | |
| 213 | static struct dtd_sandbox_spl_test dtv_spl_test2 = { |
| 214 | \t.bytearray\t\t= {0x1, 0x23, 0x34}, |
| 215 | \t.byteval\t\t= 0x8, |
| 216 | \t.intval\t\t\t= 0x3, |
Simon Glass | 21d54ac | 2017-08-29 14:15:49 -0600 | [diff] [blame] | 217 | \t.longbytearray\t\t= {0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
| 218 | \t\t0x0}, |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 219 | \t.stringval\t\t= "message2", |
| 220 | \t.intarray\t\t= {0x5, 0x0, 0x0, 0x0}, |
| 221 | \t.stringarray\t\t= {"another", "multi-word", "message"}, |
| 222 | }; |
| 223 | U_BOOT_DEVICE(spl_test2) = { |
| 224 | \t.name\t\t= "sandbox_spl_test", |
| 225 | \t.platdata\t= &dtv_spl_test2, |
| 226 | \t.platdata_size\t= sizeof(dtv_spl_test2), |
| 227 | }; |
| 228 | |
| 229 | static struct dtd_sandbox_spl_test dtv_spl_test3 = { |
| 230 | \t.stringarray\t\t= {"one", "", ""}, |
| 231 | }; |
| 232 | U_BOOT_DEVICE(spl_test3) = { |
| 233 | \t.name\t\t= "sandbox_spl_test", |
| 234 | \t.platdata\t= &dtv_spl_test3, |
| 235 | \t.platdata_size\t= sizeof(dtv_spl_test3), |
| 236 | }; |
| 237 | |
| 238 | static struct dtd_sandbox_spl_test_2 dtv_spl_test4 = { |
| 239 | }; |
| 240 | U_BOOT_DEVICE(spl_test4) = { |
| 241 | \t.name\t\t= "sandbox_spl_test_2", |
| 242 | \t.platdata\t= &dtv_spl_test4, |
| 243 | \t.platdata_size\t= sizeof(dtv_spl_test4), |
| 244 | }; |
| 245 | |
Simon Glass | 5ec741f | 2017-08-29 14:15:51 -0600 | [diff] [blame] | 246 | static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = { |
| 247 | }; |
| 248 | U_BOOT_DEVICE(i2c_at_0) = { |
| 249 | \t.name\t\t= "sandbox_i2c_test", |
| 250 | \t.platdata\t= &dtv_i2c_at_0, |
| 251 | \t.platdata_size\t= sizeof(dtv_i2c_at_0), |
| 252 | }; |
| 253 | |
| 254 | static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = { |
| 255 | \t.low_power\t\t= true, |
| 256 | \t.reg\t\t\t= {0x9, 0x0}, |
| 257 | }; |
| 258 | U_BOOT_DEVICE(pmic_at_9) = { |
| 259 | \t.name\t\t= "sandbox_pmic_test", |
| 260 | \t.platdata\t= &dtv_pmic_at_9, |
| 261 | \t.platdata_size\t= sizeof(dtv_pmic_at_9), |
| 262 | }; |
| 263 | |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 264 | ''', data) |
| 265 | |
| 266 | def test_phandle(self): |
| 267 | """Test output from a node containing a phandle reference""" |
| 268 | dtb_file = get_dtb_file('dtoc_test_phandle.dts') |
| 269 | output = tools.GetOutputFilename('output') |
| 270 | dtb_platdata.run_steps(['struct'], dtb_file, False, output) |
| 271 | with open(output) as infile: |
| 272 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 273 | self._CheckStrings(HEADER + ''' |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 274 | struct dtd_source { |
Simon Glass | 634eba4 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 275 | \tstruct phandle_2_arg clocks[4]; |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 276 | }; |
| 277 | struct dtd_target { |
| 278 | \tfdt32_t\t\tintval; |
| 279 | }; |
| 280 | ''', data) |
| 281 | |
| 282 | dtb_platdata.run_steps(['platdata'], dtb_file, False, output) |
| 283 | with open(output) as infile: |
| 284 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 285 | self._CheckStrings(C_HEADER + ''' |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 286 | static struct dtd_target dtv_phandle_target = { |
Simon Glass | 634eba4 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 287 | \t.intval\t\t\t= 0x0, |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 288 | }; |
| 289 | U_BOOT_DEVICE(phandle_target) = { |
| 290 | \t.name\t\t= "target", |
| 291 | \t.platdata\t= &dtv_phandle_target, |
| 292 | \t.platdata_size\t= sizeof(dtv_phandle_target), |
| 293 | }; |
| 294 | |
Simon Glass | 634eba4 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 295 | static struct dtd_target dtv_phandle2_target = { |
| 296 | \t.intval\t\t\t= 0x1, |
| 297 | }; |
| 298 | U_BOOT_DEVICE(phandle2_target) = { |
| 299 | \t.name\t\t= "target", |
| 300 | \t.platdata\t= &dtv_phandle2_target, |
| 301 | \t.platdata_size\t= sizeof(dtv_phandle2_target), |
| 302 | }; |
| 303 | |
| 304 | static struct dtd_target dtv_phandle3_target = { |
| 305 | \t.intval\t\t\t= 0x2, |
| 306 | }; |
| 307 | U_BOOT_DEVICE(phandle3_target) = { |
| 308 | \t.name\t\t= "target", |
| 309 | \t.platdata\t= &dtv_phandle3_target, |
| 310 | \t.platdata_size\t= sizeof(dtv_phandle3_target), |
| 311 | }; |
| 312 | |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 313 | static struct dtd_source dtv_phandle_source = { |
Simon Glass | 35d5037 | 2017-08-29 14:15:57 -0600 | [diff] [blame] | 314 | \t.clocks\t\t\t= { |
Simon Glass | 634eba4 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 315 | \t\t\t{&dtv_phandle_target, {}}, |
| 316 | \t\t\t{&dtv_phandle2_target, {11}}, |
| 317 | \t\t\t{&dtv_phandle3_target, {12, 13}}, |
| 318 | \t\t\t{&dtv_phandle_target, {}},}, |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 319 | }; |
| 320 | U_BOOT_DEVICE(phandle_source) = { |
| 321 | \t.name\t\t= "source", |
| 322 | \t.platdata\t= &dtv_phandle_source, |
| 323 | \t.platdata_size\t= sizeof(dtv_phandle_source), |
| 324 | }; |
| 325 | |
Simon Glass | 760b717 | 2018-07-06 10:27:31 -0600 | [diff] [blame^] | 326 | static struct dtd_source dtv_phandle_source2 = { |
| 327 | \t.clocks\t\t\t= { |
| 328 | \t\t\t{&dtv_phandle_target, {}},}, |
| 329 | }; |
| 330 | U_BOOT_DEVICE(phandle_source2) = { |
| 331 | \t.name\t\t= "source", |
| 332 | \t.platdata\t= &dtv_phandle_source2, |
| 333 | \t.platdata_size\t= sizeof(dtv_phandle_source2), |
| 334 | }; |
| 335 | |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 336 | ''', data) |
| 337 | |
| 338 | def test_aliases(self): |
| 339 | """Test output from a node with multiple compatible strings""" |
| 340 | dtb_file = get_dtb_file('dtoc_test_aliases.dts') |
| 341 | output = tools.GetOutputFilename('output') |
| 342 | dtb_platdata.run_steps(['struct'], dtb_file, False, output) |
| 343 | with open(output) as infile: |
| 344 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 345 | self._CheckStrings(HEADER + ''' |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 346 | struct dtd_compat1 { |
| 347 | \tfdt32_t\t\tintval; |
| 348 | }; |
| 349 | #define dtd_compat2_1_fred dtd_compat1 |
| 350 | #define dtd_compat3 dtd_compat1 |
| 351 | ''', data) |
| 352 | |
| 353 | dtb_platdata.run_steps(['platdata'], dtb_file, False, output) |
| 354 | with open(output) as infile: |
| 355 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 356 | self._CheckStrings(C_HEADER + ''' |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 357 | static struct dtd_compat1 dtv_spl_test = { |
| 358 | \t.intval\t\t\t= 0x1, |
| 359 | }; |
| 360 | U_BOOT_DEVICE(spl_test) = { |
| 361 | \t.name\t\t= "compat1", |
| 362 | \t.platdata\t= &dtv_spl_test, |
| 363 | \t.platdata_size\t= sizeof(dtv_spl_test), |
| 364 | }; |
| 365 | |
| 366 | ''', data) |
Simon Glass | c20ee0e | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 367 | |
| 368 | def test_addresses64(self): |
| 369 | """Test output from a node with a 'reg' property with na=2, ns=2""" |
| 370 | dtb_file = get_dtb_file('dtoc_test_addr64.dts') |
| 371 | output = tools.GetOutputFilename('output') |
| 372 | dtb_platdata.run_steps(['struct'], dtb_file, False, output) |
| 373 | with open(output) as infile: |
| 374 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 375 | self._CheckStrings(HEADER + ''' |
Simon Glass | c20ee0e | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 376 | struct dtd_test1 { |
| 377 | \tfdt64_t\t\treg[2]; |
| 378 | }; |
| 379 | struct dtd_test2 { |
| 380 | \tfdt64_t\t\treg[2]; |
| 381 | }; |
| 382 | struct dtd_test3 { |
| 383 | \tfdt64_t\t\treg[4]; |
| 384 | }; |
| 385 | ''', data) |
| 386 | |
| 387 | dtb_platdata.run_steps(['platdata'], dtb_file, False, output) |
| 388 | with open(output) as infile: |
| 389 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 390 | self._CheckStrings(C_HEADER + ''' |
Simon Glass | c20ee0e | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 391 | static struct dtd_test1 dtv_test1 = { |
| 392 | \t.reg\t\t\t= {0x1234, 0x5678}, |
| 393 | }; |
| 394 | U_BOOT_DEVICE(test1) = { |
| 395 | \t.name\t\t= "test1", |
| 396 | \t.platdata\t= &dtv_test1, |
| 397 | \t.platdata_size\t= sizeof(dtv_test1), |
| 398 | }; |
| 399 | |
| 400 | static struct dtd_test2 dtv_test2 = { |
| 401 | \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654}, |
| 402 | }; |
| 403 | U_BOOT_DEVICE(test2) = { |
| 404 | \t.name\t\t= "test2", |
| 405 | \t.platdata\t= &dtv_test2, |
| 406 | \t.platdata_size\t= sizeof(dtv_test2), |
| 407 | }; |
| 408 | |
| 409 | static struct dtd_test3 dtv_test3 = { |
| 410 | \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3}, |
| 411 | }; |
| 412 | U_BOOT_DEVICE(test3) = { |
| 413 | \t.name\t\t= "test3", |
| 414 | \t.platdata\t= &dtv_test3, |
| 415 | \t.platdata_size\t= sizeof(dtv_test3), |
| 416 | }; |
| 417 | |
| 418 | ''', data) |
| 419 | |
| 420 | def test_addresses32(self): |
| 421 | """Test output from a node with a 'reg' property with na=1, ns=1""" |
| 422 | dtb_file = get_dtb_file('dtoc_test_addr32.dts') |
| 423 | output = tools.GetOutputFilename('output') |
| 424 | dtb_platdata.run_steps(['struct'], dtb_file, False, output) |
| 425 | with open(output) as infile: |
| 426 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 427 | self._CheckStrings(HEADER + ''' |
Simon Glass | c20ee0e | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 428 | struct dtd_test1 { |
| 429 | \tfdt32_t\t\treg[2]; |
| 430 | }; |
| 431 | struct dtd_test2 { |
| 432 | \tfdt32_t\t\treg[4]; |
| 433 | }; |
| 434 | ''', data) |
| 435 | |
| 436 | dtb_platdata.run_steps(['platdata'], dtb_file, False, output) |
| 437 | with open(output) as infile: |
| 438 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 439 | self._CheckStrings(C_HEADER + ''' |
Simon Glass | c20ee0e | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 440 | static struct dtd_test1 dtv_test1 = { |
| 441 | \t.reg\t\t\t= {0x1234, 0x5678}, |
| 442 | }; |
| 443 | U_BOOT_DEVICE(test1) = { |
| 444 | \t.name\t\t= "test1", |
| 445 | \t.platdata\t= &dtv_test1, |
| 446 | \t.platdata_size\t= sizeof(dtv_test1), |
| 447 | }; |
| 448 | |
| 449 | static struct dtd_test2 dtv_test2 = { |
| 450 | \t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3}, |
| 451 | }; |
| 452 | U_BOOT_DEVICE(test2) = { |
| 453 | \t.name\t\t= "test2", |
| 454 | \t.platdata\t= &dtv_test2, |
| 455 | \t.platdata_size\t= sizeof(dtv_test2), |
| 456 | }; |
| 457 | |
| 458 | ''', data) |
| 459 | |
| 460 | def test_addresses64_32(self): |
| 461 | """Test output from a node with a 'reg' property with na=2, ns=1""" |
| 462 | dtb_file = get_dtb_file('dtoc_test_addr64_32.dts') |
| 463 | output = tools.GetOutputFilename('output') |
| 464 | dtb_platdata.run_steps(['struct'], dtb_file, False, output) |
| 465 | with open(output) as infile: |
| 466 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 467 | self._CheckStrings(HEADER + ''' |
Simon Glass | c20ee0e | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 468 | struct dtd_test1 { |
| 469 | \tfdt64_t\t\treg[2]; |
| 470 | }; |
| 471 | struct dtd_test2 { |
| 472 | \tfdt64_t\t\treg[2]; |
| 473 | }; |
| 474 | struct dtd_test3 { |
| 475 | \tfdt64_t\t\treg[4]; |
| 476 | }; |
| 477 | ''', data) |
| 478 | |
| 479 | dtb_platdata.run_steps(['platdata'], dtb_file, False, output) |
| 480 | with open(output) as infile: |
| 481 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 482 | self._CheckStrings(C_HEADER + ''' |
Simon Glass | c20ee0e | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 483 | static struct dtd_test1 dtv_test1 = { |
| 484 | \t.reg\t\t\t= {0x123400000000, 0x5678}, |
| 485 | }; |
| 486 | U_BOOT_DEVICE(test1) = { |
| 487 | \t.name\t\t= "test1", |
| 488 | \t.platdata\t= &dtv_test1, |
| 489 | \t.platdata_size\t= sizeof(dtv_test1), |
| 490 | }; |
| 491 | |
| 492 | static struct dtd_test2 dtv_test2 = { |
| 493 | \t.reg\t\t\t= {0x1234567890123456, 0x98765432}, |
| 494 | }; |
| 495 | U_BOOT_DEVICE(test2) = { |
| 496 | \t.name\t\t= "test2", |
| 497 | \t.platdata\t= &dtv_test2, |
| 498 | \t.platdata_size\t= sizeof(dtv_test2), |
| 499 | }; |
| 500 | |
| 501 | static struct dtd_test3 dtv_test3 = { |
| 502 | \t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3}, |
| 503 | }; |
| 504 | U_BOOT_DEVICE(test3) = { |
| 505 | \t.name\t\t= "test3", |
| 506 | \t.platdata\t= &dtv_test3, |
| 507 | \t.platdata_size\t= sizeof(dtv_test3), |
| 508 | }; |
| 509 | |
| 510 | ''', data) |
| 511 | |
| 512 | def test_addresses32_64(self): |
| 513 | """Test output from a node with a 'reg' property with na=1, ns=2""" |
| 514 | dtb_file = get_dtb_file('dtoc_test_addr32_64.dts') |
| 515 | output = tools.GetOutputFilename('output') |
| 516 | dtb_platdata.run_steps(['struct'], dtb_file, False, output) |
| 517 | with open(output) as infile: |
| 518 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 519 | self._CheckStrings(HEADER + ''' |
Simon Glass | c20ee0e | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 520 | struct dtd_test1 { |
| 521 | \tfdt64_t\t\treg[2]; |
| 522 | }; |
| 523 | struct dtd_test2 { |
| 524 | \tfdt64_t\t\treg[2]; |
| 525 | }; |
| 526 | struct dtd_test3 { |
| 527 | \tfdt64_t\t\treg[4]; |
| 528 | }; |
| 529 | ''', data) |
| 530 | |
| 531 | dtb_platdata.run_steps(['platdata'], dtb_file, False, output) |
| 532 | with open(output) as infile: |
| 533 | data = infile.read() |
Simon Glass | 57f0bc4 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 534 | self._CheckStrings(C_HEADER + ''' |
Simon Glass | c20ee0e | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 535 | static struct dtd_test1 dtv_test1 = { |
| 536 | \t.reg\t\t\t= {0x1234, 0x567800000000}, |
| 537 | }; |
| 538 | U_BOOT_DEVICE(test1) = { |
| 539 | \t.name\t\t= "test1", |
| 540 | \t.platdata\t= &dtv_test1, |
| 541 | \t.platdata_size\t= sizeof(dtv_test1), |
| 542 | }; |
| 543 | |
| 544 | static struct dtd_test2 dtv_test2 = { |
| 545 | \t.reg\t\t\t= {0x12345678, 0x9876543210987654}, |
| 546 | }; |
| 547 | U_BOOT_DEVICE(test2) = { |
| 548 | \t.name\t\t= "test2", |
| 549 | \t.platdata\t= &dtv_test2, |
| 550 | \t.platdata_size\t= sizeof(dtv_test2), |
| 551 | }; |
| 552 | |
| 553 | static struct dtd_test3 dtv_test3 = { |
| 554 | \t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3}, |
| 555 | }; |
| 556 | U_BOOT_DEVICE(test3) = { |
| 557 | \t.name\t\t= "test3", |
| 558 | \t.platdata\t= &dtv_test3, |
| 559 | \t.platdata_size\t= sizeof(dtv_test3), |
| 560 | }; |
| 561 | |
| 562 | ''', data) |