X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=frprog.py;h=b7371c1cfa226c6d2b14877d936a7fa32a3438fe;hb=c380c7da56e97c4430481fe7ccecb98330268726;hp=1f0a1fbb07a9ea2949c2afdcaa3dd4b876f163d0;hpb=fcf0066375d5e4aa15dc96d01c26714f8168f471;p=pyfrprog.git diff --git a/frprog.py b/frprog.py index 1f0a1fb..b7371c1 100755 --- a/frprog.py +++ b/frprog.py @@ -113,6 +113,59 @@ 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 + +# list of all our address/data pairs to flash +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) @@ -129,18 +182,24 @@ while 1: pass print "OK, trying to set baudrate..." - # set baudrate cmdBAUDRATE(REAL_BAUDRATE) tty = SerialPort(DEVICE, 100, REAL_BAUDRATE) -""" -print -sendByte(0x01) -print recvByte() -sendByte(0x02) -print recvByte() + +# let the fun begin! +for seq in flashseqs: + if(seq.address <= 0x40000): + addr = seq.address + else: + continue + print "RAMing", len(seq.data), "bytes at address", hex(addr) + cmdWRITE(addr, len(seq.data), seq.data) + +cmdCALL(0x30000); sys.exit(0) -""" + + +# some tests here....... """ # execute (existing) program in ram cmdCALL(0x00033ffc) @@ -218,25 +277,28 @@ print "Received Checksum:", last_checksum print """ - -""" -S006000066756AB4 -S20E0F40009B000D4ECFF11601E0FFF6 -S214148000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF67 -S804000000FB - -NOP = 0x9fa0 """ # write some data in the iram and try to execute it -# ATTENTION: before running this, run a program on the board (e.g. flashdemo). -# the bytecode will be executed after copied into iram, however it won't stop -# and executes the stuff after it in the iram. after a powerreset this can be -# randomcrap and this could be very dangerous! so pay attention please -data_wr =[0x9B,0x00,0x0D,0x4e,0xcf,0xf1,0x16,0x01,0xe0,0xff,0xf6,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0xe0, - 0xcb,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f, - 0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0,0x9f,0xa0] +data_wr =[ + 0x9B,0x00, + 0x0D,0x4e, + 0xcf,0xf1, + 0x16,0x01, + 0x9b,0x05, + 0x04,0xc7, + 0xc1,0x06, + 0x16,0x56, + 0xe0,0xfb, #branch + 0x9f,0xa0,0x9f,0xa0,0x9f,0xa0, #nop + 0x9f,0xa0,0x9f,0xa0,0x9f,0xa0, + 0x9f,0xa0,0x9f,0xa0,0x9f,0xa0, + 0x9f,0xa0,0x9f,0xa0,0x9f,0xa0, + 0x9f,0xa0,0x9f,0xa0,0x9f,0xa0, + 0x9f,0xa0,0x9f,0xa0,0x9f,0xa0, + 0x9f,0xa0,0x9f,0xa0,0x9f,0xa0] print "Writing", data_wr, "to the IRAM..." cmdWRITE(0x00030000, len(data_wr), data_wr) print "Received Checksum:", last_checksum print cmdCALL(0x00030000) +"""