From: travisutk Date: Tue, 23 Feb 2010 01:23:36 +0000 (+0000) Subject: Interactive debugger, or parts of one. X-Git-Url: http://git.rot13.org/?p=goodfet;a=commitdiff_plain;h=dbd55dca7cded37fc93f74beb7c3043f11389d6e;hp=2f740ed7513a1db4c8a7b68f02347b783a4ca7ae Interactive debugger, or parts of one. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@345 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- diff --git a/client/GoodFET.py b/client/GoodFET.py index 27ea0e5..d2beb5c 100755 --- a/client/GoodFET.py +++ b/client/GoodFET.py @@ -255,20 +255,29 @@ class GoodFET: - def I2Csetup(self): - """Move the FET into the I2C application.""" - self.writecmd(0x02,0x10,0,self.data); #SPI/SETUP - def I2Cstart(self): - """Start an I2C transaction.""" - self.writecmd(0x02,0x20,0,self.data); #SPI/SETUP - def I2Cstop(self): - """Stop an I2C transaction.""" - self.writecmd(0x02,0x21,0,self.data); #SPI/SETUP - def I2Cread(self,len=1): - """Read len bytes by I2C.""" - self.writecmd(0x02,0x00,1,[len]); #SPI/SETUP - return self.data; - def I2Cwrite(self,bytes): - """Write bytes by I2C.""" - self.writecmd(0x02,0x01,len(bytes),bytes); #SPI/SETUP - return ord(self.data[0]); + def infostring(self): + a=self.peekbyte(0xff0); + b=self.peekbyte(0xff1); + return "%02x%02x" % (a,b); + def lock(self): + print "Locking Unsupported."; + def erase(self): + print "Erasure Unsupported."; + def setup(self): + return; + def start(self): + return; + def test(self): + return; + def status(self): + return; + + + def peek32(self,address, memory="vn"): + return (self.peek16(address,memory)+ + (self.peek16(address+2,memory)<<16)); + def peek16(self,address, memory="vn"): + return (self.peek8(address,memory)+ + (self.peek8(address+1,memory)<<8)); + def peek8(self,address, memory="vn"): + return 0xde; diff --git a/client/GoodFETCC.py b/client/GoodFETCC.py index 83d0b9f..894db94 100644 --- a/client/GoodFETCC.py +++ b/client/GoodFETCC.py @@ -21,7 +21,7 @@ class GoodFETCC(GoodFET): def CCreleasecpu(self): """Resume the CPU.""" self.writecmd(0x30,0x87,0,self.data); - def CCtest(self): + def test(self): self.CCreleasecpu(); self.CChaltcpu(); #print "Status: %s" % self.CCstatusstr(); @@ -95,7 +95,8 @@ class GoodFETCC(GoodFET): 0xA5: 2048, #"CC2530", #page 52 of SWRU191 0xB5: 2048, #"CC2531", 0xFF: 0 } #"CCmissing"}; - + def infostring(self): + return self.CCidentstr(); def CCidentstr(self): ident=self.CCident(); chip=self.CCversions.get(ident&0xFF00); @@ -131,6 +132,9 @@ class GoodFETCC(GoodFET): def CCdebuginstr(self,instr): self.writecmd(0x30,0x88,len(instr),instr); return ord(self.data[0]); + def peek8(self,address, memory="vn"): + return self.CCpeekcodebyte(address); + def CCpeekcodebyte(self,adr): """Read the contents of code memory at an address.""" self.data=[adr&0xff, (adr&0xff00)>>8]; @@ -192,7 +196,7 @@ class GoodFETCC(GoodFET): 0x01 : "sel_flash_info_page" #stricken from CC2530 }; - def CCstatusstr(self): + def status(self): """Check the status as a string.""" status=self.CCstatus(); str=""; @@ -207,10 +211,10 @@ class GoodFETCC(GoodFET): self.writecmd(0x30,0x20,0,self.data); ident=self.CCidentstr(); #print "Target identifies as %s." % ident; - #print "Status: %s." % self.CCstatusstr(); + #print "Status: %s." % self.status(); self.CCreleasecpu(); self.CChaltcpu(); - #print "Status: %s." % self.CCstatusstr(); + #print "Status: %s." % self.status(); def stop(self): """Stop debugging.""" diff --git a/client/GoodFETConsole.py b/client/GoodFETConsole.py new file mode 100644 index 0000000..14fc3e3 --- /dev/null +++ b/client/GoodFETConsole.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# GoodFET Client Library +# +# (C) 2009 Travis Goodspeed +# +# This code is being rewritten and refactored. You've been warned! + +import sys; +import binascii; + +from GoodFET import GoodFET; +from intelhex import IntelHex; + +class GoodFETConsole(): + """An interactive goodfet driver.""" + + def __init__(self, client): + self.client=client; + client.serInit(); + client.setup(); + client.start(); + def handle(self, str): + """Handle a command string. First word is command.""" + args=str.split(); + if len(args)==0: + return; + try: + eval("self.CMD%s(args)" % args[0]) + except AttributeError: + print "Unknown command '%s'." % args[0]; + def CMDinfo(self,args): + print self.client.infostring() + def CMDlock(self,args): + print "Locking."; + self.client.lock(); + def CMDerase(self,args): + print "Erasing."; + self.client.erase(); + def CMDtest(self,args): + self.client.test(); + return; + def CMDstatus(self,args): + print self.client.status(); + return; + def CMDpeek(self,args): + adr=eval(args[1]); + print "0x%08x:= 0x%04x" % (adr, self.client.peek16(adr)); + return; + diff --git a/client/goodfet b/client/goodfet new file mode 100755 index 0000000..8a510a9 --- /dev/null +++ b/client/goodfet @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# GoodFET Debugger +# +# (C) 2009 Travis Goodspeed +# +# This code is being rewritten and refactored. You've been warned! + +import sys, os, readline, code, binascii; +import rlcompleter; + +from GoodFETConsole import GoodFETConsole; +from GoodFETCC import GoodFETCC; +from GoodFETMSP430 import GoodFETMSP430; +from GoodFET import GoodFET; + +from intelhex import IntelHex; + +if(len(sys.argv)==1): + print "Usage: %s driver\n" % sys.argv[0]; + print "driver:= GoodFETCC GoodFETMSP430"; + sys.exit(1); + +driver=sys.argv[1]; +print "Using driver %s" % driver; +client=eval("%s()" % driver); +console=GoodFETConsole(client); + +while 1: + sys.stdout.write("gf% "); + sys.stdout.flush(); + cmd=sys.stdin.readline(); + console.handle(cmd); + +sys.exit(0); diff --git a/client/goodfet.cc b/client/goodfet.cc index 6682650..7dbb59a 100755 --- a/client/goodfet.cc +++ b/client/goodfet.cc @@ -38,17 +38,17 @@ client.start(); if(sys.argv[1]=="explore"): print "Exploring undefined commands." - print "Status: %s" %client.CCstatusstr(); + print "Status: %s" %client.status(); cmd=0x04; #read status for foo in range(0,0x5): client.CCcmd([(0x0F<<3)|(0x00)|0x03,0x09<<3]); - print "Status %02x: %s" % (foo,client.CCstatusstr()); + print "Status %02x: %s" % (foo,client.status()); for foo in range(0,3): print "PC: %04x" % client.CCgetPC(); if(sys.argv[1]=="test"): - client.CCtest(); + client.test(); if(sys.argv[1]=="deadtest"): for i in range(1,10): print "IDENT as %s" % client.CCidentstr(); @@ -89,13 +89,13 @@ if(sys.argv[1]=="dumpdata"): i+=1; h.write_hex_file(f); if(sys.argv[1]=="status"): - print "Status: %s" %client.CCstatusstr(); + print "Status: %s" %client.status(); if(sys.argv[1]=="info"): print "%s" % client.CCidentstr(); if(sys.argv[1]=="erase"): - print "Status: %s" % client.CCstatusstr(); + print "Status: %s" % client.status(); client.CCchiperase(); - print "Status: %s" %client.CCstatusstr(); + print "Status: %s" %client.status(); if(sys.argv[1]=="peekinfo"): print "Select info flash." @@ -176,9 +176,9 @@ if(sys.argv[1]=="flash"): print "Flashed final page at %06x" % page; if(sys.argv[1]=="lock"): - print "Status: %s" %client.CCstatusstr(); + print "Status: %s" %client.status(); client.CClockchip(); - print "Status: %s" %client.CCstatusstr(); + print "Status: %s" %client.status(); if(sys.argv[1]=="flashpage"): target=0; if(len(sys.argv)>2): diff --git a/client/goodfet.monitor b/client/goodfet.monitor index 2a81c55..fb92528 100755 --- a/client/goodfet.monitor +++ b/client/goodfet.monitor @@ -45,9 +45,7 @@ if(sys.argv[1]=="exec"): client.execute(code); if(sys.argv[1]=="info"): - a=client.peekbyte(0xff0); - b=client.peekbyte(0xff1); - print "GoodFET with %02x%02x MCU" % (a,b); + print "GoodFET with %s MCU" % client.infostring(); if(sys.argv[1]=="ramfill"): client.monitor_ram_pattern(); if(sys.argv[1]=="ramdepth"):