X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFET.py;h=583f1b12bb6149421d524af2d994448a847194a1;hp=bb6741a4e13833a8a80518da28cfbbac4ab70f68;hb=e12a1ab7338cb974193113dce8c2413c0fd1bc78;hpb=5fb287d94778555a45f61421081aa7b0ffd64eae diff --git a/client/GoodFET.py b/client/GoodFET.py index bb6741a..583f1b1 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]); @@ -89,6 +127,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 +142,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.""" @@ -286,12 +334,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)); @@ -299,4 +362,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;