Repository navigation
Expand file tree
/
Copy pathsimpleflash
More file actions
executable file
·73 lines (63 loc) · 1.63 KB
/
Copy pathsimpleflash
File metadata and controls
executable file
·73 lines (63 loc) · 1.63 KB
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
#!/usr/bin/python
import time
import os
import sys
def getMounts():
d = {}
f = open('/proc/mounts')
for l in f:
if l[0] == '/':
l = l.split()
d[l[0]] = l[1].replace("\\040"," ")
return d
def check(path):
filename = path + '/firmware.bin'
try:
f = open(filename,'r')
size = os.path.getsize(filename)
if f and size == 32*1024:
f.close()
return filename
except:
pass
return None
flashed = []
if len(sys.argv) < 2:
print "Please specify a file to flash."
exit(1)
if len(sys.argv) < 3:
loop = False
else:
loop = True
firmwarefile = sys.argv[1]
print "Firmware to flash:", firmwarefile
print "Searching for a mounted r0ket flash file system."
print "Please connect a r0ket in ISP mode and mount it or have it mounted by your system."
while True:
mounts = getMounts()
unflashed = []
for device in mounts:
if not device in flashed:
unflashed.append(device)
tmp = list(flashed)
flashed = []
for device in tmp:
if device in mounts:
flashed.append(device)
for device in unflashed:
filename = check(mounts[device])
if filename:
print "writing firmware to", filename
ff = open(filename, "r+")
firmware = open(firmwarefile)
ff.write(firmware.read())
ff.flush()
os.fsync(ff.fileno())
ff.close()
firmware.close()
print 'done'
flashed.append(device)
if not loop:
exit(0)
#print mounts
time.sleep(1)