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