crashtest-r0ket/tools/bootloader/gangflash

116 lines
3.6 KiB
Plaintext
Raw Permalink Normal View History

2011-08-05 16:49:36 +00:00
#!/usr/bin/env python
# -*- coding: utf8 -*-
import os
import time
import shutil
def flash(count, target, firmware):
flashed = []
while len(flashed) != count:
filelist = []
try:
filelist = os.listdir(target)
except:
pass
oldflashed = flashed
flashed = []
for x in oldflashed:
if x in filelist:
flashed.append(x)
else:
print "removed %s" % x
filelist = [x for x in filelist if x not in flashed]
print "filelist", filelist
for device in filelist:
try:
print "open", firmware
f = open(firmware, "r")
print "open", target + device
dev = open(target + device, "w")
dev.seek(0x800)
print "write"
dev.write(f.read())
print "close f"
f.close()
print "close dev"
dev.close()
print "flashed %s" % device
except Exception, ex:
print "error!"
print ex
flashed.append(device)
time.sleep(1)
def copy(count, target, dir):
flashed = []
2011-08-06 05:11:45 +00:00
#filestocopy = os.listdir(dir)
2011-08-05 16:49:36 +00:00
os.mkdir("/tmp/r0ket")
while len(flashed) != count:
filelist = []
2011-08-06 19:52:45 +00:00
while len(filelist) != count:
try:
filelist = os.listdir(target)
except:
pass
2011-08-05 16:49:36 +00:00
oldflashed = flashed
flashed = []
for x in oldflashed:
if x in filelist:
flashed.append(x)
else:
print "removed %s" % x
filelist = [x for x in filelist if x not in flashed]
print "filelist:",filelist
for device in filelist:
try:
time.sleep(0.3)
print "mkdir", "/tmp/r0ket/"+device
os.mkdir("/tmp/r0ket/"+device)
2011-08-06 19:52:45 +00:00
print "mount -t vfat "+target+device+" "+"/tmp/r0ket/"+device
x = 1
while x != 0:
x = os.system("mount -t vfat "+target+device+" "+"/tmp/r0ket/"+device)
print "returned", x
if x != 0:
time.sleep(5)
2011-08-06 05:11:45 +00:00
os.system("../tools/crypto/generate-keys")
#for file in filestocopy:
print "cp "+dir+"/* /tmp/r0ket/"+device
os.system("cp "+dir+"/* /tmp/r0ket/"+device)
2011-08-05 16:49:36 +00:00
print "flashed %s" % device
except Exception, ex:
print "error!"
print ex
flashed.append(device)
print "sync"
os.system("sync")
mounted = os.listdir("/tmp/r0ket")
print "mounted", mounted
for mount in mounted:
print "touch /tmp/r0ket/"+mount+"/flashed.cfg"
os.system("touch /tmp/r0ket/"+mount+"/flashed.cfg")
2011-08-06 05:11:45 +00:00
print "sync"
os.system("sync")
2011-08-06 19:52:45 +00:00
time.sleep(1)
2011-08-05 16:49:36 +00:00
print "umount /tmp/r0ket/"+mount
os.system("umount /tmp/r0ket/"+mount)
print "rm /tmp/r0ket/"+mount
os.rmdir("/tmp/r0ket/"+mount)
time.sleep(1)
print "rm /tmp/r0ket"
os.rmdir("/tmp/r0ket")
2011-08-06 19:52:45 +00:00
os.system("umount /tmp/r0ket/*")
os.system("rm /tmp/r0ket -rf")
os.system("rm /dev/r0ketflash/*")
2011-08-05 16:49:36 +00:00
while True:
raw_input("Flashed firmware.\nNow cycle power and press enter.")
2011-08-06 19:52:45 +00:00
flash(9, "/dev/lpcflash/", "initial.bin")
2011-08-06 05:11:45 +00:00
raw_input("Flashed bootstrap firmware.\nNow cycle power and press enter.")
2011-08-06 19:52:45 +00:00
copy(9, "/dev/r0ketflash/","files")
flash(9, "/dev/lpcflash/", "final.bin")
2011-08-05 16:49:36 +00:00