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+
|
2016-07-04 17:58:09 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2016 Google, Inc
|
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
|
|
#
|
|
|
|
|
2017-06-19 04:08:57 +00: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 03:34:52 +00:00
|
|
|
Dtoc produces several output files - see OUTPUT_FILES in dtb_platdata.py
|
2017-06-19 04:08:57 +00: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-25 20:35:39 +00:00
|
|
|
see doc/driver-model/of-plat.rst
|
2017-06-19 04:08:57 +00:00
|
|
|
"""
|
|
|
|
|
2021-07-04 18:19:44 +00:00
|
|
|
from argparse import ArgumentParser
|
2016-07-04 17:58:09 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2017-06-19 04:09:06 +00:00
|
|
|
import unittest
|
2016-07-04 17:58:09 +00:00
|
|
|
|
|
|
|
# Bring in the patman libraries
|
|
|
|
our_path = os.path.dirname(os.path.realpath(__file__))
|
2020-04-18 00:09:04 +00:00
|
|
|
sys.path.append(os.path.join(our_path, '..'))
|
2016-07-04 17:58:09 +00:00
|
|
|
|
2018-10-02 03:12:40 +00: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 00:09:04 +00:00
|
|
|
from dtoc import dtb_platdata
|
|
|
|
from patman import test_util
|
2016-07-04 17:58:09 +00:00
|
|
|
|
2020-12-29 03:34:59 +00:00
|
|
|
def run_tests(processes, args):
|
2018-07-06 16:27:20 +00:00
|
|
|
"""Run all the test we have for dtoc
|
|
|
|
|
|
|
|
Args:
|
2020-12-29 03:34:59 +00:00
|
|
|
processes: Number of processes to use to run tests (None=same as #CPUs)
|
2018-07-06 16:27:32 +00: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-06 16:27:20 +00:00
|
|
|
"""
|
2020-12-29 03:35:07 +00:00
|
|
|
from dtoc import test_src_scan
|
|
|
|
from dtoc import test_dtoc
|
2016-07-04 17:58:09 +00:00
|
|
|
|
2017-06-19 04:09:06 +00:00
|
|
|
result = unittest.TestResult()
|
|
|
|
sys.argv = [sys.argv[0]]
|
2021-07-04 18:19:44 +00:00
|
|
|
test_name = args.files and args.files[0] or None
|
2020-12-29 03:34:59 +00:00
|
|
|
|
2021-02-03 13:00:51 +00:00
|
|
|
test_dtoc.setup()
|
|
|
|
|
2022-01-29 21:14:14 +00:00
|
|
|
test_util.run_test_suites(
|
2020-12-29 03:34:59 +00:00
|
|
|
result, debug=True, verbosity=1, test_preserve_dirs=False,
|
|
|
|
processes=processes, test_name=test_name, toolpath=[],
|
2022-01-22 12:07:28 +00:00
|
|
|
class_and_module_list=[test_dtoc.TestDtoc,test_src_scan.TestSrcScan])
|
2020-12-29 03:34:59 +00:00
|
|
|
|
2022-01-29 21:14:14 +00:00
|
|
|
return test_util.report_result('binman', test_name, result)
|
2017-06-19 04:09:06 +00:00
|
|
|
|
2018-07-06 16:27:33 +00:00
|
|
|
def RunTestCoverage():
|
|
|
|
"""Run the tests and check that we get 100% coverage"""
|
|
|
|
sys.argv = [sys.argv[0]]
|
2022-01-29 21:14:14 +00:00
|
|
|
test_util.run_test_coverage('tools/dtoc/dtoc', '/main.py',
|
2021-07-04 18:19:44 +00:00
|
|
|
['tools/patman/*.py', '*/fdt*', '*test*'], args.build_dir)
|
2018-07-06 16:27:33 +00:00
|
|
|
|
|
|
|
|
2017-06-19 04:09:06 +00:00
|
|
|
if __name__ != '__main__':
|
|
|
|
sys.exit(1)
|
2016-07-04 17:58:09 +00:00
|
|
|
|
2021-07-04 18:19:44 +00:00
|
|
|
epilog = '''Generate C code from devicetree files. See of-plat.rst for details'''
|
|
|
|
|
|
|
|
parser = ArgumentParser(epilog=epilog)
|
|
|
|
parser.add_argument('-B', '--build-dir', type=str, default='b',
|
2018-07-06 16:27:33 +00:00
|
|
|
help='Directory containing the build output')
|
2021-07-04 18:19:44 +00:00
|
|
|
parser.add_argument('-c', '--c-output-dir', action='store',
|
2020-12-29 03:34:50 +00:00
|
|
|
help='Select output directory for C files')
|
2021-07-04 18:19:44 +00:00
|
|
|
parser.add_argument('-C', '--h-output-dir', action='store',
|
2020-12-29 03:34:50 +00:00
|
|
|
help='Select output directory for H files (defaults to --c-output-di)')
|
2021-07-04 18:19:44 +00:00
|
|
|
parser.add_argument('-d', '--dtb-file', action='store',
|
2016-07-04 17:58:09 +00:00
|
|
|
help='Specify the .dtb input file')
|
2021-07-04 18:19:44 +00:00
|
|
|
parser.add_argument('-i', '--instantiate', action='store_true', default=False,
|
2021-02-03 13:01:12 +00:00
|
|
|
help='Instantiate devices to avoid needing device_bind()')
|
2021-07-04 18:19:44 +00:00
|
|
|
parser.add_argument('--include-disabled', action='store_true',
|
2016-07-04 17:58:09 +00:00
|
|
|
help='Include disabled nodes')
|
2021-07-04 18:19:44 +00:00
|
|
|
parser.add_argument('-o', '--output', action='store',
|
2016-07-04 17:58:09 +00:00
|
|
|
help='Select output filename')
|
2021-07-04 18:19:44 +00:00
|
|
|
parser.add_argument('-p', '--phase', type=str,
|
2021-02-03 13:01:02 +00:00
|
|
|
help='set phase of U-Boot this invocation is for (spl/tpl)')
|
2021-07-04 18:19:44 +00:00
|
|
|
parser.add_argument('-P', '--processes', type=int,
|
2018-10-02 03:12:47 +00:00
|
|
|
help='set number of processes to use for running tests')
|
2021-07-04 18:19:44 +00:00
|
|
|
parser.add_argument('-t', '--test', action='store_true', dest='test',
|
2017-06-19 04:09:06 +00:00
|
|
|
default=False, help='run tests')
|
2021-07-04 18:19:44 +00:00
|
|
|
parser.add_argument('-T', '--test-coverage', action='store_true',
|
|
|
|
default=False, help='run tests and check for 100%% coverage')
|
|
|
|
parser.add_argument('files', nargs='*')
|
|
|
|
args = parser.parse_args()
|
2016-07-04 17:58:09 +00:00
|
|
|
|
2017-06-19 04:09:06 +00:00
|
|
|
# Run our meagre tests
|
2021-07-04 18:19:44 +00:00
|
|
|
if args.test:
|
|
|
|
ret_code = run_tests(args.processes, args)
|
2019-07-20 18:23:23 +00:00
|
|
|
sys.exit(ret_code)
|
2017-06-19 04:09:06 +00:00
|
|
|
|
2021-07-04 18:19:44 +00:00
|
|
|
elif args.test_coverage:
|
2018-07-06 16:27:33 +00:00
|
|
|
RunTestCoverage()
|
|
|
|
|
2017-06-19 04:09:06 +00:00
|
|
|
else:
|
2021-07-04 18:19:44 +00:00
|
|
|
dtb_platdata.run_steps(args.files, args.dtb_file, args.include_disabled,
|
|
|
|
args.output,
|
|
|
|
[args.c_output_dir, args.h_output_dir],
|
|
|
|
args.phase, instantiate=args.instantiate)
|