Simon Glass | bfb0bb2 | 2019-10-31 07:42:55 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 3 | # Copyright (c) 2012 The Chromium OS Authors. |
| 4 | # |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 5 | |
| 6 | """Tests for the dtb_platdata module |
| 7 | |
Simon Glass | 70cd0d7 | 2018-07-06 10:27:20 -0600 | [diff] [blame] | 8 | This includes unit tests for some functions and functional tests for the dtoc |
| 9 | tool. |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 10 | """ |
| 11 | |
| 12 | import collections |
Simon Glass | 768ff0a | 2021-02-03 06:00:51 -0700 | [diff] [blame] | 13 | import copy |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 14 | import glob |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 15 | import os |
Simon Glass | bd310df | 2023-02-23 18:18:16 -0700 | [diff] [blame] | 16 | import pathlib |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 17 | import struct |
| 18 | import unittest |
| 19 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 20 | from dtoc import dtb_platdata |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 21 | from dtoc import fdt |
| 22 | from dtoc import fdt_util |
Simon Glass | 768ff0a | 2021-02-03 06:00:51 -0700 | [diff] [blame] | 23 | from dtoc import src_scan |
Simon Glass | 2b16007 | 2022-02-11 13:23:20 -0700 | [diff] [blame] | 24 | from dtoc.dtb_platdata import Ftype |
| 25 | from dtoc.dtb_platdata import get_value |
| 26 | from dtoc.dtb_platdata import tab_to |
Simon Glass | 9065bc9 | 2020-12-28 20:35:06 -0700 | [diff] [blame] | 27 | from dtoc.src_scan import conv_name_to_c |
| 28 | from dtoc.src_scan import get_compat_name |
Simon Glass | 131444f | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 29 | from u_boot_pylib import test_util |
| 30 | from u_boot_pylib import tools |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 31 | |
Simon Glass | bd310df | 2023-02-23 18:18:16 -0700 | [diff] [blame] | 32 | DTOC_DIR = pathlib.Path(__file__).parent |
| 33 | TEST_DATA_DIR = DTOC_DIR / 'test/' |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 34 | |
| 35 | |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 36 | HEADER = '''/* |
| 37 | * DO NOT MODIFY |
| 38 | * |
Simon Glass | 6b20884 | 2020-12-28 20:35:00 -0700 | [diff] [blame] | 39 | * Defines the structs used to hold devicetree data. |
| 40 | * This was generated by dtoc from a .dtb (device tree binary) file. |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 41 | */ |
| 42 | |
| 43 | #include <stdbool.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 44 | #include <linux/libfdt.h>''' |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 45 | |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 46 | DECL_HEADER = '''/* |
| 47 | * DO NOT MODIFY |
| 48 | * |
| 49 | * Declares externs for all device/uclass instances. |
| 50 | * This was generated by dtoc from a .dtb (device tree binary) file. |
| 51 | */ |
| 52 | ''' |
| 53 | |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 54 | C_HEADER_PRE = '''/* |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 55 | * DO NOT MODIFY |
| 56 | * |
Simon Glass | 6b20884 | 2020-12-28 20:35:00 -0700 | [diff] [blame] | 57 | * Declares the U_BOOT_DRIVER() records and platform data. |
| 58 | * This was generated by dtoc from a .dtb (device tree binary) file. |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 59 | */ |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 60 | ''' |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 61 | |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 62 | C_HEADER = C_HEADER_PRE + ''' |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 63 | /* Allow use of U_BOOT_DRVINFO() in this file */ |
Simon Glass | beddd7a | 2020-12-28 20:35:01 -0700 | [diff] [blame] | 64 | #define DT_PLAT_C |
Simon Glass | 4c73d7b | 2020-10-03 11:31:41 -0600 | [diff] [blame] | 65 | |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 66 | #include <dm.h> |
| 67 | #include <dt-structs.h> |
| 68 | ''' |
| 69 | |
Simon Glass | c7b4b83 | 2021-02-03 06:01:20 -0700 | [diff] [blame] | 70 | UCLASS_HEADER_COMMON = '''/* |
| 71 | * DO NOT MODIFY |
| 72 | * |
| 73 | * Declares the uclass instances (struct uclass). |
| 74 | * This was generated by dtoc from a .dtb (device tree binary) file. |
| 75 | */ |
| 76 | ''' |
| 77 | |
Simon Glass | 768ff0a | 2021-02-03 06:00:51 -0700 | [diff] [blame] | 78 | # Scanner saved from a previous run of the tests (to speed things up) |
| 79 | saved_scan = None |
| 80 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 81 | # This is a test so is allowed to access private things in the module it is |
| 82 | # testing |
| 83 | # pylint: disable=W0212 |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 84 | |
| 85 | def get_dtb_file(dts_fname, capture_stderr=False): |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 86 | """Compile a .dts file to a .dtb |
| 87 | |
| 88 | Args: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 89 | dts_fname (str): Filename of .dts file in the current directory |
| 90 | capture_stderr (bool): True to capture and discard stderr output |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 91 | |
| 92 | Returns: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 93 | str: Filename of compiled file in output directory |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 94 | """ |
Simon Glass | bd310df | 2023-02-23 18:18:16 -0700 | [diff] [blame] | 95 | return fdt_util.EnsureCompiled(str(TEST_DATA_DIR / dts_fname), |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 96 | capture_stderr=capture_stderr) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 97 | |
Simon Glass | 768ff0a | 2021-02-03 06:00:51 -0700 | [diff] [blame] | 98 | |
| 99 | def setup(): |
| 100 | global saved_scan |
| 101 | |
| 102 | # Disable warnings so that calls to get_normalized_compat_name() will not |
| 103 | # output things. |
Simon Glass | 695077d | 2021-03-26 16:17:25 +1300 | [diff] [blame] | 104 | saved_scan = src_scan.Scanner(None, False) |
Simon Glass | 768ff0a | 2021-02-03 06:00:51 -0700 | [diff] [blame] | 105 | saved_scan.scan_drivers() |
| 106 | |
| 107 | def copy_scan(): |
| 108 | """Get a copy of saved_scan so that each test can start clean""" |
| 109 | return copy.deepcopy(saved_scan) |
| 110 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 111 | |
| 112 | class TestDtoc(unittest.TestCase): |
| 113 | """Tests for dtoc""" |
| 114 | @classmethod |
| 115 | def setUpClass(cls): |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 116 | tools.prepare_output_dir(None) |
Simon Glass | 7f5e226 | 2020-07-07 21:32:06 -0600 | [diff] [blame] | 117 | cls.maxDiff = None |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 118 | |
| 119 | @classmethod |
| 120 | def tearDownClass(cls): |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 121 | tools.finalise_output_dir() |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 122 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 123 | @staticmethod |
| 124 | def _write_python_string(fname, data): |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 125 | """Write a string with tabs expanded as done in this Python file |
| 126 | |
| 127 | Args: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 128 | fname (str): Filename to write to |
| 129 | data (str): Raw string to convert |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 130 | """ |
| 131 | data = data.replace('\t', '\\t') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 132 | with open(fname, 'w') as fout: |
| 133 | fout.write(data) |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 134 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 135 | def _check_strings(self, expected, actual): |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 136 | """Check that a string matches its expected value |
| 137 | |
| 138 | If the strings do not match, they are written to the /tmp directory in |
| 139 | the same Python format as is used here in the test. This allows for |
| 140 | easy comparison and update of the tests. |
| 141 | |
| 142 | Args: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 143 | expected (str): Expected string |
| 144 | actual (str): Actual string |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 145 | """ |
| 146 | if expected != actual: |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 147 | self._write_python_string('/tmp/binman.expected', expected) |
| 148 | self._write_python_string('/tmp/binman.actual', actual) |
Simon Glass | 61b88e5 | 2019-05-17 22:00:31 -0600 | [diff] [blame] | 149 | print('Failures written to /tmp/binman.{expected,actual}') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 150 | self.assertEqual(expected, actual) |
Simon Glass | c47c2b3 | 2018-07-06 10:27:25 -0600 | [diff] [blame] | 151 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 152 | @staticmethod |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame] | 153 | def run_test(args, dtb_file, output, instantiate=False): |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 154 | """Run a test using dtoc |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 155 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 156 | Args: |
| 157 | args (list of str): List of arguments for dtoc |
| 158 | dtb_file (str): Filename of .dtb file |
| 159 | output (str): Filename of output file |
Simon Glass | be88d2f | 2021-02-03 06:01:07 -0700 | [diff] [blame] | 160 | |
| 161 | Returns: |
| 162 | DtbPlatdata object |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 163 | """ |
Simon Glass | 80d782c4 | 2021-02-03 06:01:10 -0700 | [diff] [blame] | 164 | # Make a copy of the 'scan' object, since it includes uclasses and |
| 165 | # drivers, which get updated during execution. |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame] | 166 | return dtb_platdata.run_steps( |
| 167 | args, dtb_file, False, output, [], None, instantiate, |
| 168 | warning_disabled=True, scan=copy_scan()) |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 169 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 170 | def test_name(self): |
| 171 | """Test conversion of device tree names to C identifiers""" |
| 172 | self.assertEqual('serial_at_0x12', conv_name_to_c('serial@0x12')) |
| 173 | self.assertEqual('vendor_clock_frequency', |
| 174 | conv_name_to_c('vendor,clock-frequency')) |
| 175 | self.assertEqual('rockchip_rk3399_sdhci_5_1', |
| 176 | conv_name_to_c('rockchip,rk3399-sdhci-5.1')) |
| 177 | |
| 178 | def test_tab_to(self): |
| 179 | """Test operation of tab_to() function""" |
| 180 | self.assertEqual('fred ', tab_to(0, 'fred')) |
| 181 | self.assertEqual('fred\t', tab_to(1, 'fred')) |
| 182 | self.assertEqual('fred was here ', tab_to(1, 'fred was here')) |
| 183 | self.assertEqual('fred was here\t\t', tab_to(3, 'fred was here')) |
| 184 | self.assertEqual('exactly8 ', tab_to(1, 'exactly8')) |
| 185 | self.assertEqual('exactly8\t', tab_to(2, 'exactly8')) |
| 186 | |
| 187 | def test_get_value(self): |
| 188 | """Test operation of get_value() function""" |
| 189 | self.assertEqual('0x45', |
Simon Glass | c9a032c | 2020-11-08 20:36:17 -0700 | [diff] [blame] | 190 | get_value(fdt.Type.INT, struct.pack('>I', 0x45))) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 191 | self.assertEqual('0x45', |
Simon Glass | c9a032c | 2020-11-08 20:36:17 -0700 | [diff] [blame] | 192 | get_value(fdt.Type.BYTE, struct.pack('<I', 0x45))) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 193 | self.assertEqual('0x0', |
Simon Glass | c9a032c | 2020-11-08 20:36:17 -0700 | [diff] [blame] | 194 | get_value(fdt.Type.BYTE, struct.pack('>I', 0x45))) |
| 195 | self.assertEqual('"test"', get_value(fdt.Type.STRING, 'test')) |
| 196 | self.assertEqual('true', get_value(fdt.Type.BOOL, None)) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 197 | |
| 198 | def test_get_compat_name(self): |
| 199 | """Test operation of get_compat_name() function""" |
| 200 | Prop = collections.namedtuple('Prop', ['value']) |
| 201 | Node = collections.namedtuple('Node', ['props']) |
| 202 | |
| 203 | prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1']) |
| 204 | node = Node({'compatible': prop}) |
Walter Lozano | 5fe734c | 2020-07-23 00:22:03 -0300 | [diff] [blame] | 205 | self.assertEqual((['rockchip_rk3399_sdhci_5_1', 'arasan_sdhci_5_1']), |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 206 | get_compat_name(node)) |
| 207 | |
| 208 | prop = Prop(['rockchip,rk3399-sdhci-5.1']) |
| 209 | node = Node({'compatible': prop}) |
Walter Lozano | 5fe734c | 2020-07-23 00:22:03 -0300 | [diff] [blame] | 210 | self.assertEqual((['rockchip_rk3399_sdhci_5_1']), |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 211 | get_compat_name(node)) |
| 212 | |
| 213 | prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1', 'third']) |
| 214 | node = Node({'compatible': prop}) |
Walter Lozano | 5fe734c | 2020-07-23 00:22:03 -0300 | [diff] [blame] | 215 | self.assertEqual((['rockchip_rk3399_sdhci_5_1', |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 216 | 'arasan_sdhci_5_1', 'third']), |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 217 | get_compat_name(node)) |
| 218 | |
| 219 | def test_empty_file(self): |
| 220 | """Test output from a device tree file with no nodes""" |
| 221 | dtb_file = get_dtb_file('dtoc_test_empty.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 222 | output = tools.get_output_filename('output') |
Simon Glass | 768ff0a | 2021-02-03 06:00:51 -0700 | [diff] [blame] | 223 | |
| 224 | # Run this one without saved_scan to complete test coverage |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame] | 225 | dtb_platdata.run_steps(['struct'], dtb_file, False, output, [], None, |
| 226 | False) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 227 | with open(output) as infile: |
| 228 | lines = infile.read().splitlines() |
Simon Glass | eb37e2d | 2017-11-12 21:52:17 -0700 | [diff] [blame] | 229 | self.assertEqual(HEADER.splitlines(), lines) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 230 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 231 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 232 | with open(output) as infile: |
| 233 | lines = infile.read().splitlines() |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 234 | self.assertEqual(C_HEADER.splitlines() + [''], lines) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 235 | |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 236 | decl_text = DECL_HEADER + ''' |
| 237 | #include <dm/device-internal.h> |
| 238 | #include <dm/uclass-internal.h> |
| 239 | |
| 240 | /* driver declarations - these allow DM_DRIVER_GET() to be used */ |
Simon Glass | ed5e6ae | 2021-03-15 17:25:11 +1300 | [diff] [blame] | 241 | extern U_BOOT_DRIVER(sandbox_i2c); |
| 242 | extern U_BOOT_DRIVER(sandbox_pmic); |
| 243 | extern U_BOOT_DRIVER(sandbox_spl_test); |
| 244 | extern U_BOOT_DRIVER(sandbox_spl_test); |
| 245 | extern U_BOOT_DRIVER(sandbox_spl_test); |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 246 | |
| 247 | /* uclass driver declarations - needed for DM_UCLASS_DRIVER_REF() */ |
Simon Glass | ed5e6ae | 2021-03-15 17:25:11 +1300 | [diff] [blame] | 248 | extern UCLASS_DRIVER(i2c); |
| 249 | extern UCLASS_DRIVER(misc); |
| 250 | extern UCLASS_DRIVER(pmic); |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 251 | ''' |
| 252 | decl_text_inst = DECL_HEADER + ''' |
| 253 | #include <dm/device-internal.h> |
| 254 | #include <dm/uclass-internal.h> |
| 255 | |
| 256 | /* driver declarations - these allow DM_DRIVER_GET() to be used */ |
Simon Glass | ed5e6ae | 2021-03-15 17:25:11 +1300 | [diff] [blame] | 257 | extern U_BOOT_DRIVER(sandbox_i2c); |
| 258 | extern U_BOOT_DRIVER(root_driver); |
| 259 | extern U_BOOT_DRIVER(denx_u_boot_test_bus); |
| 260 | extern U_BOOT_DRIVER(sandbox_spl_test); |
| 261 | extern U_BOOT_DRIVER(sandbox_spl_test); |
| 262 | extern U_BOOT_DRIVER(denx_u_boot_fdt_test); |
| 263 | extern U_BOOT_DRIVER(denx_u_boot_fdt_test); |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 264 | |
| 265 | /* device declarations - these allow DM_DEVICE_REF() to be used */ |
Simon Glass | ed5e6ae | 2021-03-15 17:25:11 +1300 | [diff] [blame] | 266 | extern DM_DEVICE_INST(i2c); |
| 267 | extern DM_DEVICE_INST(root); |
| 268 | extern DM_DEVICE_INST(some_bus); |
| 269 | extern DM_DEVICE_INST(spl_test); |
| 270 | extern DM_DEVICE_INST(spl_test3); |
| 271 | extern DM_DEVICE_INST(test); |
| 272 | extern DM_DEVICE_INST(test0); |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 273 | |
| 274 | /* uclass driver declarations - needed for DM_UCLASS_DRIVER_REF() */ |
Simon Glass | ed5e6ae | 2021-03-15 17:25:11 +1300 | [diff] [blame] | 275 | extern UCLASS_DRIVER(i2c); |
| 276 | extern UCLASS_DRIVER(misc); |
| 277 | extern UCLASS_DRIVER(root); |
| 278 | extern UCLASS_DRIVER(testbus); |
| 279 | extern UCLASS_DRIVER(testfdt); |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 280 | |
| 281 | /* uclass declarations - needed for DM_UCLASS_REF() */ |
Simon Glass | ed5e6ae | 2021-03-15 17:25:11 +1300 | [diff] [blame] | 282 | extern DM_UCLASS_INST(i2c); |
| 283 | extern DM_UCLASS_INST(misc); |
| 284 | extern DM_UCLASS_INST(root); |
| 285 | extern DM_UCLASS_INST(testbus); |
| 286 | extern DM_UCLASS_INST(testfdt); |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 287 | ''' |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 288 | struct_text = HEADER + ''' |
Simon Glass | 32a8d22 | 2021-02-03 06:00:57 -0700 | [diff] [blame] | 289 | struct dtd_sandbox_i2c { |
Simon Glass | 90e5f0a | 2017-08-29 14:15:51 -0600 | [diff] [blame] | 290 | }; |
Simon Glass | 32a8d22 | 2021-02-03 06:00:57 -0700 | [diff] [blame] | 291 | struct dtd_sandbox_pmic { |
Simon Glass | 90e5f0a | 2017-08-29 14:15:51 -0600 | [diff] [blame] | 292 | \tbool\t\tlow_power; |
Simon Glass | 94ba59e | 2021-03-26 16:17:26 +1300 | [diff] [blame] | 293 | \tfdt32_t\t\treg[1]; |
Simon Glass | 90e5f0a | 2017-08-29 14:15:51 -0600 | [diff] [blame] | 294 | }; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 295 | struct dtd_sandbox_spl_test { |
Simon Glass | 7f5e226 | 2020-07-07 21:32:06 -0600 | [diff] [blame] | 296 | \tconst char * acpi_name; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 297 | \tbool\t\tboolval; |
| 298 | \tunsigned char\tbytearray[3]; |
| 299 | \tunsigned char\tbyteval; |
Simon Glass | 3b55e3f | 2021-11-23 11:03:39 -0700 | [diff] [blame] | 300 | \tfdt32_t\t\tint64val[2]; |
Simon Glass | a7d6698 | 2021-07-28 19:23:10 -0600 | [diff] [blame] | 301 | \tfdt32_t\t\tintarray[3]; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 302 | \tfdt32_t\t\tintval; |
| 303 | \tunsigned char\tlongbytearray[9]; |
Simon Glass | 4311832 | 2021-07-28 19:23:11 -0600 | [diff] [blame] | 304 | \tfdt32_t\t\tmaybe_empty_int[1]; |
Simon Glass | 9c52633 | 2018-07-06 10:27:28 -0600 | [diff] [blame] | 305 | \tunsigned char\tnotstring[5]; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 306 | \tconst char *\tstringarray[3]; |
| 307 | \tconst char *\tstringval; |
| 308 | }; |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 309 | ''' |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 310 | platdata_text = C_HEADER + ''' |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 311 | /* |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 312 | * driver_info declarations, ordered by 'struct driver_info' linker_list idx: |
| 313 | * |
| 314 | * idx driver_info driver |
| 315 | * --- -------------------- -------------------- |
| 316 | * 0: i2c_at_0 sandbox_i2c |
| 317 | * 1: pmic_at_9 sandbox_pmic |
| 318 | * 2: spl_test sandbox_spl_test |
| 319 | * 3: spl_test2 sandbox_spl_test |
| 320 | * 4: spl_test3 sandbox_spl_test |
| 321 | * --- -------------------- -------------------- |
| 322 | */ |
| 323 | |
| 324 | /* |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 325 | * Node /i2c@0 index 0 |
| 326 | * driver sandbox_i2c parent None |
| 327 | */ |
Simon Glass | 32a8d22 | 2021-02-03 06:00:57 -0700 | [diff] [blame] | 328 | static struct dtd_sandbox_i2c dtv_i2c_at_0 = { |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 329 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 330 | U_BOOT_DRVINFO(i2c_at_0) = { |
Simon Glass | 32a8d22 | 2021-02-03 06:00:57 -0700 | [diff] [blame] | 331 | \t.name\t\t= "sandbox_i2c", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 332 | \t.plat\t\t= &dtv_i2c_at_0, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 333 | \t.plat_size\t= sizeof(dtv_i2c_at_0), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 334 | \t.parent_idx\t= -1, |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 335 | }; |
| 336 | |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 337 | /* |
| 338 | * Node /i2c@0/pmic@9 index 1 |
| 339 | * driver sandbox_pmic parent sandbox_i2c |
| 340 | */ |
Simon Glass | 32a8d22 | 2021-02-03 06:00:57 -0700 | [diff] [blame] | 341 | static struct dtd_sandbox_pmic dtv_pmic_at_9 = { |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 342 | \t.low_power\t\t= true, |
Simon Glass | 94ba59e | 2021-03-26 16:17:26 +1300 | [diff] [blame] | 343 | \t.reg\t\t\t= {0x9}, |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 344 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 345 | U_BOOT_DRVINFO(pmic_at_9) = { |
Simon Glass | 32a8d22 | 2021-02-03 06:00:57 -0700 | [diff] [blame] | 346 | \t.name\t\t= "sandbox_pmic", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 347 | \t.plat\t\t= &dtv_pmic_at_9, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 348 | \t.plat_size\t= sizeof(dtv_pmic_at_9), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 349 | \t.parent_idx\t= 0, |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 350 | }; |
| 351 | |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 352 | /* |
| 353 | * Node /spl-test index 2 |
| 354 | * driver sandbox_spl_test parent None |
| 355 | */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 356 | static struct dtd_sandbox_spl_test dtv_spl_test = { |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 357 | \t.boolval\t\t= true, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 358 | \t.bytearray\t\t= {0x6, 0x0, 0x0}, |
| 359 | \t.byteval\t\t= 0x5, |
Simon Glass | 3b55e3f | 2021-11-23 11:03:39 -0700 | [diff] [blame] | 360 | \t.int64val\t\t= {0x12345678, 0x9abcdef0}, |
Simon Glass | a7d6698 | 2021-07-28 19:23:10 -0600 | [diff] [blame] | 361 | \t.intarray\t\t= {0x2, 0x3, 0x4}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 362 | \t.intval\t\t\t= 0x1, |
Simon Glass | 131e0b0 | 2017-08-29 14:15:49 -0600 | [diff] [blame] | 363 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, |
| 364 | \t\t0x11}, |
Simon Glass | 4311832 | 2021-07-28 19:23:11 -0600 | [diff] [blame] | 365 | \t.maybe_empty_int\t= {0x0}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 366 | \t.notstring\t\t= {0x20, 0x21, 0x22, 0x10, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 367 | \t.stringarray\t\t= {"multi-word", "message", ""}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 368 | \t.stringval\t\t= "message", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 369 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 370 | U_BOOT_DRVINFO(spl_test) = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 371 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 372 | \t.plat\t\t= &dtv_spl_test, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 373 | \t.plat_size\t= sizeof(dtv_spl_test), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 374 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 375 | }; |
| 376 | |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 377 | /* |
| 378 | * Node /spl-test2 index 3 |
| 379 | * driver sandbox_spl_test parent None |
| 380 | */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 381 | static struct dtd_sandbox_spl_test dtv_spl_test2 = { |
Simon Glass | 7f5e226 | 2020-07-07 21:32:06 -0600 | [diff] [blame] | 382 | \t.acpi_name\t\t= "\\\\_SB.GPO0", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 383 | \t.bytearray\t\t= {0x1, 0x23, 0x34}, |
| 384 | \t.byteval\t\t= 0x8, |
Simon Glass | a7d6698 | 2021-07-28 19:23:10 -0600 | [diff] [blame] | 385 | \t.intarray\t\t= {0x5, 0x0, 0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 386 | \t.intval\t\t\t= 0x3, |
Simon Glass | 8034e4d | 2020-10-03 11:31:27 -0600 | [diff] [blame] | 387 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0x0, 0x0, 0x0, 0x0, |
Simon Glass | 131e0b0 | 2017-08-29 14:15:49 -0600 | [diff] [blame] | 388 | \t\t0x0}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 389 | \t.stringarray\t\t= {"another", "multi-word", "message"}, |
Simon Glass | c82de56 | 2019-05-17 22:00:32 -0600 | [diff] [blame] | 390 | \t.stringval\t\t= "message2", |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 391 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 392 | U_BOOT_DRVINFO(spl_test2) = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 393 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 394 | \t.plat\t\t= &dtv_spl_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 395 | \t.plat_size\t= sizeof(dtv_spl_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 396 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 397 | }; |
| 398 | |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 399 | /* |
| 400 | * Node /spl-test3 index 4 |
| 401 | * driver sandbox_spl_test parent None |
| 402 | */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 403 | static struct dtd_sandbox_spl_test dtv_spl_test3 = { |
Simon Glass | 8034e4d | 2020-10-03 11:31:27 -0600 | [diff] [blame] | 404 | \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, |
| 405 | \t\t0x0}, |
Simon Glass | 4311832 | 2021-07-28 19:23:11 -0600 | [diff] [blame] | 406 | \t.maybe_empty_int\t= {0x1}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 407 | \t.stringarray\t\t= {"one", "", ""}, |
| 408 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 409 | U_BOOT_DRVINFO(spl_test3) = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 410 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 411 | \t.plat\t\t= &dtv_spl_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 412 | \t.plat_size\t= sizeof(dtv_spl_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 413 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 414 | }; |
| 415 | |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 416 | ''' |
Simon Glass | c7b4b83 | 2021-02-03 06:01:20 -0700 | [diff] [blame] | 417 | uclass_text_inst = ''' |
| 418 | |
Simon Glass | c7b4b83 | 2021-02-03 06:01:20 -0700 | [diff] [blame] | 419 | #include <dm.h> |
| 420 | #include <dt-structs.h> |
| 421 | |
| 422 | /* |
Simon Glass | fea2f25 | 2021-02-03 06:01:21 -0700 | [diff] [blame] | 423 | * uclass declarations, ordered by 'struct uclass' linker_list idx: |
| 424 | * 0: i2c |
| 425 | * 1: misc |
| 426 | * 2: root |
| 427 | * 3: testbus |
| 428 | * 4: testfdt |
Simon Glass | c7b4b83 | 2021-02-03 06:01:20 -0700 | [diff] [blame] | 429 | * |
Simon Glass | fea2f25 | 2021-02-03 06:01:21 -0700 | [diff] [blame] | 430 | * Sequence numbers allocated in each uclass: |
Simon Glass | c7b4b83 | 2021-02-03 06:01:20 -0700 | [diff] [blame] | 431 | * i2c: UCLASS_I2C |
| 432 | * 4: /i2c |
| 433 | * misc: UCLASS_MISC |
| 434 | * 0: /spl-test |
| 435 | * 1: /spl-test3 |
| 436 | * root: UCLASS_ROOT |
| 437 | * 0: / |
| 438 | * testbus: UCLASS_TEST_BUS |
| 439 | * 2: /some-bus |
| 440 | * testfdt: UCLASS_TEST_FDT |
| 441 | * 1: /some-bus/test |
| 442 | * 2: /some-bus/test0 |
| 443 | */ |
| 444 | |
| 445 | struct list_head uclass_head = { |
| 446 | .prev = &DM_UCLASS_REF(testfdt)->sibling_node, |
| 447 | .next = &DM_UCLASS_REF(i2c)->sibling_node, |
| 448 | }; |
| 449 | |
| 450 | DM_UCLASS_INST(i2c) = { |
| 451 | .uc_drv = DM_UCLASS_DRIVER_REF(i2c), |
| 452 | .sibling_node = { |
| 453 | .prev = &uclass_head, |
| 454 | .next = &DM_UCLASS_REF(misc)->sibling_node, |
| 455 | }, |
| 456 | .dev_head = { |
| 457 | .prev = &DM_DEVICE_REF(i2c)->uclass_node, |
| 458 | .next = &DM_DEVICE_REF(i2c)->uclass_node, |
| 459 | }, |
| 460 | }; |
| 461 | |
| 462 | DM_UCLASS_INST(misc) = { |
| 463 | .uc_drv = DM_UCLASS_DRIVER_REF(misc), |
| 464 | .sibling_node = { |
| 465 | .prev = &DM_UCLASS_REF(i2c)->sibling_node, |
| 466 | .next = &DM_UCLASS_REF(root)->sibling_node, |
| 467 | }, |
| 468 | .dev_head = { |
| 469 | .prev = &DM_DEVICE_REF(spl_test3)->uclass_node, |
| 470 | .next = &DM_DEVICE_REF(spl_test)->uclass_node, |
| 471 | }, |
| 472 | }; |
| 473 | |
| 474 | DM_UCLASS_INST(root) = { |
| 475 | .uc_drv = DM_UCLASS_DRIVER_REF(root), |
| 476 | .sibling_node = { |
| 477 | .prev = &DM_UCLASS_REF(misc)->sibling_node, |
| 478 | .next = &DM_UCLASS_REF(testbus)->sibling_node, |
| 479 | }, |
| 480 | .dev_head = { |
| 481 | .prev = &DM_DEVICE_REF(root)->uclass_node, |
| 482 | .next = &DM_DEVICE_REF(root)->uclass_node, |
| 483 | }, |
| 484 | }; |
| 485 | |
| 486 | DM_UCLASS_INST(testbus) = { |
| 487 | .uc_drv = DM_UCLASS_DRIVER_REF(testbus), |
| 488 | .sibling_node = { |
| 489 | .prev = &DM_UCLASS_REF(root)->sibling_node, |
| 490 | .next = &DM_UCLASS_REF(testfdt)->sibling_node, |
| 491 | }, |
| 492 | .dev_head = { |
| 493 | .prev = &DM_DEVICE_REF(some_bus)->uclass_node, |
| 494 | .next = &DM_DEVICE_REF(some_bus)->uclass_node, |
| 495 | }, |
| 496 | }; |
| 497 | |
| 498 | #include <dm/test.h> |
| 499 | u8 _testfdt_priv_[sizeof(struct dm_test_uc_priv)] |
| 500 | __attribute__ ((section (".priv_data"))); |
| 501 | DM_UCLASS_INST(testfdt) = { |
| 502 | .priv_ = _testfdt_priv_, |
| 503 | .uc_drv = DM_UCLASS_DRIVER_REF(testfdt), |
| 504 | .sibling_node = { |
| 505 | .prev = &DM_UCLASS_REF(testbus)->sibling_node, |
| 506 | .next = &uclass_head, |
| 507 | }, |
| 508 | .dev_head = { |
| 509 | .prev = &DM_DEVICE_REF(test0)->uclass_node, |
| 510 | .next = &DM_DEVICE_REF(test)->uclass_node, |
| 511 | }, |
| 512 | }; |
| 513 | |
Simon Glass | fea2f25 | 2021-02-03 06:01:21 -0700 | [diff] [blame] | 514 | ''' |
| 515 | device_text_inst = '''/* |
| 516 | * DO NOT MODIFY |
| 517 | * |
| 518 | * Declares the DM_DEVICE_INST() records. |
| 519 | * This was generated by dtoc from a .dtb (device tree binary) file. |
| 520 | */ |
| 521 | |
Simon Glass | fea2f25 | 2021-02-03 06:01:21 -0700 | [diff] [blame] | 522 | #include <dm.h> |
| 523 | #include <dt-structs.h> |
| 524 | |
| 525 | /* |
| 526 | * udevice declarations, ordered by 'struct udevice' linker_list position: |
| 527 | * |
| 528 | * idx udevice driver |
| 529 | * --- -------------------- -------------------- |
| 530 | * 0: i2c sandbox_i2c |
| 531 | * 1: root root_driver |
| 532 | * 2: some_bus denx_u_boot_test_bus |
| 533 | * 3: spl_test sandbox_spl_test |
| 534 | * 4: spl_test3 sandbox_spl_test |
| 535 | * 5: test denx_u_boot_fdt_test |
| 536 | * 6: test0 denx_u_boot_fdt_test |
| 537 | * --- -------------------- -------------------- |
| 538 | */ |
| 539 | |
| 540 | /* |
| 541 | * Node /i2c index 0 |
| 542 | * driver sandbox_i2c parent root_driver |
| 543 | */ |
| 544 | static struct dtd_sandbox_i2c dtv_i2c = { |
| 545 | \t.intval\t\t\t= 0x3, |
| 546 | }; |
| 547 | |
| 548 | #include <asm/i2c.h> |
| 549 | u8 _sandbox_i2c_priv_i2c[sizeof(struct sandbox_i2c_priv)] |
| 550 | \t__attribute__ ((section (".priv_data"))); |
| 551 | #include <i2c.h> |
| 552 | u8 _sandbox_i2c_uc_priv_i2c[sizeof(struct dm_i2c_bus)] |
| 553 | \t__attribute__ ((section (".priv_data"))); |
| 554 | |
| 555 | DM_DEVICE_INST(i2c) = { |
| 556 | \t.driver\t\t= DM_DRIVER_REF(sandbox_i2c), |
| 557 | \t.name\t\t= "sandbox_i2c", |
| 558 | \t.plat_\t\t= &dtv_i2c, |
| 559 | \t.priv_\t\t= _sandbox_i2c_priv_i2c, |
| 560 | \t.uclass\t\t= DM_UCLASS_REF(i2c), |
| 561 | \t.uclass_priv_ = _sandbox_i2c_uc_priv_i2c, |
| 562 | \t.uclass_node\t= { |
| 563 | \t\t.prev = &DM_UCLASS_REF(i2c)->dev_head, |
| 564 | \t\t.next = &DM_UCLASS_REF(i2c)->dev_head, |
| 565 | \t}, |
| 566 | \t.child_head\t= { |
| 567 | \t\t.prev = &DM_DEVICE_REF(i2c)->child_head, |
| 568 | \t\t.next = &DM_DEVICE_REF(i2c)->child_head, |
| 569 | \t}, |
| 570 | \t.sibling_node\t= { |
| 571 | \t\t.prev = &DM_DEVICE_REF(root)->child_head, |
| 572 | \t\t.next = &DM_DEVICE_REF(some_bus)->sibling_node, |
| 573 | \t}, |
| 574 | \t.seq_ = 4, |
| 575 | }; |
| 576 | |
| 577 | /* |
| 578 | * Node / index 1 |
| 579 | * driver root_driver parent None |
| 580 | */ |
| 581 | static struct dtd_root_driver dtv_root = { |
| 582 | }; |
| 583 | |
| 584 | DM_DEVICE_INST(root) = { |
| 585 | \t.driver\t\t= DM_DRIVER_REF(root_driver), |
| 586 | \t.name\t\t= "root_driver", |
| 587 | \t.plat_\t\t= &dtv_root, |
| 588 | \t.uclass\t\t= DM_UCLASS_REF(root), |
| 589 | \t.uclass_node\t= { |
| 590 | \t\t.prev = &DM_UCLASS_REF(root)->dev_head, |
| 591 | \t\t.next = &DM_UCLASS_REF(root)->dev_head, |
| 592 | \t}, |
| 593 | \t.child_head\t= { |
| 594 | \t\t.prev = &DM_DEVICE_REF(spl_test3)->sibling_node, |
| 595 | \t\t.next = &DM_DEVICE_REF(i2c)->sibling_node, |
| 596 | \t}, |
| 597 | \t.seq_ = 0, |
| 598 | }; |
| 599 | |
| 600 | /* |
| 601 | * Node /some-bus index 2 |
| 602 | * driver denx_u_boot_test_bus parent root_driver |
| 603 | */ |
| 604 | |
| 605 | #include <dm/test.h> |
| 606 | struct dm_test_pdata __attribute__ ((section (".priv_data"))) |
| 607 | \t_denx_u_boot_test_bus_plat_some_bus = { |
| 608 | \t.dtplat = { |
| 609 | \t\t.ping_add\t\t= 0x4, |
| 610 | \t\t.ping_expect\t\t= 0x4, |
| 611 | \t\t.reg\t\t\t= {0x3, 0x1}, |
| 612 | \t}, |
| 613 | }; |
| 614 | #include <dm/test.h> |
| 615 | u8 _denx_u_boot_test_bus_priv_some_bus[sizeof(struct dm_test_priv)] |
| 616 | \t__attribute__ ((section (".priv_data"))); |
| 617 | #include <dm/test.h> |
Simon Glass | e330447 | 2022-05-08 04:39:23 -0600 | [diff] [blame] | 618 | u8 _denx_u_boot_test_bus_ucplat_some_bus[sizeof(struct dm_test_uclass_plat)] |
Simon Glass | fea2f25 | 2021-02-03 06:01:21 -0700 | [diff] [blame] | 619 | \t__attribute__ ((section (".priv_data"))); |
Simon Glass | d1f12cf | 2022-05-08 04:39:24 -0600 | [diff] [blame] | 620 | #include <dm/test.h> |
| 621 | u8 _denx_u_boot_test_bus_uc_priv_some_bus[sizeof(struct dm_test_uclass_priv)] |
| 622 | __attribute__ ((section (".priv_data"))); |
Simon Glass | fea2f25 | 2021-02-03 06:01:21 -0700 | [diff] [blame] | 623 | #include <test.h> |
| 624 | |
| 625 | DM_DEVICE_INST(some_bus) = { |
| 626 | \t.driver\t\t= DM_DRIVER_REF(denx_u_boot_test_bus), |
| 627 | \t.name\t\t= "denx_u_boot_test_bus", |
| 628 | \t.plat_\t\t= &_denx_u_boot_test_bus_plat_some_bus, |
| 629 | \t.uclass_plat_\t= _denx_u_boot_test_bus_ucplat_some_bus, |
| 630 | \t.driver_data\t= DM_TEST_TYPE_FIRST, |
| 631 | \t.priv_\t\t= _denx_u_boot_test_bus_priv_some_bus, |
| 632 | \t.uclass\t\t= DM_UCLASS_REF(testbus), |
Simon Glass | d1f12cf | 2022-05-08 04:39:24 -0600 | [diff] [blame] | 633 | \t.uclass_priv_ = _denx_u_boot_test_bus_uc_priv_some_bus, |
Simon Glass | fea2f25 | 2021-02-03 06:01:21 -0700 | [diff] [blame] | 634 | \t.uclass_node\t= { |
| 635 | \t\t.prev = &DM_UCLASS_REF(testbus)->dev_head, |
| 636 | \t\t.next = &DM_UCLASS_REF(testbus)->dev_head, |
| 637 | \t}, |
| 638 | \t.child_head\t= { |
| 639 | \t\t.prev = &DM_DEVICE_REF(test0)->sibling_node, |
| 640 | \t\t.next = &DM_DEVICE_REF(test)->sibling_node, |
| 641 | \t}, |
| 642 | \t.sibling_node\t= { |
| 643 | \t\t.prev = &DM_DEVICE_REF(i2c)->sibling_node, |
| 644 | \t\t.next = &DM_DEVICE_REF(spl_test)->sibling_node, |
| 645 | \t}, |
| 646 | \t.seq_ = 2, |
| 647 | }; |
| 648 | |
| 649 | /* |
| 650 | * Node /spl-test index 3 |
| 651 | * driver sandbox_spl_test parent root_driver |
| 652 | */ |
| 653 | static struct dtd_sandbox_spl_test dtv_spl_test = { |
| 654 | \t.boolval\t\t= true, |
| 655 | \t.intval\t\t\t= 0x1, |
| 656 | }; |
| 657 | |
| 658 | DM_DEVICE_INST(spl_test) = { |
| 659 | \t.driver\t\t= DM_DRIVER_REF(sandbox_spl_test), |
| 660 | \t.name\t\t= "sandbox_spl_test", |
| 661 | \t.plat_\t\t= &dtv_spl_test, |
| 662 | \t.uclass\t\t= DM_UCLASS_REF(misc), |
| 663 | \t.uclass_node\t= { |
| 664 | \t\t.prev = &DM_UCLASS_REF(misc)->dev_head, |
| 665 | \t\t.next = &DM_DEVICE_REF(spl_test3)->uclass_node, |
| 666 | \t}, |
| 667 | \t.child_head\t= { |
| 668 | \t\t.prev = &DM_DEVICE_REF(spl_test)->child_head, |
| 669 | \t\t.next = &DM_DEVICE_REF(spl_test)->child_head, |
| 670 | \t}, |
| 671 | \t.sibling_node\t= { |
| 672 | \t\t.prev = &DM_DEVICE_REF(some_bus)->sibling_node, |
| 673 | \t\t.next = &DM_DEVICE_REF(spl_test3)->sibling_node, |
| 674 | \t}, |
| 675 | \t.seq_ = 0, |
| 676 | }; |
| 677 | |
| 678 | /* |
| 679 | * Node /spl-test3 index 4 |
| 680 | * driver sandbox_spl_test parent root_driver |
| 681 | */ |
| 682 | static struct dtd_sandbox_spl_test dtv_spl_test3 = { |
| 683 | \t.longbytearray\t\t= {0x90a0b0c, 0xd0e0f10}, |
| 684 | \t.stringarray\t\t= "one", |
| 685 | }; |
| 686 | |
| 687 | DM_DEVICE_INST(spl_test3) = { |
| 688 | \t.driver\t\t= DM_DRIVER_REF(sandbox_spl_test), |
| 689 | \t.name\t\t= "sandbox_spl_test", |
| 690 | \t.plat_\t\t= &dtv_spl_test3, |
| 691 | \t.uclass\t\t= DM_UCLASS_REF(misc), |
| 692 | \t.uclass_node\t= { |
| 693 | \t\t.prev = &DM_DEVICE_REF(spl_test)->uclass_node, |
| 694 | \t\t.next = &DM_UCLASS_REF(misc)->dev_head, |
| 695 | \t}, |
| 696 | \t.child_head\t= { |
| 697 | \t\t.prev = &DM_DEVICE_REF(spl_test3)->child_head, |
| 698 | \t\t.next = &DM_DEVICE_REF(spl_test3)->child_head, |
| 699 | \t}, |
| 700 | \t.sibling_node\t= { |
| 701 | \t\t.prev = &DM_DEVICE_REF(spl_test)->sibling_node, |
| 702 | \t\t.next = &DM_DEVICE_REF(root)->child_head, |
| 703 | \t}, |
| 704 | \t.seq_ = 1, |
| 705 | }; |
| 706 | |
| 707 | /* |
| 708 | * Node /some-bus/test index 5 |
| 709 | * driver denx_u_boot_fdt_test parent denx_u_boot_test_bus |
| 710 | */ |
| 711 | |
| 712 | #include <dm/test.h> |
| 713 | struct dm_test_pdata __attribute__ ((section (".priv_data"))) |
| 714 | \t_denx_u_boot_fdt_test_plat_test = { |
| 715 | \t.dtplat = { |
| 716 | \t\t.ping_add\t\t= 0x5, |
| 717 | \t\t.ping_expect\t\t= 0x5, |
Simon Glass | 94ba59e | 2021-03-26 16:17:26 +1300 | [diff] [blame] | 718 | \t\t.reg\t\t\t= {0x5}, |
Simon Glass | fea2f25 | 2021-02-03 06:01:21 -0700 | [diff] [blame] | 719 | \t}, |
| 720 | }; |
| 721 | #include <dm/test.h> |
| 722 | u8 _denx_u_boot_fdt_test_priv_test[sizeof(struct dm_test_priv)] |
| 723 | \t__attribute__ ((section (".priv_data"))); |
| 724 | #include <dm/test.h> |
| 725 | u8 _denx_u_boot_fdt_test_parent_plat_test[sizeof(struct dm_test_parent_plat)] |
| 726 | \t__attribute__ ((section (".priv_data"))); |
| 727 | #include <dm/test.h> |
| 728 | u8 _denx_u_boot_fdt_test_parent_priv_test[sizeof(struct dm_test_parent_data)] |
| 729 | \t__attribute__ ((section (".priv_data"))); |
| 730 | |
| 731 | DM_DEVICE_INST(test) = { |
| 732 | \t.driver\t\t= DM_DRIVER_REF(denx_u_boot_fdt_test), |
| 733 | \t.name\t\t= "denx_u_boot_fdt_test", |
| 734 | \t.plat_\t\t= &_denx_u_boot_fdt_test_plat_test, |
| 735 | \t.parent_plat_\t= _denx_u_boot_fdt_test_parent_plat_test, |
| 736 | \t.driver_data\t= DM_TEST_TYPE_FIRST, |
| 737 | \t.parent\t\t= DM_DEVICE_REF(some_bus), |
| 738 | \t.priv_\t\t= _denx_u_boot_fdt_test_priv_test, |
| 739 | \t.uclass\t\t= DM_UCLASS_REF(testfdt), |
| 740 | \t.parent_priv_\t= _denx_u_boot_fdt_test_parent_priv_test, |
| 741 | \t.uclass_node\t= { |
| 742 | \t\t.prev = &DM_UCLASS_REF(testfdt)->dev_head, |
| 743 | \t\t.next = &DM_DEVICE_REF(test0)->uclass_node, |
| 744 | \t}, |
| 745 | \t.child_head\t= { |
| 746 | \t\t.prev = &DM_DEVICE_REF(test)->child_head, |
| 747 | \t\t.next = &DM_DEVICE_REF(test)->child_head, |
| 748 | \t}, |
| 749 | \t.sibling_node\t= { |
| 750 | \t\t.prev = &DM_DEVICE_REF(some_bus)->child_head, |
| 751 | \t\t.next = &DM_DEVICE_REF(test0)->sibling_node, |
| 752 | \t}, |
| 753 | \t.seq_ = 1, |
| 754 | }; |
| 755 | |
| 756 | /* |
| 757 | * Node /some-bus/test0 index 6 |
| 758 | * driver denx_u_boot_fdt_test parent denx_u_boot_test_bus |
| 759 | */ |
| 760 | |
| 761 | #include <dm/test.h> |
| 762 | struct dm_test_pdata __attribute__ ((section (".priv_data"))) |
| 763 | \t_denx_u_boot_fdt_test_plat_test0 = { |
| 764 | \t.dtplat = { |
| 765 | \t}, |
| 766 | }; |
| 767 | #include <dm/test.h> |
| 768 | u8 _denx_u_boot_fdt_test_priv_test0[sizeof(struct dm_test_priv)] |
| 769 | \t__attribute__ ((section (".priv_data"))); |
| 770 | #include <dm/test.h> |
| 771 | u8 _denx_u_boot_fdt_test_parent_plat_test0[sizeof(struct dm_test_parent_plat)] |
| 772 | \t__attribute__ ((section (".priv_data"))); |
| 773 | #include <dm/test.h> |
| 774 | u8 _denx_u_boot_fdt_test_parent_priv_test0[sizeof(struct dm_test_parent_data)] |
| 775 | \t__attribute__ ((section (".priv_data"))); |
| 776 | |
| 777 | DM_DEVICE_INST(test0) = { |
| 778 | \t.driver\t\t= DM_DRIVER_REF(denx_u_boot_fdt_test), |
| 779 | \t.name\t\t= "denx_u_boot_fdt_test", |
| 780 | \t.plat_\t\t= &_denx_u_boot_fdt_test_plat_test0, |
| 781 | \t.parent_plat_\t= _denx_u_boot_fdt_test_parent_plat_test0, |
| 782 | \t.driver_data\t= DM_TEST_TYPE_SECOND, |
| 783 | \t.parent\t\t= DM_DEVICE_REF(some_bus), |
| 784 | \t.priv_\t\t= _denx_u_boot_fdt_test_priv_test0, |
| 785 | \t.uclass\t\t= DM_UCLASS_REF(testfdt), |
| 786 | \t.parent_priv_\t= _denx_u_boot_fdt_test_parent_priv_test0, |
| 787 | \t.uclass_node\t= { |
| 788 | \t\t.prev = &DM_DEVICE_REF(test)->uclass_node, |
| 789 | \t\t.next = &DM_UCLASS_REF(testfdt)->dev_head, |
| 790 | \t}, |
| 791 | \t.child_head\t= { |
| 792 | \t\t.prev = &DM_DEVICE_REF(test0)->child_head, |
| 793 | \t\t.next = &DM_DEVICE_REF(test0)->child_head, |
| 794 | \t}, |
| 795 | \t.sibling_node\t= { |
| 796 | \t\t.prev = &DM_DEVICE_REF(test)->sibling_node, |
| 797 | \t\t.next = &DM_DEVICE_REF(some_bus)->child_head, |
| 798 | \t}, |
| 799 | \t.seq_ = 2, |
| 800 | }; |
| 801 | |
| 802 | ''' |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 803 | |
| 804 | def test_simple(self): |
| 805 | """Test output from some simple nodes with various types of data""" |
| 806 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 807 | output = tools.get_output_filename('output') |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 808 | self.run_test(['struct'], dtb_file, output) |
| 809 | with open(output) as infile: |
| 810 | data = infile.read() |
| 811 | |
| 812 | self._check_strings(self.struct_text, data) |
| 813 | |
| 814 | self.run_test(['platdata'], dtb_file, output) |
| 815 | with open(output) as infile: |
| 816 | data = infile.read() |
| 817 | |
| 818 | self._check_strings(self.platdata_text, data) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 819 | |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 820 | self.run_test(['decl'], dtb_file, output) |
| 821 | with open(output) as infile: |
| 822 | data = infile.read() |
| 823 | |
| 824 | self._check_strings(self.decl_text, data) |
| 825 | |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 826 | # Try the 'all' command |
| 827 | self.run_test(['all'], dtb_file, output) |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 828 | data = tools.read_file(output, binary=False) |
Simon Glass | fea2f25 | 2021-02-03 06:01:21 -0700 | [diff] [blame] | 829 | self._check_strings( |
Simon Glass | 705b84b | 2021-04-27 08:19:48 +1200 | [diff] [blame] | 830 | self.decl_text + self.platdata_text + self.struct_text, data) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 831 | |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 832 | def test_driver_alias(self): |
| 833 | """Test output from a device tree file with a driver alias""" |
| 834 | dtb_file = get_dtb_file('dtoc_test_driver_alias.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 835 | output = tools.get_output_filename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 836 | self.run_test(['struct'], dtb_file, output) |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 837 | with open(output) as infile: |
| 838 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 839 | self._check_strings(HEADER + ''' |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 840 | struct dtd_sandbox_gpio { |
| 841 | \tconst char *\tgpio_bank_name; |
| 842 | \tbool\t\tgpio_controller; |
| 843 | \tfdt32_t\t\tsandbox_gpio_count; |
| 844 | }; |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 845 | ''', data) |
| 846 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 847 | self.run_test(['platdata'], dtb_file, output) |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 848 | with open(output) as infile: |
| 849 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 850 | self._check_strings(C_HEADER + ''' |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 851 | /* |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 852 | * driver_info declarations, ordered by 'struct driver_info' linker_list idx: |
| 853 | * |
| 854 | * idx driver_info driver |
| 855 | * --- -------------------- -------------------- |
| 856 | * 0: gpios_at_0 sandbox_gpio |
| 857 | * --- -------------------- -------------------- |
| 858 | */ |
| 859 | |
| 860 | /* |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 861 | * Node /gpios@0 index 0 |
| 862 | * driver sandbox_gpio parent None |
| 863 | */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 864 | static struct dtd_sandbox_gpio dtv_gpios_at_0 = { |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 865 | \t.gpio_bank_name\t\t= "a", |
| 866 | \t.gpio_controller\t= true, |
| 867 | \t.sandbox_gpio_count\t= 0x14, |
| 868 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 869 | U_BOOT_DRVINFO(gpios_at_0) = { |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 870 | \t.name\t\t= "sandbox_gpio", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 871 | \t.plat\t\t= &dtv_gpios_at_0, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 872 | \t.plat_size\t= sizeof(dtv_gpios_at_0), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 873 | \t.parent_idx\t= -1, |
Walter Lozano | e675d96 | 2020-07-03 08:07:17 -0300 | [diff] [blame] | 874 | }; |
| 875 | |
| 876 | ''', data) |
| 877 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 878 | def test_invalid_driver(self): |
| 879 | """Test output from a device tree file with an invalid driver""" |
| 880 | dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 881 | output = tools.get_output_filename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 882 | with test_util.capture_sys_output() as _: |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame] | 883 | dtb_platdata.run_steps( |
| 884 | ['struct'], dtb_file, False, output, [], None, False, |
| 885 | scan=copy_scan()) |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 886 | with open(output) as infile: |
| 887 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 888 | self._check_strings(HEADER + ''' |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 889 | struct dtd_invalid { |
| 890 | }; |
| 891 | ''', data) |
| 892 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 893 | with test_util.capture_sys_output() as _: |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame] | 894 | dtb_platdata.run_steps( |
| 895 | ['platdata'], dtb_file, False, output, [], None, False, |
| 896 | scan=copy_scan()) |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 897 | with open(output) as infile: |
| 898 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 899 | self._check_strings(C_HEADER + ''' |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 900 | /* |
| 901 | * driver_info declarations, ordered by 'struct driver_info' linker_list idx: |
| 902 | * |
| 903 | * idx driver_info driver |
| 904 | * --- -------------------- -------------------- |
| 905 | * 0: spl_test invalid |
| 906 | * --- -------------------- -------------------- |
| 907 | */ |
| 908 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 909 | /* Node /spl-test index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 910 | static struct dtd_invalid dtv_spl_test = { |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 911 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 912 | U_BOOT_DRVINFO(spl_test) = { |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 913 | \t.name\t\t= "invalid", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 914 | \t.plat\t\t= &dtv_spl_test, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 915 | \t.plat_size\t= sizeof(dtv_spl_test), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 916 | \t.parent_idx\t= -1, |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 917 | }; |
| 918 | |
| 919 | ''', data) |
| 920 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 921 | def test_phandle(self): |
| 922 | """Test output from a node containing a phandle reference""" |
| 923 | dtb_file = get_dtb_file('dtoc_test_phandle.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 924 | output = tools.get_output_filename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 925 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 926 | with open(output) as infile: |
| 927 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 928 | self._check_strings(HEADER + ''' |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 929 | struct dtd_source { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 930 | \tstruct phandle_2_arg clocks[4]; |
Simon Glass | e8cea0e | 2023-01-11 16:10:18 -0700 | [diff] [blame] | 931 | \tunsigned char phandle_name_offset[13]; |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 932 | }; |
| 933 | struct dtd_target { |
| 934 | \tfdt32_t\t\tintval; |
| 935 | }; |
| 936 | ''', data) |
| 937 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 938 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 939 | with open(output) as infile: |
| 940 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 941 | self._check_strings(C_HEADER + ''' |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 942 | /* |
| 943 | * driver_info declarations, ordered by 'struct driver_info' linker_list idx: |
| 944 | * |
| 945 | * idx driver_info driver |
| 946 | * --- -------------------- -------------------- |
| 947 | * 0: phandle2_target target |
| 948 | * 1: phandle3_target target |
| 949 | * 2: phandle_source source |
| 950 | * 3: phandle_source2 source |
| 951 | * 4: phandle_target target |
| 952 | * --- -------------------- -------------------- |
| 953 | */ |
| 954 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 955 | /* Node /phandle2-target index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 956 | static struct dtd_target dtv_phandle2_target = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 957 | \t.intval\t\t\t= 0x1, |
| 958 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 959 | U_BOOT_DRVINFO(phandle2_target) = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 960 | \t.name\t\t= "target", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 961 | \t.plat\t\t= &dtv_phandle2_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 962 | \t.plat_size\t= sizeof(dtv_phandle2_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 963 | \t.parent_idx\t= -1, |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 964 | }; |
| 965 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 966 | /* Node /phandle3-target index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 967 | static struct dtd_target dtv_phandle3_target = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 968 | \t.intval\t\t\t= 0x2, |
| 969 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 970 | U_BOOT_DRVINFO(phandle3_target) = { |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 971 | \t.name\t\t= "target", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 972 | \t.plat\t\t= &dtv_phandle3_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 973 | \t.plat_size\t= sizeof(dtv_phandle3_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 974 | \t.parent_idx\t= -1, |
Simon Glass | 3deeb47 | 2017-08-29 14:15:59 -0600 | [diff] [blame] | 975 | }; |
| 976 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 977 | /* Node /phandle-source index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 978 | static struct dtd_source dtv_phandle_source = { |
Simon Glass | d0cd075 | 2017-08-29 14:15:57 -0600 | [diff] [blame] | 979 | \t.clocks\t\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 980 | \t\t\t{4, {}}, |
| 981 | \t\t\t{0, {11}}, |
| 982 | \t\t\t{1, {12, 13}}, |
| 983 | \t\t\t{4, {}},}, |
Simon Glass | e8cea0e | 2023-01-11 16:10:18 -0700 | [diff] [blame] | 984 | \t.phandle_name_offset = {0x0, 0x0, 0x0, 0x3, 0x66, 0x72, 0x65, 0x64, |
| 985 | \t\t0x0, 0x0, 0x0, 0x0, 0x7b}, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 986 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 987 | U_BOOT_DRVINFO(phandle_source) = { |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 988 | \t.name\t\t= "source", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 989 | \t.plat\t\t= &dtv_phandle_source, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 990 | \t.plat_size\t= sizeof(dtv_phandle_source), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 991 | \t.parent_idx\t= -1, |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 992 | }; |
| 993 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 994 | /* Node /phandle-source2 index 3 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 995 | static struct dtd_source dtv_phandle_source2 = { |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 996 | \t.clocks\t\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 997 | \t\t\t{4, {}},}, |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 998 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 999 | U_BOOT_DRVINFO(phandle_source2) = { |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 1000 | \t.name\t\t= "source", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1001 | \t.plat\t\t= &dtv_phandle_source2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1002 | \t.plat_size\t= sizeof(dtv_phandle_source2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1003 | \t.parent_idx\t= -1, |
Simon Glass | 609e2b1 | 2018-07-06 10:27:31 -0600 | [diff] [blame] | 1004 | }; |
| 1005 | |
Simon Glass | 16382ce | 2020-12-28 20:35:04 -0700 | [diff] [blame] | 1006 | /* Node /phandle-target index 4 */ |
| 1007 | static struct dtd_target dtv_phandle_target = { |
| 1008 | \t.intval\t\t\t= 0x0, |
| 1009 | }; |
| 1010 | U_BOOT_DRVINFO(phandle_target) = { |
| 1011 | \t.name\t\t= "target", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1012 | \t.plat\t\t= &dtv_phandle_target, |
Simon Glass | 16382ce | 2020-12-28 20:35:04 -0700 | [diff] [blame] | 1013 | \t.plat_size\t= sizeof(dtv_phandle_target), |
| 1014 | \t.parent_idx\t= -1, |
| 1015 | }; |
| 1016 | |
Simon Glass | 9d2eb92 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 1017 | ''', data) |
| 1018 | |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1019 | def test_phandle_single(self): |
| 1020 | """Test output from a node containing a phandle reference""" |
| 1021 | dtb_file = get_dtb_file('dtoc_test_phandle_single.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1022 | output = tools.get_output_filename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1023 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1024 | with open(output) as infile: |
| 1025 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1026 | self._check_strings(HEADER + ''' |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1027 | struct dtd_source { |
| 1028 | \tstruct phandle_0_arg clocks[1]; |
| 1029 | }; |
| 1030 | struct dtd_target { |
| 1031 | \tfdt32_t\t\tintval; |
| 1032 | }; |
| 1033 | ''', data) |
| 1034 | |
| 1035 | def test_phandle_reorder(self): |
| 1036 | """Test that phandle targets are generated before their references""" |
| 1037 | dtb_file = get_dtb_file('dtoc_test_phandle_reorder.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1038 | output = tools.get_output_filename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1039 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1040 | with open(output) as infile: |
| 1041 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1042 | self._check_strings(C_HEADER + ''' |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1043 | /* |
| 1044 | * driver_info declarations, ordered by 'struct driver_info' linker_list idx: |
| 1045 | * |
| 1046 | * idx driver_info driver |
| 1047 | * --- -------------------- -------------------- |
| 1048 | * 0: phandle_source2 source |
| 1049 | * 1: phandle_target target |
| 1050 | * --- -------------------- -------------------- |
| 1051 | */ |
| 1052 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1053 | /* Node /phandle-source2 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1054 | static struct dtd_source dtv_phandle_source2 = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1055 | \t.clocks\t\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 1056 | \t\t\t{1, {}},}, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1057 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1058 | U_BOOT_DRVINFO(phandle_source2) = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1059 | \t.name\t\t= "source", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1060 | \t.plat\t\t= &dtv_phandle_source2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1061 | \t.plat_size\t= sizeof(dtv_phandle_source2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1062 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1063 | }; |
| 1064 | |
Simon Glass | 16382ce | 2020-12-28 20:35:04 -0700 | [diff] [blame] | 1065 | /* Node /phandle-target index 1 */ |
| 1066 | static struct dtd_target dtv_phandle_target = { |
| 1067 | }; |
| 1068 | U_BOOT_DRVINFO(phandle_target) = { |
| 1069 | \t.name\t\t= "target", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1070 | \t.plat\t\t= &dtv_phandle_target, |
Simon Glass | 16382ce | 2020-12-28 20:35:04 -0700 | [diff] [blame] | 1071 | \t.plat_size\t= sizeof(dtv_phandle_target), |
| 1072 | \t.parent_idx\t= -1, |
| 1073 | }; |
| 1074 | |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1075 | ''', data) |
| 1076 | |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1077 | def test_phandle_cd_gpio(self): |
| 1078 | """Test that phandle targets are generated when unsing cd-gpios""" |
| 1079 | dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1080 | output = tools.get_output_filename('output') |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame] | 1081 | dtb_platdata.run_steps( |
| 1082 | ['platdata'], dtb_file, False, output, [], None, False, |
| 1083 | warning_disabled=True, scan=copy_scan()) |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1084 | with open(output) as infile: |
| 1085 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1086 | self._check_strings(C_HEADER + ''' |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1087 | /* |
| 1088 | * driver_info declarations, ordered by 'struct driver_info' linker_list idx: |
| 1089 | * |
| 1090 | * idx driver_info driver |
| 1091 | * --- -------------------- -------------------- |
| 1092 | * 0: phandle2_target target |
| 1093 | * 1: phandle3_target target |
| 1094 | * 2: phandle_source source |
| 1095 | * 3: phandle_source2 source |
| 1096 | * 4: phandle_target target |
| 1097 | * --- -------------------- -------------------- |
| 1098 | */ |
| 1099 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1100 | /* Node /phandle2-target index 0 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1101 | static struct dtd_target dtv_phandle2_target = { |
| 1102 | \t.intval\t\t\t= 0x1, |
| 1103 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1104 | U_BOOT_DRVINFO(phandle2_target) = { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1105 | \t.name\t\t= "target", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1106 | \t.plat\t\t= &dtv_phandle2_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1107 | \t.plat_size\t= sizeof(dtv_phandle2_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1108 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1109 | }; |
| 1110 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1111 | /* Node /phandle3-target index 1 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1112 | static struct dtd_target dtv_phandle3_target = { |
| 1113 | \t.intval\t\t\t= 0x2, |
| 1114 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1115 | U_BOOT_DRVINFO(phandle3_target) = { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1116 | \t.name\t\t= "target", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1117 | \t.plat\t\t= &dtv_phandle3_target, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1118 | \t.plat_size\t= sizeof(dtv_phandle3_target), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1119 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1120 | }; |
| 1121 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1122 | /* Node /phandle-source index 2 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1123 | static struct dtd_source dtv_phandle_source = { |
| 1124 | \t.cd_gpios\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 1125 | \t\t\t{4, {}}, |
| 1126 | \t\t\t{0, {11}}, |
| 1127 | \t\t\t{1, {12, 13}}, |
| 1128 | \t\t\t{4, {}},}, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1129 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1130 | U_BOOT_DRVINFO(phandle_source) = { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1131 | \t.name\t\t= "source", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1132 | \t.plat\t\t= &dtv_phandle_source, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1133 | \t.plat_size\t= sizeof(dtv_phandle_source), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1134 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1135 | }; |
| 1136 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1137 | /* Node /phandle-source2 index 3 */ |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1138 | static struct dtd_source dtv_phandle_source2 = { |
| 1139 | \t.cd_gpios\t\t= { |
Simon Glass | 5792f4b | 2020-10-03 11:31:40 -0600 | [diff] [blame] | 1140 | \t\t\t{4, {}},}, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1141 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1142 | U_BOOT_DRVINFO(phandle_source2) = { |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1143 | \t.name\t\t= "source", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1144 | \t.plat\t\t= &dtv_phandle_source2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1145 | \t.plat_size\t= sizeof(dtv_phandle_source2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1146 | \t.parent_idx\t= -1, |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1147 | }; |
| 1148 | |
Simon Glass | 16382ce | 2020-12-28 20:35:04 -0700 | [diff] [blame] | 1149 | /* Node /phandle-target index 4 */ |
| 1150 | static struct dtd_target dtv_phandle_target = { |
| 1151 | \t.intval\t\t\t= 0x0, |
| 1152 | }; |
| 1153 | U_BOOT_DRVINFO(phandle_target) = { |
| 1154 | \t.name\t\t= "target", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1155 | \t.plat\t\t= &dtv_phandle_target, |
Simon Glass | 16382ce | 2020-12-28 20:35:04 -0700 | [diff] [blame] | 1156 | \t.plat_size\t= sizeof(dtv_phandle_target), |
| 1157 | \t.parent_idx\t= -1, |
| 1158 | }; |
| 1159 | |
Walter Lozano | 5541fc0 | 2020-06-25 01:10:17 -0300 | [diff] [blame] | 1160 | ''', data) |
| 1161 | |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1162 | def test_phandle_bad(self): |
| 1163 | """Test a node containing an invalid phandle fails""" |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 1164 | dtb_file = get_dtb_file('dtoc_test_phandle_bad.dts', |
| 1165 | capture_stderr=True) |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1166 | output = tools.get_output_filename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1167 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1168 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1169 | self.assertIn("Cannot parse 'clocks' in node 'phandle-source'", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1170 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1171 | |
| 1172 | def test_phandle_bad2(self): |
| 1173 | """Test a phandle target missing its #*-cells property""" |
Simon Glass | 0415002 | 2018-10-01 21:12:43 -0600 | [diff] [blame] | 1174 | dtb_file = get_dtb_file('dtoc_test_phandle_bad2.dts', |
| 1175 | capture_stderr=True) |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1176 | output = tools.get_output_filename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1177 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1178 | self.run_test(['struct'], dtb_file, output) |
Walter Lozano | 179f0b6 | 2020-06-25 01:10:16 -0300 | [diff] [blame] | 1179 | self.assertIn("Node 'phandle-target' has no cells property", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1180 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1181 | |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1182 | def test_addresses64(self): |
| 1183 | """Test output from a node with a 'reg' property with na=2, ns=2""" |
| 1184 | dtb_file = get_dtb_file('dtoc_test_addr64.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1185 | output = tools.get_output_filename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1186 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1187 | with open(output) as infile: |
| 1188 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1189 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1190 | struct dtd_test1 { |
| 1191 | \tfdt64_t\t\treg[2]; |
| 1192 | }; |
| 1193 | struct dtd_test2 { |
| 1194 | \tfdt64_t\t\treg[2]; |
| 1195 | }; |
| 1196 | struct dtd_test3 { |
| 1197 | \tfdt64_t\t\treg[4]; |
| 1198 | }; |
| 1199 | ''', data) |
| 1200 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1201 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1202 | with open(output) as infile: |
| 1203 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1204 | self._check_strings(C_HEADER + ''' |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1205 | /* |
| 1206 | * driver_info declarations, ordered by 'struct driver_info' linker_list idx: |
| 1207 | * |
| 1208 | * idx driver_info driver |
| 1209 | * --- -------------------- -------------------- |
| 1210 | * 0: test1 test1 |
| 1211 | * 1: test2 test2 |
| 1212 | * 2: test3 test3 |
| 1213 | * --- -------------------- -------------------- |
| 1214 | */ |
| 1215 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1216 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1217 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1218 | \t.reg\t\t\t= {0x1234, 0x5678}, |
| 1219 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1220 | U_BOOT_DRVINFO(test1) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1221 | \t.name\t\t= "test1", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1222 | \t.plat\t\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1223 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1224 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1225 | }; |
| 1226 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1227 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1228 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1229 | \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654}, |
| 1230 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1231 | U_BOOT_DRVINFO(test2) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1232 | \t.name\t\t= "test2", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1233 | \t.plat\t\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1234 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1235 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1236 | }; |
| 1237 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1238 | /* Node /test3 index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1239 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1240 | \t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3}, |
| 1241 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1242 | U_BOOT_DRVINFO(test3) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1243 | \t.name\t\t= "test3", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1244 | \t.plat\t\t= &dtv_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1245 | \t.plat_size\t= sizeof(dtv_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1246 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1247 | }; |
| 1248 | |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 1249 | ''', data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1250 | |
| 1251 | def test_addresses32(self): |
| 1252 | """Test output from a node with a 'reg' property with na=1, ns=1""" |
| 1253 | dtb_file = get_dtb_file('dtoc_test_addr32.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1254 | output = tools.get_output_filename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1255 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1256 | with open(output) as infile: |
| 1257 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1258 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1259 | struct dtd_test1 { |
| 1260 | \tfdt32_t\t\treg[2]; |
| 1261 | }; |
| 1262 | struct dtd_test2 { |
| 1263 | \tfdt32_t\t\treg[4]; |
| 1264 | }; |
| 1265 | ''', data) |
| 1266 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1267 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1268 | with open(output) as infile: |
| 1269 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1270 | self._check_strings(C_HEADER + ''' |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1271 | /* |
| 1272 | * driver_info declarations, ordered by 'struct driver_info' linker_list idx: |
| 1273 | * |
| 1274 | * idx driver_info driver |
| 1275 | * --- -------------------- -------------------- |
| 1276 | * 0: test1 test1 |
| 1277 | * 1: test2 test2 |
| 1278 | * --- -------------------- -------------------- |
| 1279 | */ |
| 1280 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1281 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1282 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1283 | \t.reg\t\t\t= {0x1234, 0x5678}, |
| 1284 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1285 | U_BOOT_DRVINFO(test1) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1286 | \t.name\t\t= "test1", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1287 | \t.plat\t\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1288 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1289 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1290 | }; |
| 1291 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1292 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1293 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1294 | \t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3}, |
| 1295 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1296 | U_BOOT_DRVINFO(test2) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1297 | \t.name\t\t= "test2", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1298 | \t.plat\t\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1299 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1300 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1301 | }; |
| 1302 | |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 1303 | ''', data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1304 | |
| 1305 | def test_addresses64_32(self): |
| 1306 | """Test output from a node with a 'reg' property with na=2, ns=1""" |
| 1307 | dtb_file = get_dtb_file('dtoc_test_addr64_32.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1308 | output = tools.get_output_filename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1309 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1310 | with open(output) as infile: |
| 1311 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1312 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1313 | struct dtd_test1 { |
| 1314 | \tfdt64_t\t\treg[2]; |
| 1315 | }; |
| 1316 | struct dtd_test2 { |
| 1317 | \tfdt64_t\t\treg[2]; |
| 1318 | }; |
| 1319 | struct dtd_test3 { |
| 1320 | \tfdt64_t\t\treg[4]; |
| 1321 | }; |
| 1322 | ''', data) |
| 1323 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1324 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1325 | with open(output) as infile: |
| 1326 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1327 | self._check_strings(C_HEADER + ''' |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1328 | /* |
| 1329 | * driver_info declarations, ordered by 'struct driver_info' linker_list idx: |
| 1330 | * |
| 1331 | * idx driver_info driver |
| 1332 | * --- -------------------- -------------------- |
| 1333 | * 0: test1 test1 |
| 1334 | * 1: test2 test2 |
| 1335 | * 2: test3 test3 |
| 1336 | * --- -------------------- -------------------- |
| 1337 | */ |
| 1338 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1339 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1340 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1341 | \t.reg\t\t\t= {0x123400000000, 0x5678}, |
| 1342 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1343 | U_BOOT_DRVINFO(test1) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1344 | \t.name\t\t= "test1", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1345 | \t.plat\t\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1346 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1347 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1348 | }; |
| 1349 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1350 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1351 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1352 | \t.reg\t\t\t= {0x1234567890123456, 0x98765432}, |
| 1353 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1354 | U_BOOT_DRVINFO(test2) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1355 | \t.name\t\t= "test2", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1356 | \t.plat\t\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1357 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1358 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1359 | }; |
| 1360 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1361 | /* Node /test3 index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1362 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1363 | \t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3}, |
| 1364 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1365 | U_BOOT_DRVINFO(test3) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1366 | \t.name\t\t= "test3", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1367 | \t.plat\t\t= &dtv_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1368 | \t.plat_size\t= sizeof(dtv_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1369 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1370 | }; |
| 1371 | |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 1372 | ''', data) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1373 | |
| 1374 | def test_addresses32_64(self): |
| 1375 | """Test output from a node with a 'reg' property with na=1, ns=2""" |
| 1376 | dtb_file = get_dtb_file('dtoc_test_addr32_64.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1377 | output = tools.get_output_filename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1378 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1379 | with open(output) as infile: |
| 1380 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1381 | self._check_strings(HEADER + ''' |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1382 | struct dtd_test1 { |
| 1383 | \tfdt64_t\t\treg[2]; |
| 1384 | }; |
| 1385 | struct dtd_test2 { |
| 1386 | \tfdt64_t\t\treg[2]; |
| 1387 | }; |
| 1388 | struct dtd_test3 { |
| 1389 | \tfdt64_t\t\treg[4]; |
| 1390 | }; |
| 1391 | ''', data) |
| 1392 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1393 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1394 | with open(output) as infile: |
| 1395 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1396 | self._check_strings(C_HEADER + ''' |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1397 | /* |
| 1398 | * driver_info declarations, ordered by 'struct driver_info' linker_list idx: |
| 1399 | * |
| 1400 | * idx driver_info driver |
| 1401 | * --- -------------------- -------------------- |
| 1402 | * 0: test1 test1 |
| 1403 | * 1: test2 test2 |
| 1404 | * 2: test3 test3 |
| 1405 | * --- -------------------- -------------------- |
| 1406 | */ |
| 1407 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1408 | /* Node /test1 index 0 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1409 | static struct dtd_test1 dtv_test1 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1410 | \t.reg\t\t\t= {0x1234, 0x567800000000}, |
| 1411 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1412 | U_BOOT_DRVINFO(test1) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1413 | \t.name\t\t= "test1", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1414 | \t.plat\t\t= &dtv_test1, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1415 | \t.plat_size\t= sizeof(dtv_test1), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1416 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1417 | }; |
| 1418 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1419 | /* Node /test2 index 1 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1420 | static struct dtd_test2 dtv_test2 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1421 | \t.reg\t\t\t= {0x12345678, 0x9876543210987654}, |
| 1422 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1423 | U_BOOT_DRVINFO(test2) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1424 | \t.name\t\t= "test2", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1425 | \t.plat\t\t= &dtv_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1426 | \t.plat_size\t= sizeof(dtv_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1427 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1428 | }; |
| 1429 | |
Simon Glass | 192f813 | 2020-10-03 11:31:25 -0600 | [diff] [blame] | 1430 | /* Node /test3 index 2 */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1431 | static struct dtd_test3 dtv_test3 = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1432 | \t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3}, |
| 1433 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1434 | U_BOOT_DRVINFO(test3) = { |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1435 | \t.name\t\t= "test3", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1436 | \t.plat\t\t= &dtv_test3, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1437 | \t.plat_size\t= sizeof(dtv_test3), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1438 | \t.parent_idx\t= -1, |
Simon Glass | 1b1fe41 | 2017-08-29 14:15:50 -0600 | [diff] [blame] | 1439 | }; |
| 1440 | |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 1441 | ''', data) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1442 | |
| 1443 | def test_bad_reg(self): |
| 1444 | """Test that a reg property with an invalid type generates an error""" |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 1445 | # Capture stderr since dtc will emit warnings for this file |
| 1446 | dtb_file = get_dtb_file('dtoc_test_bad_reg.dts', capture_stderr=True) |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1447 | output = tools.get_output_filename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1448 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1449 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1450 | self.assertIn("Node 'spl-test' reg property is not an int", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1451 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1452 | |
| 1453 | def test_bad_reg2(self): |
| 1454 | """Test that a reg property with an invalid cell count is detected""" |
Simon Glass | 3bce93d | 2018-07-06 10:27:37 -0600 | [diff] [blame] | 1455 | # Capture stderr since dtc will emit warnings for this file |
| 1456 | dtb_file = get_dtb_file('dtoc_test_bad_reg2.dts', capture_stderr=True) |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1457 | output = tools.get_output_filename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1458 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1459 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1460 | self.assertIn( |
Simon Glass | 4415dc1 | 2021-03-26 16:17:27 +1300 | [diff] [blame] | 1461 | "Node 'spl-test' (parent '/') reg property has 3 cells which is not a multiple of na + ns = 1 + 1)", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1462 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1463 | |
| 1464 | def test_add_prop(self): |
| 1465 | """Test that a subequent node can add a new property to a struct""" |
| 1466 | dtb_file = get_dtb_file('dtoc_test_add_prop.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1467 | output = tools.get_output_filename('output') |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1468 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1469 | with open(output) as infile: |
| 1470 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1471 | self._check_strings(HEADER + ''' |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1472 | struct dtd_sandbox_spl_test { |
| 1473 | \tfdt32_t\t\tintarray; |
| 1474 | \tfdt32_t\t\tintval; |
| 1475 | }; |
| 1476 | ''', data) |
| 1477 | |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1478 | self.run_test(['platdata'], dtb_file, output) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1479 | with open(output) as infile: |
| 1480 | data = infile.read() |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1481 | self._check_strings(C_HEADER + ''' |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 1482 | /* |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1483 | * driver_info declarations, ordered by 'struct driver_info' linker_list idx: |
| 1484 | * |
| 1485 | * idx driver_info driver |
| 1486 | * --- -------------------- -------------------- |
| 1487 | * 0: spl_test sandbox_spl_test |
| 1488 | * 1: spl_test2 sandbox_spl_test |
| 1489 | * --- -------------------- -------------------- |
| 1490 | */ |
| 1491 | |
| 1492 | /* |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 1493 | * Node /spl-test index 0 |
| 1494 | * driver sandbox_spl_test parent None |
| 1495 | */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1496 | static struct dtd_sandbox_spl_test dtv_spl_test = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1497 | \t.intval\t\t\t= 0x1, |
| 1498 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1499 | U_BOOT_DRVINFO(spl_test) = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1500 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1501 | \t.plat\t\t= &dtv_spl_test, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1502 | \t.plat_size\t= sizeof(dtv_spl_test), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1503 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1504 | }; |
| 1505 | |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 1506 | /* |
| 1507 | * Node /spl-test2 index 1 |
| 1508 | * driver sandbox_spl_test parent None |
| 1509 | */ |
Walter Lozano | dc5b437 | 2020-06-25 01:10:13 -0300 | [diff] [blame] | 1510 | static struct dtd_sandbox_spl_test dtv_spl_test2 = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1511 | \t.intarray\t\t= 0x5, |
| 1512 | }; |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 1513 | U_BOOT_DRVINFO(spl_test2) = { |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1514 | \t.name\t\t= "sandbox_spl_test", |
Simon Glass | e211908 | 2021-02-03 06:01:19 -0700 | [diff] [blame] | 1515 | \t.plat\t\t= &dtv_spl_test2, |
Simon Glass | 39edb95 | 2020-12-03 16:55:19 -0700 | [diff] [blame] | 1516 | \t.plat_size\t= sizeof(dtv_spl_test2), |
Simon Glass | 36b15e2 | 2020-10-03 11:31:35 -0600 | [diff] [blame] | 1517 | \t.parent_idx\t= -1, |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1518 | }; |
| 1519 | |
Simon Glass | 2500de2 | 2020-12-28 20:35:05 -0700 | [diff] [blame] | 1520 | ''', data) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1521 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1522 | def test_stdout(self): |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1523 | """Test output to stdout""" |
| 1524 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 1525 | with test_util.capture_sys_output() as (stdout, _): |
Simon Glass | 6ca0c7a | 2020-12-28 20:34:48 -0700 | [diff] [blame] | 1526 | self.run_test(['struct'], dtb_file, None) |
Simon Glass | 07ee48e | 2020-12-28 20:34:49 -0700 | [diff] [blame] | 1527 | self._check_strings(self.struct_text, stdout.getvalue()) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1528 | |
Simon Glass | c3a310a8 | 2020-12-28 20:34:51 -0700 | [diff] [blame] | 1529 | def test_multi_to_file(self): |
| 1530 | """Test output of multiple pieces to a single file""" |
| 1531 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1532 | output = tools.get_output_filename('output') |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 1533 | self.run_test(['all'], dtb_file, output) |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1534 | data = tools.read_file(output, binary=False) |
Simon Glass | fea2f25 | 2021-02-03 06:01:21 -0700 | [diff] [blame] | 1535 | self._check_strings( |
Simon Glass | 705b84b | 2021-04-27 08:19:48 +1200 | [diff] [blame] | 1536 | self.decl_text + self.platdata_text + self.struct_text, data) |
Simon Glass | c3a310a8 | 2020-12-28 20:34:51 -0700 | [diff] [blame] | 1537 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1538 | def test_no_command(self): |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1539 | """Test running dtoc without a command""" |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1540 | with self.assertRaises(ValueError) as exc: |
Walter Lozano | a324e41 | 2020-06-25 01:10:08 -0300 | [diff] [blame] | 1541 | self.run_test([], '', '') |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1542 | self.assertIn("Please specify a command: struct, platdata", |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1543 | str(exc.exception)) |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1544 | |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1545 | def test_bad_command(self): |
Simon Glass | 961c1ce | 2018-07-06 10:27:35 -0600 | [diff] [blame] | 1546 | """Test running dtoc with an invalid command""" |
| 1547 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1548 | output = tools.get_output_filename('output') |
Simon Glass | a60cabd | 2020-12-28 20:34:47 -0700 | [diff] [blame] | 1549 | with self.assertRaises(ValueError) as exc: |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 1550 | self.run_test(['invalid-cmd'], dtb_file, output) |
| 1551 | self.assertIn( |
Simon Glass | db2b9ca | 2021-03-25 06:40:51 +1300 | [diff] [blame] | 1552 | "Unknown command 'invalid-cmd': (use: decl, platdata, struct)", |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 1553 | str(exc.exception)) |
Walter Lozano | d82062b | 2020-07-28 19:06:23 -0300 | [diff] [blame] | 1554 | |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 1555 | def test_output_conflict(self): |
| 1556 | """Test a conflict between and output dirs and output file""" |
| 1557 | with self.assertRaises(ValueError) as exc: |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame] | 1558 | dtb_platdata.run_steps( |
| 1559 | ['all'], None, False, 'out', ['cdir'], None, False, |
| 1560 | warning_disabled=True, scan=copy_scan()) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 1561 | self.assertIn("Must specify either output or output_dirs, not both", |
| 1562 | str(exc.exception)) |
| 1563 | |
Simon Glass | 705b84b | 2021-04-27 08:19:48 +1200 | [diff] [blame] | 1564 | def check_output_dirs(self, instantiate): |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 1565 | # Remove the directory so that files from other tests are not there |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1566 | tools._remove_output_dir() |
| 1567 | tools.prepare_output_dir(None) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 1568 | |
| 1569 | # This should create the .dts and .dtb in the output directory |
| 1570 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1571 | outdir = tools.get_output_dir() |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 1572 | fnames = glob.glob(outdir + '/*') |
| 1573 | self.assertEqual(2, len(fnames)) |
| 1574 | |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame] | 1575 | dtb_platdata.run_steps( |
Simon Glass | 705b84b | 2021-04-27 08:19:48 +1200 | [diff] [blame] | 1576 | ['all'], dtb_file, False, None, [outdir], None, instantiate, |
Simon Glass | 3809ad9 | 2021-02-03 06:01:12 -0700 | [diff] [blame] | 1577 | warning_disabled=True, scan=copy_scan()) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 1578 | fnames = glob.glob(outdir + '/*') |
Simon Glass | 705b84b | 2021-04-27 08:19:48 +1200 | [diff] [blame] | 1579 | return fnames |
| 1580 | |
| 1581 | def test_output_dirs(self): |
| 1582 | """Test outputting files to a directory""" |
| 1583 | fnames = self.check_output_dirs(False) |
| 1584 | self.assertEqual(5, len(fnames)) |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 1585 | |
| 1586 | leafs = set(os.path.basename(fname) for fname in fnames) |
| 1587 | self.assertEqual( |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 1588 | {'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb', |
Simon Glass | 705b84b | 2021-04-27 08:19:48 +1200 | [diff] [blame] | 1589 | 'dt-decl.h'}, |
| 1590 | leafs) |
| 1591 | |
| 1592 | def test_output_dirs_inst(self): |
| 1593 | """Test outputting files to a directory with instantiation""" |
| 1594 | fnames = self.check_output_dirs(True) |
| 1595 | self.assertEqual(6, len(fnames)) |
| 1596 | |
| 1597 | leafs = set(os.path.basename(fname) for fname in fnames) |
| 1598 | self.assertEqual( |
| 1599 | {'dt-structs-gen.h', 'source.dts', 'source.dtb', |
Simon Glass | fea2f25 | 2021-02-03 06:01:21 -0700 | [diff] [blame] | 1600 | 'dt-uclass.c', 'dt-decl.h', 'dt-device.c'}, |
Simon Glass | 4e8e846 | 2020-12-28 20:34:52 -0700 | [diff] [blame] | 1601 | leafs) |
Simon Glass | 047a480 | 2021-02-03 06:01:00 -0700 | [diff] [blame] | 1602 | |
| 1603 | def setup_process_test(self): |
| 1604 | """Set up a test of process_nodes() |
| 1605 | |
| 1606 | This uses saved_scan but returns a deep copy of it, so it is safe to |
| 1607 | modify it in these tests |
| 1608 | |
| 1609 | Returns: |
| 1610 | tuple: |
| 1611 | DtbPlatdata: object to test |
| 1612 | Scanner: scanner to use |
| 1613 | """ |
| 1614 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1615 | output = tools.get_output_filename('output') |
Simon Glass | 047a480 | 2021-02-03 06:01:00 -0700 | [diff] [blame] | 1616 | |
| 1617 | # Take a copy before messing with it |
Simon Glass | c14fd0c | 2021-02-03 06:01:11 -0700 | [diff] [blame] | 1618 | scan = copy_scan() |
Simon Glass | 047a480 | 2021-02-03 06:01:00 -0700 | [diff] [blame] | 1619 | plat = dtb_platdata.DtbPlatdata(scan, dtb_file, False) |
| 1620 | plat.scan_dtb() |
Simon Glass | c14fd0c | 2021-02-03 06:01:11 -0700 | [diff] [blame] | 1621 | plat.scan_tree(False) |
Simon Glass | 047a480 | 2021-02-03 06:01:00 -0700 | [diff] [blame] | 1622 | plat.prepare_nodes() |
| 1623 | return plat, scan |
| 1624 | |
| 1625 | def test_process_nodes(self): |
| 1626 | """Test processing nodes to add various info""" |
| 1627 | plat, scan = self.setup_process_test() |
| 1628 | plat.process_nodes(True) |
| 1629 | |
| 1630 | i2c_node = plat._fdt.GetNode('/i2c@0') |
| 1631 | pmic_node = plat._fdt.GetNode('/i2c@0/pmic@9') |
| 1632 | pmic = scan._drivers['sandbox_pmic'] |
| 1633 | i2c = scan._drivers['sandbox_i2c'] |
| 1634 | self.assertEqual('DM_DEVICE_REF(pmic_at_9)', pmic_node.dev_ref) |
| 1635 | self.assertEqual(pmic, pmic_node.driver) |
| 1636 | self.assertEqual(i2c_node, pmic_node.parent) |
| 1637 | self.assertEqual(i2c, pmic_node.parent_driver) |
| 1638 | |
| 1639 | # The pmic is the only child |
| 1640 | self.assertEqual(pmic_node.parent_seq, 0) |
| 1641 | self.assertEqual([pmic_node], i2c_node.child_devs) |
| 1642 | |
| 1643 | # Start and end of the list should be the child_head |
| 1644 | ref = '&DM_DEVICE_REF(i2c_at_0)->child_head' |
| 1645 | self.assertEqual( |
| 1646 | {-1: ref, 0: '&DM_DEVICE_REF(pmic_at_9)->sibling_node', 1: ref}, |
| 1647 | i2c_node.child_refs) |
| 1648 | |
| 1649 | def test_process_nodes_bad_parent(self): |
| 1650 | # Pretend that i2c has a parent (the pmic) and delete that driver |
| 1651 | plat, scan = self.setup_process_test() |
| 1652 | |
| 1653 | i2c_node = plat._fdt.GetNode('/i2c@0') |
| 1654 | pmic_node = plat._fdt.GetNode('/i2c@0/pmic@9') |
| 1655 | del scan._drivers['sandbox_pmic'] |
| 1656 | i2c_node.parent = pmic_node |
| 1657 | |
| 1658 | # Process twice, the second time to generate an exception |
| 1659 | plat.process_nodes(False) |
| 1660 | with self.assertRaises(ValueError) as exc: |
| 1661 | plat.process_nodes(True) |
| 1662 | self.assertIn( |
| 1663 | "Cannot parse/find parent driver 'sandbox_pmic' for 'sandbox_i2c", |
| 1664 | str(exc.exception)) |
| 1665 | |
| 1666 | def test_process_nodes_bad_node(self): |
| 1667 | plat, scan = self.setup_process_test() |
| 1668 | |
| 1669 | # Now remove the pmic driver |
| 1670 | del scan._drivers['sandbox_pmic'] |
| 1671 | |
| 1672 | # Process twice, the second time to generate an exception |
| 1673 | plat.process_nodes(False) |
| 1674 | with self.assertRaises(ValueError) as exc: |
| 1675 | plat.process_nodes(True) |
| 1676 | self.assertIn("Cannot parse/find driver for 'sandbox_pmic", |
| 1677 | str(exc.exception)) |
Simon Glass | eb3c249 | 2021-02-03 06:01:01 -0700 | [diff] [blame] | 1678 | |
Simon Glass | 80d782c4 | 2021-02-03 06:01:10 -0700 | [diff] [blame] | 1679 | def test_process_nodes_bad_uclass(self): |
| 1680 | plat, scan = self.setup_process_test() |
| 1681 | |
| 1682 | self.assertIn('UCLASS_I2C', scan._uclass) |
| 1683 | del scan._uclass['UCLASS_I2C'] |
| 1684 | with self.assertRaises(ValueError) as exc: |
| 1685 | plat.process_nodes(True) |
| 1686 | self.assertIn("Cannot parse/find uclass 'UCLASS_I2C' for driver 'sandbox_i2c'", |
| 1687 | str(exc.exception)) |
| 1688 | |
Simon Glass | eb3c249 | 2021-02-03 06:01:01 -0700 | [diff] [blame] | 1689 | def test_process_nodes_used(self): |
| 1690 | """Test processing nodes to add various info""" |
| 1691 | plat, scan = self.setup_process_test() |
| 1692 | plat.process_nodes(True) |
| 1693 | |
| 1694 | pmic = scan._drivers['sandbox_pmic'] |
| 1695 | self.assertTrue(pmic.used) |
| 1696 | |
| 1697 | gpio = scan._drivers['sandbox_gpio'] |
| 1698 | self.assertFalse(gpio.used) |
Simon Glass | be88d2f | 2021-02-03 06:01:07 -0700 | [diff] [blame] | 1699 | |
| 1700 | def test_alias_read(self): |
| 1701 | """Test obtaining aliases""" |
| 1702 | dtb_file = get_dtb_file('dtoc_test_inst.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1703 | output = tools.get_output_filename('output') |
Simon Glass | be88d2f | 2021-02-03 06:01:07 -0700 | [diff] [blame] | 1704 | plat = self.run_test(['struct'], dtb_file, output) |
| 1705 | |
| 1706 | scan = plat._scan |
| 1707 | testfdt_node = plat._fdt.GetNode('/some-bus/test') |
Simon Glass | 80d782c4 | 2021-02-03 06:01:10 -0700 | [diff] [blame] | 1708 | test0_node = plat._fdt.GetNode('/some-bus/test0') |
Simon Glass | be88d2f | 2021-02-03 06:01:07 -0700 | [diff] [blame] | 1709 | self.assertIn('UCLASS_TEST_FDT', scan._uclass) |
| 1710 | uc = scan._uclass['UCLASS_TEST_FDT'] |
Simon Glass | 80d782c4 | 2021-02-03 06:01:10 -0700 | [diff] [blame] | 1711 | self.assertEqual({1: testfdt_node, 2: test0_node}, |
| 1712 | uc.alias_num_to_node) |
| 1713 | self.assertEqual({'/some-bus/test': 1, '/some-bus/test0': 2}, |
| 1714 | uc.alias_path_to_num) |
Simon Glass | be88d2f | 2021-02-03 06:01:07 -0700 | [diff] [blame] | 1715 | |
| 1716 | # Try adding an alias that doesn't exist |
| 1717 | self.assertFalse(scan.add_uclass_alias('fred', 3, None)) |
| 1718 | |
| 1719 | # Try adding an alias for a missing node |
| 1720 | self.assertIsNone(scan.add_uclass_alias('testfdt', 3, None)) |
| 1721 | |
| 1722 | def test_alias_read_bad(self): |
| 1723 | """Test invalid alias property name""" |
| 1724 | dtb_file = get_dtb_file('dtoc_test_alias_bad.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1725 | output = tools.get_output_filename('output') |
Simon Glass | be88d2f | 2021-02-03 06:01:07 -0700 | [diff] [blame] | 1726 | with self.assertRaises(ValueError) as exc: |
| 1727 | plat = self.run_test(['struct'], dtb_file, output) |
| 1728 | self.assertIn("Cannot decode alias 'i2c4-'", str(exc.exception)) |
| 1729 | |
| 1730 | def test_alias_read_bad_path(self): |
| 1731 | """Test alias pointing to a non-existent node""" |
| 1732 | # This line may produce a warning, so capture it: |
| 1733 | # Warning (alias_paths): /aliases:i2c4: aliases property is not a valid |
| 1734 | # node (/does/not/exist) |
| 1735 | dtb_file = get_dtb_file('dtoc_test_alias_bad_path.dts', True) |
| 1736 | |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1737 | output = tools.get_output_filename('output') |
Simon Glass | be88d2f | 2021-02-03 06:01:07 -0700 | [diff] [blame] | 1738 | with self.assertRaises(ValueError) as exc: |
| 1739 | plat = self.run_test(['struct'], dtb_file, output) |
| 1740 | self.assertIn("Alias 'i2c4' path '/does/not/exist' not found", |
| 1741 | str(exc.exception)) |
| 1742 | |
| 1743 | def test_alias_read_bad_uclass(self): |
| 1744 | """Test alias for a uclass that doesn't exist""" |
| 1745 | dtb_file = get_dtb_file('dtoc_test_alias_bad_uc.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1746 | output = tools.get_output_filename('output') |
Simon Glass | be88d2f | 2021-02-03 06:01:07 -0700 | [diff] [blame] | 1747 | with test_util.capture_sys_output() as (stdout, _): |
| 1748 | plat = self.run_test(['struct'], dtb_file, output) |
| 1749 | self.assertEqual("Could not find uclass for alias 'other1'", |
| 1750 | stdout.getvalue().strip()) |
Simon Glass | df56e0b | 2021-02-03 06:01:09 -0700 | [diff] [blame] | 1751 | |
| 1752 | def test_sequence(self): |
| 1753 | """Test assignment of sequence numnbers""" |
| 1754 | dtb_file = get_dtb_file('dtoc_test_inst.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1755 | output = tools.get_output_filename('output') |
Simon Glass | df56e0b | 2021-02-03 06:01:09 -0700 | [diff] [blame] | 1756 | plat = self.run_test(['struct'], dtb_file, output) |
Simon Glass | 80d782c4 | 2021-02-03 06:01:10 -0700 | [diff] [blame] | 1757 | |
| 1758 | scan = plat._scan |
| 1759 | testfdt = plat._fdt.GetNode('/some-bus/test') |
| 1760 | self.assertEqual(1, testfdt.seq) |
| 1761 | i2c = plat._fdt.GetNode('/i2c') |
| 1762 | |
| 1763 | # For now this uclass is not compiled in, so no sequence is assigned |
| 1764 | self.assertEqual(4, i2c.seq) |
| 1765 | spl = plat._fdt.GetNode('/spl-test') |
| 1766 | self.assertEqual(0, spl.seq) |
Simon Glass | c14fd0c | 2021-02-03 06:01:11 -0700 | [diff] [blame] | 1767 | |
| 1768 | def test_process_root(self): |
| 1769 | """Test assignment of sequence numnbers""" |
| 1770 | dtb_file = get_dtb_file('dtoc_test_simple.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1771 | output = tools.get_output_filename('output') |
Simon Glass | c14fd0c | 2021-02-03 06:01:11 -0700 | [diff] [blame] | 1772 | |
| 1773 | # Take a copy before messing with it |
| 1774 | scan = copy_scan() |
| 1775 | plat = dtb_platdata.DtbPlatdata(scan, dtb_file, False) |
| 1776 | plat.scan_dtb() |
| 1777 | root = plat._fdt.GetRoot() |
| 1778 | |
| 1779 | plat.scan_tree(False) |
| 1780 | self.assertNotIn(root, plat._valid_nodes) |
| 1781 | |
| 1782 | plat.scan_tree(True) |
| 1783 | self.assertIn(root, plat._valid_nodes) |
| 1784 | self.assertEqual('root_driver', |
| 1785 | scan.get_normalized_compat_name(root)[0]) |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 1786 | |
| 1787 | def test_simple_inst(self): |
| 1788 | """Test output from some simple nodes with instantiate enabled""" |
Simon Glass | c7b4b83 | 2021-02-03 06:01:20 -0700 | [diff] [blame] | 1789 | dtb_file = get_dtb_file('dtoc_test_inst.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1790 | output = tools.get_output_filename('output') |
Simon Glass | 3fa3bbb | 2021-02-03 06:01:14 -0700 | [diff] [blame] | 1791 | |
| 1792 | self.run_test(['decl'], dtb_file, output, True) |
| 1793 | with open(output) as infile: |
| 1794 | data = infile.read() |
| 1795 | |
| 1796 | self._check_strings(self.decl_text_inst, data) |
Simon Glass | be74900 | 2021-02-03 06:01:15 -0700 | [diff] [blame] | 1797 | |
Simon Glass | c7b4b83 | 2021-02-03 06:01:20 -0700 | [diff] [blame] | 1798 | self.run_test(['uclass'], dtb_file, output, True) |
| 1799 | with open(output) as infile: |
| 1800 | data = infile.read() |
| 1801 | |
| 1802 | self._check_strings(UCLASS_HEADER_COMMON + self.uclass_text_inst, data) |
| 1803 | |
Simon Glass | fea2f25 | 2021-02-03 06:01:21 -0700 | [diff] [blame] | 1804 | self.run_test(['device'], dtb_file, output, True) |
| 1805 | with open(output) as infile: |
| 1806 | data = infile.read() |
| 1807 | |
| 1808 | self._check_strings(self.device_text_inst, data) |
| 1809 | |
Simon Glass | c7b4b83 | 2021-02-03 06:01:20 -0700 | [diff] [blame] | 1810 | def test_inst_no_hdr(self): |
Simon Glass | fea2f25 | 2021-02-03 06:01:21 -0700 | [diff] [blame] | 1811 | """Test dealing with a struct tsssshat has no header""" |
Simon Glass | c7b4b83 | 2021-02-03 06:01:20 -0700 | [diff] [blame] | 1812 | dtb_file = get_dtb_file('dtoc_test_inst.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1813 | output = tools.get_output_filename('output') |
Simon Glass | c7b4b83 | 2021-02-03 06:01:20 -0700 | [diff] [blame] | 1814 | |
| 1815 | # Run it once to set everything up |
| 1816 | plat = self.run_test(['decl'], dtb_file, output, True) |
| 1817 | scan = plat._scan |
| 1818 | |
| 1819 | # Restart the output file and delete any record of the uclass' struct |
| 1820 | plat.setup_output(Ftype.SOURCE, output) |
| 1821 | del scan._structs['dm_test_uc_priv'] |
| 1822 | |
| 1823 | # Now generate the uclasses, which should provide a warning |
| 1824 | with test_util.capture_sys_output() as (stdout, _): |
| 1825 | plat.generate_uclasses() |
| 1826 | self.assertEqual( |
| 1827 | 'Warning: Cannot find header file for struct dm_test_uc_priv', |
| 1828 | stdout.getvalue().strip()) |
Simon Glass | 4415dc1 | 2021-03-26 16:17:27 +1300 | [diff] [blame] | 1829 | |
| 1830 | def test_missing_props(self): |
| 1831 | """Test detection of a parent node with no properties""" |
| 1832 | dtb_file = get_dtb_file('dtoc_test_noprops.dts', capture_stderr=True) |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1833 | output = tools.get_output_filename('output') |
Simon Glass | 4415dc1 | 2021-03-26 16:17:27 +1300 | [diff] [blame] | 1834 | with self.assertRaises(ValueError) as exc: |
| 1835 | self.run_test(['struct'], dtb_file, output) |
| 1836 | self.assertIn("Parent node '/i2c@0' has no properties - do you need", |
| 1837 | str(exc.exception)) |
| 1838 | |
| 1839 | def test_single_reg(self): |
| 1840 | """Test detection of a parent node with no properties""" |
| 1841 | dtb_file = get_dtb_file('dtoc_test_single_reg.dts') |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1842 | output = tools.get_output_filename('output') |
Simon Glass | 4415dc1 | 2021-03-26 16:17:27 +1300 | [diff] [blame] | 1843 | self.run_test(['struct'], dtb_file, output) |
Simon Glass | 9ebd551 | 2021-06-27 17:51:10 -0600 | [diff] [blame] | 1844 | |
| 1845 | def test_missing_parent(self): |
| 1846 | """Test detection of a parent node with no properties""" |
| 1847 | dtb_file = get_dtb_file('dtoc_test_noparent.dts', capture_stderr=True) |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 1848 | output = tools.get_output_filename('output') |
Simon Glass | 9ebd551 | 2021-06-27 17:51:10 -0600 | [diff] [blame] | 1849 | with self.assertRaises(ValueError) as exc: |
| 1850 | self.run_test(['device'], dtb_file, output, instantiate=True) |
| 1851 | self.assertIn("Node '/i2c@0/spl-test/pmic@9' requires parent node " |
| 1852 | "'/i2c@0/spl-test' but it is not in the valid list", |
| 1853 | str(exc.exception)) |