Skip to content

Commit 79c284b

Browse files
lzalanordicjm
authored andcommitted
scripts: imgtool: Fix img verify for hex file format
Currently imgtool --verify fails for hex files with: Invalid image magic; is this an MCUboot image? Added support for hex files by converting hex to bin using IntelHex::tobinstr(). Reusing image.load() needs a bit of rework, maybe a common load method will be done in the future, Signed-off-by: Lucian Zala <[email protected]>
1 parent a4eda30 commit 79c284b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

scripts/imgtool/image.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,15 @@ def pad_to(self, size):
623623

624624
@staticmethod
625625
def verify(imgfile, key):
626-
with open(imgfile, "rb") as f:
627-
b = f.read()
626+
ext = os.path.splitext(imgfile)[1][1:].lower()
627+
try:
628+
if ext == INTEL_HEX_EXT:
629+
b = IntelHex(imgfile).tobinstr()
630+
else:
631+
with open(imgfile, 'rb') as f:
632+
b = f.read()
633+
except FileNotFoundError:
634+
raise click.UsageError(f"Image file {imgfile} not found")
628635

629636
magic, _, header_size, _, img_size = struct.unpack('IIHHI', b[:16])
630637
version = struct.unpack('BBHI', b[20:28])

0 commit comments

Comments
 (0)