summaryrefslogtreecommitdiff
path: root/uboot2bin/u2b.py
blob: 4505c98daaf388186fa8ea27f7b5999970d1dc46 (plain) (blame)
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
36
37
38
39
40
41
42
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()