aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/buildrom.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2014-05-22 16:59:16 -0400
committerKevin O'Connor <kevin@koconnor.net>2014-05-27 10:38:50 -0400
commite51488c5f8800a52ac5c8da7a31b85cca5cc95d2 (patch)
treec48e6efdb07126c25d966452120e7ec3cd27ec3f /scripts/buildrom.py
parent7eac0c4e9d37a70ae69ee78dfc11f27a63f36b7d (diff)
downloadseabios-e51488c5f8800a52ac5c8da7a31b85cca5cc95d2.tar.gz
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>
Diffstat (limited to 'scripts/buildrom.py')
-rwxr-xr-xscripts/buildrom.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/scripts/buildrom.py b/scripts/buildrom.py
index 8ff60e25..0499049c 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 @@ def alignpos(pos, alignbytes):
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 @@ def main():
# 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')