1# 2# Option ROM signing utility 3# 4# Authors: 5# Jan Kiszka <jan.kiszka@siemens.com> 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 10import sys 11import struct 12 13if len(sys.argv) < 3: 14 print('usage: signrom.py input output') 15 sys.exit(1) 16 17fin = open(sys.argv[1], 'rb') 18fout = open(sys.argv[2], 'wb') 19 20fin.seek(2) 21size = ord(fin.read(1)) * 512 - 1 22 23fin.seek(0) 24data = fin.read(size) 25fout.write(data) 26 27checksum = 0 28for b in data: 29 # catch Python 2 vs. 3 differences 30 if isinstance(b, int): 31 checksum += b 32 else: 33 checksum += ord(b) 34checksum = (256 - checksum) % 256 35 36# Python 3 no longer allows chr(checksum) 37fout.write(struct.pack('B', checksum)) 38 39fin.close() 40fout.close() 41