RAM usage monitor, see blog for details.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 20 Aug 2009 15:08:47 +0000 (15:08 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 20 Aug 2009 15:08:47 +0000 (15:08 +0000)
Also support for recognizing the M45PE10 SPI Flash chip, thanks to Ben Byer.

git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@82 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFET.py
client/goodfet.cc
client/goodfet.monitor [new file with mode: 0755]
client/goodfet.msp430
client/goodfet.spiflash

index f48d9cd..8d588ed 100755 (executable)
@@ -6,9 +6,7 @@
 # This code is ugly as sin, for bootstrapping the firmware only.
 # Rewrite cleanly as soon as is convenient.
 
-import sys, time, string, cStringIO, struct
-#sys.path.append("/usr/lib/tinyos")
-import serial
+import sys, time, string, cStringIO, struct, glob, serial
 
 
 class GoodFET:
@@ -16,8 +14,18 @@ class GoodFET:
         self.data=[0];
     def timeout(self):
         print "timout\n";
-    def serInit(self, port):
+    def serInit(self, port=None):
         """Open the serial port"""
+        
+        if port is None:
+            glob_list = glob.glob("/dev/tty.usbserial*");
+            if len(glob_list) > 0:
+                port = glob_list[0];
+        if port is None:
+            glob_list = glob.glob("/dev/ttyUSB*");
+            if len(glob_list) > 0:
+                port = glob_list[0];
+        
         self.serialport = serial.Serial(
             port,
             #9600,
@@ -69,6 +77,19 @@ class GoodFET:
         self.data=[address&0xff,address>>8,value];
         self.writecmd(0,0x03,3,self.data);
         return ord(self.data[0]);
+    def dumpmem(self,begin,end):
+        i=begin;
+        while i<end:
+            print "%04x %04x" % (i, self.peekword(i));
+            i+=2;
+    def monitor_ram_pattern(self):
+        """Overwrite all of RAM with 0xBEEF."""
+        self.writecmd(0,0x90,0,self.data);
+        return;
+    def monitor_ram_depth(self):
+        """Determine how many bytes of RAM are unused by looking for 0xBEEF.."""
+        self.writecmd(0,0x91,0,self.data);
+        return ord(self.data[0])+(ord(self.data[1])<<8);
     def setBaud(self,baud):
         rates=[9600, 9600, 19200, 38400];
         self.data=[baud];
@@ -116,7 +137,9 @@ class GoodFET:
     
     JEDECmanufacturers={0xFF: "MISSING",
                         0xEF: "Winbond",
-                        0xC2: "MXIC"};
+                        0xC2: "MXIC",
+                        0x20: "Numonyx/ST"
+                        };
 
     JEDECdevices={0xFFFFFF: "MISSING",
                   0xEF3014: "W25X80L",
@@ -124,7 +147,8 @@ class GoodFET:
                   0xEF3012: "W25X20L",
                   0xEF3011: "W25X10L",
                   0xC22014: "MX25L8005",
-                  0xC22013: "MX25L4005"
+                  0xC22013: "MX25L4005",
+                  0x204011: "M45PE10"
                   };
     def SPIjedec(self):
         """Grab an SPI Flash ROM's JEDEC bytes."""
index 10442b1..3b97280 100755 (executable)
@@ -23,7 +23,7 @@ if(len(sys.argv)==1):
 
 #Initailize FET and set baud rate
 client=GoodFET();
-client.serInit("/dev/ttyUSB0")
+client.serInit()
 
 #Connect to target
 client.CCsetup();
@@ -83,11 +83,11 @@ if(sys.argv[1]=="erase"):
     
 #     h = IntelHex(f);
     
-#     client.MSP430masserase();
+#     client.CCchiperase();
 #     for i in h._buf.keys():
 #         #print "%04x: %04x"%(i,h[i>>1]);
 #         if(i>=start and i<=stop  and i&1==0):
-#             client.MSP430writeflash(i,h[i>>1]);
+#             client.CCwriteflash(i,h[i>>1]);
 #             if(i%0x100==0):
 #                 print "%04x" % i;
 if(sys.argv[1]=="writedata"):
@@ -106,8 +106,8 @@ if(sys.argv[1]=="writedata"):
             client.CCpokedatabyte(i,h[i]);
             if(i%0x100==0):
                 print "%04x" % i;
-if(sys.argv[1]=="flashtest"):
-    client.MSP430flashtest();
+#if(sys.argv[1]=="flashtest"):
+#    client.CCflashtest();
 if(sys.argv[1]=="peekdata"):
     start=0x0000;
     if(len(sys.argv)>2):
diff --git a/client/goodfet.monitor b/client/goodfet.monitor
new file mode 100755 (executable)
index 0000000..249454f
--- /dev/null
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+
+import sys;
+import binascii;
+
+from GoodFET import GoodFET;
+from intelhex import IntelHex16bit;
+
+if(len(sys.argv)==1):
+    print "Usage: %s verb [objects]\n" % sys.argv[0];
+    print "%s test" % sys.argv[0];
+    print "%s dump $foo.hex [0x$start 0x$stop]" % sys.argv[0];
+    print "%s ivt" % sys.argv[0];
+    print "%s peek [0x$start 0x$stop]" % sys.argv[0];
+    print "%s verify $foo.hex [0x$start 0x$stop]" % sys.argv[0];
+    print "%s ramfill" % sys.argv[0];
+    print "%s ramdepth" % sys.argv[0];
+    sys.exit();
+
+#Initailize FET and set baud rate
+client=GoodFET();
+client.serInit()
+
+
+if(sys.argv[1]=="ramfill"):
+    client.monitor_ram_pattern();
+if(sys.argv[1]=="ramdepth"):
+    print "0x%04x RAM bytes free." % client.monitor_ram_depth();
+if(sys.argv[1]=="test"):
+    client.monitortest();
+if(sys.argv[1]=="dump"):
+    f = sys.argv[2];
+    start=0x0200;
+    stop=0xFFFF;
+    if(len(sys.argv)>3):
+        start=int(sys.argv[3],16);
+    if(len(sys.argv)>4):
+        stop=int(sys.argv[4],16);
+    
+    print "Dumping from %04x to %04x as %s." % (start,stop,f);
+    h = IntelHex16bit(None);
+    i=start;
+    while i<stop:
+        h[i>>1]=client.peekword(i);
+        if(i%0x100==0):
+            print "Dumped %04x."%i;
+        i+=2;
+    h.write_hex_file(f);
+if(sys.argv[1]=="erase"):
+    client.masserase();
+if(sys.argv[1]=="ivt"):
+    client.dumpmem(0xFFE0,0xFFFF);
+
+if(sys.argv[1]=="peek"):
+    start=0xFFE0;
+    stop=0xFFFF;
+    if(len(sys.argv)>2):
+        start=int(sys.argv[2],16);
+    if(len(sys.argv)>3):
+        stop=int(sys.argv[3],16);
+    
+    client.dumpmem(start,stop);
+if(sys.argv[1]=="verify"):
+    f=sys.argv[2];
+    start=0;
+    stop=0xFFFF;
+    if(len(sys.argv)>3):
+        start=int(sys.argv[3],16);
+    if(len(sys.argv)>4):
+        stop=int(sys.argv[4],16);
+    
+    h = IntelHex16bit(f);
+    for i in h._buf.keys():
+        if(i>=start and i<stop and i&1==0):
+            peek=client.peek(i)
+            if(h[i>>1]!=peek):
+                print "ERROR at %04x, found %04x not %04x"%(i,peek,h[i>>1]);
+            if(i%0x100==0):
+                print "%04x" % i;
+
+if(sys.argv[1]=="whatever"):
+    for i in [0x24FF, 0x2500, 0x2502, 0x2504]:
+        print "%04x" % client.peekword(i);
+
index 7e5c065..591f2ea 100755 (executable)
@@ -19,9 +19,7 @@ if(len(sys.argv)==1):
 
 #Initailize FET and set baud rate
 client=GoodFET();
-client.serInit("/dev/ttyUSB0")
-
-
+client.serInit()
 
 #Connect to target
 client.MSP430setup();
index 354d502..c2bc60b 100755 (executable)
@@ -26,7 +26,7 @@ if(len(sys.argv)==1):
 
 #Initailize FET and set baud rate
 client=GoodFET();
-client.serInit("/dev/ttyUSB0")
+client.serInit()
 
 
 client.SPIsetup();