Example #1
0
def CalcMspGangChksum(file_name, verbose):
    # create new instance of TI-TXT class
    ti_txt = TiTxtParser(verbose)

    # parse the TI-TXT
    content = ti_txt.parse(file_name)
    if content == {}:
        if verbose == True:
            print "Failed to parse TI-TXT file:", file_name
        return None

    # calculate the checksum
    if verbose == True:
        print "\n== Calculating MSP-GANG CS =="
    cs = 0
    start_addresses = content.keys()
    start_addresses.sort()
    for start_addr in start_addresses:
        i = 0
        for byte in content[start_addr]:
            if i == 0:
                cs = cs + byte
                i = 1
            else:
                cs = cs + (byte * 256)
                i = 0
        if i == 1:
            cs = cs + (0xFF * 256)

    # return the calculated checksum
    return cs
Example #2
0
def GenUniqueId(in_file, out_file, num_of_output, verbose):
    # create new instance of TI-TXT class
    ti_txt = TiTxtParser(verbose)

    # parse the TI-TXT
    content = ti_txt.parse(in_file)
    if(content == {}):
        if(verbose == True):
            print "Failed to parse TI-TXT file:", in_file
        return None

    # check if the ID fields is available
    try:
        if((len(content[0x1000]) == 6) and (verbose == True)):
            print "6 bytes Unique ID starting at address 0x1000 is found"
    except:
        if(verbose == True):
            print "No Unique ID starting at address 0x1000 is found"
            return False
    
    
    # start creating files
    if(verbose == True):
        print "\n== Generating output file with Unique ID =="
    for i in range(0, num_of_output):
      file_name = out_file.split('.')[0] + "-" + str(i) + "." + out_file.split('.')[1]
      temp = content
      temp[0x1000][5] = i
      if(verbose == True):
          id = temp[0x1000]
          id_string = hex(id[0]) + ":" + hex(id[1]) + ":" + hex(id[2]) + ":" + \
              hex(id[3]) + ":" + hex(id[4]) + ":" + hex(id[5])
          print "\nOutput file name: ", file_name, " - ID: ", id_string
      ti_txt.print_ti_txt(file_name, temp)
      
    return True
Example #3
0
    def flash_target(self):
        # create new instance of TI-TXT class
        ti_txt = TiTxtParser(self.verbose_mode)

        # parse the TI-TXT
        content = ti_txt.parse(self.file_name)
        if(content == {}):
            if(self.verbose_mode == True):
                print "Failed to parse TI-TXT file:", self.file_name
            return False
        #ti_txt.debug_print_content()

        # try to fill the data
        full_content = ti_txt.fill(content, self.start_addr, 0xFFFF, 0xFF)
        if(full_content == {}):
            if(self.verbose_mode == True):
                print "Failed to fill TI-TXT file"
            return False
        #ti_txt.debug_print_full_content(full_content)

        if(self.verbose_mode == True):
            print "\n== Flashing Target Device =="

        # try to open the serial-port
        try:
            if(self.verbose_mode == True):
                print "Opening Serial Port:", self.serial_port
            ser = serial.Serial(self.serial_port, timeout=8)
        except:
            if(self.verbose_mode == True):
                print "Failed to open serial port"
            return False

        # flush input output
        ser.flushInput()
        ser.flushOutput()

        # send CMD_SYNC byte
        if(self.verbose_mode == True):
            print "Sending SYNC byte (", hex(CMD_SYNC),")"
        ser.write(('' + chr(CMD_SYNC)))
        time.sleep(SLEEP_1MS * 100) # device needs time to rewrite int.vector

        # send the data bytes and calculate checksum while sending
        if(self.verbose_mode == True):
            data_len = len(range(self.start_addr, 0xFFFE))
            print "Sending binary data - length:", data_len, "(",
            print hex(data_len), ") bytes"
        chksum = 0
        for addr in range(self.start_addr, 0xFFFE):
            byte = full_content[self.start_addr][addr-self.start_addr]
            ser.write(('' + chr(byte)))
            time.sleep(SLEEP_1MS * 5) # sleep 5 ms between sending bytes
            chksum ^= byte

        # send checksum
        if(self.verbose_mode == True):
            print "Sending checksum byte (", hex(chksum),")"
        ser.write(('' + chr(chksum)))
        time.sleep(SLEEP_1MS * 5) # sleep 5 ms between sending bytes

        # wait for reply
        if(self.verbose_mode == True):
        	print "Reading reply from target"
        byte = ser.read()
        ser.close()
        if(byte == chr(ACK)):
            if(self.verbose_mode == True):
                print "received ACK - SUCCESS"
            return True
        else:
            if(self.verbose_mode == True):
            	print "received NACK - ERROR"
            return False