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