2 # Script to check a bios image and report info on it.
4 # Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
6 # This file may be distributed under the terms of the GNU GPLv3 license.
13 objinfo, rawfile, outfile = sys.argv[1:]
16 objinfofile = open(objinfo, 'rb')
17 symbols = layoutrom.parseObjDump(objinfofile, 'in')[1]
20 f = open(rawfile, 'rb')
23 datasize = len(rawdata)
25 if datasize > 64*1024:
27 if datasize > 128*1024:
31 start = symbols['code32flat_start'].offset
32 end = symbols['code32flat_end'].offset
33 expend = layoutrom.BUILD_BIOS_ADDR + layoutrom.BUILD_BIOS_SIZE
35 print "Error! Code does not end at 0x%x (got 0x%x)" % (
38 if datasize > finalsize:
39 print "Error! Code is too big (0x%x vs 0x%x)" % (
42 expdatasize = end - start
43 if datasize != expdatasize:
44 print "Error! Unknown extra data (0x%x vs 0x%x)" % (
45 datasize, expdatasize)
49 runtimesize = datasize
50 if '_reloc_abs_start' in symbols:
51 runtimesize = end - symbols['code32init_end'].offset
52 print "Total size: %d Fixed: %d Free: %d (used %.1f%% of %dKiB rom)" % (
53 datasize, runtimesize, finalsize - datasize
54 , (datasize / float(finalsize)) * 100.0
58 f = open(outfile, 'wb')
59 f.write(("\0" * (finalsize - datasize)) + rawdata)
62 if __name__ == '__main__':