Skip to content

Commit d272c32

Browse files
committed
imgtool: Add support for hex files in dumpinfo and tests
Signed-off-by: Rustam Ismayilov <[email protected]> Change-Id: I37b54000955f30f87aff8f23a1ea71804bf967cd
1 parent 623cc90 commit d272c32

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

scripts/imgtool/dumpinfo.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323

2424
import click
2525
import yaml
26+
from intelhex import IntelHex
2627

2728
from imgtool import image
29+
from imgtool.image import INTEL_HEX_EXT
2830

2931
HEADER_ITEMS = ("magic", "load_addr", "hdr_size", "protected_tlv_size",
3032
"img_size", "flags", "version")
@@ -129,9 +131,14 @@ def dump_imginfo(imgfile, outfile=None, silent=False):
129131
trailer = {}
130132
key_field_len = None
131133

134+
ext = os.path.splitext(imgfile)[1][1:].lower()
132135
try:
133-
with open(imgfile, "rb") as f:
134-
b = f.read()
136+
if ext == INTEL_HEX_EXT:
137+
ih = IntelHex(imgfile)
138+
b = ih.tobinstr()
139+
else:
140+
with open(imgfile, "rb") as f:
141+
b = f.read()
135142
except FileNotFoundError:
136143
raise click.UsageError("Image file not found ({})".format(imgfile))
137144

scripts/tests/test_dumpinfo.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,12 @@ def test_dumpinfo_padded_multiflag(self, tmp_path_persistent, key_type):
326326
assert "ROM_FIXED" in result.stdout
327327
assert DUMPINFO_SUCCESS_LITERAL in result.stdout
328328
assert DUMPINFO_ENCRYPTED_TRAILER in result.stdout
329+
330+
@pytest.mark.parametrize("hex_addr", ("0", "16", "35"))
331+
def test_dumpinfo_hex(self, tmp_path_persistent, hex_addr):
332+
self.image_signed = signed_images_dir + "/hex/" + f"zero_hex-addr_{hex_addr}" + ".hex"
333+
result = self.runner.invoke(
334+
imgtool, ["dumpinfo", str(self.image_signed)]
335+
)
336+
assert result.exit_code == 0
337+
assert DUMPINFO_SUCCESS_LITERAL in result.stdout

0 commit comments

Comments
 (0)