diff --git a/scripts/imgtool/image.py b/scripts/imgtool/image.py index 67f4a30b..3de8357a 100644 --- a/scripts/imgtool/image.py +++ b/scripts/imgtool/image.py @@ -623,8 +623,15 @@ class Image(): @staticmethod def verify(imgfile, key): - with open(imgfile, "rb") as f: - b = f.read() + ext = os.path.splitext(imgfile)[1][1:].lower() + try: + if ext == INTEL_HEX_EXT: + b = IntelHex(imgfile).tobinstr() + else: + with open(imgfile, 'rb') as f: + b = f.read() + except FileNotFoundError: + raise click.UsageError(f"Image file {imgfile} not found") magic, _, header_size, _, img_size = struct.unpack('IIHHI', b[:16]) version = struct.unpack('BBHI', b[20:28])