]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dtoc: Allow providing a directory to write files to
authorSimon Glass <sjg@chromium.org>
Tue, 29 Dec 2020 03:34:50 +0000 (20:34 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 5 Jan 2021 19:26:35 +0000 (12:26 -0700)
At present dtoc writes only a single file on each invocation. U-Boot
writes the two files it needs by separate invocations of dtoc. Since dtoc
now scans all U-Boot driver source, this is fairly slow (about 1 second
per file).

It would be better if dtoc could write all the files at once.

In preparation for this, add a way to specify an output directory for the
files.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/dtoc/dtb_platdata.py
tools/dtoc/main.py
tools/dtoc/test_dtoc.py

index 118b1a5f4327e50e6f9a3cdf8ebecf4c20cfa35f..62a65d6214aaca5bd943036f59d4916379d9e340 100644 (file)
@@ -757,8 +757,9 @@ class DtbPlatdata():
 
         self.out(''.join(self.get_buf()))
 
-def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False,
-              drivers_additional=None):
+
+def run_steps(args, dtb_file, include_disabled, output, output_dirs,
+              warning_disabled=False, drivers_additional=None):
     """Run all the steps of the dtoc tool
 
     Args:
@@ -766,6 +767,9 @@ def run_steps(args, dtb_file, include_disabled, output, warning_disabled=False,
         dtb_file (str): Filename of dtb file to process
         include_disabled (bool): True to include disabled nodes
         output (str): Name of output file (None for stdout)
+        output_dirs (tuple of str):
+            Directory to put C output files
+            Directory to put H output files
         warning_disabled (bool): True to avoid showing warnings about missing
             drivers
         drivers_additional (list): List of additional drivers to use during
index 7686c8784d8fb20d2804d5135401bacfd9b956e2..244c184cedd8670624ec99a4ec6cd0bd206b84ac 100755 (executable)
@@ -87,6 +87,10 @@ if __name__ != '__main__':
 parser = OptionParser()
 parser.add_option('-B', '--build-dir', type='string', default='b',
         help='Directory containing the build output')
+parser.add_option('-c', '--c-output-dir', action='store',
+                  help='Select output directory for C files')
+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('--include-disabled', action='store_true',
@@ -111,4 +115,5 @@ elif options.test_coverage:
 
 else:
     dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled,
-                           options.output)
+                           options.output,
+                           [options.c_output_dir, options.h_output_dir])
index 7cf2a5187c690c4c6d4b69057f6e1e766094c377..b023a1e14a5a2ec245d77530e18a2268fbf246d6 100755 (executable)
@@ -122,7 +122,7 @@ class TestDtoc(unittest.TestCase):
             dtb_file (str): Filename of .dtb file
             output (str): Filename of output file
         """
-        dtb_platdata.run_steps(args, dtb_file, False, output, True)
+        dtb_platdata.run_steps(args, dtb_file, False, output, [], True)
 
     def test_name(self):
         """Test conversion of device tree names to C identifiers"""
@@ -343,7 +343,7 @@ void dm_populate_phandle_data(void) {
         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)
+            dtb_platdata.run_steps(['struct'], dtb_file, False, output, [])
         with open(output) as infile:
             data = infile.read()
         self._check_strings(HEADER + '''
@@ -352,7 +352,7 @@ struct dtd_invalid {
 ''', data)
 
         with test_util.capture_sys_output() as _:
-            dtb_platdata.run_steps(['platdata'], dtb_file, False, output)
+            dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [])
         with open(output) as infile:
             data = infile.read()
         self._check_strings(C_HEADER + '''
@@ -508,7 +508,7 @@ void dm_populate_phandle_data(void) {
         """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)
+        dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [], True)
         with open(output) as infile:
             data = infile.read()
         self._check_strings(C_HEADER + '''
@@ -907,7 +907,7 @@ U_BOOT_DEVICE(spl_test2) = {
         output = tools.GetOutputFilename('output')
         with test_util.capture_sys_output() as _:
             dtb_platdata.run_steps(
-                ['struct'], dtb_file, False, output, True,
+                ['struct'], dtb_file, False, output, [], True,
                 [None, '', 'tools/dtoc/dtoc_test_scan_drivers.cxx'])
 
     @staticmethod
@@ -925,8 +925,8 @@ U_BOOT_DEVICE(spl_test2) = {
             fout.write(b'\x81')
 
         with test_util.capture_sys_output() as _:
-            dtb_platdata.run_steps(['struct'], dtb_file, False, output, True,
-                                   [driver_fn])
+            dtb_platdata.run_steps(['struct'], dtb_file, False, output, [],
+                                   True, [driver_fn])
 
     def test_driver(self):
         """Test the Driver class"""