fix: sort segments if ram_only_header is used

There are a few scenarios that segment sorting is required.
This is (as for now) a zephyr-case scenario only, where
flash section can be created during in-between ram linking.
Without segment sorting, flash segments will overlap and ELF won't
be created.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
This commit is contained in:
Sylvio Alves
2024-05-17 16:52:09 +02:00
parent a15089a6d5
commit 4c5874a3c4
2 changed files with 9 additions and 2 deletions

View File

@@ -352,6 +352,11 @@ class BaseFirmwareImage(object):
irom_segment = self.get_irom_segment()
return [s for s in self.segments if s != irom_segment]
def sort_segments(self):
if not self.segments:
return # nothing to sort
self.segments = sorted(self.segments, key=lambda s: s.addr)
def merge_adjacent_segments(self):
if not self.segments:
return # nothing to merge

View File

@@ -1039,8 +1039,6 @@ def elf2image(args):
args.chip = "esp8266"
print("Creating {} image...".format(args.chip))
if args.ram_only_header:
print("ROM segments hidden - only RAM segments are visible to the ROM loader!")
if args.chip != "esp8266":
image = CHIP_DEFS[args.chip].BOOTLOADER_IMAGE()
@@ -1076,6 +1074,10 @@ def elf2image(args):
image.elf_sha256 = e.sha256()
image.elf_sha256_offset = args.elf_sha256_offset
if args.ram_only_header:
print("ROM segments hidden - only RAM segments are visible to the ROM loader!")
image.sort_segments()
before = len(image.segments)
image.merge_adjacent_segments()
if len(image.segments) != before: