Interactive debugger, or parts of one.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Tue, 23 Feb 2010 01:23:36 +0000 (01:23 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Tue, 23 Feb 2010 01:23:36 +0000 (01:23 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@345 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFET.py
client/GoodFETCC.py
client/GoodFETConsole.py [new file with mode: 0644]
client/goodfet [new file with mode: 0755]
client/goodfet.cc
client/goodfet.monitor

index 27ea0e5..d2beb5c 100755 (executable)
@@ -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;
index 83d0b9f..894db94 100644 (file)
@@ -21,7 +21,7 @@ class GoodFETCC(GoodFET):
     def CCreleasecpu(self):
         """Resume the CPU."""
         self.writecmd(0x30,0x87,0,self.data);
     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();
         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"};
                  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);
     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 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];
     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
                   };
                   
                   0x01 : "sel_flash_info_page" #stricken from CC2530
                   };
                   
-    def CCstatusstr(self):
+    def status(self):
         """Check the status as a string."""
         status=self.CCstatus();
         str="";
         """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;
         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();
         self.CCreleasecpu();
         self.CChaltcpu();
-        #print "Status: %s." % self.CCstatusstr();
+        #print "Status: %s." % self.status();
         
     def stop(self):
         """Stop debugging."""
         
     def stop(self):
         """Stop debugging."""
diff --git a/client/GoodFETConsole.py b/client/GoodFETConsole.py
new file mode 100644 (file)
index 0000000..14fc3e3
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+# GoodFET Client Library
+# 
+# (C) 2009 Travis Goodspeed <travis at radiantmachines.com>
+#
+# 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 (executable)
index 0000000..8a510a9
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+# GoodFET Debugger
+# 
+# (C) 2009 Travis Goodspeed <travis at radiantmachines.com>
+#
+# 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);
index 6682650..7dbb59a 100755 (executable)
@@ -38,17 +38,17 @@ client.start();
 
 if(sys.argv[1]=="explore"):
     print "Exploring undefined commands."
 
 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]);
     
     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"):
     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();
 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"):
         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"):
 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();
     client.CCchiperase();
-    print "Status: %s" %client.CCstatusstr();
+    print "Status: %s" %client.status();
 
 if(sys.argv[1]=="peekinfo"):
     print "Select info flash."
 
 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 "Flashed final page at %06x" % page;
      
 if(sys.argv[1]=="lock"):
-    print "Status: %s" %client.CCstatusstr();
+    print "Status: %s" %client.status();
     client.CClockchip();
     client.CClockchip();
-    print "Status: %s" %client.CCstatusstr();
+    print "Status: %s" %client.status();
 if(sys.argv[1]=="flashpage"):
     target=0;
     if(len(sys.argv)>2):
 if(sys.argv[1]=="flashpage"):
     target=0;
     if(len(sys.argv)>2):
index 2a81c55..fb92528 100755 (executable)
@@ -45,9 +45,7 @@ if(sys.argv[1]=="exec"):
     client.execute(code);
     
 if(sys.argv[1]=="info"):
     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"):
 if(sys.argv[1]=="ramfill"):
     client.monitor_ram_pattern();
 if(sys.argv[1]=="ramdepth"):