diff options
author | FreeArtMan <dos21h@gmail.com> | 2016-08-25 21:44:51 +0100 |
---|---|---|
committer | FreeArtMan <dos21h@gmail.com> | 2016-08-25 21:44:51 +0100 |
commit | 1af64014935ad7877bbeda1331fee514ff3502af (patch) | |
tree | 3543038038b8edc31ace6d6c347f25c41a725261 /uboot2bin | |
parent | 77c068fdb1287d2ce71633344ea9783485ea2967 (diff) | |
download | code-snippets-1af64014935ad7877bbeda1331fee514ff3502af.tar.gz code-snippets-1af64014935ad7877bbeda1331fee514ff3502af.zip |
u2b convert uboot memdump file converter to binary file
Diffstat (limited to 'uboot2bin')
-rw-r--r-- | uboot2bin/u2b.py | 43 |
1 files changed, 43 insertions, 0 deletions
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 |