From: theStack Date: Sun, 13 Dec 2009 07:01:11 +0000 (+0100) Subject: first version of mhx file support impl. X-Git-Tag: v0.1~51 X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=pyfrprog.git;a=commitdiff_plain;h=254be031fd624c96ae36205a2bf33d2a45e5f781 first version of mhx file support impl. o it can only handle S2 records (which means max. 6 bytes for the addresses) by now, but other data records shouldn't be used by the fujitsu converter anyway i guess? o data is only read and printed to stdout, but not really used, that will be done in the next commit --- diff --git a/frprog.py b/frprog.py index b90465f..f6a7418 100755 --- a/frprog.py +++ b/frprog.py @@ -113,6 +113,57 @@ def cmdBAUDRATE(baudrate): sendByte((baudrate >> 16) & 0xFF) sendByte((baudrate >> 24) & 0xFF) +class FlashSequence(object): + def __init__(self, address, data): + self.address = address + self.data = data + +flashseqs = [] + +# check command line arguments +if len(sys.argv) != 2: + print "Usage: " + sys.argv[0] + " [mhx-file]" + sys.exit(1) + +# read in data from mhx-file before starting +try: + fp = open(sys.argv[1], "r") +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)) + +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) @@ -133,14 +184,7 @@ print "OK, trying to set baudrate..." cmdBAUDRATE(REAL_BAUDRATE) tty = SerialPort(DEVICE, 100, REAL_BAUDRATE) -""" -print -sendByte(0x01) -print recvByte() -sendByte(0x02) -print recvByte() -sys.exit(0) -""" + """ # execute (existing) program in ram cmdCALL(0x00033ffc)