-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage_bin.py
45 lines (33 loc) · 1.04 KB
/
package_bin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import argparse
PAGE_SIZE = 8192
APP_PAGES = 28
TOTAL_SIZE = APP_PAGES * PAGE_SIZE
"""
Package a device image for use with the bootstrapper
"""
def package_binary(bin_path, image_path):
# Read input binaries
with open(bin_path, "rb") as fp:
bl_data = fp.read()
# Pad bootloader to max size
image_bl_pad_len = TOTAL_SIZE - len(bl_data)
image_bl_padding = b"\xff" * image_bl_pad_len
image_bl_data = bl_data + image_bl_padding
# Write output binary
with open(image_path, "wb") as fp:
fp.write(image_bl_data)
def main():
parser = argparse.ArgumentParser(
prog="b01lers packager tool",
description="package a dumped supply chain binary into a proper 224 KiB img that can be flashed",
)
parser.add_argument(
"-f", "--file", required=True, help="File to package"
)
parser.add_argument(
"-o", "--output", required=True, help="Output packaged file"
)
args = parser.parse_args()
package_binary(args.file, args.output)
if __name__ == '__main__':
main()