Masahiro Yamada | 94b13bb | 2018-01-21 18:34:57 +0900 | [diff] [blame^] | 1 | #!/usr/bin/env python2 |
Simon Glass | 69f2ed7 | 2016-07-04 11:58:09 -0600 | [diff] [blame] | 2 | # |
| 3 | # Copyright (C) 2016 Google, Inc |
| 4 | # Written by Simon Glass <sjg@chromium.org> |
| 5 | # |
| 6 | # SPDX-License-Identifier: GPL-2.0+ |
| 7 | # |
| 8 | |
Simon Glass | 14f5acf | 2017-06-18 22:08:57 -0600 | [diff] [blame] | 9 | """Device tree to C tool |
| 10 | |
| 11 | This tool converts a device tree binary file (.dtb) into two C files. The |
| 12 | indent is to allow a C program to access data from the device tree without |
| 13 | having to link against libfdt. By putting the data from the device tree into |
| 14 | C structures, normal C code can be used. This helps to reduce the size of the |
| 15 | compiled program. |
| 16 | |
| 17 | Dtoc produces two output files: |
| 18 | |
| 19 | dt-structs.h - contains struct definitions |
| 20 | dt-platdata.c - contains data from the device tree using the struct |
| 21 | definitions, as well as U-Boot driver definitions. |
| 22 | |
| 23 | This tool is used in U-Boot to provide device tree data to SPL without |
| 24 | increasing the code size of SPL. This supports the CONFIG_SPL_OF_PLATDATA |
| 25 | options. For more information about the use of this options and tool please |
| 26 | see doc/driver-model/of-plat.txt |
| 27 | """ |
| 28 | |
Simon Glass | 7581c01 | 2017-06-18 22:08:58 -0600 | [diff] [blame] | 29 | from optparse import OptionParser |
Simon Glass | 69f2ed7 | 2016-07-04 11:58:09 -0600 | [diff] [blame] | 30 | import os |
| 31 | import sys |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 32 | import unittest |
Simon Glass | 69f2ed7 | 2016-07-04 11:58:09 -0600 | [diff] [blame] | 33 | |
Simon Glass | 69f2ed7 | 2016-07-04 11:58:09 -0600 | [diff] [blame] | 34 | # Bring in the patman libraries |
| 35 | our_path = os.path.dirname(os.path.realpath(__file__)) |
| 36 | sys.path.append(os.path.join(our_path, '../patman')) |
| 37 | |
Simon Glass | 7581c01 | 2017-06-18 22:08:58 -0600 | [diff] [blame] | 38 | import dtb_platdata |
Simon Glass | 69f2ed7 | 2016-07-04 11:58:09 -0600 | [diff] [blame] | 39 | |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 40 | def run_tests(): |
| 41 | """Run all the test we have for dtoc""" |
| 42 | import test_dtoc |
Simon Glass | 69f2ed7 | 2016-07-04 11:58:09 -0600 | [diff] [blame] | 43 | |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 44 | result = unittest.TestResult() |
| 45 | sys.argv = [sys.argv[0]] |
| 46 | for module in (test_dtoc.TestDtoc,): |
| 47 | suite = unittest.TestLoader().loadTestsFromTestCase(module) |
| 48 | suite.run(result) |
| 49 | |
| 50 | print result |
| 51 | for _, err in result.errors: |
| 52 | print err |
| 53 | for _, err in result.failures: |
| 54 | print err |
| 55 | |
| 56 | if __name__ != '__main__': |
| 57 | sys.exit(1) |
Simon Glass | 69f2ed7 | 2016-07-04 11:58:09 -0600 | [diff] [blame] | 58 | |
| 59 | parser = OptionParser() |
| 60 | parser.add_option('-d', '--dtb-file', action='store', |
| 61 | help='Specify the .dtb input file') |
| 62 | parser.add_option('--include-disabled', action='store_true', |
| 63 | help='Include disabled nodes') |
| 64 | parser.add_option('-o', '--output', action='store', default='-', |
| 65 | help='Select output filename') |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 66 | parser.add_option('-t', '--test', action='store_true', dest='test', |
| 67 | default=False, help='run tests') |
Simon Glass | 69f2ed7 | 2016-07-04 11:58:09 -0600 | [diff] [blame] | 68 | (options, args) = parser.parse_args() |
| 69 | |
Simon Glass | c079192 | 2017-06-18 22:09:06 -0600 | [diff] [blame] | 70 | # Run our meagre tests |
| 71 | if options.test: |
| 72 | run_tests() |
| 73 | |
| 74 | else: |
| 75 | dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled, |
| 76 | options.output) |