Skip to content

Commit

Permalink
imgtool: Add support for hex files in dumpinfo and tests
Browse files Browse the repository at this point in the history
Signed-off-by: Rustam Ismayilov <rustam.ismayilov@arm.com>
Change-Id: I37b54000955f30f87aff8f23a1ea71804bf967cd
  • Loading branch information
rustammendel committed Jun 22, 2024
1 parent 62dfb9d commit b4afd95
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions scripts/imgtool/dumpinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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))

Expand Down
9 changes: 9 additions & 0 deletions scripts/tests/test_dumpinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b4afd95

Please sign in to comment.