Example #1
0
    def __init__(self, file_name):
        """

        """
        self.blocks = []
        with open(file_name) as sfile:
            blk = Blocks()
            for srec in sfile:
                srec = srec.strip("\n").strip("\r")
                record_type, data_len, addr, data, checksum = srecutils.parse_srec(srec)

                if record_type == 'S1' or record_type == 'S2' or record_type == 'S3':
                    addr_int = int(addr,16)
                    if blk.end_addr and addr_int > blk.end_addr:
                        self.blocks.append(blk)
                        blk = Blocks()
                    if not blk.start_addr:
                        blk.start_addr = addr_int
                    blk.data+=data
                    blk.end_addr = addr_int + (int(data_len,16) - 4)
                    raw_data = data
            self.blocks.append(blk)
            pass
Example #2
0
    # open input file
    scn_file = open(args[1])

    linecount = 0
    for srec in scn_file:
        # Strip some file content
        srec = srec.strip("\n")
        srec = srec.strip("\r")

        # Validate checksum and parse record
        if options.validate_checksum and not srecutils.validate_srec_checksum(
                srec):
            print "Invalid checksum found!"
        else:
            # Extract data from the srec
            record_type, data_len, addr, data, checksum = srecutils.parse_srec(
                srec)

            if record_type == 'S1' or record_type == 'S2' or record_type == 'S3':
                # Make a copy of the original data record for checksum calculation
                raw_data = data

                # Apply offset (default is 0)
                data = srecutils.offset_data(data, int(options.offset),
                                             options.readable,
                                             options.wraparound)

                # Get checksum of the new offset srec
                raw_offset_srec = ''.join(
                    [record_type, data_len, addr, raw_data])
                int_checksum = srecutils.compute_srec_checksum(raw_offset_srec)
                checksum = srecutils.int_to_padded_hex_byte(int_checksum)
Example #3
0
def getFlashData(filename, startAddr):

  print "Write %s " % filename
  # open input file
  scn_file = open(filename)
  
  endAddr = 0xFFFF;
  programBuff = bytearray(endAddr-startAddr+1); #Array to store 16K of memory, and program it in one shot

  #Fill the byte array with default values (recommended ff so we dont exec anything in the chip inevitably)
  for i in xrange(0,endAddr-startAddr+1):
    programBuff[i] = 0xFF

  linecount = 0
  for srec in scn_file:
      # Strip some file content
      srec = srec.strip("\n")
      srec = srec.strip("\r")
  
      # Validate checksum and parse record
      if not srecutils.validate_srec_checksum(srec):
          print "Invalid checksum found!"
      else:
          # Extract data from the srec
          record_type, data_len, addr, data, checksum = srecutils.parse_srec(srec)
  
          if record_type == 'S1':
              # Make a copy of the original data record for checksum calculation
              raw_data = data
  
              # Apply offset (default is 0)
              data = srecutils.offset_data(data, 0, 0, 0)
  
              # Get checksum of the new offset srec
              raw_offset_srec = ''.join([record_type, data_len, addr, raw_data])
              int_checksum = srecutils.compute_srec_checksum(raw_offset_srec)
              checksum = srecutils.int_to_padded_hex_byte(int_checksum)

              # output to file
              print ''.join([str(linecount), ':', data, '\n']),

  
              #data = ''.join([record_type, data_len, addr, data, checksum])
              plen = int(data_len,16) - 3 #Convert to a number and subtract the addr and length 
              decAddr = int(addr, 16)

              idx = decAddr-startAddr
              #Check the the address is in range
              if (idx < 0 or idx+plen > endAddr):
                print "ERR: Invalid address given %X" % decAddr
                break
              #Set the buffer with the program data
              print "Addr %X %X" % (decAddr, idx)
              #Convert the hex byte into in and store in our program memory
              for i in xrange(0,plen):
                programBuff[idx+i] = int(data[i*2:(i*2)+2],16)

          # All the other record types
          else:
              output_str = ' No Action '.join([srec, '\n'])
  
              output_str = ''.join([str(linecount), ': ', output_str])
  
              print output_str,
  
  
      # increment our fancy linecounter
      linecount += 1
  
  scn_file.close()

  return programBuff
Example #4
0
    # open input file
    scn_file = open(args[1])

    linecount = 0
    for srec in scn_file:
        # Strip some file content
        srec = srec.strip("\n")
        srec = srec.strip("\r")

        # Validate checksum and parse record
        if options.validate_checksum and not srecutils.validate_srec_checksum(srec):
            print "Invalid checksum found!"
        else:
            # Extract data from the srec
            record_type, data_len, addr, data, checksum = srecutils.parse_srec(srec)

            if record_type == 'S1' or record_type == 'S2' or record_type == 'S3':
                # Make a copy of the original data record for checksum calculation
                raw_data = data

                # Apply offset (default is 0)
                data = srecutils.offset_data(data, int(options.offset), options.readable, options.wraparound)

                # Get checksum of the new offset srec
                raw_offset_srec = ''.join([record_type, data_len, addr, raw_data])
                int_checksum = srecutils.compute_srec_checksum(raw_offset_srec)
                checksum = srecutils.int_to_padded_hex_byte(int_checksum)

                if not options.data_only:
                    data =  ''.join([record_type, data_len, addr, data, checksum])
Example #5
0
def getFlashData(filename, startAddr):

    print "Write %s " % filename
    # open input file
    scn_file = open(filename)

    endAddr = 0xFFFF
    programBuff = bytearray(endAddr - startAddr + 1)
    #Array to store 16K of memory, and program it in one shot

    #Fill the byte array with default values (recommended ff so we dont exec anything in the chip inevitably)
    for i in xrange(0, endAddr - startAddr + 1):
        programBuff[i] = 0xFF

    linecount = 0
    for srec in scn_file:
        # Strip some file content
        srec = srec.strip("\n")
        srec = srec.strip("\r")

        # Validate checksum and parse record
        if not srecutils.validate_srec_checksum(srec):
            print "Invalid checksum found!"
        else:
            # Extract data from the srec
            record_type, data_len, addr, data, checksum = srecutils.parse_srec(
                srec)

            if record_type == 'S1':
                # Make a copy of the original data record for checksum calculation
                raw_data = data

                # Apply offset (default is 0)
                data = srecutils.offset_data(data, 0, 0, 0)

                # Get checksum of the new offset srec
                raw_offset_srec = ''.join(
                    [record_type, data_len, addr, raw_data])
                int_checksum = srecutils.compute_srec_checksum(raw_offset_srec)
                checksum = srecutils.int_to_padded_hex_byte(int_checksum)

                # output to file
                print ''.join([str(linecount), ':', data, '\n']),

                #data = ''.join([record_type, data_len, addr, data, checksum])
                plen = int(
                    data_len, 16
                ) - 3  #Convert to a number and subtract the addr and length
                decAddr = int(addr, 16)

                idx = decAddr - startAddr
                #Check the the address is in range
                if (idx < 0 or idx + plen > endAddr):
                    print "ERR: Invalid address given %X" % decAddr
                    break
                #Set the buffer with the program data
                print "Addr %X %X" % (decAddr, idx)
                #Convert the hex byte into in and store in our program memory
                for i in xrange(0, plen):
                    programBuff[idx + i] = int(data[i * 2:(i * 2) + 2], 16)

            # All the other record types
            else:
                output_str = ' No Action '.join([srec, '\n'])

                output_str = ''.join([str(linecount), ': ', output_str])

                print output_str,

        # increment our fancy linecounter
        linecount += 1

    scn_file.close()

    return programBuff