2 # Fill in checksum/size of an option rom, and pad it to proper length.
4 # Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net>
6 # This file may be distributed under the terms of the GNU GPLv3 license.
10 def alignpos(pos, alignbytes):
12 return (pos + mask) & ~mask
23 f = open(inname, 'rb')
27 # Pad to a 512 byte boundary
28 data += "\0" * (alignpos(count, 512) - count)
31 # Fill in size field; clear checksum field
32 data = data[:2] + chr(count/512) + data[3:6] + "\0" + data[7:]
35 newsum = (256 - checksum(data)) & 0xff
36 data = data[:6] + chr(newsum) + data[7:]
39 f = open(outname, 'wb')
42 if __name__ == '__main__':