From 4cc2883224b771a625ee0bfb7d40bd2c968f7079 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 8 Jan 2021 01:25:33 +1000 Subject: [PATCH] Add script to pad a BIOS image Mainly useful for openbios. --- scripts/pad-bios.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 scripts/pad-bios.py diff --git a/scripts/pad-bios.py b/scripts/pad-bios.py new file mode 100644 index 000000000..0e0570bd1 --- /dev/null +++ b/scripts/pad-bios.py @@ -0,0 +1,28 @@ +import sys +import os + +def pad_bios(in_name, out_name): + print("Reading %s..." % in_name) + with open(in_name, "rb") as f: + indata = f.read() + if len(indata) > (512 * 1024): + print("Input file %s is too large (%u bytes)", in_name, len(indata)) + sys.exit(1) + + padding_size = (512 * 1024) - len(indata) + padding = b'\0' * padding_size + print("Padding with %u bytes" % padding_size) + + print("Writing %s..." % out_name) + with open(out_name, "wb") as f: + f.write(indata) + f.write(padding) + + +if __name__ == "__main__": + if len(sys.argv) < 3: + print("Usage: %s " % sys.argv[0]) + sys.exit(1) + + pad_bios(sys.argv[1], sys.argv[2]) + sys.exit(0) \ No newline at end of file