3 # devicetree_convert Tool to convert a DTB to a static C file
4 # Copyright (C) 2018 Facebook Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
17 from pyfdt
.pyfdt
import FdtBlobParse
20 parser
= argparse
.ArgumentParser(description
='Cavium DTB to C converter')
21 parser
.add_argument('--indtb', help='Compiled devicetree blob to parse')
22 parser
.add_argument('--out', help='The file to write')
23 parser
.add_argument('--verbose', help='Be verbose', action
='store_true', default
=False)
24 args
= parser
.parse_args()
27 if args
.out
is not None:
28 outfile
= open(args
.out
, 'w')
29 outfile
.write("// This file is part of the coreboot project.\n")
30 outfile
.write("// This file is automatically generated.\n")
31 outfile
.write("// DO NOT EDIT BY HAND.\n\n")
32 outfile
.write("#include <bdk-devicetree.h>\n\n")
33 outfile
.write("const struct bdk_devicetree_key_value devtree[] = {\n")
35 with
open(args
.indtb
) as infile
:
36 dtb
= FdtBlobParse(infile
)
38 for (path
, node
) in fdt
.resolve_path('/cavium,bdk').walk():
40 path
= path
.replace("/", "")
43 if type(i
) is not unicode:
44 print "%s: Type is not string" % path
47 print "%s = %s" % (path
, i
)
48 if outfile
is not None:
49 outfile
.write("{\"%s\", \"%s\"},\n" % (path
, i
))
51 print "%s: Arrays aren't supported" % path
53 if outfile
is not None:
54 outfile
.write("{0, 0},\n")