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