Annotation of qemu/roms/seabios/tools/checkrom.py, revision 1.1.1.3

1.1       root        1: #!/usr/bin/env python
                      2: # Script to check a bios image and report info on it.
                      3: #
                      4: # Copyright (C) 2008  Kevin O'Connor <[email protected]>
                      5: #
                      6: # This file may be distributed under the terms of the GNU GPLv3 license.
                      7: 
                      8: import sys
                      9: import layoutrom
                     10: 
                     11: def main():
                     12:     # Get args
                     13:     objinfo, rawfile, outfile = sys.argv[1:]
                     14: 
                     15:     # Read in symbols
                     16:     objinfofile = open(objinfo, 'rb')
                     17:     symbols = layoutrom.parseObjDump(objinfofile)[1]
                     18:     syms = {}
                     19:     for name, (addr, section) in symbols.items():
                     20:         syms[name] = addr
                     21: 
                     22:     # Read in raw file
                     23:     f = open(rawfile, 'rb')
                     24:     rawdata = f.read()
                     25:     f.close()
                     26:     datasize = len(rawdata)
                     27:     finalsize = 64*1024
                     28:     if datasize > 64*1024:
                     29:         finalsize = 128*1024
                     30: 
                     31:     # Sanity checks
1.1.1.3 ! root       32:     start = syms['code32flat_start']
        !            33:     end = syms['code32flat_end']
        !            34:     expend = layoutrom.BUILD_BIOS_ADDR + layoutrom.BUILD_BIOS_SIZE
        !            35:     if end != expend:
        !            36:         print "Error!  Code does not end at 0x%x (got 0x%x)" % (
        !            37:             expend, end)
1.1       root       38:         sys.exit(1)
                     39:     if datasize > finalsize:
                     40:         print "Error!  Code is too big (0x%x vs 0x%x)" % (
                     41:             datasize, finalsize)
                     42:         sys.exit(1)
1.1.1.3 ! root       43:     expdatasize = end - start
        !            44:     if datasize != expdatasize:
1.1.1.2   root       45:         print "Error!  Unknown extra data (0x%x vs 0x%x)" % (
1.1.1.3 ! root       46:             datasize, expdatasize)
1.1.1.2   root       47:         sys.exit(1)
1.1       root       48: 
                     49:     # Print statistics
                     50:     print "Total size: %d  Free space: %d  Percent used: %.1f%% (%dKiB rom)" % (
1.1.1.3 ! root       51:         datasize, finalsize - datasize
        !            52:         , (datasize / float(finalsize)) * 100.0
1.1       root       53:         , finalsize / 1024)
                     54: 
                     55:     # Write final file
                     56:     f = open(outfile, 'wb')
                     57:     f.write(("\0" * (finalsize - datasize)) + rawdata)
                     58:     f.close()
                     59: 
                     60: if __name__ == '__main__':
                     61:     main()

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.