blob: 47f37f2868aebf3a643291e3c806d4a966aab69d [file] [log] [blame]
roxfanb637d682014-05-08 14:04:58 +02001#!/usr/bin/env python
2#
3# parse CSMCORE.raw from AMI UEFI
4# 3-clause BSD license
5# roxfan@skynet.be
6
7import struct, sys
8if len(sys.argv) < 2:
9 fn = "CSMCORE.raw"
10else:
11 fn = sys.argv[1]
12f = open(fn, "rb")
13while True:
14 print "%08X"%f.tell(),
15 hdr = f.read(10)
16 if len(hdr) == 0:
17 break
18 typ, vid, did, size = struct.unpack("<HHHI", hdr)
19 if (typ & 0xFF00) == 0xA000:
20 #print "Multi-ID module"
21 count = typ & 0xFF
22 print "M %2X %04X %04X %8X" % (count, vid, did, size),
23 for i in range(count):
24 typ, vid, did = struct.unpack("<HHH", f.read(6))
25 print "\n %4X %04X %04X " % (typ, vid, did),
26 else:
27 print "%4X %04X %04X %8X" % (typ, vid, did, size),
28 fname = "csm_%02X_%04X_%04X.rom" % (typ, vid, did)
29 print " => %s" % fname
30 if size == 0xFFFFFFFF:
31 d = f.read()
32 else:
33 d = f.read(size)
34 open(fname, "wb").write(d)