Skip to content

Commit

Permalink
fix(esptool): Proper alignment for SoCs with offset load
Browse files Browse the repository at this point in the history
Update the --ram-only-header segments handling
for the ESP32 and ESP32-S2 SoC.

Signed-off-by: Marek Matej <[email protected]>
  • Loading branch information
Marek Matej committed Jan 11, 2024
1 parent e948993 commit 17866a5
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions esptool/bin_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,15 +738,23 @@ def get_alignment_data_needed(segment):
flash_segments.reverse()
for segment in flash_segments:
pad_len = get_alignment_data_needed(segment)
while pad_len > 0:
pad_segment = ImageSegment(0, b"\x00" * pad_len, f.tell())
self.save_segment(f, pad_segment)
total_segments += 1
pad_len = get_alignment_data_needed(segment)
# write the flash segment
assert (
f.tell() + 8
) % self.IROM_ALIGN == segment.addr % self.IROM_ALIGN
# Some chips have a non-zero load offset (eg. 0x1000)
# therefore we shift the ROM segments "-load_offset"
# so it will be aligned properly after it is flashed
align_min = (
self.ROM_LOADER.BOOTLOADER_FLASH_OFFSET - self.SEG_HEADER_LEN
)
if pad_len < align_min:
print("Unable to align the segment!")
break
pad_len -= self.ROM_LOADER.BOOTLOADER_FLASH_OFFSET
pad_segment = ImageSegment(0, b"\x00" * pad_len, f.tell())
self.save_segment(f, pad_segment)
total_segments += 1
# check the alignment
assert (f.tell() + 8 + self.ROM_LOADER.BOOTLOADER_FLASH_OFFSET) % (
self.IROM_ALIGN
) == segment.addr % self.IROM_ALIGN
# save the flash segment but not saving its checksum neither
# saving the number of flash segments, since ROM bootloader
# should "not see" them
Expand Down

0 comments on commit 17866a5

Please sign in to comment.