Skip to content

Commit 30218db

Browse files
committed
imgtool: Fix tlv type encoded as 8-bit integer
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
1 parent ded02c9 commit 30218db

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

scripts/imgtool/dumpinfo.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ def dump_imginfo(imgfile, outfile=None, silent=False):
175175

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

194193
# Iterating through the TLV area
195194
while tlv_off < tlv_end:
196-
tlv_type, _, tlv_len = struct.unpack(order + 'BBH',
197-
b[tlv_off:(tlv_off + image.TLV_INFO_SIZE)])
195+
tlv_type, tlv_len = struct.unpack(order + 'HH',
196+
b[tlv_off:(tlv_off + image.TLV_INFO_SIZE)])
198197
tlv_off += image.TLV_INFO_SIZE
199198
tlv_data = b[tlv_off:(tlv_off + tlv_len)]
200199
tlv_area["tlvs"].append(

scripts/imgtool/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def add(self, kind, payload):
124124
raise click.UsageError(msg)
125125
buf = struct.pack(e + 'HH', kind, len(payload))
126126
else:
127-
buf = struct.pack(e + 'BBH', TLV_VALUES[kind], 0, len(payload))
127+
buf = struct.pack(e + 'HH', TLV_VALUES[kind], len(payload))
128128
self.buf += buf
129129
self.buf += payload
130130

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

0 commit comments

Comments
 (0)