def write_map(self, wf, base_offset, prefix=""): """Display the field names and offsets of a single TFTF header""" # Add the symbol for the start of this header if prefix: wf.write("{0:s} {1:08x}\n".format(prefix, base_offset)) prefix += "." # Add the header fields wf.write("{0:s}sentinel {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_SENTINEL)) wf.write("{0:s}header_size {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_HEADER_SIZE)) wf.write("{0:s}timestamp {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_TIMESTAMP)) wf.write("{0:s}firmware_name {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_NAME)) wf.write("{0:s}package_type {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_PACKAGE_TYPE)) wf.write("{0:s}start_location {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_START_LOCATION)) wf.write("{0:s}unipro_mfgr_id {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_UNIPRO_MFGR_ID)) wf.write("{0:s}unipro_product_id {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_UNIPRO_PRODUCT_ID)) wf.write("{0:s}ara_vendor_id {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_ARA_VENDOR_ID)) wf.write("{0:s}ara_product_id {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_ARA_PRODUCT_ID)) for i in range(len(self.reserved)): wf.write("{0:s}reserved[{1:d}] {2:08x}\n". format(prefix, i, base_offset + TFTF_HDR_OFF_RESERVED + (TFTF_RSVD_SIZE * i))) # Dump the section descriptors (used and free) section_offset = base_offset + TFTF_HDR_OFF_SECTIONS for index in range(TFTF_HDR_NUM_SECTIONS): wf.write("{0:s}section[{1:d}].type {2:08x}\n". format(prefix, index, section_offset + TFTF_SECTION_OFF_TYPE)) wf.write("{0:s}section[{1:d}].class {2:08x}\n". format(prefix, index, section_offset + TFTF_SECTION_OFF_CLASS)) wf.write("{0:s}section[{1:d}].id {2:08x}\n". format(prefix, index, section_offset + TFTF_SECTION_OFF_ID)) wf.write("{0:s}section[{1:d}].section_length {2:08x}\n". format(prefix, index, section_offset + TFTF_SECTION_OFF_LENGTH)) wf.write("{0:s}section[{1:d}].load_address {2:08x}\n". format(prefix, index, section_offset + TFTF_SECTION_OFF_LOAD_ADDRESS)) wf.write("{0:s}section[{1:d}].expanded_length {2:08x}\n". format(prefix, index, section_offset + TFTF_SECTION_OFF_EXPANDED_LENGTH)) section_offset += TFTF_SECTION_LEN # Dump the section starts base_offset += self.header_size for index, section in enumerate(self.sections): sn_name = "{0:s}section[{1:d}].{2:s}".\ format(prefix, index, section.section_short_name(section.section_type)) # If we know the structure of the section, dump the map for that if section.section_type == TFTF_SECTION_TYPE_END_OF_DESCRIPTORS: break elif section.section_type == TFTF_SECTION_TYPE_SIGNATURE: signature_block_write_map(wf, base_offset, sn_name) else: # Otherwise, just describe it generically wf.write("{0:s} {1:08x}\n".format(sn_name, base_offset)) base_offset += section.section_length
def write_map(self, wf, base_offset, prefix=""): """Display the field names and offsets of a single TFTF header""" # Add the symbol for the start of this header if prefix: wf.write("{0:s} {1:08x}\n".format(prefix, base_offset)) prefix += "." # Add the header fields wf.write("{0:s}sentinel {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_SENTINEL)) wf.write("{0:s}timestamp {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_TIMESTAMP)) wf.write("{0:s}firmware_name {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_NAME)) wf.write("{0:s}load_length {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_LENGTH)) wf.write("{0:s}load_base {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_LOAD_BASE)) wf.write("{0:s}expanded_length {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_EXPANDED_LENGTH)) wf.write("{0:s}star_location {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_START_LOCATION)) wf.write("{0:s}unipro_mfgr_id {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_UNIPRO_MFGR_ID)) wf.write("{0:s}unipro_product_id {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_UNIPRO_PRODUCT_ID)) wf.write("{0:s}ara_vendor_id {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_ARA_VENDOR_ID)) wf.write("{0:s}ara_producgt_id {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_ARA_PRODUCT_ID)) # Dump the section descriptors (used and free) section_offset = base_offset + TFTF_HDR_OFF_SECTIONS for index in range(TFTF_MAX_SECTIONS): wf.write("{0:s}section[{1:d}].section_length {2:08x}\n". format(prefix, index, section_offset + TFTF_SECTION_OFF_LENGTH)) wf.write("{0:s}section[{1:d}].expanded_length {2:08x}\n". format(prefix, index, section_offset + TFTF_SECTION_OFF_EXPANDED_LENGTH)) wf.write("{0:s}section[{1:d}].copy_offset {2:08x}\n". format(prefix, index, section_offset + TFTF_SECTION_OFF_COPY_OFFSET)) wf.write("{0:s}section[{1:d}].type {2:08x}\n". format(prefix, index, section_offset + TFTF_SECTION_OFF_SECTION_TYPE)) section_offset += TFTF_SECTION_HDR_LENGTH # Dump the padding (the remainder of the TFTF header wf.write("{0:s}padding {1:08x}\n". format(prefix, base_offset + TFTF_HDR_OFF_PADDING)) # Dump the section starts base_offset += TFTF_HDR_LENGTH for index, section in enumerate(self.sections): sn_name = "{0:s}section[{1:d}].{2:s}".\ format(prefix, index, section.section_short_name(section.section_type)) # If we know the structure of the section, dump the map for that if section.section_type == TFTF_SECTION_TYPE_END_OF_DESCRIPTORS: break elif section.section_type == TFTF_SECTION_TYPE_SIGNATURE: signature_block_write_map(wf, base_offset, sn_name) else: # Otherwise, just describe it generically wf.write("{0:s} {1:08x}\n".format(sn_name, base_offset)) base_offset += section.section_length