From 1af64014935ad7877bbeda1331fee514ff3502af Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Thu, 25 Aug 2016 21:44:51 +0100 Subject: u2b convert uboot memdump file converter to binary file --- uboot2bin/u2b.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 uboot2bin/u2b.py (limited to 'uboot2bin') diff --git a/uboot2bin/u2b.py b/uboot2bin/u2b.py new file mode 100644 index 0000000..4505c98 --- /dev/null +++ b/uboot2bin/u2b.py @@ -0,0 +1,43 @@ +#!/usr/bin/python +import argparse +import sys +import os + +s="9f000000: 10 00 00 ff 00 00 00 00 10 00 00 fd 00 00 00 00 ................" + +def uboot2str(s): + ret = "" + s = s.replace("\n","") + s = s.replace(" ","") + ret = s.split(":")[1][:32] + return ret + +def str2byte(s): + ret = [] + l = len(s) + for i in range(0,l,2): + num = s[i]+s[i+1] + ret.append(int(num,16)) + return ret + +def byte2bfile(f,bytes): + ba = bytearray(bytes) + f.write(ba) + +ap = argparse.ArgumentParser() +ap.add_argument("--ifile",dest='ifname',action='store',required=True,help="Run test") +ap.add_argument("--ofile",dest='ofname',action='store',required=True,help="Run test") + +if __name__=="__main__": + apn = ap.parse_args() + args = vars(apn) + in_f = open(args["ifname"],"r") + if in_f == None: + print("Cant open %s"%ifname) + out_f = open(args["ofname"],"wb") + + for line in in_f: + byte2bfile(out_f,str2byte(uboot2str(line))) + + in_f.close() + out_f.close() \ No newline at end of file -- cgit v1.2.3