X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=tools%2Fcheckrom.py;h=69d65e8d935fd5a734c72704544a7ada79516a61;hb=refs%2Fheads%2Fcoreboot;hp=7dc5afcbab5d75917ccc9c61bc8e25883cd19bbc;hpb=b1a0d3a2ee7dce27066b742444634bdf7ecbef7a;p=seabios.git diff --git a/tools/checkrom.py b/tools/checkrom.py index 7dc5afc..69d65e8 100755 --- a/tools/checkrom.py +++ b/tools/checkrom.py @@ -6,33 +6,58 @@ # This file may be distributed under the terms of the GNU GPLv3 license. import sys +import layoutrom def main(): - # Read in symbols (that are valid) - syms = {} - for line in sys.stdin.readlines(): - try: - addr, type, sym = line.split() - syms[sym] = int(addr, 16) - except: - pass - - c16e = syms['code16_end'] + 0xf0000 - f16e = syms['final_code16_end'] - if c16e != f16e: - print "Error! 16bit code moved during linking (0x%x vs 0x%x)" % ( - c16e, f16e) + # Get args + objinfo, rawfile, outfile = sys.argv[1:] + + # Read in symbols + objinfofile = open(objinfo, 'rb') + symbols = layoutrom.parseObjDump(objinfofile, 'in')[1] + + # Read in raw file + f = open(rawfile, 'rb') + rawdata = f.read() + f.close() + datasize = len(rawdata) + finalsize = 64*1024 + if datasize > 64*1024: + finalsize = 128*1024 + if datasize > 128*1024: + finalsize = 256*1024 + + # Sanity checks + start = symbols['code32flat_start'].offset + end = symbols['code32flat_end'].offset + expend = layoutrom.BUILD_BIOS_ADDR + layoutrom.BUILD_BIOS_SIZE + if end != expend: + print "Error! Code does not end at 0x%x (got 0x%x)" % ( + expend, end) sys.exit(1) + if datasize > finalsize: + print "Error! Code is too big (0x%x vs 0x%x)" % ( + datasize, finalsize) + sys.exit(1) + expdatasize = end - start + if datasize != expdatasize: + print "Error! Unknown extra data (0x%x vs 0x%x)" % ( + datasize, expdatasize) + sys.exit(1) + + # Print statistics + runtimesize = datasize + if '_reloc_abs_start' in symbols: + runtimesize = end - symbols['code32init_end'].offset + print "Total size: %d Fixed: %d Free: %d (used %.1f%% of %dKiB rom)" % ( + datasize, runtimesize, finalsize - datasize + , (datasize / float(finalsize)) * 100.0 + , finalsize / 1024) - sizefree = syms['freespace_end'] - syms['freespace_start'] - size16 = syms['code16_end'] - syms['code16_start'] - size32 = syms['code32_end'] - syms['code32_start'] - totalc = size16+size32 - print "16bit size: %d" % size16 - print "32bit size: %d" % size32 - print "Total size: %d Free space: %d Percent used: %.1f%%" % ( - totalc, sizefree - , (totalc / float(size16+size32+sizefree)) * 100.0) + # Write final file + f = open(outfile, 'wb') + f.write(("\0" * (finalsize - datasize)) + rawdata) + f.close() if __name__ == '__main__': main()