JTAGARM7 is back up and running, folks! Tested Halt/Release, Get/Set Registers,...
[goodfet] / client / GoodFETSPI.py
index 044aea2..c303b21 100644 (file)
@@ -5,7 +5,7 @@
 #
 # This code is being rewritten and refactored.  You've been warned!
 
-import sys, time, string, cStringIO, struct, glob, serial, os;
+import sys, time, string, cStringIO, struct, glob, os;
 
 from GoodFET import GoodFET;
 
@@ -25,12 +25,28 @@ class GoodFETSPI(GoodFET):
         self.writecmd(0x01,0x00,len(data),data);
         return self.data;
 
+class GoodFETSPI25C(GoodFETSPI):
+    #opcodes
+    WREN=0x06;
+    WRDI=0x04;
+    RDSR=0x05;
+    WRSR=0x01;
+    READ=0x03;
+    WRITE=0x02;
+    
+    def peek8(self,adr,memory="vn"):
+        """Read a byte from the given address."""
+        data=self.SPItrans([self.READ,(adr>>8)&0xFF,adr&0xFF,0x00]);
+        return ord(data[3]);
+
+
 class GoodFETSPIFlash(GoodFETSPI):
     JEDECmanufacturers={0xFF: "MISSING",
                         0xEF: "Winbond",
                         0xC2: "MXIC",
                         0x20: "Numonyx/ST",
-                        0x1F: "Atmel"
+                        0x1F: "Atmel",
+                        0x01: "AMD/Spansion"
                         };
 
     JEDECdevices={0xFFFFFF: "MISSING",
@@ -44,7 +60,9 @@ class GoodFETSPIFlash(GoodFETSPI):
                   0xC22015: "MX25L1605D",
                   0xC22014: "MX25L8005",
                   0xC22013: "MX25L4005",
-                  0x204011: "M45PE10"
+                  0x204011: "M45PE10",
+                  0x202014: "M25P80",
+                  0x1f4501: "AT24DF081",
                   };
     
     JEDECsizes={0x17: 0x800000,
@@ -59,16 +77,27 @@ class GoodFETSPIFlash(GoodFETSPI):
     JEDECsize=0;
 
     def SPIjedec(self):
-        """Grab an SPI Flash ROM's JEDEC bytes."""
+        """Grab an SPI Flash ROM's JEDEC bytes.  Some chips don't implement
+        this, such as Numonyx M25P* except in the 110nm processed."""
         data=[0x9f, 0, 0, 0];
         data=self.SPItrans(data);
+        jedec=0;
         self.JEDECmanufacturer=ord(data[1]);
-        self.JEDECtype=ord(data[2]);
-        self.JEDECcapacity=ord(data[3]);
+        if self.JEDECmanufacturer==0xFF:
+            self.JEDECtype=0x20;
+            self.JEDECcapacity=0x14;
+            jedec=0x202014;
+        else:
+            self.JEDECtype=ord(data[2]);
+            self.JEDECcapacity=ord(data[3]);
+            jedec=(ord(data[1])<<16)+(ord(data[2])<<8)+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]);
+        
+        if jedec==0x1F4501:
+            self.JEDECsize=1024**2;
+        self.JEDECdevice=jedec;
         return data;
     def SPIpeek(self,adr):
         """Grab a byte from an SPI Flash ROM."""
@@ -91,11 +120,13 @@ class GoodFETSPIFlash(GoodFETSPI):
     def SPIpokebyte(self,adr,val):
         self.SPIpokebytes(adr,[val]);
     def SPIpokebytes(self,adr,data):
-        #self.SPIwriteenable();
-        adranddata=[(adr&0xFF0000)>>16,
-              (adr&0xFF00)>>8,
-              adr&0xFF
-              ]+data;
+        #Used to be 24 bits, BE, not 32 bits, LE.
+        adranddata=[adr&0xFF,
+                    (adr&0xFF00)>>8,
+                    (adr&0xFF0000)>>16,
+                    0, #MSB
+                    ]+data;
+        #print "%06x: poking %i bytes" % (adr,len(data));
         self.writecmd(0x01,0x03,
                       len(adranddata),adranddata);