From 4d25fe2d952dd66d0f6c3f0dfdd4303e85d65333 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 17 Apr 2020 18:08:57 -0600 Subject: dtoc: Rename the main module Python does not like the module name being the same as the module directory. To allow dtoc modules to be used from other tools, rename it. Signed-off-by: Simon Glass --- tools/dtoc/dtoc | 2 +- tools/dtoc/dtoc.py | 114 ----------------------------------------------------- tools/dtoc/main.py | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 115 deletions(-) delete mode 100755 tools/dtoc/dtoc.py create mode 100755 tools/dtoc/main.py (limited to 'tools') diff --git a/tools/dtoc/dtoc b/tools/dtoc/dtoc index 896ca44e62..11a5d8e18a 120000 --- a/tools/dtoc/dtoc +++ b/tools/dtoc/dtoc @@ -1 +1 @@ -dtoc.py \ No newline at end of file +main.py \ No newline at end of file diff --git a/tools/dtoc/dtoc.py b/tools/dtoc/dtoc.py deleted file mode 100755 index 8e05b43431..0000000000 --- a/tools/dtoc/dtoc.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env python3 -# SPDX-License-Identifier: GPL-2.0+ -# -# Copyright (C) 2016 Google, Inc -# Written by Simon Glass -# - -"""Device tree to C tool - -This tool converts a device tree binary file (.dtb) into two C files. The -indent is to allow a C program to access data from the device tree without -having to link against libfdt. By putting the data from the device tree into -C structures, normal C code can be used. This helps to reduce the size of the -compiled program. - -Dtoc produces two output files: - - dt-structs.h - contains struct definitions - dt-platdata.c - contains data from the device tree using the struct - definitions, as well as U-Boot driver definitions. - -This tool is used in U-Boot to provide device tree data to SPL without -increasing the code size of SPL. This supports the CONFIG_SPL_OF_PLATDATA -options. For more information about the use of this options and tool please -see doc/driver-model/of-plat.rst -""" - -from optparse import OptionParser -import os -import sys -import unittest - -# Bring in the patman libraries -our_path = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(our_path, '../patman')) - -# Bring in the libfdt module -sys.path.insert(0, 'scripts/dtc/pylibfdt') -sys.path.insert(0, os.path.join(our_path, - '../../build-sandbox_spl/scripts/dtc/pylibfdt')) - -import dtb_platdata -import test_util - -def run_tests(args): - """Run all the test we have for dtoc - - Args: - args: List of positional args provided to dtoc. This can hold a test - name to execute (as in 'dtoc -t test_empty_file', for example) - """ - import test_dtoc - - result = unittest.TestResult() - sys.argv = [sys.argv[0]] - test_name = args and args[0] or None - for module in (test_dtoc.TestDtoc,): - if test_name: - try: - suite = unittest.TestLoader().loadTestsFromName(test_name, module) - except AttributeError: - continue - else: - suite = unittest.TestLoader().loadTestsFromTestCase(module) - suite.run(result) - - print(result) - for _, err in result.errors: - print(err) - for _, err in result.failures: - print(err) - if result.errors or result.failures: - print('dtoc tests FAILED') - return 1 - return 0 - -def RunTestCoverage(): - """Run the tests and check that we get 100% coverage""" - sys.argv = [sys.argv[0]] - test_util.RunTestCoverage('tools/dtoc/dtoc.py', '/dtoc.py', - ['tools/patman/*.py', '*/fdt*', '*test*'], options.build_dir) - - -if __name__ != '__main__': - sys.exit(1) - -parser = OptionParser() -parser.add_option('-B', '--build-dir', type='string', default='b', - help='Directory containing the build output') -parser.add_option('-d', '--dtb-file', action='store', - help='Specify the .dtb input file') -parser.add_option('--include-disabled', action='store_true', - help='Include disabled nodes') -parser.add_option('-o', '--output', action='store', default='-', - help='Select output filename') -parser.add_option('-P', '--processes', type=int, - help='set number of processes to use for running tests') -parser.add_option('-t', '--test', action='store_true', dest='test', - default=False, help='run tests') -parser.add_option('-T', '--test-coverage', action='store_true', - default=False, help='run tests and check for 100% coverage') -(options, args) = parser.parse_args() - -# Run our meagre tests -if options.test: - ret_code = run_tests(args) - sys.exit(ret_code) - -elif options.test_coverage: - RunTestCoverage() - -else: - dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled, - options.output) diff --git a/tools/dtoc/main.py b/tools/dtoc/main.py new file mode 100755 index 0000000000..b1eee21f17 --- /dev/null +++ b/tools/dtoc/main.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2016 Google, Inc +# Written by Simon Glass +# + +"""Device tree to C tool + +This tool converts a device tree binary file (.dtb) into two C files. The +indent is to allow a C program to access data from the device tree without +having to link against libfdt. By putting the data from the device tree into +C structures, normal C code can be used. This helps to reduce the size of the +compiled program. + +Dtoc produces two output files: + + dt-structs.h - contains struct definitions + dt-platdata.c - contains data from the device tree using the struct + definitions, as well as U-Boot driver definitions. + +This tool is used in U-Boot to provide device tree data to SPL without +increasing the code size of SPL. This supports the CONFIG_SPL_OF_PLATDATA +options. For more information about the use of this options and tool please +see doc/driver-model/of-plat.rst +""" + +from optparse import OptionParser +import os +import sys +import unittest + +# Bring in the patman libraries +our_path = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(our_path, '../patman')) + +# Bring in the libfdt module +sys.path.insert(0, 'scripts/dtc/pylibfdt') +sys.path.insert(0, os.path.join(our_path, + '../../build-sandbox_spl/scripts/dtc/pylibfdt')) + +import dtb_platdata +import test_util + +def run_tests(args): + """Run all the test we have for dtoc + + Args: + args: List of positional args provided to dtoc. This can hold a test + name to execute (as in 'dtoc -t test_empty_file', for example) + """ + import test_dtoc + + result = unittest.TestResult() + sys.argv = [sys.argv[0]] + test_name = args and args[0] or None + for module in (test_dtoc.TestDtoc,): + if test_name: + try: + suite = unittest.TestLoader().loadTestsFromName(test_name, module) + except AttributeError: + continue + else: + suite = unittest.TestLoader().loadTestsFromTestCase(module) + suite.run(result) + + print(result) + for _, err in result.errors: + print(err) + for _, err in result.failures: + print(err) + if result.errors or result.failures: + print('dtoc tests FAILED') + return 1 + return 0 + +def RunTestCoverage(): + """Run the tests and check that we get 100% coverage""" + sys.argv = [sys.argv[0]] + test_util.RunTestCoverage('tools/dtoc/dtoc', '/main.py', + ['tools/patman/*.py', '*/fdt*', '*test*'], options.build_dir) + + +if __name__ != '__main__': + sys.exit(1) + +parser = OptionParser() +parser.add_option('-B', '--build-dir', type='string', default='b', + help='Directory containing the build output') +parser.add_option('-d', '--dtb-file', action='store', + help='Specify the .dtb input file') +parser.add_option('--include-disabled', action='store_true', + help='Include disabled nodes') +parser.add_option('-o', '--output', action='store', default='-', + help='Select output filename') +parser.add_option('-P', '--processes', type=int, + help='set number of processes to use for running tests') +parser.add_option('-t', '--test', action='store_true', dest='test', + default=False, help='run tests') +parser.add_option('-T', '--test-coverage', action='store_true', + default=False, help='run tests and check for 100% coverage') +(options, args) = parser.parse_args() + +# Run our meagre tests +if options.test: + ret_code = run_tests(args) + sys.exit(ret_code) + +elif options.test_coverage: + RunTestCoverage() + +else: + dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled, + options.output) -- cgit v1.2.3