X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFET.py;h=d7875bc6e2a68f695eb238fee8dedd00092b1eea;hp=077ee75b0fa4e00f5ad881e62042a45d2b2ffbdc;hb=a3dbd267c9f9a20853ccbf64011ce3e185182106;hpb=8f024cc02ed60aaca66ecca2de8d56ca1dfd2c9e diff --git a/client/GoodFET.py b/client/GoodFET.py index 077ee75..d7875bc 100755 --- a/client/GoodFET.py +++ b/client/GoodFET.py @@ -6,6 +6,9 @@ # This code is being rewritten and refactored. You've been warned! import sys, time, string, cStringIO, struct, glob, serial, os; +import sqlite3; + +fmt = ("B", ">16)&0xFF]); print "Got %02x%02x buffer size." % (self.data[1],self.data[0]); @@ -89,6 +129,9 @@ class GoodFET: #little endian 16-bit length self.serialport.write(chr(count&0xFF)); self.serialport.write(chr(count>>8)); + + if self.verbose: + print "Tx: ( 0x%02x, 0x%02x, 0x%04x )" % ( app, verb, count ) #print "count=%02x, len(data)=%04x" % (count,len(data)); @@ -101,34 +144,41 @@ class GoodFET: outstr=''.join(data); self.serialport.write(outstr); if not self.besilent: - self.readcmd(); - - besilent=0; - app=0; - verb=0; - count=0; - data=""; + return self.readcmd() + else: + return [] def readcmd(self): """Read a reply from the GoodFET.""" - while 1: - #print "Reading..."; - self.app=ord(self.serialport.read(1)); - #print "APP=%2x" % self.app; - self.verb=ord(self.serialport.read(1)); - #print "VERB=%02x" % self.verb; - self.count=( - ord(self.serialport.read(1)) - +(ord(self.serialport.read(1))<<8) - ); + while 1:#self.serialport.inWaiting(): # Loop while input data is available + try: + #print "Reading..."; + self.app=ord(self.serialport.read(1)); + #print "APP=%2x" % self.app; + self.verb=ord(self.serialport.read(1)); + #print "VERB=%02x" % self.verb; + self.count=( + ord(self.serialport.read(1)) + +(ord(self.serialport.read(1))<<8) + ); + + if self.verbose: + print "Rx: ( 0x%02x, 0x%02x, 0x%04x )" % ( self.app, self.verb, self.count ) - #Debugging string; print, but wait. - if self.app==0xFF and self.verb==0xFF: - print "# DEBUG %s" % self.serialport.read(self.count); - sys.stdout.flush(); - else: - self.data=self.serialport.read(self.count); - return self.data; + #Debugging string; print, but wait. + if self.app==0xFF: + if self.verb==0xFF: + print "# DEBUG %s" % self.serialport.read(self.count) + elif self.verb==0xFE: + print "# DEBUG 0x%x" % struct.unpack(fmt[self.count-1], self.serialport.read(self.count))[0] + sys.stdout.flush(); + else: + self.data=self.serialport.read(self.count); + return self.data; + except TypeError: + print "Error: waiting for serial read timed out (most likely)." + sys.exit(-1) + #Glitching stuff. def glitchApp(self,app): """Glitch into a device by its application.""" @@ -173,7 +223,9 @@ class GoodFET: self.besilent=s; print "besilent is %i" % self.besilent; self.writecmd(0,0xB0,1,[s]); - + def mon_connected(self): + """Announce to the monitor that the connection is good.""" + self.writecmd(0,0xB1,0,[]); def out(self,byte): """Write a byte to P5OUT.""" self.writecmd(0,0xA1,1,[byte]); @@ -286,16 +338,27 @@ class GoodFET: def start(self): return; def test(self): + print "Unimplemented."; return; def status(self): + print "Unimplemented."; return; def halt(self): + print "Unimplemented."; return; def resume(self): + print "Unimplemented."; return; + def getpc(self): + print "Unimplemented."; + return 0xdead; def flash(self,file): """Flash an intel hex file to code memory.""" print "Flash not implemented."; + def dump(self,file,start=0,stop=0xffff): + """Dump an intel hex file from code memory.""" + print "Dump not implemented."; + def peek32(self,address, memory="vn"): return (self.peek16(address,memory)+ (self.peek16(address+2,memory)<<16)); @@ -303,4 +366,6 @@ class GoodFET: return (self.peek8(address,memory)+ (self.peek8(address+1,memory)<<8)); def peek8(self,address, memory="vn"): - return 0xde; + return self.peekbyte(address); #monitor + def loadsymbols(self): + return;