X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=frprog.py;h=d481f89ae8f6075f84d39a667aee8b3460d2d471;hb=62bcf1a4c62cd5b7738bdab866e9b6dde5bf774d;hp=8afad3f01e1f4ecb9dbe0181bd41afcc76dd6205;hpb=8c5456a034353e922d4afe23b737973e825de4b6;p=pyfrprog.git diff --git a/frprog.py b/frprog.py index 8afad3f..d481f89 100755 --- a/frprog.py +++ b/frprog.py @@ -15,7 +15,6 @@ last_checksum = 0 def sendByte(byte): time.sleep(0.001) # just to get sure, wait 1ms tty.write(chr(byte)) - tty.flush() def sendWord(word): sendByte(word & 0xFF) @@ -98,8 +97,6 @@ def cmdCHECKSUM(): recvChecksum() def cmdBAUDRATE(baudrate): - global last_checksum - # send BAUDRATE command sendByte(0x01) if (recvByte() != 0xF1): @@ -108,18 +105,45 @@ def cmdBAUDRATE(baudrate): if (recvByte() != 0x86): raise Exception # send desired baudrate - sendByte(baudrate & 0xFF) - sendByte((baudrate >> 8) & 0xFF) - sendByte((baudrate >> 16) & 0xFF) - sendByte((baudrate >> 24) & 0xFF) + sendDWord(baudrate) + class FlashSequence(object): def __init__(self, address, data): self.address = address self.data = data -# list of all our address/data pairs to flash -flashseqs = [] +def readMHXFile(fp): # needs a file handle to the desired mhx file + retval = [] # returns a list of FlashSequence objects + linecount = 0 + for line in fp: + linecount += 1 + # get rid of newline characters + line = line.strip() + + # we're only interested in S2 (data sequence with 3 address bytes) records by now + if line[0:2] == "S2": + byte_count = int(line[2:4], 16) + # just to get sure, check if byte count field is valid + if (len(line)-4) != (byte_count*2): + print sys.argv[0] + ": Warning - inavlid byte count field in " + \ + sys.argv[1] + ":" + str(linecount) + ", skipping line!" + continue + + # address and checksum bytes are not needed + byte_count -= 4 + address = int(line[4:10], 16) + datastr = line[10:10+byte_count*2] + + # convert data hex-byte-string to real byte data list + data = [] + for i in range(0, len(datastr)/2): + data.append(int(datastr[2*i:2*i+2], 16)) + + # add flash sequence to our list + retval.append(FlashSequence(address, data)) + return retval + # check command line arguments if len(sys.argv) != 2: @@ -132,40 +156,13 @@ try: except IOError: print sys.argv[0] + ": Error - couldn't open file " + sys.argv[1] + "!" sys.exit(1) - -linecount = 0 -for line in fp: - linecount += 1 - # get rid of newline characters - line = line.strip() - - # we're only interested in S2 (data sequence with 3 address bytes) records by now - if line[0:2] == "S2": - byte_count = int(line[2:4], 16) - # just to get sure, check if byte count field is valid - if (len(line)-4) != (byte_count*2): - print sys.argv[0] + ": Warning - inavlid byte count field in " + \ - sys.argv[1] + ":" + str(linecount) + ", skipping line!" - continue - - # address and checksum bytes are not needed - byte_count -= 4 - address = int(line[4:10], 16) - datastr = line[10:10+byte_count*2] - - # convert data hex-byte-string to real byte data list - data = [] - for i in range(0, len(datastr)/2): - data.append(int(datastr[2*i:2*i+2], 16)) - - # add flash sequence to our list - flashseqs.append(FlashSequence(address, data)) +flashseqs = readMHXFile(fp) +fp.close() print "The following flash sequences have been read in:" for seq in flashseqs: print hex(seq.address) + ":", seq.data - print "Initializing serial port..." tty = SerialPort(DEVICE, 100, INIT_BAUDRATE) @@ -188,10 +185,13 @@ tty = SerialPort(DEVICE, 100, REAL_BAUDRATE) # let the fun begin! for seq in flashseqs: - if(seq.address >= 0x148000): + if(seq.address <= 0x40000): + addr = seq.address + else: continue - print "RAMing", len(seq.data), "bytes at address", hex(seq.address) - cmdWRITE(seq.address - flashseqs[0].address + 0x30000, len(seq.data), seq.data) + print "RAMing", len(seq.data), "bytes at address", hex(addr) + cmdWRITE(addr, len(seq.data), seq.data) + tty.flush() cmdCALL(0x30000); sys.exit(0)