]>
Commit | Line | Data |
---|---|---|
69f2ed77 SG |
1 | #!/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 | ||
14f5acfc SG |
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 | ||
7581c01a | 29 | from optparse import OptionParser |
69f2ed77 SG |
30 | import os |
31 | import sys | |
32 | ||
69f2ed77 SG |
33 | # Bring in the patman libraries |
34 | our_path = os.path.dirname(os.path.realpath(__file__)) | |
35 | sys.path.append(os.path.join(our_path, '../patman')) | |
36 | ||
7581c01a | 37 | import dtb_platdata |
69f2ed77 SG |
38 | |
39 | ||
40 | if __name__ != "__main__": | |
41 | pass | |
42 | ||
43 | parser = OptionParser() | |
44 | parser.add_option('-d', '--dtb-file', action='store', | |
45 | help='Specify the .dtb input file') | |
46 | parser.add_option('--include-disabled', action='store_true', | |
47 | help='Include disabled nodes') | |
48 | parser.add_option('-o', '--output', action='store', default='-', | |
49 | help='Select output filename') | |
50 | (options, args) = parser.parse_args() | |
51 | ||
52 | if not args: | |
53 | raise ValueError('Please specify a command: struct, platdata') | |
54 | ||
e36024b0 | 55 | plat = dtb_platdata.DtbPlatdata(options.dtb_file, options.include_disabled) |
2be282ca SG |
56 | plat.scan_dtb() |
57 | plat.scan_tree() | |
58 | plat.setup_output(options.output) | |
59 | structs = plat.scan_structs() | |
60 | plat.scan_phandles() | |
69f2ed77 SG |
61 | |
62 | for cmd in args[0].split(','): | |
63 | if cmd == 'struct': | |
2be282ca | 64 | plat.generate_structs(structs) |
69f2ed77 | 65 | elif cmd == 'platdata': |
2be282ca | 66 | plat.generate_tables() |
69f2ed77 SG |
67 | else: |
68 | raise ValueError("Unknown command '%s': (use: struct, platdata)" % cmd) |