imgtool: Fix output of confirmed image in HEX format
The image_ok was written to the wrong offset
when outputting HEX format. This commit fixes that.
Drive-by change: Use actual length of boot magic
instead of assuming it's 16 bytes long.
@@ -243,12 +243,11 @@ class Image():
self.enctlv_len)
trailer_addr = (self.base_addr + self.slot_size) - trailer_size
if self.confirm and not self.overwrite_only:
- magic_size = 16
- magic_align_size = align_up(magic_size, self.max_align)
+ magic_align_size = align_up(len(self.boot_magic), self.max_align)
image_ok_idx = -(magic_align_size + self.max_align)
- flag = bytearray([self.erased_val] * magic_align_size)
+ flag = bytearray([self.erased_val] * self.max_align)
flag[0] = 0x01 # image_ok = 0x01
- h.puts(trailer_addr + image_ok_idx, bytes(flag))
+ h.puts(trailer_addr + trailer_size + image_ok_idx, bytes(flag))
h.puts(trailer_addr + (trailer_size - len(self.boot_magic)),
bytes(self.boot_magic))
h.tofile(path, 'hex')
