+ if bytes!=0:
+ print "%i bytes don't match." % bytes
+
+ file.close()
+
+if(sys.argv[1]=="flash"):
+ 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 "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=0x100;
+
+ while i<=stop:
+ bytes=range(0,chunksize);
+ for j in range(0,chunksize):
+ bytes[j]=ord(chars[i+j]);
+ client.SPIpokebytes(i,bytes);
+
+ i+=chunksize;
+ if(i%0x1000==0):
+ print "Flashed %06x."%i;
+
+
+ file.close()
+