See JSONDeviceTree.md for format @author: Neil 'superna' Armstrong <*****@*****.**> """ 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())
with open(args.in_dtb1) as infile: dtb1 = FdtBlobParse(infile) fdt1 = dtb1.to_fdt() elif args.format1 == 'json': with open(args.in_dtb1) as infile: fdt1 = FdtJsonParse(infile.read()) else: fdt1 = FdtFsParse(args.in_dtb1) if args.format2 == 'dtb': with open(args.in_dtb2) as infile: dtb2 = FdtBlobParse(infile) fdt2 = dtb2.to_fdt() elif args.format2 == 'json': with open(args.in_dtb2) as infile: fdt2 = FdtJsonParse(infile.read()) else: fdt2 = FdtFsParse(args.in_dtb2) fdt1.get_rootnode().merge(fdt2.get_rootnode()) if args.outformat == "dts": with open(args.out_filename, 'wb') as outfile: outfile.write(fdt1.to_dts()) elif args.outformat == "dtb": with open(args.out_filename, 'wb') as outfile: outfile.write(fdt1.to_dtb()) elif args.outformat == "json": with open(args.out_filename, 'wb') as outfile: outfile.write(fdt1.to_json())