1
- # Copyright 2023 Arm Limited
1
+ # Copyright 2023-2024 Arm Limited
2
2
#
3
3
# SPDX-License-Identifier: Apache-2.0
4
4
#
28
28
"img_size" , "flags" , "version" )
29
29
TLV_TYPES = dict ((value , key ) for key , value in image .TLV_VALUES .items ())
30
30
BOOT_MAGIC = bytes ([
31
- 0x77 , 0xc2 , 0x95 , 0xf3 ,
32
- 0x60 , 0xd2 , 0xef , 0x7f ,
33
- 0x35 , 0x52 , 0x50 , 0x0f ,
34
- 0x2c , 0xb6 , 0x79 , 0x80 , ])
31
+ 0x77 , 0xc2 , 0x95 , 0xf3 ,
32
+ 0x60 , 0xd2 , 0xef , 0x7f ,
33
+ 0x35 , 0x52 , 0x50 , 0x0f ,
34
+ 0x2c , 0xb6 , 0x79 , 0x80 , ])
35
35
BOOT_MAGIC_2 = bytes ([
36
- 0x2d , 0xe1 , 0x5d , 0x29 ,
37
- 0x41 , 0x0b , 0x8d , 0x77 ,
38
- 0x67 , 0x9c , 0x11 , 0x0f ,
39
- 0x1f , 0x8a , ])
36
+ 0x2d , 0xe1 , 0x5d , 0x29 ,
37
+ 0x41 , 0x0b , 0x8d , 0x77 ,
38
+ 0x67 , 0x9c , 0x11 , 0x0f ,
39
+ 0x1f , 0x8a , ])
40
40
BOOT_MAGIC_SIZE = len (BOOT_MAGIC )
41
41
_LINE_LENGTH = 60
42
42
@@ -47,20 +47,32 @@ def print_tlv_records(tlv_list):
47
47
print (" " * indent , "-" * 45 )
48
48
tlv_type , tlv_length , tlv_data = tlv .keys ()
49
49
50
- print (" " * indent , "{}: {} ({})" .format (
50
+ if tlv [tlv_type ] in TLV_TYPES :
51
+ print (" " * indent , "{}: {} ({})" .format (
51
52
tlv_type , TLV_TYPES [tlv [tlv_type ]], hex (tlv [tlv_type ])))
53
+ else :
54
+ print (" " * indent , "{}: {} ({})" .format (
55
+ tlv_type , "UNKNOWN" , hex (tlv [tlv_type ])))
52
56
print (" " * indent , "{}: " .format (tlv_length ), hex (tlv [tlv_length ]))
53
57
print (" " * indent , "{}: " .format (tlv_data ), end = "" )
54
58
55
59
for j , data in enumerate (tlv [tlv_data ]):
56
- print ("{0:#04x}" .format (data ), end = " " )
57
- if ((j + 1 ) % 8 == 0 ) and ((j + 1 ) != len (tlv [tlv_data ])):
58
- print ("\n " , end = " " * (indent + 7 ))
60
+ print ("{0:#04x}" .format (data ), end = " " )
61
+ if ((j + 1 ) % 8 == 0 ) and ((j + 1 ) != len (tlv [tlv_data ])):
62
+ print ("\n " , end = " " * (indent + 7 ))
59
63
print ()
60
64
61
65
62
66
def dump_imginfo (imgfile , outfile = None , silent = False ):
63
- '''Parse a signed image binary and print/save the available information.'''
67
+ """Parse a signed image binary and print/save the available information."""
68
+ trailer_magic = None
69
+ swap_size = 0
70
+ swap_info = 0
71
+ copy_done = 0
72
+ image_ok = 0
73
+ trailer = {}
74
+ key_field_len = None
75
+
64
76
try :
65
77
with open (imgfile , "rb" ) as f :
66
78
b = f .read ()
@@ -128,7 +140,6 @@ def dump_imginfo(imgfile, outfile=None, silent=False):
128
140
129
141
if _img_pad_size :
130
142
# Parsing the image trailer
131
- trailer = {}
132
143
trailer_off = - BOOT_MAGIC_SIZE
133
144
trailer_magic = b [trailer_off :]
134
145
trailer ["magic" ] = trailer_magic
@@ -138,7 +149,7 @@ def dump_imginfo(imgfile, outfile=None, silent=False):
138
149
max_align = 8
139
150
elif trailer_magic [- len (BOOT_MAGIC_2 ):] == BOOT_MAGIC_2 :
140
151
# The alignment value is encoded in the magic field
141
- max_align = int (trailer_magic [:2 ], 0 )
152
+ max_align = int . from_bytes (trailer_magic [:2 ], "little" )
142
153
else :
143
154
# Invalid magic: the rest of the image trailer cannot be processed.
144
155
print ("Warning: the trailer magic value is invalid!" )
@@ -165,7 +176,6 @@ def dump_imginfo(imgfile, outfile=None, silent=False):
165
176
trailer ["swap_size" ] = swap_size
166
177
167
178
# Encryption key 0/1
168
- key_field_len = None
169
179
if ((header ["flags" ] & image .IMAGE_F ["ENCRYPTED_AES128" ]) or
170
180
(header ["flags" ] & image .IMAGE_F ["ENCRYPTED_AES256" ])):
171
181
# The image is encrypted
@@ -200,7 +210,7 @@ def dump_imginfo(imgfile, outfile=None, silent=False):
200
210
else :
201
211
flag_string = ""
202
212
for flag in image .IMAGE_F .keys ():
203
- if ( value & image .IMAGE_F [flag ]) :
213
+ if value & image .IMAGE_F [flag ]:
204
214
if flag_string :
205
215
flag_string += ("\n " + (" " * 20 ))
206
216
flag_string += "{} ({})" .format (
@@ -209,7 +219,7 @@ def dump_imginfo(imgfile, outfile=None, silent=False):
209
219
210
220
if type (value ) != str :
211
221
value = hex (value )
212
- print (key , ":" , " " * (19 - len (key )), value , sep = "" )
222
+ print (key , ":" , " " * (19 - len (key )), value , sep = "" )
213
223
print ("#" * _LINE_LENGTH )
214
224
215
225
# Image payload
@@ -281,7 +291,7 @@ def dump_imginfo(imgfile, outfile=None, silent=False):
281
291
print ("boot magic: " , end = "" )
282
292
for i in range (BOOT_MAGIC_SIZE ):
283
293
print ("{0:#04x}" .format (trailer_magic [i ]), end = " " )
284
- if ( i == (BOOT_MAGIC_SIZE / 2 - 1 ) ):
294
+ if i == (BOOT_MAGIC_SIZE / 2 - 1 ):
285
295
print ("\n " , end = " " )
286
296
print ()
287
297
0 commit comments