-
Notifications
You must be signed in to change notification settings - Fork 18
/
jsonfdtdump.py
executable file
·35 lines (28 loc) · 1.16 KB
/
jsonfdtdump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
JSON to Fdt dumper
See JSONDeviceTree.md for format
@author: Neil 'superna' Armstrong <[email protected]>
"""
import argparse
from pyfdt.pyfdt import FdtJsonParse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Device Tree Blob JSON to DTB')
parser.add_argument('--format', dest = 'format' ,help="output format (dts, dtb or json), default to dts", default = "dts")
parser.add_argument('in_filename', help="input filename")
parser.add_argument('out_filename', help="output filename")
args = parser.parse_args()
if args.format not in ('dts', 'dtb', 'json'):
raise Exception('Invalid Output Format')
with open(args.in_filename) as infile:
fdt = FdtJsonParse(infile.read())
if args.format == "dts":
with open(args.out_filename, 'wb') as outfile:
outfile.write(fdt.to_dts())
elif args.format == "dtb":
with open(args.out_filename, 'wb') as outfile:
outfile.write(fdt.to_dtb())
elif args.format == "json":
with open(args.out_filename, 'wb') as outfile:
outfile.write(fdt.to_json())