X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FGoodFET.py;h=353d937ec80f1f4f68c441f9a970f397fdbce2b9;hp=154bd389d98de4f1f533b3a5b27004230d1e5473;hb=1ef22a7f7983e4bb7513686cd573776a8338c904;hpb=8eed366711c123dbd740b0bc0d5ca0e0c0d770e8 diff --git a/client/GoodFET.py b/client/GoodFET.py index 154bd38..353d937 100755 --- a/client/GoodFET.py +++ b/client/GoodFET.py @@ -72,7 +72,7 @@ class GoodFET: return self.symbols.get(name); def timeout(self): print "timeout\n"; - def serInit(self, port=None, timeout=2): + def serInit(self, port=None, timeout=2, attemptlimit=None): """Open the serial port""" # Make timeout None to wait forever, 0 for non-blocking mode. @@ -90,6 +90,10 @@ class GoodFET: glob_list = glob.glob("/dev/ttyUSB*"); if len(glob_list) > 0: port = glob_list[0]; + if port is None: + glob_list = glob.glob("/dev/ttyU0"); + if len(glob_list) > 0: + port = glob_list[0]; if os.name=='nt': from scanwin32 import winScan; scan=winScan(); @@ -115,7 +119,10 @@ class GoodFET: connected=0; while connected==0: while self.verb!=0x7F or self.data!="http://goodfet.sf.net/": - #print "Resyncing."; + if attemptlimit is not None and attempts >= attemptlimit: + return + elif attempts>2: + print "Resyncing."; self.serialport.flushInput() self.serialport.flushOutput() #Explicitly set RTS and DTR to halt board. @@ -126,6 +133,7 @@ class GoodFET: #TelosB reset, prefer software to I2C SPST Switch. if(os.environ.get("platform")=='telosb'): + #print "TelosB Reset"; self.telosBReset(); #self.serialport.write(chr(0x80)); #self.serialport.write(chr(0x80)); @@ -150,6 +158,9 @@ class GoodFET: break; if self.verbose: print "Connected after %02i attempts." % attempts; self.mon_connected(); + self.serialport.setTimeout(12); + def serClose(self): + self.serialport.close(); def telosSetSCL(self, level): self.serialport.setRTS(not level) def telosSetSDA(self, level): @@ -287,9 +298,9 @@ class GoodFET: return self.data; except TypeError: if self.connected: - print "Error: waiting for serial read timed out (most likely)."; - print "This shouldn't happen after syncing. Exiting for safety."; - sys.exit(-1) + print "Warning: waiting for serial read timed out (most likely)."; + #print "This shouldn't happen after syncing. Exiting for safety."; + #sys.exit(-1) return self.data; #Glitching stuff. def glitchApp(self,app): @@ -313,8 +324,11 @@ class GoodFET: """Time the execution of a verb.""" if data==None: data=[]; self.data=[app&0xff, verb&0xFF]+data; + print "Timing app %02x verb %02x." % (app,verb); self.writecmd(self.GLITCHAPP,0x82,len(self.data),self.data); - return ord(self.data[0])+(ord(self.data[1])<<8); + time=ord(self.data[0])+(ord(self.data[1])<<8); + print "Timed to be %i." % time; + return time; def glitchVoltages(self,low=0x0880, high=0x0fff): """Set glitching voltages. (0x0fff is max.)""" self.data=[low&0xff, (low>>8)&0xff, @@ -354,39 +368,60 @@ class GoodFET: """Execute supplied code.""" self.writecmd(0,0x31,2,#len(code), code); - def peekbyte(self,address): + def MONpeek8(self,address): """Read a byte of memory from the monitor.""" self.data=[address&0xff,address>>8]; self.writecmd(0,0x02,2,self.data); #self.readcmd(); return ord(self.data[0]); - def peekword(self,address): + def MONpeek16(self,address): """Read a word of memory from the monitor.""" - return self.peekbyte(address)+(self.peekbyte(address+1)<<8); + return self.MONpeek8(address)+(self.MONpeek8(address+1)<<8); def peek(self,address): """Read a word of memory from the monitor.""" - return self.peekbyte(address)+(self.peekbyte(address+1)<<8); + return self.MONpeek8(address)+(self.MONpeek8(address+1)<<8); def eeprompeek(self,address): """Read a word of memory from the monitor.""" - return self.peekbyte(address)+(self.peekbyte(address+1)<<8); - - def pokebyte(self,address,value): + print "EEPROM peeking not supported for the monitor."; + #return self.MONpeek8(address)+(self.MONpeek8(address+1)<<8); + def peekbysym(self,name): + """Read a value by its symbol name.""" + #TODO include memory in symbol. + reg=self.symbols.get(name); + return self.peek8(reg,"data"); + def pokebysym(self,name,val): + """Write a value by its symbol name.""" + #TODO include memory in symbol. + reg=self.symbols.get(name); + return self.pokebyte(reg,val); + def pokebyte(self,address,value,memory="vn"): """Set a byte of memory by the monitor.""" self.data=[address&0xff,address>>8,value]; self.writecmd(0,0x03,3,self.data); return ord(self.data[0]); + def poke16(self,address,value): + """Set a word of memory by the monitor.""" + self.pokebyte(address,value&0xFF); + self.pokebyte(address,(value>>8)&0xFF); + return value; def setsecret(self,value): """Set a secret word for later retreival. Used by glitcher.""" - self.eeprompoke(0,value); - self.eeprompoke(1,value); + #self.eeprompoke(0,value); + #self.eeprompoke(1,value); + print "Secret setting is not yet suppored for this target."; + print "Aborting."; + def getsecret(self): """Get a secret word. Used by glitcher.""" - self.eeprompeek(0); + #self.eeprompeek(0); + print "Secret setting is not yet suppored for this target."; + print "Aborting."; + sys.exit(); def dumpmem(self,begin,end): i=begin; while i