From: Bernhard Urban Date: Mon, 14 Dec 2009 05:23:17 +0000 (+0100) Subject: w00t :) X-Git-Tag: v0.1~30 X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=pyfrprog.git;a=commitdiff_plain;h=89576267a3ec91de6d4ac380969ae5d19ac7f1af w00t :) the trick: erase first *all* sectors and then flash it, not erase, flash, erase, flash, ... --- diff --git a/pkernel/kernel.py b/pkernel/kernel.py index 91bbcc4..54a9fd3 100755 --- a/pkernel/kernel.py +++ b/pkernel/kernel.py @@ -10,12 +10,12 @@ KERNEL_BAUDRATE=38400 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() @@ -29,6 +29,17 @@ def sendDWord(dword): 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 @@ -38,6 +49,7 @@ def pkernWRITE(address, size, data): # tell desired address and size sendDWord(address) sendWord(size) + if (recvByte() != 0x04): raise Exception print "Received Metadata." @@ -50,10 +62,6 @@ def pkernWRITE(address, size, data): raise Exception print "Received Data." - if (recvByte() != 0x18): - raise Exception - print "Erasing done." - if (recvByte() != 0x28): raise Exception print "Flashing done." @@ -113,10 +121,14 @@ for line in fp: 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) diff --git a/pkernel/main.c b/pkernel/main.c index 3676387..452c388 100644 --- a/pkernel/main.c +++ b/pkernel/main.c @@ -20,10 +20,10 @@ static unsigned char recvbyte(void) 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; } @@ -35,7 +35,7 @@ static unsigned int recvdword(void) 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; } @@ -48,7 +48,6 @@ static void halt(void) static void panic(void) { - PDR14 = 0xff; PDR14 = 0x22; halt(); } @@ -56,7 +55,7 @@ static void panic(void) 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 */ @@ -72,6 +71,24 @@ void main(void) 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(); @@ -91,17 +108,10 @@ void main(void) Putch4(0x08); //Received Data. PDR14 = 0xff; - for(i=0; i