X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2Fgoodfet.spiflash;h=dcdc68be9ab4fa486c2143dfb631b67b5dbf6e98;hp=c2bc60b9010c1556a4ab93bfd3e7f001665170b7;hb=0a6754712a364a01d149dc518f44b258a3a37cf8;hpb=8f05454eedc506a9b46c2b8bce9af2480089827f diff --git a/client/goodfet.spiflash b/client/goodfet.spiflash index c2bc60b..dcdc68b 100755 --- a/client/goodfet.spiflash +++ b/client/goodfet.spiflash @@ -10,22 +10,22 @@ import sys; import binascii; import array; -from GoodFET import GoodFET; +from GoodFETSPI import GoodFETSPIFlash; from intelhex import IntelHex; if(len(sys.argv)==1): print "Usage: %s verb [objects]\n" % sys.argv[0]; print "%s info" % sys.argv[0]; - print "%s dump $foo.hex [0x$start 0x$stop]" % sys.argv[0]; + print "%s dump $foo.rom [0x$start 0x$stop]" % sys.argv[0]; print "%s erase" % sys.argv[0]; - print "%s write $foo.hex [0x$start 0x$stop]" % sys.argv[0]; - print "%s verify $foo.hex [0x$start 0x$stop]" % sys.argv[0]; + print "%s flash $foo.rom [0x$start 0x$stop]" % sys.argv[0]; + print "%s verify $foo.rom [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(); -#Initailize FET and set baud rate -client=GoodFET(); +#Initialize FET and set baud rate +client=GoodFETSPIFlash(); client.serInit() @@ -53,19 +53,33 @@ if(sys.argv[1]=="test"): print "Some success, some failures. Is a wire loose?"; else: print "All reads succeeded. Wiring is probably good."; - + print "Erasing."; + client.SPIchiperase(); + print "Testing erase."; + data=client.SPIpeekblock(0); + for i in data: + if ord(i)!=0xFF: + print "ERROR not properly erased!"; + data=range(0,10); + client.SPIpokebytes(0,data); + print "Testing flash write."; + for i in data: + if(client.SPIpeek(i)!=i): + print "%06x not properly poked to %02x" % (i,i); + print "Test complete."; if(sys.argv[1]=="info"): data=client.SPIjedec(); - print "Ident as %s\nManufacturer: %02x %s\nType: %02x\nCapacity: %02x" % ( + print "Ident as %s\nManufacturer: %02x %s\nType: %02x\nCapacity: %02x (%i bytes)" % ( client.SPIjedecstr(), ord(data[1]),client.SPIjedecmanstr(), ord(data[2]), - ord(data[3])); + ord(data[3]), + client.JEDECsize); if(sys.argv[1]=="dump"): f = sys.argv[2]; start=0x0000; - stop=0x100000; #TODO, adjust this by the JEDEC size parameter. + stop=client.JEDECsize; if(len(sys.argv)>3): start=int(sys.argv[3],16); if(len(sys.argv)>4): @@ -73,44 +87,77 @@ if(sys.argv[1]=="dump"): 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: + if i3): + 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; + bytes=0; while i<=stop: data=client.SPIpeekblock(i); - - - if(i%0x100==0): - print "Dumped %06x."%i; + print "Verified %06x." % i; for j in data: - file.write(j); + if i3): 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); + print "FIXME This might fail if the file is of an odd size."; file = open(f, mode='rb') i=start; chars=list(file.read()); - chunksize=0x80; + chunksize=0x100; 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): + if(i%0x1000==0): print "Flashed %06x."%i; + + file.close()