2018-01-21 09:34:57 +00:00
|
|
|
#!/usr/bin/env python2
|
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.
|
|
|
|
|
|
|
|
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.txt
|
|
|
|
"""
|
|
|
|
|
2017-06-19 04:08:58 +00:00
|
|
|
from optparse import OptionParser
|
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__))
|
|
|
|
sys.path.append(os.path.join(our_path, '../patman'))
|
|
|
|
|
2017-06-19 04:08:58 +00:00
|
|
|
import dtb_platdata
|
2016-07-04 17:58:09 +00:00
|
|
|
|
2018-07-06 16:27:20 +00:00
|
|
|
def run_tests(args):
|
|
|
|
"""Run all the test we have for dtoc
|
|
|
|
|
|
|
|
Args:
|
|
|
|
args: List of positional args provided to binman. This can hold a test
|
|
|
|
name to execute (as in 'binman -t testSections', for example)
|
|
|
|
"""
|
2017-06-19 04:09:06 +00:00
|
|
|
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]]
|
2018-07-06 16:27:20 +00:00
|
|
|
test_name = args and args[0] or None
|
2017-06-19 04:09:06 +00:00
|
|
|
for module in (test_dtoc.TestDtoc,):
|
2018-07-06 16:27:20 +00:00
|
|
|
if test_name:
|
|
|
|
try:
|
|
|
|
suite = unittest.TestLoader().loadTestsFromName(test_name, module)
|
|
|
|
except AttributeError:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(module)
|
2017-06-19 04:09:06 +00:00
|
|
|
suite.run(result)
|
|
|
|
|
|
|
|
print result
|
|
|
|
for _, err in result.errors:
|
|
|
|
print err
|
|
|
|
for _, err in result.failures:
|
|
|
|
print err
|
|
|
|
|
|
|
|
if __name__ != '__main__':
|
|
|
|
sys.exit(1)
|
2016-07-04 17:58:09 +00:00
|
|
|
|
|
|
|
parser = OptionParser()
|
|
|
|
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')
|
2017-06-19 04:09:06 +00:00
|
|
|
parser.add_option('-t', '--test', action='store_true', dest='test',
|
|
|
|
default=False, help='run tests')
|
2016-07-04 17:58:09 +00:00
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
2017-06-19 04:09:06 +00:00
|
|
|
# Run our meagre tests
|
|
|
|
if options.test:
|
2018-07-06 16:27:20 +00:00
|
|
|
run_tests(args)
|
2017-06-19 04:09:06 +00:00
|
|
|
|
|
|
|
else:
|
|
|
|
dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled,
|
|
|
|
options.output)
|