Fix timing in readserial.py - use 10 bits per byte.
[seabios.git] / tools / checkrom.py
index 6b5f1e9f26d34df5a8ed88d6e65d2a9f397f9e66..b1d732a017082bc66323a1f882eb66a626955171 100755 (executable)
@@ -6,35 +6,56 @@
 # 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)
+    # Get args
+    objinfo, rawfile, outfile = sys.argv[1:]
+
+    # Read in symbols
+    objinfofile = open(objinfo, 'rb')
+    symbols = layoutrom.parseObjDump(objinfofile)[1]
     syms = {}
-    for line in sys.stdin.readlines():
-        try:
-            addr, type, sym = line.split()
-            syms[sym] = int(addr, 16)
-        except:
-            pass
-
-    c16s = syms['code16_start'] + 0xf0000
-    c32s = syms['final_code16_start']
-    if c16s != c32s:
+    for name, (addr, section) in symbols.items():
+        syms[name] = addr
+
+    # 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
+
+    # Sanity checks
+    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)" % (
-            c32s, c16s)
+            c16e, f16e)
+        sys.exit(1)
+    if datasize > finalsize:
+        print "Error!  Code is too big (0x%x vs 0x%x)" % (
+            datasize, finalsize)
         sys.exit(1)
 
-    sizefree = syms['freespace1_end'] - syms['freespace1_start']
-    size16 = syms['code16_end'] - syms['code16_start'] - sizefree
+    # Print statistics
+    sizefree = syms['freespace_end'] - syms['freespace_start']
+    size16 = syms['code16_end'] - syms['code16_start']
     size32 = syms['code32_end'] - syms['code32_start']
     totalc = size16+size32
-    tablefree = syms['freespace2_end'] - syms['freespace2_start']
     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)
-    print "BIOS table space:  %d" % tablefree
+    print "Total size: %d  Free space: %d  Percent used: %.1f%% (%dKiB rom)" % (
+        totalc, sizefree + finalsize - datasize
+        , (totalc / float(finalsize)) * 100.0
+        , finalsize / 1024)
+
+    # Write final file
+    f = open(outfile, 'wb')
+    f.write(("\0" * (finalsize - datasize)) + rawdata)
+    f.close()
 
 if __name__ == '__main__':
     main()