def add_element(self, element_type, element_id, element_generation, element_location, element_length, filename): """Add a new element to the element table Adds an element to the element table but doesn't load the TFTF file into the ROMimage buffer. That is done later by post_process. Returns a success flag (We would typically be called by "create-ffff" after parsing element parameters.) """ if len(self.elements) < FFFF_MAX_ELEMENTS: element = FfffElement(len(self.elements), self.ffff_buf, self.flash_capacity, self.erase_block_size, element_type, element_id, element_generation, element_location, element_length, filename) if element.init(): self.elements.append(element) span_start = element.element_location span_end = span_start + len(element.tftf_blob.tftf_buf) self.ffff_buf[span_start:span_end] = element.tftf_blob.tftf_buf return True else: return False else: error("too many elements") return False
def add_element(self, element_type, element_id, element_generation, element_location, element_length, filename): """Add a new element to the element table Adds an element to the element table but doesn't load the TFTF file into the ROMimage buffer. That is done later by post_process. Returns a success flag (We would typically be called by "create-ffff" after parsing element parameters.) """ if len(self.elements) < FFFF_MAX_ELEMENTS: element = FfffElement(len(self.elements), self.ffff_buf, self.flash_capacity, self.erase_block_size, element_type, element_id, element_generation, element_location, element_length, filename) if element.init(): self.elements.append(element) span_start = element.element_location span_end = span_start + len(element.tftf_blob.tftf_buf) self.ffff_buf[span_start:span_end] = element.tftf_blob.tftf_buf return True else: return False else: error("too many elements") return False
def unpack(self): """Unpack an FFFF header from a buffer""" fmt_string = "<16s16s48sLLLLL" + "L" * FFFF_HDR_NUM_RESERVED ffff_hdr = unpack_from(fmt_string, self.ffff_buf, self.header_offset) self.sentinel = ffff_hdr[0] self.timestamp = ffff_hdr[1] self.flash_image_name = ffff_hdr[2] self.flash_capacity = ffff_hdr[3] self.erase_block_size = ffff_hdr[4] self.header_size = ffff_hdr[5] self.flash_image_length = ffff_hdr[6] self.header_generation_number = ffff_hdr[7] for i in range(FFFF_HDR_NUM_RESERVED): self.reserved[i] = ffff_hdr[8+i] # Now that we have parsed the header_size, recalculate the size of the # element table and the offsets to all FFFF header fields which follow # it. self.recalculate_header_offsets() # Unpack the tail sentinel ffff_hdr = unpack_from("<16s", self.ffff_buf, self.header_offset + FFFF_HDR_OFF_TAIL_SENTINEL) self.tail_sentinel = ffff_hdr[0] # Determine the ROM range that can hold the elements self.element_location_min = 2 * self.get_header_block_size() self.element_location_max = self.flash_capacity # Parse the table of element headers self.elements = [] offset = FFFF_HDR_OFF_ELEMENT_TBL for index in range(FFFF_HDR_NUM_ELEMENTS): element = FfffElement(index, self.ffff_buf, self.flash_capacity, self.erase_block_size, 0, 0, 0, 0, 0, 0) eot = element.unpack(self.ffff_buf, offset) self.elements.append(element) offset += FFFF_ELT_LENGTH if eot: print("unpack done") break self.validate_ffff_header()
def add_element(self, element_type, element_class, element_id, element_length, element_location, element_generation, filename): """Add a new element to the element table Adds an element to the element table but doesn't load the TFTF file into the ROMimage buffer. That is done later by post_process. Returns a success flag (We would typically be called by "create-ffff" after parsing element parameters.) """ num_elements = len(self.elements) if num_elements < FFFF_HDR_NUM_ELEMENTS: element = FfffElement(len(self.elements), self.ffff_buf, self.flash_capacity, self.erase_block_size, element_type, element_class, element_id, element_length, element_location, element_generation, filename) if element_type == FFFF_ELEMENT_END_OF_ELEMENT_TABLE: if num_elements == 0: # Special case, add the EOT element self.elements.append(element) return True if element.init(): # Because the table always ends in a EOT entry, we "append" # new elements by inserting them just before the EOT element. self.elements.insert(num_elements - 1, element) span_start = element.element_location span_end = span_start + len(element.tftf_blob.tftf_buf) self.ffff_buf[span_start:span_end] = element.tftf_blob.tftf_buf return True else: return False else: error("too many elements") return False
def unpack(self): """Unpack an FFFF header from a buffer""" ffff_hdr = unpack_from("<16s16s48sLLLLL", self.ffff_buf, self.header_offset) self.sentinel = ffff_hdr[0] self.timestamp = ffff_hdr[1] self.flash_image_name = ffff_hdr[2] self.flash_capacity = ffff_hdr[3] self.erase_block_size = ffff_hdr[4] self.header_size = ffff_hdr[5] self.flash_image_length = ffff_hdr[6] self.header_generation_number = ffff_hdr[7] # unpack the tail sentinel ffff_hdr = unpack_from("<16s", self.ffff_buf, self.header_offset + FFFF_HDR_OFF_TAIL_SENTINEL) self.tail_sentinel = ffff_hdr[0] # Determine the ROM range that can hold the elements self.element_location_min = 2 * self.header_block_size() self.element_location_max = self.flash_capacity # Parse the table of element headers self.elements = [] offset = FFFF_HDR_OFF_ELEMENT_TBL for index in range(FFFF_MAX_ELEMENTS): element = FfffElement(index, self.ffff_buf, self.flash_capacity, self.erase_block_size, 0, 0, 0, 0, 0) if not element.unpack(self.ffff_buf, offset): self.elements.append(element) offset += FFFF_ELT_LENGTH else: # Stop on the first unused element print("unpack done") break self.validate_ffff_header()
def unpack(self): """Unpack an FFFF header from a buffer""" ffff_hdr = unpack_from("<16s16s48sLLLLL", self.ffff_buf, self.header_offset) self.sentinel = ffff_hdr[0] self.timestamp = ffff_hdr[1] self.flash_image_name = ffff_hdr[2] self.flash_capacity = ffff_hdr[3] self.erase_block_size = ffff_hdr[4] self.header_size = ffff_hdr[5] self.flash_image_length = ffff_hdr[6] self.header_generation_number = ffff_hdr[7] # unpack the tail sentinel ffff_hdr = unpack_from("<16s", self.ffff_buf, self.header_offset + FFFF_HDR_OFF_TAIL_SENTINEL) self.tail_sentinel = ffff_hdr[0] # Determine the ROM range that can hold the elements self.element_location_min = 2 * self.header_block_size() self.element_location_max = self.flash_capacity # Parse the table of element headers self.elements = [] offset = FFFF_HDR_OFF_ELEMENT_TBL for index in range(FFFF_MAX_ELEMENTS): element = FfffElement(index, self.ffff_buf, self.flash_capacity, self.erase_block_size, 0, 0, 0, 0, 0) if not element.unpack(self.ffff_buf, offset): self.elements.append(element) offset += FFFF_ELT_LENGTH else: # Stop on the first unused element print("unpack done") break self.validate_ffff_header()