acpi: update RSDP on guest access
[qemu/cris-port.git] / scripts / signrom.py
blobf9c35ccfca0ac5ff82583eb5974ff3cde02337f3
2 # Option ROM signing utility
4 # Authors:
5 # Jan Kiszka <jan.kiszka@siemens.com>
7 # This work is licensed under the terms of the GNU GPL, version 2 or later.
8 # See the COPYING file in the top-level directory.
10 import sys
11 import struct
13 if len(sys.argv) < 3:
14 print('usage: signrom.py input output')
15 sys.exit(1)
17 fin = open(sys.argv[1], 'rb')
18 fout = open(sys.argv[2], 'wb')
20 fin.seek(2)
21 size = ord(fin.read(1)) * 512 - 1
23 fin.seek(0)
24 data = fin.read(size)
25 fout.write(data)
27 checksum = 0
28 for b in data:
29 # catch Python 2 vs. 3 differences
30 if isinstance(b, int):
31 checksum += b
32 else:
33 checksum += ord(b)
34 checksum = (256 - checksum) % 256
36 # Python 3 no longer allows chr(checksum)
37 fout.write(struct.pack('B', checksum))
39 fin.close()
40 fout.close()