mb/dell: Add Latitude E5520 (Sandy Bridge)
[coreboot.git] / util / cavium / devicetree_convert.py
blob05f85aad4aa23013357f05d1c3f39a25c4758b0b
1 #!/usr/bin/env python2
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 # devicetree_convert Tool to convert a DTB to a static C file
5 from pyfdt.pyfdt import FdtBlobParse
6 import argparse
8 parser = argparse.ArgumentParser(description='Cavium DTB to C converter')
9 parser.add_argument('--indtb', help='Compiled devicetree blob to parse')
10 parser.add_argument('--out', help='The file to write')
11 parser.add_argument('--verbose', help='Be verbose', action='store_true', default=False)
12 args = parser.parse_args()
14 outfile = None
15 if args.out is not None:
16 outfile = open(args.out, 'w')
17 outfile.write("// This file is automatically generated.\n")
18 outfile.write("// DO NOT EDIT BY HAND.\n\n")
19 outfile.write("#include <bdk-devicetree.h>\n\n")
20 outfile.write("const struct bdk_devicetree_key_value devtree[] = {\n")
22 with open(args.indtb) as infile:
23 dtb = FdtBlobParse(infile)
24 fdt = dtb.to_fdt()
25 for (path, node) in fdt.resolve_path('/cavium,bdk').walk():
26 if "/" in path:
27 path = path.replace("/", "")
28 if len(node) == 1:
29 for i in node:
30 if type(i) is not unicode:
31 print "%s: Type is not string" % path
32 continue
33 if args.verbose:
34 print "%s = %s" % (path, i)
35 if outfile is not None:
36 outfile.write("{\"%s\", \"%s\"},\n" % (path, i))
37 else:
38 print "%s: Arrays aren't supported" % path
40 if outfile is not None:
41 outfile.write("{0, 0},\n")
42 outfile.write("};\n")