summaryrefslogtreecommitdiff
path: root/tools/fillsize.py
blob: fa472d11b4259b0ba7ba8d27fd58a2de40ebb0bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/env python3
# fillsize.py - stamp image_size into the arm64 Image header of a
# built binary. the linker cannot know the final file size, the
# header field stays 0 through the link, this runs after objcopy.
import struct
import sys

path = sys.argv[1]
d = bytearray(open(path, 'rb').read())
assert d[0x38:0x3c] == b'ARM\x64', 'no Image magic, refusing to stamp'
struct.pack_into('<Q', d, 0x10, len(d))
open(path, 'wb').write(d)
print('image_size %d stamped' % len(d))