Exemplo n.º 1
0
def gen_flash_map_bin (flash_map_file, comp_list):
    flash_map = FLASH_MAP()
    for comp in reversed(comp_list):
        desc  = FLASH_MAP_DESC ()
        if comp['bname'] not in FLASH_MAP.FLASH_MAP_COMPONENT_SIGNATURE:
            if len(comp['bname']) < 4:
                # For short names, prefix with '_'
                bname = '_' * (4 - len(comp['bname'])) + comp['bname']
            else:
                # For long names, use the 1st 4 chars
                bname = comp['bname'][:4]
            desc.sig    = bname.encode()
        else:
            desc.sig    = FLASH_MAP.FLASH_MAP_COMPONENT_SIGNATURE[comp['bname']].encode()
        desc.flags  = comp['flag']
        desc.offset = comp['offset']
        desc.size   = comp['size']
        flash_map.add (desc)
    flash_map.finalize ()

    fd = open (flash_map_file, 'wb')
    fd.write(flash_map)
    for desc in flash_map.descriptors:
        fd.write(desc)
    fd.close()
Exemplo n.º 2
0
def gen_flash_map_bin (flash_map_file, comp_list):
	flash_map = FLASH_MAP()
	for comp in reversed(comp_list):
		desc  = FLASH_MAP_DESC ()
		desc.sig    = FLASH_MAP.FLASH_MAP_COMPONENT_SIGNATURE[comp['bname']].encode()
		desc.flags  = comp['flag']
		desc.offset = comp['offset']
		desc.size   = comp['size']
		flash_map.add (desc)
	flash_map.finalize ()

	fd = open (flash_map_file, 'wb')
	fd.write(flash_map)
	for desc in flash_map.descriptors:
		fd.write(desc)
	fd.close()
Exemplo n.º 3
0
def decode_flash_map (flash_map_file, print_address = True):

    if not os.path.exists(flash_map_file):
        raise Exception("No layout file '%s' found !" % flash_map_file)
        return

    fmap_bins = open (flash_map_file, 'rb')
    flash_map_data = bytearray(fmap_bins.read())
    fmap_bins.close()

    flash_map = FLASH_MAP.from_buffer (flash_map_data)
    entry_num = (flash_map.length - sizeof(FLASH_MAP)) // sizeof(FLASH_MAP_DESC)

    image_size = flash_map.romsize
    image_base = 0x100000000 - image_size

    flash_map_lines = [
            "\nFlash Map Information:\n" \
            "\t+------------------------------------------------------------------------+\n" \
            "\t|                              FLASH  MAP                                |\n" \
            "\t|                         (RomSize = 0x%08X)                         |\n"     \
            "\t+------------------------------------------------------------------------+\n" \
            "\t|   NAME   |     OFFSET  (BASE)     |    SIZE    |         FLAGS         |\n" \
            "\t+----------+------------------------+------------+-----------------------+\n"  % image_size]

    region   = '      '
    prev_rgn = 'TS'
    disp_rgn = ''

    for idx in range (entry_num):
        desc  = FLASH_MAP_DESC.from_buffer (flash_map_data, sizeof(FLASH_MAP) + idx * sizeof(FLASH_MAP_DESC))
        flags = 'Compressed  '  if (desc.flags & FLASH_MAP.FLASH_MAP_DESC_FLAGS['COMPRESSED']) else 'Uncompressed'
        for rgn_name, rgn_flag in list(FLASH_MAP.FLASH_MAP_DESC_FLAGS.items()):
            if rgn_flag == (desc.flags & 0x0F):
                if rgn_flag & (FLASH_MAP.FLASH_MAP_DESC_FLAGS['NON_REDUNDANT'] | FLASH_MAP.FLASH_MAP_DESC_FLAGS['NON_VOLATILE']):
                    rgn_suf      = ''
                    disp_rgn_suf = ''
                else:
                    suffixes = 'B' if desc.flags & FLASH_MAP.FLASH_MAP_DESC_FLAGS['BACKUP'] else 'A'
                    rgn_suf      = '_' + suffixes
                    disp_rgn_suf = ' ' + suffixes
                region   = ''.join([word[0] for word in rgn_name.split('_')]) + rgn_suf
                disp_rgn = rgn_name.replace('_', ' ') + disp_rgn_suf
                region   = region.center(4, ' ')
                disp_rgn = disp_rgn.center(23, ' ')
                break

        if region != '      ':
            if region != prev_rgn:
                prev_rgn = region
                flash_map_lines.append (
                  "\t+------------------------------------------------------------------------+\n" \
                  "\t|                        %s                         |\n"                      \
                  "\t+------------------------------------------------------------------------+\n" % disp_rgn)
            flags += ', '
        flags += region
        if print_address:
            address = '0x%08X' % (desc.offset + image_base)
        else:
            address = ' ???????? '
        flash_map_lines.append ("\t|   %s   |  0x%06x(%s)  |  0x%06x  |  %s   |\n" \
            % (desc.sig.decode(), desc.offset, address, desc.size, flags))

    flash_map_lines.append ("\t+----------+------------------------+------------+-----------------------+\n")

    return ''.join(flash_map_lines)