fix(elf2image): fix elf2image for ram app when sha256 offset not specified

This commit fixes issue where elf2image fails to generate image for ram
app when sha256 offset is not specified. This commit adds a check to
verify if the app description segment is in the flash region and if not
it will not add the sha256 offset to the image header.
This commit is contained in:
Radim Karniš
2025-03-12 22:59:07 +01:00
parent 552096328b
commit 9fd7b7afd7

View File

@@ -1164,10 +1164,14 @@ def elf2image(args):
if args.elf_sha256_offset:
image.elf_sha256 = e.sha256()
image.elf_sha256_offset = args.elf_sha256_offset
# If the ELF file contains an app_desc section, put the SHA256 digest at the correct offset
elif any(".flash.appdesc" in seg.name for seg in image.segments):
image.elf_sha256 = e.sha256()
image.elf_sha256_offset = 0xB0
else:
# If ELF file contains an app_desc section and it is in flash,
# put the SHA256 digest at correct offset.
# If it is flash build, it should always be 0xB0.
appdesc_segs = [seg for seg in image.segments if ".flash.appdesc" in seg.name]
if appdesc_segs and image.is_flash_addr(appdesc_segs[0].addr):
image.elf_sha256 = e.sha256()
image.elf_sha256_offset = 0xB0
if args.ram_only_header:
print(