From 4a092350d18d1aea637de6be8802a9de0cca194f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 3 Feb 2021 06:01:12 -0700 Subject: [PATCH] dtoc: Add an option for device instantiation Add an option to instantiate devices at build time. For now this just parses the option and sets up a few parameters. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 17 +++++++++++------ tools/dtoc/main.py | 4 +++- tools/dtoc/test_dtoc.py | 37 ++++++++++++++++++++++--------------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index e08b92cf8a..46e2725a86 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -153,8 +153,10 @@ class DtbPlatdata(): _basedir (str): Base directory of source tree _valid_uclasses (list of src_scan.Uclass): List of uclasses needed for the selected devices (see _valid_node), in alphabetical order + _instantiate: Instantiate devices so they don't need to be bound at + run-time """ - def __init__(self, scan, dtb_fname, include_disabled): + def __init__(self, scan, dtb_fname, include_disabled, instantiate=False): self._scan = scan self._fdt = None self._dtb_fname = dtb_fname @@ -167,6 +169,7 @@ class DtbPlatdata(): self._struct_data = collections.OrderedDict() self._basedir = None self._valid_uclasses = None + self._instantiate = instantiate def setup_output_dirs(self, output_dirs): """Set up the output directories @@ -802,8 +805,8 @@ OUTPUT_FILES = { def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase, - warning_disabled=False, drivers_additional=None, basedir=None, - scan=None): + instantiate, warning_disabled=False, drivers_additional=None, + basedir=None, scan=None): """Run all the steps of the dtoc tool Args: @@ -816,6 +819,8 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase, Directory to put H output files phase: The phase of U-Boot that we are generating data for, e.g. 'spl' or 'tpl'. None if not known + instantiate: Instantiate devices so they don't need to be bound at + run-time warning_disabled (bool): True to avoid showing warnings about missing drivers drivers_additional (list): List of additional drivers to use during @@ -843,15 +848,15 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase, do_process = True else: do_process = False - plat = DtbPlatdata(scan, dtb_file, include_disabled) + plat = DtbPlatdata(scan, dtb_file, include_disabled, instantiate) plat.scan_dtb() - plat.scan_tree(add_root=False) + plat.scan_tree(add_root=instantiate) plat.prepare_nodes() plat.scan_reg_sizes() plat.setup_output_dirs(output_dirs) plat.scan_structs() plat.scan_phandles() - plat.process_nodes(False) + plat.process_nodes(instantiate) plat.read_aliases() plat.assign_seqs() diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py index 15a8ff167a..93706de89b 100755 --- a/tools/dtoc/main.py +++ b/tools/dtoc/main.py @@ -81,6 +81,8 @@ parser.add_option('-C', '--h-output-dir', action='store', help='Select output directory for H files (defaults to --c-output-di)') parser.add_option('-d', '--dtb-file', action='store', help='Specify the .dtb input file') +parser.add_option('-i', '--instantiate', action='store_true', default=False, + help='Instantiate devices to avoid needing device_bind()') parser.add_option('--include-disabled', action='store_true', help='Include disabled nodes') parser.add_option('-o', '--output', action='store', @@ -107,4 +109,4 @@ else: dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled, options.output, [options.c_output_dir, options.h_output_dir], - phase=options.phase) + options.phase, instantiate=options.instantiate) diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index ed8c7e4788..cbddd62424 100755 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -130,7 +130,7 @@ class TestDtoc(unittest.TestCase): self.assertEqual(expected, actual) @staticmethod - def run_test(args, dtb_file, output): + def run_test(args, dtb_file, output, instantiate=False): """Run a test using dtoc Args: @@ -143,8 +143,9 @@ class TestDtoc(unittest.TestCase): """ # Make a copy of the 'scan' object, since it includes uclasses and # drivers, which get updated during execution. - return dtb_platdata.run_steps(args, dtb_file, False, output, [], None, - warning_disabled=True, scan=copy_scan()) + return dtb_platdata.run_steps( + args, dtb_file, False, output, [], None, instantiate, + warning_disabled=True, scan=copy_scan()) def test_name(self): """Test conversion of device tree names to C identifiers""" @@ -201,7 +202,8 @@ class TestDtoc(unittest.TestCase): output = tools.GetOutputFilename('output') # Run this one without saved_scan to complete test coverage - dtb_platdata.run_steps(['struct'], dtb_file, False, output, [], True) + dtb_platdata.run_steps(['struct'], dtb_file, False, output, [], None, + False) with open(output) as infile: lines = infile.read().splitlines() self.assertEqual(HEADER.splitlines(), lines) @@ -369,8 +371,9 @@ U_BOOT_DRVINFO(gpios_at_0) = { dtb_file = get_dtb_file('dtoc_test_invalid_driver.dts') output = tools.GetOutputFilename('output') with test_util.capture_sys_output() as _: - dtb_platdata.run_steps(['struct'], dtb_file, False, output, [], - None, scan=copy_scan()) + dtb_platdata.run_steps( + ['struct'], dtb_file, False, output, [], None, False, + scan=copy_scan()) with open(output) as infile: data = infile.read() self._check_strings(HEADER + ''' @@ -379,8 +382,9 @@ struct dtd_invalid { ''', data) with test_util.capture_sys_output() as _: - dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [], - None, scan=copy_scan()) + dtb_platdata.run_steps( + ['platdata'], dtb_file, False, output, [], None, False, + scan=copy_scan()) with open(output) as infile: data = infile.read() self._check_strings(C_HEADER + ''' @@ -530,8 +534,9 @@ U_BOOT_DRVINFO(phandle_target) = { """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, - scan=copy_scan()) + dtb_platdata.run_steps( + ['platdata'], dtb_file, False, output, [], None, False, + warning_disabled=True, scan=copy_scan()) with open(output) as infile: data = infile.read() self._check_strings(C_HEADER + ''' @@ -925,15 +930,16 @@ U_BOOT_DRVINFO(spl_test2) = { dtb_file = get_dtb_file('dtoc_test_simple.dts') output = tools.GetOutputFilename('output') with self.assertRaises(ValueError) as exc: - self.run_test(['invalid-cmd'], dtb_file, output) + self.run_test(['invalid-cmd'], dtb_file, output, False) self.assertIn("Unknown command 'invalid-cmd': (use: platdata, struct)", str(exc.exception)) def test_output_conflict(self): """Test a conflict between and output dirs and output file""" with self.assertRaises(ValueError) as exc: - dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], None, - warning_disabled=True, scan=copy_scan()) + dtb_platdata.run_steps( + ['all'], None, False, 'out', ['cdir'], None, False, + warning_disabled=True, scan=copy_scan()) self.assertIn("Must specify either output or output_dirs, not both", str(exc.exception)) @@ -949,8 +955,9 @@ U_BOOT_DRVINFO(spl_test2) = { fnames = glob.glob(outdir + '/*') self.assertEqual(2, len(fnames)) - dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], None, - warning_disabled=True, scan=copy_scan()) + dtb_platdata.run_steps( + ['all'], dtb_file, False, None, [outdir], None, False, + warning_disabled=True, scan=copy_scan()) fnames = glob.glob(outdir + '/*') self.assertEqual(4, len(fnames)) -- 2.39.5