def recvByte():
i = tty.read()
- while len(i)==0:
- time.sleep(0.01)
- i = tty.read()
return ord(i)
def sendByte(byte):
- time.sleep(0.501) # just to get sure, wait 1ms
+ time.sleep(0.005) # just to get sure, wait 5ms
tty.write(chr(byte))
tty.flush()
sendByte((dword >> 16) & 0xFF)
sendByte((dword >> 24) & 0xFF)
+def pkernCHIPERASE():
+ sendByte(0x15)
+ if (recvByte() != 0x45):
+ raise Exception
+ print "wait..."
+ if (recvByte() != 0x23):
+ raise Exception
+ print "Chip erasing done."
+
+def pkernERASE(address, size):
+ sendByte(0x12)
+ if (recvByte() != 0x11):
+ raise Exception
+ sendDWord(address)
+ sendWord(size)
+ if (recvByte() != 0x18):
+ raise Exception
+ print "Erasing done."
+
+
def pkernWRITE(address, size, data):
print "address:", hex(address), "size:", size
# send WRITE command
# tell desired address and size
sendDWord(address)
sendWord(size)
+
if (recvByte() != 0x04):
raise Exception
print "Received Metadata."
raise Exception
print "Received Data."
- if (recvByte() != 0x18):
- raise Exception
- print "Erasing done."
-
if (recvByte() != 0x28):
raise Exception
print "Flashing done."
print "Initializing serial port..."
-tty = SerialPort(DEVICE, 0, KERNEL_BAUDRATE)
+tty = SerialPort(DEVICE, None, KERNEL_BAUDRATE)
# check command line arguments
if len(sys.argv) != 2:
print "The following flash sequences have been read in:"
for seq in flashseqs:
- print hex(seq.address) + ":", seq.data
+ print hex(seq.address) + ":", [hex(x) for x in seq.data]
# let the fun begin!
+"""
+for seq in flashseqs:
+ print "Erasing", len(seq.data), "bytes at address", hex(seq.address)
+ pkernERASE(seq.address, len(seq.data))
+"""
+print "ChipErase..."
+pkernCHIPERASE()
+
+
for seq in flashseqs:
print "Flashing", len(seq.data), "bytes at address", hex(seq.address)
pkernWRITE(seq.address, len(seq.data), seq.data)