Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/python
import sys
import serial
a = "[000F5BD7][0x00015c60] 1000d8e4 100070dd 10006ad5 1000a482"
# 0x00015c60
reflen = len(a)
MODE_NONE = 0
MODE_WAIT = 1
MODE_READ = 2
ser = serial.Serial()
ser.port = "/dev/ttyUSB0"
ser.baudrate = 115200
ser.timeout=10
try:
ser.open()
except:
print "fuck - couldn't open serial"
sys.exit(0)
mode = MODE_NONE
# addr = 0x54e200f0
# addr = 0x54d1ab50
# addr = 0x54c155b0
# addr = 0x54b10000
# end = addr + 4003784
# addr = 0xf5466c00
# end = addr + 0x1000
# addr = 0x55b08000
# end = addr + 494419
# end = 0x60000000
addr = 0xe0000000
end = 0xe0100000
f = open("e000_to_e010","wb")
f.write("[00065E71]exc: d(%08x, ffffffff, 00000000, 00000000, 00000000, 00000000)\n" % addr)
import time
while 1:
try:
line = ser.readline().rstrip()
except:
print "TIMEOUT: the mode is %x" % mode
mode = MODE_NONE
continue
# print "[%s]" % line
if mode == MODE_NONE and "for commands help" in line:
ser.write("M\r")
mode = MODE_WAIT
elif mode == MODE_WAIT:
if "m3 #" in line:
mode = MODE_READ
ser.write("\r\r\rd 0x%08x 0xffffffff\r" % addr)
else:
ser.write("\r")
elif mode == MODE_READ:
if len(line) != reflen:
if "= 0" in line:
print "Done (m3 console prompt in read mode)"
f.close()
sys.exit(0)
elif "UnSec" in line or "FASTBOOT" in line:
mode = MODE_NONE
else:
# print line
addr = int(line.split("][")[1][0:10],16)
if addr > end:
print "Done (addr > end)"
f.close()
sys.exit(0)
else:
print line
f.write(line)
f.write("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment