Skip to content

Commit

Permalink
imgtool: Fix tlv type encoded as 8-bit integer
Browse files Browse the repository at this point in the history
Use "HH" (16+16) format for struct instead of "BBH" (8+8+16) and
remove padding.
TLV types have modified to be 16-bit in image.h. This change was
not fully reflected in image creation, dumpinfo and verify commands.

Signed-off-by: Rustam Ismayilov <[email protected]>
Change-Id: I7780aeae171aea3428335f5448bde45760a76070
  • Loading branch information
rustammendel committed Jul 25, 2024
1 parent 4fb4592 commit 4400413
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions scripts/imgtool/dumpinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ def dump_imginfo(imgfile, outfile=None, silent=False):

# Iterating through the protected TLV area
while tlv_off < tlv_end:
tlv_type, tlv_len = struct.unpack(
order + 'HH',
b[tlv_off:(tlv_off + image.TLV_INFO_SIZE)])
tlv_type, tlv_len = struct.unpack(order + 'HH',
b[tlv_off:(tlv_off + image.TLV_INFO_SIZE)])
tlv_off += image.TLV_INFO_SIZE
tlv_data = b[tlv_off:(tlv_off + tlv_len)]
tlv_area["tlvs_prot"].append(
Expand All @@ -193,8 +192,8 @@ def dump_imginfo(imgfile, outfile=None, silent=False):

# Iterating through the TLV area
while tlv_off < tlv_end:
tlv_type, _, tlv_len = struct.unpack(order + 'BBH',
b[tlv_off:(tlv_off + image.TLV_INFO_SIZE)])
tlv_type, tlv_len = struct.unpack(order + 'HH',
b[tlv_off:(tlv_off + image.TLV_INFO_SIZE)])
tlv_off += image.TLV_INFO_SIZE
tlv_data = b[tlv_off:(tlv_off + tlv_len)]
tlv_area["tlvs"].append(
Expand Down
4 changes: 2 additions & 2 deletions scripts/imgtool/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def add(self, kind, payload):
raise click.UsageError(msg)
buf = struct.pack(e + 'HH', kind, len(payload))
else:
buf = struct.pack(e + 'BBH', TLV_VALUES[kind], 0, len(payload))
buf = struct.pack(e + 'HH', TLV_VALUES[kind], len(payload))
self.buf += buf
self.buf += payload

Expand Down Expand Up @@ -679,7 +679,7 @@ def verify(imgfile, key):
tlv_off += TLV_INFO_SIZE # skip tlv info
while tlv_off < tlv_end:
tlv = b[tlv_off:tlv_off + TLV_SIZE]
tlv_type, _, tlv_len = struct.unpack(e + 'BBH', tlv)
tlv_type, tlv_len = struct.unpack(e + 'HH', tlv)
if tlv_type == TLV_VALUES["SHA256"] or tlv_type == TLV_VALUES["SHA384"]:
if not tlv_matches_key_type(tlv_type, key):
return VerifyResult.KEY_MISMATCH, None, None
Expand Down

0 comments on commit 4400413

Please sign in to comment.