blob: 140a19e9d4719384215d543d2b0e26e57e6f8988 [file] [log] [blame]
Simon Glass69f2ed72016-07-04 11:58:09 -06001#!/usr/bin/python
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 Glass14f5acf2017-06-18 22:08:57 -06009"""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
Simon Glass7581c012017-06-18 22:08:58 -060029from optparse import OptionParser
Simon Glass69f2ed72016-07-04 11:58:09 -060030import os
31import sys
32
Simon Glass69f2ed72016-07-04 11:58:09 -060033# Bring in the patman libraries
34our_path = os.path.dirname(os.path.realpath(__file__))
35sys.path.append(os.path.join(our_path, '../patman'))
36
Simon Glass7581c012017-06-18 22:08:58 -060037import dtb_platdata
Simon Glass69f2ed72016-07-04 11:58:09 -060038
39
40if __name__ != "__main__":
41 pass
42
43parser = OptionParser()
44parser.add_option('-d', '--dtb-file', action='store',
45 help='Specify the .dtb input file')
46parser.add_option('--include-disabled', action='store_true',
47 help='Include disabled nodes')
48parser.add_option('-o', '--output', action='store', default='-',
49 help='Select output filename')
50(options, args) = parser.parse_args()
51
Simon Glassfa0ea5b2017-06-18 22:09:03 -060052dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled,
53 options.output)