#!/usr/bin/env python3 # Tool to check final Katapult binary size # # Copyright (C) 2022 Kevin O'Connor # # This file may be distributed under the terms of the GNU GPLv3 license. import sys, argparse, struct ERR_MSG = """ The Katapult binary is too large for the configured LAUNCH_APP_ADDRESS. Rerun "make menuconfig" and either increase the LAUNCH_APP_ADDRESS or disable features to reduce the final binary size. """ C_TEMPLATE = """ /* DO NOT EDIT! This is an autogenerated file. See scripts/buildbinary.py. */ #include #include "deployer.h" const uint8_t deployer_canboot_binary[] = { %s }; const uint32_t deployer_canboot_binary_size = %d; """ def format_c_code(data): ldata = len(data) data = data + (b"\xff" * (8 - (ldata % 8))) vals = [" "] for i, d in enumerate(data): vals.append("0x%02x," % (d,)) if i % 14 == 13: vals.append("\n ") return C_TEMPLATE % ("".join(vals), ldata) def update_lpc176x_checksum(data): data28 = data[:28] words = struct.unpack(' max_size: msg = "\nMaximum size %d. Current size %d.\n\n" % (max_size, len(data)) sys.stderr.write(ERR_MSG + msg) sys.exit(-1) if args.lpc176x: data = update_lpc176x_checksum(data) if args.code: f = open(args.code, 'w') f.write(format_c_code(data)) f.close() f = open(args.output_file, 'wb') f.write(data) f.close() if __name__ == '__main__': main()