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
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()
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
)
25 for (path
, node
) in fdt
.resolve_path('/cavium,bdk').walk():
27 path
= path
.replace("/", "")
30 if type(i
) is not unicode:
31 print "%s: Type is not string" % path
34 print "%s = %s" % (path
, i
)
35 if outfile
is not None:
36 outfile
.write("{\"%s\", \"%s\"},\n" % (path
, i
))
38 print "%s: Arrays aren't supported" % path
40 if outfile
is not None:
41 outfile
.write("{0, 0},\n")