Example #1
0
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())
Example #2
0
    parser.add_argument('in_dtb2', help="input filename 2")
    parser.add_argument('out_filename', help="output filename")
    args = parser.parse_args()

    if args.format1 not in ('fs', 'dtb', 'json'):
        raise Exception('Invalid Format1')
    if args.format2 not in ('fs', 'dtb', 'json'):
        raise Exception('Invalid Format2')

    if args.format1 == 'dtb':
        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())
Example #3
0
    parser.add_argument("in_dtb1", help="input filename 1")
    parser.add_argument("in_dtb2", help="input filename 2")
    args = parser.parse_args()

    if args.format1 not in ("fs", "dtb", "json"):
        raise Exception("Invalid Format1")
    if args.format2 not in ("fs", "dtb", "json"):
        raise Exception("Invalid Format2")

    if args.format1 == "dtb":
        with open(args.in_dtb1, "rb") 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, "rb") as infile:
            dtb2 = FdtBlobParse(infile)
        fdt2 = dtb2.to_fdt()
    elif args.format2 == "json":
        with open(args.in_dtb2, "r") as infile:
            fdt2 = FdtJsonParse(infile.read())
    else:
        fdt2 = FdtFsParse(args.in_dtb2)

    if fdt1.get_rootnode() == fdt2.get_rootnode():
        sys.exit(0)
Example #4
0
    parser.add_argument('in_dtb1', help="input filename 1")
    parser.add_argument('in_dtb2', help="input filename 2")
    args = parser.parse_args()

    if args.format1 not in ('fs', 'dtb', 'json'):
        raise Exception('Invalid Format1')
    if args.format2 not in ('fs', 'dtb', 'json'):
        raise Exception('Invalid Format2')

    if args.format1 == 'dtb':
        with open(args.in_dtb1, 'rb') 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, 'rb') as infile:
            dtb2 = FdtBlobParse(infile)
        fdt2 = dtb2.to_fdt()
    elif args.format2 == 'json':
        with open(args.in_dtb2, 'r') as infile:
            fdt2 = FdtJsonParse(infile.read())
    else:
        fdt2 = FdtFsParse(args.in_dtb2)

    if fdt1.get_rootnode() == fdt2.get_rootnode():
        sys.exit(0)