Project is archived and read-only.

Issue 1167 attachment: extract_sw_id_field.py (1.5 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os, sys, re

def main():

if len(sys.argv) != 2:
print "USAGE: %s <TRUSTLET_DIR>" % sys.argv[0]
return
trustlet_dir = sys.argv[1]

image_version_map = {}
for root, dirs, files in os.walk(trustlet_dir):
for name in files:

#Making sure this is an mdt
if not name.endswith(".mdt"):
continue

#Searching for the SW_ID
fullpath = os.path.join(root, name)
mdt = ""
try:
mdt = open(fullpath, "rb").read()
except:
print "Failed to open %s, skipping" % fullpath
continue

m = re.search("01 ([0-9A-F]{16}) SW_ID", mdt)
if not m:
print "Couldn't find SW_ID in %s" % fullpath
continue

#Extracting the SW_ID
sw_id = m.group(1)
image_version = int(sw_id[:8], 16)
image_id = int(sw_id[8:], 16)

#Is this a TA image_id?
if image_id == 0xC:
if not name in image_version_map:
image_version_map[name] = []
image_version_map[name].append((fullpath, image_version))

for image_name in image_version_map:
print "------------------------------------"
print "IMAGE: %s" % image_name
for fullpath, image_version in image_version_map[image_name]:
print " version: %02d, path: %s" % (image_version, fullpath)

if __name__ == "__main__":
main()