Faster SPI Flash dumping, but it's a bit ugly.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 3 Sep 2009 05:25:46 +0000 (05:25 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 3 Sep 2009 05:25:46 +0000 (05:25 +0000)
I'll rewrite this soon to be more standardized.

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

client/GoodFET.py
client/goodfet.spiflash
firmware/Makefile
firmware/apps/spi/spi.c

index 99756ba..b335b4d 100755 (executable)
@@ -47,7 +47,7 @@ class GoodFET:
         if(self.verb!=0x7F):
             print "Verb %02x is wrong.  Incorrect firmware?" % self.verb;
         #print "Connected."
         if(self.verb!=0x7F):
             print "Verb %02x is wrong.  Incorrect firmware?" % self.verb;
         #print "Connected."
-    def writecmd(self, app, verb, count, data):
+    def writecmd(self, app, verb, count, data=[], blocks=1):
         """Write a command and some data to the GoodFET."""
         self.serialport.write(chr(app));
         self.serialport.write(chr(verb));
         """Write a command and some data to the GoodFET."""
         self.serialport.write(chr(app));
         self.serialport.write(chr(verb));
@@ -56,14 +56,15 @@ class GoodFET:
         if count!=0:
             for d in data:
                 self.serialport.write(chr(d));
         if count!=0:
             for d in data:
                 self.serialport.write(chr(d));
-        self.readcmd();  #Uncomment this later, to ensure a response.
-    def readcmd(self):
+        
+        self.readcmd(blocks);  #Uncomment this later, to ensure a response.
+    def readcmd(self,blocks=1):
         """Read a reply from the GoodFET."""
         self.app=ord(self.serialport.read(1));
         self.verb=ord(self.serialport.read(1));
         self.count=ord(self.serialport.read(1));
         """Read a reply from the GoodFET."""
         self.app=ord(self.serialport.read(1));
         self.verb=ord(self.serialport.read(1));
         self.count=ord(self.serialport.read(1));
-        if self.count>0:
-            self.data=self.serialport.read(self.count);
+        self.data=self.serialport.read(self.count*blocks);
+        return self.data;
         #print "READ %02x %02x %02x " % (self.app, self.verb, self.count);
         
     #Monitor stuff
         #print "READ %02x %02x %02x " % (self.app, self.verb, self.count);
         
     #Monitor stuff
@@ -193,6 +194,8 @@ class GoodFET:
         self.JEDECtype=ord(data[2]);
         self.JEDECcapacity=ord(data[3]);
         self.JEDECsize=self.JEDECsizes.get(self.JEDECcapacity);
         self.JEDECtype=ord(data[2]);
         self.JEDECcapacity=ord(data[3]);
         self.JEDECsize=self.JEDECsizes.get(self.JEDECcapacity);
+        if self.JEDECsize==None:
+            self.JEDECsize=0;
         self.JEDECdevice=(ord(data[1])<<16)+(ord(data[2])<<8)+ord(data[3]);
         return data;
     def SPIpeek(self,adr):
         self.JEDECdevice=(ord(data[1])<<16)+(ord(data[2])<<8)+ord(data[3]);
         return data;
     def SPIpeek(self,adr):
@@ -204,14 +207,24 @@ class GoodFET:
               0];
         self.SPItrans(data);
         return ord(self.data[4]);
               0];
         self.SPItrans(data);
         return ord(self.data[4]);
-    def SPIpeekblock(self,adr):
-        """Grab a block from an SPI Flash ROM.  Block size is unknown"""
+#     def SPIpeekblock(self,adr):
+#         """Grab a block from an SPI Flash ROM.  Block size is unknown"""
+#         data=[(adr&0xFF0000)>>16,
+#               (adr&0xFF00)>>8,
+#               adr&0xFF];
+        
+#         self.writecmd(0x01,0x02,3,data);
+#         return self.data;
+    def SPIpeekblock(self,adr,blocks=1):
+        """Grab a few block from an SPI Flash ROM.  Block size is unknown"""
         data=[(adr&0xFF0000)>>16,
               (adr&0xFF00)>>8,
         data=[(adr&0xFF0000)>>16,
               (adr&0xFF00)>>8,
-              adr&0xFF];
+              adr&0xFF,
+              blocks];
         
         
-        self.writecmd(0x01,0x02,3,data);
+        self.writecmd(0x01,0x02,4,data,blocks);
         return self.data;
         return self.data;
