]>
Commit | Line | Data |
---|---|---|
0d6b9cc7 JK |
1 | # |
2 | # Option ROM signing utility | |
3 | # | |
4 | # Authors: | |
5 | # Jan Kiszka <[email protected]> | |
6 | # | |
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. | |
9 | ||
10 | import sys | |
11 | import struct | |
12 | ||
13 | if len(sys.argv) < 3: | |
14 | print('usage: signrom.py input output') | |
15 | sys.exit(1) | |
16 | ||
17 | fin = open(sys.argv[1], 'rb') | |
18 | fout = open(sys.argv[2], 'wb') | |
19 | ||
20 | fin.seek(2) | |
21 | size = ord(fin.read(1)) * 512 - 1 | |
22 | ||
23 | fin.seek(0) | |
24 | data = fin.read(size) | |
25 | fout.write(data) | |
26 | ||
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 | |
35 | ||
36 | # Python 3 no longer allows chr(checksum) | |
37 | fout.write(struct.pack('B', checksum)) | |
38 | ||
39 | fin.close() | |
40 | fout.close() |