X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2Fgoodfet.spiflash;h=354d5025444ee52f790b6377600fc0ab758b4e8f;hp=5c73eda163d628d7ff377c0ecc9a1d21ec367104;hb=c6e02600ef0e12eb9a7309755740a23b71a62205;hpb=f13d84c954960084c69440ad035e68b6017572dc diff --git a/client/goodfet.spiflash b/client/goodfet.spiflash index 5c73eda..354d502 100755 --- a/client/goodfet.spiflash +++ b/client/goodfet.spiflash @@ -8,6 +8,7 @@ import sys; import binascii; +import array; from GoodFET import GoodFET; from intelhex import IntelHex; @@ -27,8 +28,13 @@ if(len(sys.argv)==1): client=GoodFET(); client.serInit("/dev/ttyUSB0") + 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; @@ -65,8 +71,6 @@ if(sys.argv[1]=="dump"): 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') @@ -81,6 +85,35 @@ if(sys.argv[1]=="dump"): 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 "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: + 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 "Flashed %06x."%i; + file.close() + + if(sys.argv[1]=="erase"): client.SPIchiperase(); @@ -104,6 +137,8 @@ if(sys.argv[1]=="poke"): if(len(sys.argv)>3): val=int(sys.argv[3],16); print "Poking %06x to become %02x." % (start,val); - client.SPIpokebyte(start,val); - + + while client.SPIpeek(start)!=val: + client.SPIpokebyte(start,val); + print "Poked to %02x" % client.SPIpeek(start);