16-bit MSP430 support working well from 1612.
[goodfet] / client / goodfet.spiflash
index 571ddc4..88635b0 100755 (executable)
@@ -10,22 +10,22 @@ import sys;
 import binascii;
 import array;
 
-from GoodFET import GoodFET;
+from GoodFETSPI import GoodFETSPIFlash;
 from intelhex import IntelHex;
 
 if(len(sys.argv)==1):
     print "Usage: %s verb [objects]\n" % sys.argv[0];
     print "%s info" % sys.argv[0];
-    print "%s dump $foo.hex [0x$start 0x$stop]" % sys.argv[0];
+    print "%s dump $foo.rom [0x$start 0x$stop]" % sys.argv[0];
     print "%s erase" % sys.argv[0];
-    print "%s flash $foo.hex [0x$start 0x$stop]" % sys.argv[0];
-    #print "%s verify $foo.hex [0x$start 0x$stop]" % sys.argv[0];
+    print "%s flash $foo.rom [0x$start 0x$stop]" % sys.argv[0];
+    print "%s verify $foo.rom [0x$start 0x$stop]" % sys.argv[0];
     print "%s peek 0x$start [0x$stop]" % sys.argv[0];
     print "%s poke 0x$adr 0x$val" % sys.argv[0];
     sys.exit();
 
-#Initailize FET and set baud rate
-client=GoodFET();
+#Initialize FET and set baud rate
+client=GoodFETSPIFlash();
 client.serInit()
 
 
@@ -74,7 +74,7 @@ if(sys.argv[1]=="dump"):
     
     print "Dumping code from %06x to %06x as %s." % (start,stop,f);
     file = open(f, mode='wb')
-
+    
     i=start;
     while i<=stop:
         data=client.SPIpeekblock(i,255);
@@ -84,6 +84,33 @@ if(sys.argv[1]=="dump"):
             if i<stop: file.write(j);
             i+=1;
     file.close()
+
+if(sys.argv[1]=="verify"):
+    f = sys.argv[2];
+    start=0x0000;
+    stop=client.JEDECsize;
+    if(len(sys.argv)>3):
+        start=int(sys.argv[3],16);
+    if(len(sys.argv)>4):
+        stop=int(sys.argv[4],16);
+    
+    print "Verifying code from %06x to %06x as %s." % (start,stop,f);
+    file = open(f, mode='rb')
+    
+    i=start;
+    bits=0;
+    while i<=stop:
+        data=client.SPIpeekblock(i,255);
+        print "Verified %06x." % i;
+        for j in data:
+            if i<stop:
+                bits|=ord(file.read(1))^ord(j);
+            i+=1;
+        if bits!=0:
+            print "Bits don't match."
+
+    file.close()
+
 if(sys.argv[1]=="flash"):
     f = sys.argv[2];
     start=0x0000;
@@ -99,18 +126,22 @@ if(sys.argv[1]=="flash"):
 
     i=start;
     chars=list(file.read());
+    
+    #N.B., chunksize must be an even fraction of 0x100.
     chunksize=0x80;
     
+    #client.silent(1);
     while i<=stop:
         bytes=range(0,chunksize);
         for j in range(0,chunksize):
             bytes[j]=ord(chars[i+j]);
-        #client.SPIpokebyte(i,ord(chars[i]));
         client.SPIpokebytes(i,bytes);
         
         i+=chunksize;
         if(i%0x1000==0):
             print "Flashed %06x."%i;
+    print "Done, ending silence.";
+    #client.silent(0);
     file.close()