summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/fillsize.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/tools/fillsize.py b/tools/fillsize.py
new file mode 100644
index 0000000..fa472d1
--- /dev/null
+++ b/tools/fillsize.py
@@ -0,0 +1,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))