2019-10-31 22:42:55 +09:00
|
|
|
#!/usr/bin/env python3
|
2018-05-07 06:58:06 +09:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2016-07-05 02:58:09 +09:00
|
|
|
#
|
|
|
|
# Copyright (C) 2016 Google, Inc
|
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
|
|
#
|
|
|
|
|
2017-06-19 13:08:57 +09:00
|
|
|
"""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.
|
|
|
|
|
2020-12-29 12:34:52 +09:00
|
|
|
Dtoc produces several output files - see OUTPUT_FILES in dtb_platdata.py
|
2017-06-19 13:08:57 +09:00
|
|
|
|
|
|
|
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
|
2020-02-26 05:35:39 +09:00
|
|
|
see doc/driver-model/of-plat.rst
|
2017-06-19 13:08:57 +09:00
|
|
|
"""
|
|
|
|
|
2017-06-19 13:08:58 +09:00
|
|
|
from optparse import OptionParser
|
2016-07-05 02:58:09 +09:00
|
|
|
import os
|
|
|
|
import sys
|
2017-06-19 13:09:06 +09:00
|
|
|
import unittest
|
2016-07-05 02:58:09 +09:00
|
|
|
|
|
|
|
# Bring in the patman libraries
|
|
|
|
our_path = os.path.dirname(os.path.realpath(__file__))
|
2020-04-18 09:09:04 +09:00
|
|
|
sys.path.append(os.path.join(our_path, '..'))
|
2016-07-05 02:58:09 +09:00
|
|
|
|
2018-10-02 12:12:40 +09:00
|
|
|
# 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'))
|
|
|
|
|
2020-04-18 09:09:04 +09:00
|
|
|
from dtoc import dtb_platdata
|
|
|
|
from patman import test_util
|
2016-07-05 02:58:09 +09:00
|
|
|
|
2018-07-07 01:27:20 +09:00
|
|
|
def run_tests(args):
|
|
|
|
"""Run all the test we have for dtoc
|
|
|
|
|
|
|
|
Args:
|
2018-07-07 01:27:32 +09:00
|
|
|
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)
|
2018-07-07 01:27:20 +09:00
|
|
|
"""
|
2017-06-19 13:09:06 +09:00
|
|
|
import test_dtoc
|
2016-07-05 02:58:09 +09:00
|
|
|
|
2017-06-19 13:09:06 +09:00
|
|
|
result = unittest.TestResult()
|
|
|
|
sys.argv = [sys.argv[0]]
|
2018-07-07 01:27:20 +09:00
|
|
|
test_name = args and args[0] or None
|
2017-06-19 13:09:06 +09:00
|
|
|
for module in (test_dtoc.TestDtoc,):
|
2018-07-07 01:27:20 +09:00
|
|
|
if test_name:
|
|
|
|
try:
|
|
|
|
suite = unittest.TestLoader().loadTestsFromName(test_name, module)
|
|
|
|
except AttributeError:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(module)
|
2017-06-19 13:09:06 +09:00
|
|
|
suite.run(result)
|
|
|
|
|
2019-05-18 13:00:31 +09:00
|
|
|
print(result)
|
2017-06-19 13:09:06 +09:00
|
|
|
for _, err in result.errors:
|
2019-05-18 13:00:31 +09:00
|
|
|
print(err)
|
2017-06-19 13:09:06 +09:00
|
|
|
for _, err in result.failures:
|
2019-05-18 13:00:31 +09:00
|
|
|
print(err)
|
2019-07-21 03:23:23 +09:00
|
|
|
if result.errors or result.failures:
|
|
|
|
print('dtoc tests FAILED')
|
|
|
|
return 1
|
|
|
|
return 0
|
2017-06-19 13:09:06 +09:00
|
|
|
|
2018-07-07 01:27:33 +09:00
|
|
|
def RunTestCoverage():
|
|
|
|
"""Run the tests and check that we get 100% coverage"""
|
|
|
|
sys.argv = [sys.argv[0]]
|
2020-04-18 09:08:57 +09:00
|
|
|
test_util.RunTestCoverage('tools/dtoc/dtoc', '/main.py',
|
2018-07-07 01:27:33 +09:00
|
|
|
['tools/patman/*.py', '*/fdt*', '*test*'], options.build_dir)
|
|
|
|
|
|
|
|
|
2017-06-19 13:09:06 +09:00
|
|
|
if __name__ != '__main__':
|
|
|
|
sys.exit(1)
|
2016-07-05 02:58:09 +09:00
|
|
|
|
|
|
|
parser = OptionParser()
|
2018-07-07 01:27:33 +09:00
|
|
|
parser.add_option('-B', '--build-dir', type='string', default='b',
|
|
|
|
help='Directory containing the build output')
|
2020-12-29 12:34:50 +09:00
|
|
|
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)')
|
2016-07-05 02:58:09 +09:00
|
|
|
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')
|
2020-12-29 12:34:48 +09:00
|
|
|
parser.add_option('-o', '--output', action='store',
|
2016-07-05 02:58:09 +09:00
|
|
|
help='Select output filename')
|
2018-10-02 12:12:47 +09:00
|
|
|
parser.add_option('-P', '--processes', type=int,
|
|
|
|
help='set number of processes to use for running tests')
|
2017-06-19 13:09:06 +09:00
|
|
|
parser.add_option('-t', '--test', action='store_true', dest='test',
|
|
|
|
default=False, help='run tests')
|
2018-07-07 01:27:33 +09:00
|
|
|
parser.add_option('-T', '--test-coverage', action='store_true',
|
|
|
|
default=False, help='run tests and check for 100% coverage')
|
2016-07-05 02:58:09 +09:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
2017-06-19 13:09:06 +09:00
|
|
|
# Run our meagre tests
|
|
|
|
if options.test:
|
2019-07-21 03:23:23 +09:00
|
|
|
ret_code = run_tests(args)
|
|
|
|
sys.exit(ret_code)
|
2017-06-19 13:09:06 +09:00
|
|
|
|
2018-07-07 01:27:33 +09:00
|
|
|
elif options.test_coverage:
|
|
|
|
RunTestCoverage()
|
|
|
|
|
2017-06-19 13:09:06 +09:00
|
|
|
else:
|
|
|
|
dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled,
|
2020-12-29 12:34:50 +09:00
|
|
|
options.output,
|
|
|
|
[options.c_output_dir, options.h_output_dir])
|