python3 fixes for vgabios and csm builds.

Avoid using chr() as this produces unicode strings on python3.  Make
sure to only use ord() on slices as the python3 bytearray type returns
an integer on a non-slice array access.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
diff --git a/scripts/buildrom.py b/scripts/buildrom.py
index 8ff60e2..0499049 100755
--- a/scripts/buildrom.py
+++ b/scripts/buildrom.py
@@ -5,7 +5,7 @@
 #
 # This file may be distributed under the terms of the GNU GPLv3 license.
 
-import sys
+import sys, struct
 
 from python23compat import as_bytes
 
@@ -14,8 +14,11 @@
     return (pos + mask) & ~mask
 
 def checksum(data):
-    ords = map(ord, data)
-    return sum(ords)
+    if (sys.version_info > (3, 0)):
+        cksum = sum(data)
+    else:
+        cksum = sum(map(ord, data))
+    return struct.pack('<B', (0x100 - cksum) & 0xff)
 
 def main():
     inname = sys.argv[1]
@@ -34,14 +37,15 @@
     # Check if a pci header is present
     pcidata = ord(data[24:25]) + (ord(data[25:26]) << 8)
     if pcidata != 0:
-        data = data[:pcidata + 16] + chr(int(count/512)) + chr(0) + data[pcidata + 18:]
+        blocks = struct.pack('<H', int(count/512))
+        data = data[:pcidata + 16] + blocks + data[pcidata + 18:]
 
     # Fill in size field; clear checksum field
-    data = data[:2] + chr(int(count/512)) + data[3:6] + as_bytes("\0") + data[7:]
+    blocks = struct.pack('<B', int(count/512))
+    data = data[:2] + blocks + data[3:6] + as_bytes("\0") + data[7:]
 
     # Checksum rom
-    newsum = (256 - checksum(data)) & 0xff
-    data = data[:6] + chr(newsum) + data[7:]
+    data = data[:6] + checksum(data) + data[7:]
 
     # Write new rom
     f = open(outname, 'wb')