2019-10-31 13:42:55 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-05-06 21:58:06 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2017-06-19 04:09:06 +00:00
|
|
|
# Copyright (c) 2012 The Chromium OS Authors.
|
|
|
|
#
|
|
|
|
|
|
|
|
"""Tests for the dtb_platdata module
|
|
|
|
|
2018-07-06 16:27:20 +00:00
|
|
|
This includes unit tests for some functions and functional tests for the dtoc
|
|
|
|
tool.
|
2017-06-19 04:09:06 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import collections
|
|
|
|
import os
|
|
|
|
import struct
|
2020-06-25 04:10:08 +00:00
|
|
|
import sys
|
2020-07-28 22:06:23 +00:00
|
|
|
import tempfile
|
2017-06-19 04:09:06 +00:00
|
|
|
import unittest
|
|
|
|
|
2020-04-18 00:09:04 +00:00
|
|
|
from dtoc import dtb_platdata
|
2017-06-19 04:09:06 +00:00
|
|
|
from dtb_platdata import conv_name_to_c
|
|
|
|
from dtb_platdata import get_compat_name
|
|
|
|
from dtb_platdata import get_value
|
|
|
|
from dtb_platdata import tab_to
|
2020-04-18 00:09:04 +00:00
|
|
|
from dtoc import fdt
|
|
|
|
from dtoc import fdt_util
|
|
|
|
from patman import test_util
|
|
|
|
from patman import tools
|
2017-06-19 04:09:06 +00:00
|
|
|
|
|
|
|
our_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
|
|
|
|
2017-11-13 04:52:17 +00:00
|
|
|
HEADER = '''/*
|
|
|
|
* DO NOT MODIFY
|
|
|
|
*
|
|
|
|
* This file was generated by dtoc from a .dtb (device tree binary) file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>'''
|
2017-11-13 04:52:17 +00:00
|
|
|
|
|
|
|
C_HEADER = '''/*
|
|
|
|
* DO NOT MODIFY
|
|
|
|
*
|
|
|
|
* This file was generated by dtoc from a .dtb (device tree binary) file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <dt-structs.h>
|
|
|
|
'''
|
|
|
|
|
2020-06-25 04:10:13 +00:00
|
|
|
C_EMPTY_POPULATE_PHANDLE_DATA = '''void dm_populate_phandle_data(void) {
|
|
|
|
}
|
|
|
|
'''
|
2017-11-13 04:52:17 +00:00
|
|
|
|
2018-07-06 16:27:37 +00:00
|
|
|
|
|
|
|
def get_dtb_file(dts_fname, capture_stderr=False):
|
2017-06-19 04:09:06 +00:00
|
|
|
"""Compile a .dts file to a .dtb
|
|
|
|
|
|
|
|
Args:
|
|
|
|
dts_fname: Filename of .dts file in the current directory
|
2018-07-06 16:27:37 +00:00
|
|
|
capture_stderr: True to capture and discard stderr output
|
2017-06-19 04:09:06 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
Filename of compiled file in output directory
|
|
|
|
"""
|
2018-07-06 16:27:37 +00:00
|
|
|
return fdt_util.EnsureCompiled(os.path.join(our_path, dts_fname),
|
|
|
|
capture_stderr=capture_stderr)
|
2017-06-19 04:09:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestDtoc(unittest.TestCase):
|
|
|
|
"""Tests for dtoc"""
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
tools.PrepareOutputDir(None)
|
2020-07-08 03:32:06 +00:00
|
|
|
cls.maxDiff = None
|
2017-06-19 04:09:06 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
tools._RemoveOutputDir()
|
|
|
|
|
2018-07-06 16:27:25 +00:00
|
|
|
def _WritePythonString(self, fname, data):
|
|
|
|
"""Write a string with tabs expanded as done in this Python file
|
|
|
|
|
|
|
|
Args:
|
|
|
|
fname: Filename to write to
|
|
|
|
data: Raw string to convert
|
|
|
|
"""
|
|
|
|
data = data.replace('\t', '\\t')
|
|
|
|
with open(fname, 'w') as fd:
|
|
|
|
fd.write(data)
|
|
|
|
|
|
|
|
def _CheckStrings(self, expected, actual):
|
|
|
|
"""Check that a string matches its expected value
|
|
|
|
|
|
|
|
If the strings do not match, they are written to the /tmp directory in
|
|
|
|
the same Python format as is used here in the test. This allows for
|
|
|
|
easy comparison and update of the tests.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
expected: Expected string
|
|
|
|
actual: Actual string
|
|
|
|
"""
|
|
|
|
if expected != actual:
|
|
|
|
self._WritePythonString('/tmp/binman.expected', expected)
|
|
|
|
self._WritePythonString('/tmp/binman.actual', actual)
|
2019-05-18 04:00:31 +00:00
|
|
|
print('Failures written to /tmp/binman.{expected,actual}')
|
2018-07-06 16:27:25 +00:00
|
|
|
self.assertEquals(expected, actual)
|
|
|
|
|
2020-06-25 04:10:08 +00:00
|
|
|
|
|
|
|
def run_test(self, args, dtb_file, output):
|
|
|
|
dtb_platdata.run_steps(args, dtb_file, False, output, True)
|
|
|
|
|
2017-06-19 04:09:06 +00:00
|
|
|
def test_name(self):
|
|
|
|
"""Test conversion of device tree names to C identifiers"""
|
|
|
|
self.assertEqual('serial_at_0x12', conv_name_to_c('serial@0x12'))
|
|
|
|
self.assertEqual('vendor_clock_frequency',
|
|
|
|
conv_name_to_c('vendor,clock-frequency'))
|
|
|
|
self.assertEqual('rockchip_rk3399_sdhci_5_1',
|
|
|
|
conv_name_to_c('rockchip,rk3399-sdhci-5.1'))
|
|
|
|
|
|
|
|
def test_tab_to(self):
|
|
|
|
"""Test operation of tab_to() function"""
|
|
|
|
self.assertEqual('fred ', tab_to(0, 'fred'))
|
|
|
|
self.assertEqual('fred\t', tab_to(1, 'fred'))
|
|
|
|
self.assertEqual('fred was here ', tab_to(1, 'fred was here'))
|
|
|
|
self.assertEqual('fred was here\t\t', tab_to(3, 'fred was here'))
|
|
|
|
self.assertEqual('exactly8 ', tab_to(1, 'exactly8'))
|
|
|
|
self.assertEqual('exactly8\t', tab_to(2, 'exactly8'))
|
|
|
|
|
|
|
|
def test_get_value(self):
|
|
|
|
"""Test operation of get_value() function"""
|
|
|
|
self.assertEqual('0x45',
|
|
|
|
get_value(fdt.TYPE_INT, struct.pack('>I', 0x45)))
|
|
|
|
self.assertEqual('0x45',
|
|
|
|
get_value(fdt.TYPE_BYTE, struct.pack('<I', 0x45)))
|
|
|
|
self.assertEqual('0x0',
|
|
|
|
get_value(fdt.TYPE_BYTE, struct.pack('>I', 0x45)))
|
|
|
|
self.assertEqual('"test"', get_value(fdt.TYPE_STRING, 'test'))
|
|
|
|
self.assertEqual('true', get_value(fdt.TYPE_BOOL, None))
|
|
|
|
|
|
|
|
def test_get_compat_name(self):
|
|
|
|
"""Test operation of get_compat_name() function"""
|
|
|
|
Prop = collections.namedtuple('Prop', ['value'])
|
|
|
|
Node = collections.namedtuple('Node', ['props'])
|
|
|
|
|
|
|
|
prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1'])
|
|
|
|
node = Node({'compatible': prop})
|
2020-07-23 03:22:03 +00:00
|
|
|
self.assertEqual((['rockchip_rk3399_sdhci_5_1', 'arasan_sdhci_5_1']),
|
2017-06-19 04:09:06 +00:00
|
|
|
get_compat_name(node))
|
|
|
|
|
|
|
|
prop = Prop(['rockchip,rk3399-sdhci-5.1'])
|
|
|
|
node = Node({'compatible': prop})
|
2020-07-23 03:22:03 +00:00
|
|
|
self.assertEqual((['rockchip_rk3399_sdhci_5_1']),
|
2017-06-19 04:09:06 +00:00
|
|
|
get_compat_name(node))
|
|
|
|
|
|
|
|
prop = Prop(['rockchip,rk3399-sdhci-5.1', 'arasan,sdhci-5.1', 'third'])
|
|
|
|
node = Node({'compatible': prop})
|
2020-07-23 03:22:03 +00:00
|
|
|
self.assertEqual((['rockchip_rk3399_sdhci_5_1',
|
|
|
|
'arasan_sdhci_5_1', 'third']),
|
2017-06-19 04:09:06 +00:00
|
|
|
get_compat_name(node))
|
|
|
|
|
|
|
|
def test_empty_file(self):
|
|
|
|
"""Test output from a device tree file with no nodes"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_empty.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2017-06-19 04:09:06 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
lines = infile.read().splitlines()
|
2017-11-13 04:52:17 +00:00
|
|
|
self.assertEqual(HEADER.splitlines(), lines)
|
2017-06-19 04:09:06 +00:00
|
|
|
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['platdata'], dtb_file, output)
|
2017-06-19 04:09:06 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
lines = infile.read().splitlines()
|
2020-06-25 04:10:13 +00:00
|
|
|
self.assertEqual(C_HEADER.splitlines() + [''] +
|
|
|
|
C_EMPTY_POPULATE_PHANDLE_DATA.splitlines(), lines)
|
2017-06-19 04:09:06 +00:00
|
|
|
|
|
|
|
def test_simple(self):
|
|
|
|
"""Test output from some simple nodes with various types of data"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_simple.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2017-06-19 04:09:06 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
2018-07-06 16:27:25 +00:00
|
|
|
self._CheckStrings(HEADER + '''
|
2017-08-29 20:15:51 +00:00
|
|
|
struct dtd_sandbox_i2c_test {
|
|
|
|
};
|
|
|
|
struct dtd_sandbox_pmic_test {
|
|
|
|
\tbool\t\tlow_power;
|
|
|
|
\tfdt64_t\t\treg[2];
|
|
|
|
};
|
2017-06-19 04:09:06 +00:00
|
|
|
struct dtd_sandbox_spl_test {
|
2020-07-08 03:32:06 +00:00
|
|
|
\tconst char * acpi_name;
|
2017-06-19 04:09:06 +00:00
|
|
|
\tbool\t\tboolval;
|
|
|
|
\tunsigned char\tbytearray[3];
|
|
|
|
\tunsigned char\tbyteval;
|
|
|
|
\tfdt32_t\t\tintarray[4];
|
|
|
|
\tfdt32_t\t\tintval;
|
|
|
|
\tunsigned char\tlongbytearray[9];
|
2018-07-06 16:27:28 +00:00
|
|
|
\tunsigned char\tnotstring[5];
|
2017-06-19 04:09:06 +00:00
|
|
|
\tconst char *\tstringarray[3];
|
|
|
|
\tconst char *\tstringval;
|
|
|
|
};
|
|
|
|
struct dtd_sandbox_spl_test_2 {
|
|
|
|
};
|
|
|
|
''', data)
|
|
|
|
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['platdata'], dtb_file, output)
|
2017-06-19 04:09:06 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
2018-07-06 16:27:25 +00:00
|
|
|
self._CheckStrings(C_HEADER + '''
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /i2c@0 index 0 */
|
|
|
|
static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = {
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(i2c_at_0) = {
|
|
|
|
\t.name\t\t= "sandbox_i2c_test",
|
|
|
|
\t.platdata\t= &dtv_i2c_at_0,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_i2c_at_0),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Node /i2c@0/pmic@9 index 1 */
|
|
|
|
static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = {
|
|
|
|
\t.low_power\t\t= true,
|
|
|
|
\t.reg\t\t\t= {0x9, 0x0},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(pmic_at_9) = {
|
|
|
|
\t.name\t\t= "sandbox_pmic_test",
|
|
|
|
\t.platdata\t= &dtv_pmic_at_9,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_pmic_at_9),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Node /spl-test index 2 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_sandbox_spl_test dtv_spl_test = {
|
2019-05-18 04:00:32 +00:00
|
|
|
\t.boolval\t\t= true,
|
2017-06-19 04:09:06 +00:00
|
|
|
\t.bytearray\t\t= {0x6, 0x0, 0x0},
|
|
|
|
\t.byteval\t\t= 0x5,
|
2019-05-18 04:00:32 +00:00
|
|
|
\t.intarray\t\t= {0x2, 0x3, 0x4, 0x0},
|
2017-06-19 04:09:06 +00:00
|
|
|
\t.intval\t\t\t= 0x1,
|
2017-08-29 20:15:49 +00:00
|
|
|
\t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10,
|
|
|
|
\t\t0x11},
|
2019-05-18 04:00:32 +00:00
|
|
|
\t.notstring\t\t= {0x20, 0x21, 0x22, 0x10, 0x0},
|
2017-06-19 04:09:06 +00:00
|
|
|
\t.stringarray\t\t= {"multi-word", "message", ""},
|
2019-05-18 04:00:32 +00:00
|
|
|
\t.stringval\t\t= "message",
|
2017-06-19 04:09:06 +00:00
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(spl_test) = {
|
|
|
|
\t.name\t\t= "sandbox_spl_test",
|
|
|
|
\t.platdata\t= &dtv_spl_test,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_spl_test),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /spl-test2 index 3 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_sandbox_spl_test dtv_spl_test2 = {
|
2020-07-08 03:32:06 +00:00
|
|
|
\t.acpi_name\t\t= "\\\\_SB.GPO0",
|
2017-06-19 04:09:06 +00:00
|
|
|
\t.bytearray\t\t= {0x1, 0x23, 0x34},
|
|
|
|
\t.byteval\t\t= 0x8,
|
2019-05-18 04:00:32 +00:00
|
|
|
\t.intarray\t\t= {0x5, 0x0, 0x0, 0x0},
|
2017-06-19 04:09:06 +00:00
|
|
|
\t.intval\t\t\t= 0x3,
|
2017-08-29 20:15:49 +00:00
|
|
|
\t.longbytearray\t\t= {0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
|
|
|
|
\t\t0x0},
|
2017-06-19 04:09:06 +00:00
|
|
|
\t.stringarray\t\t= {"another", "multi-word", "message"},
|
2019-05-18 04:00:32 +00:00
|
|
|
\t.stringval\t\t= "message2",
|
2017-06-19 04:09:06 +00:00
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(spl_test2) = {
|
|
|
|
\t.name\t\t= "sandbox_spl_test",
|
|
|
|
\t.platdata\t= &dtv_spl_test2,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_spl_test2),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /spl-test3 index 4 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_sandbox_spl_test dtv_spl_test3 = {
|
2017-06-19 04:09:06 +00:00
|
|
|
\t.stringarray\t\t= {"one", "", ""},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(spl_test3) = {
|
|
|
|
\t.name\t\t= "sandbox_spl_test",
|
|
|
|
\t.platdata\t= &dtv_spl_test3,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_spl_test3),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /spl-test4 index 5 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_sandbox_spl_test_2 dtv_spl_test4 = {
|
2017-06-19 04:09:06 +00:00
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(spl_test4) = {
|
|
|
|
\t.name\t\t= "sandbox_spl_test_2",
|
|
|
|
\t.platdata\t= &dtv_spl_test4,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_spl_test4),
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:13 +00:00
|
|
|
''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
|
2020-07-03 11:07:17 +00:00
|
|
|
|
|
|
|
def test_driver_alias(self):
|
|
|
|
"""Test output from a device tree file with a driver alias"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_driver_alias.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2020-07-03 11:07:17 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
|
|
|
self._CheckStrings(HEADER + '''
|
|
|
|
struct dtd_sandbox_gpio {
|
|
|
|
\tconst char *\tgpio_bank_name;
|
|
|
|
\tbool\t\tgpio_controller;
|
|
|
|
\tfdt32_t\t\tsandbox_gpio_count;
|
|
|
|
};
|
|
|
|
''', data)
|
|
|
|
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['platdata'], dtb_file, output)
|
2020-07-03 11:07:17 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
|
|
|
self._CheckStrings(C_HEADER + '''
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /gpios@0 index 0 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_sandbox_gpio dtv_gpios_at_0 = {
|
2020-07-03 11:07:17 +00:00
|
|
|
\t.gpio_bank_name\t\t= "a",
|
|
|
|
\t.gpio_controller\t= true,
|
|
|
|
\t.sandbox_gpio_count\t= 0x14,
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(gpios_at_0) = {
|
|
|
|
\t.name\t\t= "sandbox_gpio",
|
|
|
|
\t.platdata\t= &dtv_gpios_at_0,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_gpios_at_0),
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:13 +00:00
|
|
|
void dm_populate_phandle_data(void) {
|
|
|
|
}
|
2020-06-25 04:10:08 +00:00
|
|
|
''', data)
|
|
|
|
|
|
|
|
def test_invalid_driver(self):
|
|
|
|
"""Test output from a device tree file with an invalid driver"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
|
|
|
with test_util.capture_sys_output() as (stdout, stderr):
|
|
|
|
dtb_platdata.run_steps(['struct'], dtb_file, False, output)
|
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
|
|
|
self._CheckStrings(HEADER + '''
|
|
|
|
struct dtd_invalid {
|
|
|
|
};
|
|
|
|
''', data)
|
|
|
|
|
|
|
|
with test_util.capture_sys_output() as (stdout, stderr):
|
|
|
|
dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
|
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
|
|
|
self._CheckStrings(C_HEADER + '''
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /spl-test index 0 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_invalid dtv_spl_test = {
|
2020-06-25 04:10:08 +00:00
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(spl_test) = {
|
|
|
|
\t.name\t\t= "invalid",
|
|
|
|
\t.platdata\t= &dtv_spl_test,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_spl_test),
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:13 +00:00
|
|
|
void dm_populate_phandle_data(void) {
|
|
|
|
}
|
2017-06-19 04:09:06 +00:00
|
|
|
''', data)
|
|
|
|
|
|
|
|
def test_phandle(self):
|
|
|
|
"""Test output from a node containing a phandle reference"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_phandle.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2017-06-19 04:09:06 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
2018-07-06 16:27:25 +00:00
|
|
|
self._CheckStrings(HEADER + '''
|
2017-06-19 04:09:06 +00:00
|
|
|
struct dtd_source {
|
2017-08-29 20:15:59 +00:00
|
|
|
\tstruct phandle_2_arg clocks[4];
|
2017-06-19 04:09:06 +00:00
|
|
|
};
|
|
|
|
struct dtd_target {
|
|
|
|
\tfdt32_t\t\tintval;
|
|
|
|
};
|
|
|
|
''', data)
|
|
|
|
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['platdata'], dtb_file, output)
|
2017-06-19 04:09:06 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
2018-07-06 16:27:25 +00:00
|
|
|
self._CheckStrings(C_HEADER + '''
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /phandle2-target index 0 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_target dtv_phandle2_target = {
|
2017-08-29 20:15:59 +00:00
|
|
|
\t.intval\t\t\t= 0x1,
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(phandle2_target) = {
|
|
|
|
\t.name\t\t= "target",
|
|
|
|
\t.platdata\t= &dtv_phandle2_target,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_phandle2_target),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /phandle3-target index 1 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_target dtv_phandle3_target = {
|
2017-08-29 20:15:59 +00:00
|
|
|
\t.intval\t\t\t= 0x2,
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(phandle3_target) = {
|
|
|
|
\t.name\t\t= "target",
|
|
|
|
\t.platdata\t= &dtv_phandle3_target,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_phandle3_target),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /phandle-target index 4 */
|
|
|
|
static struct dtd_target dtv_phandle_target = {
|
|
|
|
\t.intval\t\t\t= 0x0,
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(phandle_target) = {
|
|
|
|
\t.name\t\t= "target",
|
|
|
|
\t.platdata\t= &dtv_phandle_target,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_phandle_target),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Node /phandle-source index 2 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_source dtv_phandle_source = {
|
2017-08-29 20:15:57 +00:00
|
|
|
\t.clocks\t\t\t= {
|
2020-06-25 04:10:13 +00:00
|
|
|
\t\t\t{NULL, {}},
|
|
|
|
\t\t\t{NULL, {11}},
|
|
|
|
\t\t\t{NULL, {12, 13}},
|
|
|
|
\t\t\t{NULL, {}},},
|
2017-06-19 04:09:06 +00:00
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(phandle_source) = {
|
|
|
|
\t.name\t\t= "source",
|
|
|
|
\t.platdata\t= &dtv_phandle_source,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_phandle_source),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /phandle-source2 index 3 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_source dtv_phandle_source2 = {
|
2018-07-06 16:27:31 +00:00
|
|
|
\t.clocks\t\t\t= {
|
2020-06-25 04:10:13 +00:00
|
|
|
\t\t\t{NULL, {}},},
|
2018-07-06 16:27:31 +00:00
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(phandle_source2) = {
|
|
|
|
\t.name\t\t= "source",
|
|
|
|
\t.platdata\t= &dtv_phandle_source2,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_phandle_source2),
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:13 +00:00
|
|
|
void dm_populate_phandle_data(void) {
|
|
|
|
\tdtv_phandle_source.clocks[0].node = DM_GET_DEVICE(phandle_target);
|
|
|
|
\tdtv_phandle_source.clocks[1].node = DM_GET_DEVICE(phandle2_target);
|
|
|
|
\tdtv_phandle_source.clocks[2].node = DM_GET_DEVICE(phandle3_target);
|
|
|
|
\tdtv_phandle_source.clocks[3].node = DM_GET_DEVICE(phandle_target);
|
|
|
|
\tdtv_phandle_source2.clocks[0].node = DM_GET_DEVICE(phandle_target);
|
|
|
|
}
|
2017-06-19 04:09:06 +00:00
|
|
|
''', data)
|
|
|
|
|
2018-07-06 16:27:35 +00:00
|
|
|
def test_phandle_single(self):
|
|
|
|
"""Test output from a node containing a phandle reference"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_phandle_single.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2018-07-06 16:27:35 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
|
|
|
self._CheckStrings(HEADER + '''
|
|
|
|
struct dtd_source {
|
|
|
|
\tstruct phandle_0_arg clocks[1];
|
|
|
|
};
|
|
|
|
struct dtd_target {
|
|
|
|
\tfdt32_t\t\tintval;
|
|
|
|
};
|
|
|
|
''', data)
|
|
|
|
|
|
|
|
def test_phandle_reorder(self):
|
|
|
|
"""Test that phandle targets are generated before their references"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_phandle_reorder.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['platdata'], dtb_file, output)
|
2018-07-06 16:27:35 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
|
|
|
self._CheckStrings(C_HEADER + '''
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /phandle-target index 1 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_target dtv_phandle_target = {
|
2018-07-06 16:27:35 +00:00
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(phandle_target) = {
|
|
|
|
\t.name\t\t= "target",
|
|
|
|
\t.platdata\t= &dtv_phandle_target,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_phandle_target),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /phandle-source2 index 0 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_source dtv_phandle_source2 = {
|
2018-07-06 16:27:35 +00:00
|
|
|
\t.clocks\t\t\t= {
|
2020-06-25 04:10:13 +00:00
|
|
|
\t\t\t{NULL, {}},},
|
2018-07-06 16:27:35 +00:00
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(phandle_source2) = {
|
|
|
|
\t.name\t\t= "source",
|
|
|
|
\t.platdata\t= &dtv_phandle_source2,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_phandle_source2),
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:13 +00:00
|
|
|
void dm_populate_phandle_data(void) {
|
|
|
|
\tdtv_phandle_source2.clocks[0].node = DM_GET_DEVICE(phandle_target);
|
|
|
|
}
|
2020-06-25 04:10:17 +00:00
|
|
|
''', data)
|
|
|
|
|
|
|
|
def test_phandle_cd_gpio(self):
|
|
|
|
"""Test that phandle targets are generated when unsing cd-gpios"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_phandle_cd_gpios.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
|
|
|
dtb_platdata.run_steps(['platdata'], dtb_file, False, output, True)
|
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
|
|
|
self._CheckStrings(C_HEADER + '''
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /phandle2-target index 0 */
|
2020-06-25 04:10:17 +00:00
|
|
|
static struct dtd_target dtv_phandle2_target = {
|
|
|
|
\t.intval\t\t\t= 0x1,
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(phandle2_target) = {
|
|
|
|
\t.name\t\t= "target",
|
|
|
|
\t.platdata\t= &dtv_phandle2_target,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_phandle2_target),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /phandle3-target index 1 */
|
2020-06-25 04:10:17 +00:00
|
|
|
static struct dtd_target dtv_phandle3_target = {
|
|
|
|
\t.intval\t\t\t= 0x2,
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(phandle3_target) = {
|
|
|
|
\t.name\t\t= "target",
|
|
|
|
\t.platdata\t= &dtv_phandle3_target,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_phandle3_target),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /phandle-target index 4 */
|
|
|
|
static struct dtd_target dtv_phandle_target = {
|
|
|
|
\t.intval\t\t\t= 0x0,
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(phandle_target) = {
|
|
|
|
\t.name\t\t= "target",
|
|
|
|
\t.platdata\t= &dtv_phandle_target,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_phandle_target),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Node /phandle-source index 2 */
|
2020-06-25 04:10:17 +00:00
|
|
|
static struct dtd_source dtv_phandle_source = {
|
|
|
|
\t.cd_gpios\t\t= {
|
|
|
|
\t\t\t{NULL, {}},
|
|
|
|
\t\t\t{NULL, {11}},
|
|
|
|
\t\t\t{NULL, {12, 13}},
|
|
|
|
\t\t\t{NULL, {}},},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(phandle_source) = {
|
|
|
|
\t.name\t\t= "source",
|
|
|
|
\t.platdata\t= &dtv_phandle_source,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_phandle_source),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /phandle-source2 index 3 */
|
2020-06-25 04:10:17 +00:00
|
|
|
static struct dtd_source dtv_phandle_source2 = {
|
|
|
|
\t.cd_gpios\t\t= {
|
|
|
|
\t\t\t{NULL, {}},},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(phandle_source2) = {
|
|
|
|
\t.name\t\t= "source",
|
|
|
|
\t.platdata\t= &dtv_phandle_source2,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_phandle_source2),
|
|
|
|
};
|
|
|
|
|
|
|
|
void dm_populate_phandle_data(void) {
|
|
|
|
\tdtv_phandle_source.cd_gpios[0].node = DM_GET_DEVICE(phandle_target);
|
|
|
|
\tdtv_phandle_source.cd_gpios[1].node = DM_GET_DEVICE(phandle2_target);
|
|
|
|
\tdtv_phandle_source.cd_gpios[2].node = DM_GET_DEVICE(phandle3_target);
|
|
|
|
\tdtv_phandle_source.cd_gpios[3].node = DM_GET_DEVICE(phandle_target);
|
|
|
|
\tdtv_phandle_source2.cd_gpios[0].node = DM_GET_DEVICE(phandle_target);
|
|
|
|
}
|
2018-07-06 16:27:35 +00:00
|
|
|
''', data)
|
|
|
|
|
|
|
|
def test_phandle_bad(self):
|
|
|
|
"""Test a node containing an invalid phandle fails"""
|
2018-10-02 03:12:43 +00:00
|
|
|
dtb_file = get_dtb_file('dtoc_test_phandle_bad.dts',
|
|
|
|
capture_stderr=True)
|
2018-07-06 16:27:35 +00:00
|
|
|
output = tools.GetOutputFilename('output')
|
|
|
|
with self.assertRaises(ValueError) as e:
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2018-07-06 16:27:35 +00:00
|
|
|
self.assertIn("Cannot parse 'clocks' in node 'phandle-source'",
|
|
|
|
str(e.exception))
|
|
|
|
|
|
|
|
def test_phandle_bad2(self):
|
|
|
|
"""Test a phandle target missing its #*-cells property"""
|
2018-10-02 03:12:43 +00:00
|
|
|
dtb_file = get_dtb_file('dtoc_test_phandle_bad2.dts',
|
|
|
|
capture_stderr=True)
|
2018-07-06 16:27:35 +00:00
|
|
|
output = tools.GetOutputFilename('output')
|
|
|
|
with self.assertRaises(ValueError) as e:
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2020-06-25 04:10:16 +00:00
|
|
|
self.assertIn("Node 'phandle-target' has no cells property",
|
2018-07-06 16:27:35 +00:00
|
|
|
str(e.exception))
|
|
|
|
|
2017-08-29 20:15:50 +00:00
|
|
|
def test_addresses64(self):
|
|
|
|
"""Test output from a node with a 'reg' property with na=2, ns=2"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_addr64.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2017-08-29 20:15:50 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
2018-07-06 16:27:25 +00:00
|
|
|
self._CheckStrings(HEADER + '''
|
2017-08-29 20:15:50 +00:00
|
|
|
struct dtd_test1 {
|
|
|
|
\tfdt64_t\t\treg[2];
|
|
|
|
};
|
|
|
|
struct dtd_test2 {
|
|
|
|
\tfdt64_t\t\treg[2];
|
|
|
|
};
|
|
|
|
struct dtd_test3 {
|
|
|
|
\tfdt64_t\t\treg[4];
|
|
|
|
};
|
|
|
|
''', data)
|
|
|
|
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['platdata'], dtb_file, output)
|
2017-08-29 20:15:50 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
2018-07-06 16:27:25 +00:00
|
|
|
self._CheckStrings(C_HEADER + '''
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /test1 index 0 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_test1 dtv_test1 = {
|
2017-08-29 20:15:50 +00:00
|
|
|
\t.reg\t\t\t= {0x1234, 0x5678},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(test1) = {
|
|
|
|
\t.name\t\t= "test1",
|
|
|
|
\t.platdata\t= &dtv_test1,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_test1),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /test2 index 1 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_test2 dtv_test2 = {
|
2017-08-29 20:15:50 +00:00
|
|
|
\t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(test2) = {
|
|
|
|
\t.name\t\t= "test2",
|
|
|
|
\t.platdata\t= &dtv_test2,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_test2),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /test3 index 2 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_test3 dtv_test3 = {
|
2017-08-29 20:15:50 +00:00
|
|
|
\t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(test3) = {
|
|
|
|
\t.name\t\t= "test3",
|
|
|
|
\t.platdata\t= &dtv_test3,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_test3),
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:13 +00:00
|
|
|
''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
|
2017-08-29 20:15:50 +00:00
|
|
|
|
|
|
|
def test_addresses32(self):
|
|
|
|
"""Test output from a node with a 'reg' property with na=1, ns=1"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_addr32.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2017-08-29 20:15:50 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
2018-07-06 16:27:25 +00:00
|
|
|
self._CheckStrings(HEADER + '''
|
2017-08-29 20:15:50 +00:00
|
|
|
struct dtd_test1 {
|
|
|
|
\tfdt32_t\t\treg[2];
|
|
|
|
};
|
|
|
|
struct dtd_test2 {
|
|
|
|
\tfdt32_t\t\treg[4];
|
|
|
|
};
|
|
|
|
''', data)
|
|
|
|
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['platdata'], dtb_file, output)
|
2017-08-29 20:15:50 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
2018-07-06 16:27:25 +00:00
|
|
|
self._CheckStrings(C_HEADER + '''
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /test1 index 0 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_test1 dtv_test1 = {
|
2017-08-29 20:15:50 +00:00
|
|
|
\t.reg\t\t\t= {0x1234, 0x5678},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(test1) = {
|
|
|
|
\t.name\t\t= "test1",
|
|
|
|
\t.platdata\t= &dtv_test1,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_test1),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /test2 index 1 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_test2 dtv_test2 = {
|
2017-08-29 20:15:50 +00:00
|
|
|
\t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(test2) = {
|
|
|
|
\t.name\t\t= "test2",
|
|
|
|
\t.platdata\t= &dtv_test2,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_test2),
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:13 +00:00
|
|
|
''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
|
2017-08-29 20:15:50 +00:00
|
|
|
|
|
|
|
def test_addresses64_32(self):
|
|
|
|
"""Test output from a node with a 'reg' property with na=2, ns=1"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_addr64_32.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2017-08-29 20:15:50 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
2018-07-06 16:27:25 +00:00
|
|
|
self._CheckStrings(HEADER + '''
|
2017-08-29 20:15:50 +00:00
|
|
|
struct dtd_test1 {
|
|
|
|
\tfdt64_t\t\treg[2];
|
|
|
|
};
|
|
|
|
struct dtd_test2 {
|
|
|
|
\tfdt64_t\t\treg[2];
|
|
|
|
};
|
|
|
|
struct dtd_test3 {
|
|
|
|
\tfdt64_t\t\treg[4];
|
|
|
|
};
|
|
|
|
''', data)
|
|
|
|
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['platdata'], dtb_file, output)
|
2017-08-29 20:15:50 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
2018-07-06 16:27:25 +00:00
|
|
|
self._CheckStrings(C_HEADER + '''
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /test1 index 0 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_test1 dtv_test1 = {
|
2017-08-29 20:15:50 +00:00
|
|
|
\t.reg\t\t\t= {0x123400000000, 0x5678},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(test1) = {
|
|
|
|
\t.name\t\t= "test1",
|
|
|
|
\t.platdata\t= &dtv_test1,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_test1),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /test2 index 1 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_test2 dtv_test2 = {
|
2017-08-29 20:15:50 +00:00
|
|
|
\t.reg\t\t\t= {0x1234567890123456, 0x98765432},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(test2) = {
|
|
|
|
\t.name\t\t= "test2",
|
|
|
|
\t.platdata\t= &dtv_test2,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_test2),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /test3 index 2 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_test3 dtv_test3 = {
|
2017-08-29 20:15:50 +00:00
|
|
|
\t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(test3) = {
|
|
|
|
\t.name\t\t= "test3",
|
|
|
|
\t.platdata\t= &dtv_test3,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_test3),
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:13 +00:00
|
|
|
''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
|
2017-08-29 20:15:50 +00:00
|
|
|
|
|
|
|
def test_addresses32_64(self):
|
|
|
|
"""Test output from a node with a 'reg' property with na=1, ns=2"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_addr32_64.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2017-08-29 20:15:50 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
2018-07-06 16:27:25 +00:00
|
|
|
self._CheckStrings(HEADER + '''
|
2017-08-29 20:15:50 +00:00
|
|
|
struct dtd_test1 {
|
|
|
|
\tfdt64_t\t\treg[2];
|
|
|
|
};
|
|
|
|
struct dtd_test2 {
|
|
|
|
\tfdt64_t\t\treg[2];
|
|
|
|
};
|
|
|
|
struct dtd_test3 {
|
|
|
|
\tfdt64_t\t\treg[4];
|
|
|
|
};
|
|
|
|
''', data)
|
|
|
|
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['platdata'], dtb_file, output)
|
2017-08-29 20:15:50 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
2018-07-06 16:27:25 +00:00
|
|
|
self._CheckStrings(C_HEADER + '''
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /test1 index 0 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_test1 dtv_test1 = {
|
2017-08-29 20:15:50 +00:00
|
|
|
\t.reg\t\t\t= {0x1234, 0x567800000000},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(test1) = {
|
|
|
|
\t.name\t\t= "test1",
|
|
|
|
\t.platdata\t= &dtv_test1,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_test1),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /test2 index 1 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_test2 dtv_test2 = {
|
2017-08-29 20:15:50 +00:00
|
|
|
\t.reg\t\t\t= {0x12345678, 0x9876543210987654},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(test2) = {
|
|
|
|
\t.name\t\t= "test2",
|
|
|
|
\t.platdata\t= &dtv_test2,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_test2),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /test3 index 2 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_test3 dtv_test3 = {
|
2017-08-29 20:15:50 +00:00
|
|
|
\t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3},
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(test3) = {
|
|
|
|
\t.name\t\t= "test3",
|
|
|
|
\t.platdata\t= &dtv_test3,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_test3),
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:13 +00:00
|
|
|
''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
|
2018-07-06 16:27:35 +00:00
|
|
|
|
|
|
|
def test_bad_reg(self):
|
|
|
|
"""Test that a reg property with an invalid type generates an error"""
|
2018-07-06 16:27:37 +00:00
|
|
|
# Capture stderr since dtc will emit warnings for this file
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_bad_reg.dts', capture_stderr=True)
|
2018-07-06 16:27:35 +00:00
|
|
|
output = tools.GetOutputFilename('output')
|
|
|
|
with self.assertRaises(ValueError) as e:
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2018-07-06 16:27:35 +00:00
|
|
|
self.assertIn("Node 'spl-test' reg property is not an int",
|
|
|
|
str(e.exception))
|
|
|
|
|
|
|
|
def test_bad_reg2(self):
|
|
|
|
"""Test that a reg property with an invalid cell count is detected"""
|
2018-07-06 16:27:37 +00:00
|
|
|
# Capture stderr since dtc will emit warnings for this file
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_bad_reg2.dts', capture_stderr=True)
|
2018-07-06 16:27:35 +00:00
|
|
|
output = tools.GetOutputFilename('output')
|
|
|
|
with self.assertRaises(ValueError) as e:
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2018-07-06 16:27:35 +00:00
|
|
|
self.assertIn("Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)",
|
|
|
|
str(e.exception))
|
|
|
|
|
|
|
|
def test_add_prop(self):
|
|
|
|
"""Test that a subequent node can add a new property to a struct"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_add_prop.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, output)
|
2018-07-06 16:27:35 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
|
|
|
self._CheckStrings(HEADER + '''
|
|
|
|
struct dtd_sandbox_spl_test {
|
|
|
|
\tfdt32_t\t\tintarray;
|
|
|
|
\tfdt32_t\t\tintval;
|
|
|
|
};
|
|
|
|
''', data)
|
|
|
|
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['platdata'], dtb_file, output)
|
2018-07-06 16:27:35 +00:00
|
|
|
with open(output) as infile:
|
|
|
|
data = infile.read()
|
|
|
|
self._CheckStrings(C_HEADER + '''
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /spl-test index 0 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_sandbox_spl_test dtv_spl_test = {
|
2018-07-06 16:27:35 +00:00
|
|
|
\t.intval\t\t\t= 0x1,
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(spl_test) = {
|
|
|
|
\t.name\t\t= "sandbox_spl_test",
|
|
|
|
\t.platdata\t= &dtv_spl_test,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_spl_test),
|
|
|
|
};
|
|
|
|
|
2020-10-03 17:31:25 +00:00
|
|
|
/* Node /spl-test2 index 1 */
|
2020-06-25 04:10:13 +00:00
|
|
|
static struct dtd_sandbox_spl_test dtv_spl_test2 = {
|
2018-07-06 16:27:35 +00:00
|
|
|
\t.intarray\t\t= 0x5,
|
|
|
|
};
|
|
|
|
U_BOOT_DEVICE(spl_test2) = {
|
|
|
|
\t.name\t\t= "sandbox_spl_test",
|
|
|
|
\t.platdata\t= &dtv_spl_test2,
|
|
|
|
\t.platdata_size\t= sizeof(dtv_spl_test2),
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:13 +00:00
|
|
|
''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
|
2018-07-06 16:27:35 +00:00
|
|
|
|
|
|
|
def testStdout(self):
|
|
|
|
"""Test output to stdout"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_simple.dts')
|
|
|
|
with test_util.capture_sys_output() as (stdout, stderr):
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['struct'], dtb_file, '-')
|
2018-07-06 16:27:35 +00:00
|
|
|
|
|
|
|
def testNoCommand(self):
|
|
|
|
"""Test running dtoc without a command"""
|
|
|
|
with self.assertRaises(ValueError) as e:
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test([], '', '')
|
2018-07-06 16:27:35 +00:00
|
|
|
self.assertIn("Please specify a command: struct, platdata",
|
|
|
|
str(e.exception))
|
|
|
|
|
|
|
|
def testBadCommand(self):
|
|
|
|
"""Test running dtoc with an invalid command"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_simple.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
|
|
|
with self.assertRaises(ValueError) as e:
|
2020-06-25 04:10:08 +00:00
|
|
|
self.run_test(['invalid-cmd'], dtb_file, output)
|
2018-07-06 16:27:35 +00:00
|
|
|
self.assertIn("Unknown command 'invalid-cmd': (use: struct, platdata)",
|
|
|
|
str(e.exception))
|
2020-07-28 22:06:23 +00:00
|
|
|
|
|
|
|
def testScanDrivers(self):
|
|
|
|
"""Test running dtoc with additional drivers to scan"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_simple.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
|
|
|
with test_util.capture_sys_output() as (stdout, stderr):
|
|
|
|
dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
|
|
|
|
[None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
|
|
|
|
|
|
|
|
def testUnicodeError(self):
|
|
|
|
"""Test running dtoc with an invalid unicode file
|
|
|
|
|
|
|
|
To be able to perform this test without adding a weird text file which
|
|
|
|
would produce issues when using checkpatch.pl or patman, generate the
|
|
|
|
file at runtime and then process it.
|
|
|
|
"""
|
|
|
|
dtb_file = get_dtb_file('dtoc_test_simple.dts')
|
|
|
|
output = tools.GetOutputFilename('output')
|
|
|
|
driver_fn = '/tmp/' + next(tempfile._get_candidate_names())
|
|
|
|
with open(driver_fn, 'wb+') as df:
|
|
|
|
df.write(b'\x81')
|
|
|
|
|
|
|
|
with test_util.capture_sys_output() as (stdout, stderr):
|
|
|
|
dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
|
|
|
|
[driver_fn])
|