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