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();
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);
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;
#define MISO BIT2
#define SCK BIT3
+
//This could be more accurate.
//Does it ever need to be?
#define SPISPEED 0
P5OUT|=SS;
}
+
//! Read and write an SPI bit.
unsigned char spitrans8(unsigned char byte){
unsigned int bit;
return byte;
}
+
//! Enable SPI writing
void spiflash_wrten(){
P5OUT&=~SS; //Drop !SS to begin transaction.
P5OUT|=SS; //Raise !SS to end transaction.
}
+
//! Grab the SPI flash status byte.
unsigned char spiflash_status(){
unsigned char c;
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.
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);
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();
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.
P5OUT|=SS; //Raise !SS to end transaction.
txdata(app,verb,0);
break;
+
+
case SETUP:
spisetup();
txdata(app,verb,0);