def recvByte():
i = tty.read()
while len(i)==0:
- time.sleep(0.01)
+ time.sleep(0.03)
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 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 "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))
+
for seq in flashseqs:
print "Flashing", len(seq.data), "bytes at address", hex(seq.address)
pkernWRITE(seq.address, len(seq.data), seq.data)
static unsigned short recvword(void)
{
static unsigned char b1, b2;
- static unsigned int ret;
+ static unsigned short ret;
b1 = recvbyte();
b2 = recvbyte();
- ret = (b2 << 8) | b1;
+ ret = (unsigned short)(b2 << 8) | b1;
return ret;
}
b2 = recvbyte();
b3 = recvbyte();
b4 = recvbyte();
- ret = (b4 << 24) | (b3 << 16) | (b2 << 8) | b1;
+ ret = ((unsigned int) (b4 << 24)) | ((unsigned int) (b3 << 16)) | ((unsigned int) (b2 << 8)) |(unsigned int)b1;
return ret;
}
static void panic(void)
{
- PDR14 = 0xff;
PDR14 = 0x22;
halt();
}
void main(void)
{
unsigned int address;
- unsigned short i, size;
+ unsigned short i, size, next;
unsigned char running = 1, data[BUFSIZE] = {0};
PORTEN = 0x3; /* enable I/O Ports */
cleardata();
increaseled();
switch(recvbyte()) {
+ case 0x12: //erase
+ Putch4(0x11);
+ address = recvdword();
+ increaseled();
+
+ size = recvword();
+ increaseled();
+
+ PDR14 = 0xff;
+ for(i=0; i<(size+4); i+=4) { /* erase */
+ if(FLASH_SectorErase(address + i) != 1) {
+ panic();
+ }
+ increaseled();
+ }
+ Putch4(0x18); //Erasing done.
+ break;
+
case 0x13: //receive
Putch4(0x37);
increaseled();
Putch4(0x08); //Received Data.
PDR14 = 0xff;
- for(i=0; i<size; i+=4) { /* erase */
- if(FLASH_SectorErase(address + i) != 1) {
- panic();
- }
- increaseled();
- }
-
- Putch4(0x18); //Erasing done.
- for(i=0; i<size; i++) { /* flash the data */
+ for(i=0; i<size; i+=2) { /* flash the data */
increaseled();
- if(FLASH_WriteHalfWord(address + (2*i), data[i]) != 1) {
+ next = (((unsigned short)data[i])<<8) | (unsigned short)data[i+1];
+ if(FLASH_WriteHalfWord(address + i, next) != 1) {
panic();
}
}