goodfet.spiflash now does verification.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 3 Sep 2009 06:40:53 +0000 (06:40 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 3 Sep 2009 06:40:53 +0000 (06:40 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@111 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/goodfet.spiflash
firmware/apps/spi/spi.c

index 571ddc4..e396f55 100755 (executable)
@@ -19,7 +19,7 @@ if(len(sys.argv)==1):
     print "%s dump $foo.hex [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 verify $foo.hex [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();
@@ -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;
index 7f9777b..a5f72b8 100644 (file)
@@ -17,6 +17,7 @@
 #define MISO BIT2
 #define SCK  BIT3
 
+
 //This could be more accurate.
 //Does it ever need to be?
 #define SPISPEED 0
@@ -41,6 +42,7 @@ void spisetup(){
   P5OUT|=SS;
 }
 
+
 //! Read and write an SPI bit.
 unsigned char spitrans8(unsigned char byte){
   unsigned int bit;
@@ -70,6 +72,7 @@ unsigned char spitrans8(unsigned char byte){
   return byte;
 }
 
+
 //! Enable SPI writing
 void spiflash_wrten(){
   P5OUT&=~SS; //Drop !SS to begin transaction.
@@ -80,6 +83,7 @@ void spiflash_wrten(){
   P5OUT|=SS;  //Raise !SS to end transaction.
 }
 
+
 //! Grab the SPI flash status byte.
 unsigned char spiflash_status(){
   unsigned char c;
@@ -90,6 +94,8 @@ unsigned char spiflash_status(){
   P5OUT|=SS;  //Raise !SS to end transaction.
   return c;
 }
+
+
 //! Grab the SPI flash status byte.
 void spiflash_setstatus(unsigned char c){
   P5OUT&=~SS; //Drop !SS to begin transaction.
@@ -151,6 +157,8 @@ void spihandle(unsigned char app,
     P5OUT|=SS;  //Raise !SS to end transaction.
     txdata(app,verb,len);
     break;
+
+
   case SPI_JEDEC://Grab 3-byte JEDEC ID.
     P5OUT&=~SS; //Drop !SS to begin transaction.
     spitrans8(0x9f);
@@ -160,10 +168,13 @@ void spihandle(unsigned char app,
     txdata(app,verb,len);
     P5OUT|=SS;  //Raise !SS to end transaction.
     break;
+
+
   case PEEK://Grab 128 bytes from an SPI Flash ROM
-    
     spiflash_peek(app,verb,len);
     break;
+
+
   case POKE://Poke up bytes from an SPI Flash ROM.
     spiflash_setstatus(0x02);
     spiflash_wrten();
@@ -178,6 +189,8 @@ void spihandle(unsigned char app,
     while(spiflash_status()&0x01);//while busy
     txdata(app,verb,len);
     break;
+
+
   case SPI_ERASE://Erase the SPI Flash ROM.
     spiflash_wrten();
     P5OUT&=~SS; //Drop !SS to begin transaction.
@@ -185,6 +198,8 @@ void spihandle(unsigned char app,
     P5OUT|=SS;  //Raise !SS to end transaction.
     txdata(app,verb,0);
     break;
+
+
   case SETUP:
     spisetup();
     txdata(app,verb,0);