+    
     def SPIpokebyte(self,adr,val):
         self.SPIpokebytes(adr,[val]);
     def SPIpokebytes(self,adr,data):
     def SPIpokebyte(self,adr,val):
         self.SPIpokebytes(adr,[val]);
     def SPIpokebytes(self,adr,data):
index efca070..571ddc4 100755 (executable)
@@ -77,11 +77,11 @@ if(sys.argv[1]=="dump"):
 
     i=start;
     while i<=stop:
 
     i=start;
     while i<=stop:
-        data=client.SPIpeekblock(i);
-        if(i%0x1000==0):
-            print "Dumped %06x."%i;
+        data=client.SPIpeekblock(i,255);
+        #if(i%0x1000==0):
+        print "Dumped %06x."%i;
         for j in data:
         for j in data:
-            file.write(j);
+            if i<stop: file.write(j);
             i+=1;
     file.close()
 if(sys.argv[1]=="flash"):
             i+=1;
     file.close()
 if(sys.argv[1]=="flash"):
index 3e8271d..4e4cbc4 100644 (file)
@@ -33,7 +33,7 @@ install: $(app).hex
 verify:
        $(BSL) -P $(app).hex -v $(app).hex
 dumpinfo:
 verify:
        $(BSL) -P $(app).hex -v $(app).hex
 dumpinfo:
-       $(BSL) --dumpinfo -c /dev/ttyUSB0
+       $(BSL) --dumpinfo
 $(app): $(app).c $(libs) $(apps)
 $(app).hex: $(app)
        msp430-objcopy goodfet -O ihex goodfet.hex
 $(app): $(app).c $(libs) $(apps)
 $(app).hex: $(app)
        msp430-objcopy goodfet -O ihex goodfet.hex
index 5c733eb..7f9777b 100644 (file)
@@ -99,6 +99,38 @@ void spiflash_setstatus(unsigned char c){
   //return c;
 }
 
   //return c;
 }
 
+//! Peek some blocks.
+void spiflash_peek(unsigned char app,
+                  unsigned char verb,
+                  unsigned char len){
+  register char blocks=(len>3?cmddata[3]:1);
+  unsigned char i,j;
+  
+  P5OUT&=~SS; //Drop !SS to begin transaction.
+  spitrans8(0x03);//Flash Read Command
+  len=3;//write 3 byte pointer
+  for(i=0;i<len;i++)
+    spitrans8(cmddata[i]);
+  
+  //Send reply header
+  len=0x80;//128 byte chunk, repeated for each block
+  serial_tx(app);
+  serial_tx(verb);
+  serial_tx(len); //multiplied by block count.
+  
+  while(blocks--){
+    for(i=0;i<len;i++)
+      serial_tx(spitrans8(0));
+    
+    /* old fashioned
+    for(i=0;i<len;i++)
+      cmddata[i]=spitrans8(0);
+    txdata(app,verb,len);
+    */
+  }
+  P5OUT|=SS;  //Raise !SS to end transaction.
+}
+
 //! Handles a monitor command.
 void spihandle(unsigned char app,
               unsigned char verb,
 //! Handles a monitor command.
 void spihandle(unsigned char app,
               unsigned char verb,
@@ -129,16 +161,8 @@ void spihandle(unsigned char app,
     P5OUT|=SS;  //Raise !SS to end transaction.
     break;
   case PEEK://Grab 128 bytes from an SPI Flash ROM
     P5OUT|=SS;  //Raise !SS to end transaction.
     break;
   case PEEK://Grab 128 bytes from an SPI Flash ROM
-    P5OUT&=~SS; //Drop !SS to begin transaction.
-    spitrans8(0x03);//Flash Read Command
-    len=3;//write 3 byte pointer
-    for(i=0;i<len;i++)
-      spitrans8(cmddata[i]);
-    len=0x80;//128 byte chunk
-    for(i=0;i<len;i++)
-      cmddata[i]=spitrans8(0);
-    P5OUT|=SS;  //Raise !SS to end transaction.
-    txdata(app,verb,len);
+    
+    spiflash_peek(app,verb,len);
     break;
   case POKE://Poke up bytes from an SPI Flash ROM.
     spiflash_setstatus(0x02);
     break;
   case POKE://Poke up bytes from an SPI Flash ROM.
     spiflash_setstatus(0x02);