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