-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdtbdump.py
executable file
·35 lines (28 loc) · 1.17 KB
/
dtbdump.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 -*-
"""
Python DTB dumper
@author: Neil 'superna' Armstrong <[email protected]>
"""
import argparse
from pyfdt.pyfdt import FdtBlobParse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Device Tree Blob dump')
parser.add_argument('--format', dest = 'format' ,help="output format (dts, json or dtb), 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', 'json', 'dtb'):
raise Exception('Invalid Output Format')
with open(args.in_filename, 'rb') as infile:
dtb = FdtBlobParse(infile)
fdt = dtb.to_fdt()
if args.format == "dts":
with open(args.out_filename, 'wb') as outfile:
outfile.write(fdt.to_dts().encode('ascii'))
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().encode('ascii'))