-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdnw-send
executable file
·111 lines (99 loc) · 3.16 KB
/
dnw-send
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/python
import string
import struct
import signal
import sys,os
from getopt import getopt, GetoptError
from glob import glob
import fileinput
class SizedFile(file):
def __len__(self):
oldpos = self.tell()
self.seek(0, 2)
length = self.tell()
self.seek(oldpos)
return length
def go_dnw(address,send_name):
int_addr = int(address,16)
print "%s %s" %(address,send_name)
print "------------------------------"
if os.access(send_name,os.R_OK):
a = SizedFile(send_name)
else:
print "%s Must be existed QUiT.." % send_name
return
binfile = open('/tmp/binfile','wb')
data = struct.pack('I',int_addr)
data1 = struct.pack('i',len(a)+len(data))
binfile.write(data)
binfile.write(data1)
lines = words = chars = 0
for line in fileinput.input(glob(send_name)):
binfile.write(line)
lines += 1
words += len(line.split())
chars += len(line)
binfile.close()
if os.access("/dev/dnwOTG",os.R_OK):
os.system("cat /tmp/binfile > /dev/dnwOTG")
print "%s is sended via USB DNW" % send_name
os.unlink("/tmp/binfile")
else:
print "dnwOTG Device not founded"
if os.access("/tmp/binfile",os.R_OK):
os.unlink("/tmp/binfile")
def profile():
global address,send_name
print "reteive info ..."
dnwparams={}
if os.access(os.environ['HOME']+'/.dnwrc0',os.R_OK):
for ln in open(os.environ['HOME']+'/.dnwrc0').readlines():
if not ln[0] in ('#',';'):
key,val=ln.strip().split('=',1)
dnwparams[key.lower()]=val
for mandatory in ['address','fname']:
if mandatory not in dnwparams.keys():
open(os.environ['HOME']+'/.dnwrc0','w').write('#Uncomment fields before use and type in correct credentials.\n#address=0x57e00000\n#fname=/tftpboot/u-boot.bin\n')
print 'Please point ~/.dnwrc0 config file to valid address and fname messages.'
sys.exit(0)
address=dnwparams['address']
send_name=dnwparams['fname']
go_dnw(address,send_name)
def cmd_profile(addr,nimg):
go_dnw(addr,nimg)
def main(*argv):
from getopt import getopt, GetoptError
try:
(opts, args) = getopt(argv[1:],\
'ha:n:',\
[])
except GetoptError, e:
print e
print __doc__
return 1
Running = 0
for o, a in opts:
if o in ('-h', '--help'):
print "usage:"
print "dnw-send -a0x57000000 -nzImage"
return 0
elif o in ('-a', '--addr'):
addr = a
print addr
Running = Running + 1
elif o in ('-n', '--name'):
nimg = a
print nimg
Running = Running + 1
else:
print "Unknown argument: %s" % o
print __doc__
return 1
if (Running == 2):
print "Send DNW cmd...."
cmd_profile(addr,nimg)
return 0
if (len(args)==0):
profile()
if __name__ == '__main__':
sys.exit(main(*sys.argv))