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 # Check if a pci header is present
32 pcidata = ord(data[24:25]) + (ord(data[25:26]) << 8)
34 data = data[:pcidata + 16] + chr(count/512) + chr(0) + data[pcidata + 18:]
36 # Fill in size field; clear checksum field
37 data = data[:2] + chr(count/512) + data[3:6] + "\0" + data[7:]
40 newsum = (256 - checksum(data)) & 0xff
41 data = data[:6] + chr(newsum) + data[7:]
44 f = open(outname, 'wb')
47 if __name__ == '__main__':