]> git.ipfire.org Git - people/ms/u-boot.git/blame - tools/dtoc/dtoc.py
host-tools: use python2 explicitly for shebang
[people/ms/u-boot.git] / tools / dtoc / dtoc.py
CommitLineData
94b13bba 1#!/usr/bin/env python2
69f2ed77
SG
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
14f5acfc
SG
9"""Device tree to C tool
10
11This tool converts a device tree binary file (.dtb) into two C files. The
12indent is to allow a C program to access data from the device tree without
13having to link against libfdt. By putting the data from the device tree into
14C structures, normal C code can be used. This helps to reduce the size of the
15compiled program.
16
17Dtoc 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
23This tool is used in U-Boot to provide device tree data to SPL without
24increasing the code size of SPL. This supports the CONFIG_SPL_OF_PLATDATA
25options. For more information about the use of this options and tool please
26see doc/driver-model/of-plat.txt
27"""
28
7581c01a 29from optparse import OptionParser
69f2ed77
SG
30import os
31import sys
c0791928 32import unittest
69f2ed77 33
69f2ed77
SG
34# Bring in the patman libraries
35our_path = os.path.dirname(os.path.realpath(__file__))
36sys.path.append(os.path.join(our_path, '../patman'))
37
7581c01a 38import dtb_platdata
69f2ed77 39
c0791928
SG
40def run_tests():
41 """Run all the test we have for dtoc"""
42 import test_dtoc
69f2ed77 43
c0791928
SG
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
56if __name__ != '__main__':
57 sys.exit(1)
69f2ed77
SG
58
59parser = OptionParser()
60parser.add_option('-d', '--dtb-file', action='store',
61 help='Specify the .dtb input file')
62parser.add_option('--include-disabled', action='store_true',
63 help='Include disabled nodes')
64parser.add_option('-o', '--output', action='store', default='-',
65 help='Select output filename')
c0791928
SG
66parser.add_option('-t', '--test', action='store_true', dest='test',
67 default=False, help='run tests')
69f2ed77
SG
68(options, args) = parser.parse_args()
69
c0791928
SG
70# Run our meagre tests
71if options.test:
72 run_tests()
73
74else:
75 dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled,
76 options.output)