import sys;
import binascii;
+import array;
from GoodFET import GoodFET;
from intelhex import IntelHex;
#Initailize FET and set baud rate
client=GoodFET();
-client.serInit("/dev/ttyUSB0")
+client.serInit()
+
client.SPIsetup();
+#Dummy read.
+#Might read as all ones if chip has a startup delay.
+client.SPIjedec();
+
if(sys.argv[1]=="test"):
result="";
dropped=0;
if(sys.argv[1]=="dump"):
f = sys.argv[2];
start=0x0000;
- stop=0xFFFF;
+ stop=0x100000; #TODO, adjust this by the JEDEC size parameter.
+ if(len(sys.argv)>3):
+ start=int(sys.argv[3],16);
+ if(len(sys.argv)>4):
+ stop=int(sys.argv[4],16);
+
+ 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);
+ if(i%0x1000==0):
+ print "Dumped %06x."%i;
+ for j in data:
+ file.write(j);
+ i+=1;
+ file.close()
+if(sys.argv[1]=="flash"):
+ f = sys.argv[2];
+ start=0x0000;
+ stop=0x100000; #TODO, adjust this by the JEDEC size parameter.
if(len(sys.argv)>3):
start=int(sys.argv[3],16);
if(len(sys.argv)>4):
stop=int(sys.argv[4],16);
- print "Dumping code from %04x to %04x as %s." % (start,stop,f);
- h = IntelHex(None);
+ print "Flashing code from %06x to %06x with %s." % (start,stop,f);
+ file = open(f, mode='rb')
+
i=start;
+ chars=list(file.read());
+ chunksize=0x80;
+
while i<=stop:
- h[i>>1]=client.SPIpeek(i);
+ 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%0x100==0):
- print "Dumped %04x."%i;
- i+=1;
- h.write_hex_file(f);
+ print "Flashed %06x."%i;
+ file.close()
+
if(sys.argv[1]=="erase"):
- print "Status: %s" % client.CCstatusstr();
- client.CCchiperase();
- print "Status: %s" %client.CCstatusstr();
+ client.SPIchiperase();
if(sys.argv[1]=="peek"):
start=0x0000;
stop=start;
if(len(sys.argv)>3):
stop=int(sys.argv[3],16);
- print "Peeking from %04x to %04x." % (start,stop);
+ print "Peeking from %06x to %06x." % (start,stop);
while start<=stop:
- print "%04x: %02x" % (start,client.SPIpeek(start));
+ print "%06x: %02x" % (start,client.SPIpeek(start));
start=start+1;
-# if(sys.argv[1]=="poke"):
-# start=0x0000;
-# val=0x00;
-# if(len(sys.argv)>2):
-# start=int(sys.argv[2],16);
-# if(len(sys.argv)>3):
-# val=int(sys.argv[3],16);
-# print "Poking %04x to become %02x." % (start,val);
-# client.CCpokedatabyte(start,val);
+if(sys.argv[1]=="poke"):
+ start=0x0000;
+ val=0x00;
+ if(len(sys.argv)>2):
+ start=int(sys.argv[2],16);
+ if(len(sys.argv)>3):
+ val=int(sys.argv[3],16);
+ print "Poking %06x to become %02x." % (start,val);
+
+ while client.SPIpeek(start)!=val:
+ client.SPIpokebyte(start,val);
+ print "Poked to %02x" % client.SPIpeek(start);