forked from robovero/firmware
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflash.py
More file actions
executable file
·75 lines (62 loc) · 1.8 KB
/
flash.py
File metadata and controls
executable file
·75 lines (62 loc) · 1.8 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
74
75
#!/usr/bin/env python
import os, subprocess, sys, time, os, platform, json
arch = platform.machine()
debug = open("debug.log", "w")
ESC = chr(27)
try:
config_file = open("flashconfig")
except:
exit("\n"
"ERROR: flashconfig not found. try:\n"
" $ cp flashconfig.sample flashconfig\n"
" set OPENOCD_PATH and GDB_PATH in flashconfig and retry.\n")
try:
config = json.load(config_file)
except:
exit("\n"
"ERROR: invalid flashconfig")
print "getting sudo password"
sudo_cmd = "sudo echo".split()
if subprocess.call(sudo_cmd):
raw_input("error: wrong password")
exit(1)
print "starting openocd:",
openocd_cmd = ("sudo %sopenocd -f interface/openocd-usb.cfg -f target/lpc1769.cfg" % config["OPENOCD_PATH"]).split()
openocd = subprocess.Popen(openocd_cmd, stdout=debug, stderr=debug)
time.sleep(1)
openocd.poll()
while openocd.returncode == 1:
print "jtag not detected. retrying"
openocd = subprocess.Popen(openocd_cmd, stdout=debug, stderr=debug)
time.sleep(1)
openocd.poll()
print "jtag chain detected"
print "gdb runtime: 0s",
sys.stdout.flush()
gdb_cmd = ("%sarm-bare_newlib_cortex_m3_nommu-eabi-gdb -x .gdbflash firmware" % config["GDB_PATH"]).split()
gdb = subprocess.Popen(gdb_cmd, stdout=debug, stderr=debug)
elapsed = 0
while gdb.returncode == None:
gdb.poll()
if elapsed > 120:
sys.stdout.write("\r" + ESC + "[2K")
sys.stdout.write("gdb runtime: timeout")
sys.stdout.flush()
gdb.terminate()
gdb.returncode = 1
break
time.sleep(1)
elapsed += 1
sys.stdout.write("\r" + ESC + "[2K")
sys.stdout.write("gdb runtime: %ds" % elapsed)
sys.stdout.flush()
print ""
"closing openocd. flash",
kill_openocd_cmd = ("sudo kill %d" % openocd.pid).split()
subprocess.call(kill_openocd_cmd)
if gdb.returncode:
raw_input("failed. please try again")
exit(1)
else:
print "succeeded"
raw_input("done. ")