Example #1
0
    if len(args) <= 1 or len(args) > 2:
        parser.print_help()
        sys.exit()

    # 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)
Example #2
0
    if len(args) <= 1 or len(args) > 2:
        parser.print_help()
        sys.exit()

    # 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)
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
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