X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=pkernel%2Fkernel.py;h=e495a86b693f10d2a9557d15a57f1052898e5ca4;hb=3d2bcfa368af1ffb347209c34a433df16554dde7;hp=91bbcc41ab0baac967fb34a9d012309af4262b4b;hpb=53f7a41d712ea632f433699ad64900fd23d42a89;p=pyfrprog.git diff --git a/pkernel/kernel.py b/pkernel/kernel.py index 91bbcc4..e495a86 100755 --- a/pkernel/kernel.py +++ b/pkernel/kernel.py @@ -9,13 +9,10 @@ KERNEL_BAUDRATE=38400 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() @@ -29,6 +26,26 @@ def sendDWord(dword): 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 @@ -38,6 +55,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 +68,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." @@ -69,7 +83,7 @@ flashseqs = [] 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: @@ -113,10 +127,19 @@ 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)) +""" +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)