diff --git a/scripts/imgtool/dumpinfo.py b/scripts/imgtool/dumpinfo.py index 55446574c..3f97a49f5 100644 --- a/scripts/imgtool/dumpinfo.py +++ b/scripts/imgtool/dumpinfo.py @@ -23,8 +23,10 @@ import click import yaml +from intelhex import IntelHex from imgtool import image +from imgtool.image import INTEL_HEX_EXT HEADER_ITEMS = ("magic", "load_addr", "hdr_size", "protected_tlv_size", "img_size", "flags", "version") @@ -129,9 +131,14 @@ def dump_imginfo(imgfile, outfile=None, silent=False): trailer = {} key_field_len = None + ext = os.path.splitext(imgfile)[1][1:].lower() try: - with open(imgfile, "rb") as f: - b = f.read() + if ext == INTEL_HEX_EXT: + ih = IntelHex(imgfile) + b = ih.tobinstr() + else: + with open(imgfile, "rb") as f: + b = f.read() except FileNotFoundError: raise click.UsageError("Image file not found ({})".format(imgfile)) diff --git a/scripts/tests/test_dumpinfo.py b/scripts/tests/test_dumpinfo.py index d8ba8515d..8bc817b53 100644 --- a/scripts/tests/test_dumpinfo.py +++ b/scripts/tests/test_dumpinfo.py @@ -326,3 +326,12 @@ def test_dumpinfo_padded_multiflag(self, tmp_path_persistent, key_type): assert "ROM_FIXED" in result.stdout assert DUMPINFO_SUCCESS_LITERAL in result.stdout assert DUMPINFO_ENCRYPTED_TRAILER in result.stdout + + @pytest.mark.parametrize("hex_addr", ("0", "16", "35")) + def test_dumpinfo_hex(self, tmp_path_persistent, hex_addr): + self.image_signed = signed_images_dir + "/hex/" + f"zero_hex-addr_{hex_addr}" + ".hex" + result = self.runner.invoke( + imgtool, ["dumpinfo", str(self.image_signed)] + ) + assert result.exit_code == 0 + assert DUMPINFO_SUCCESS_LITERAL in result.stdout