"""Package the application image for the platform's existing firmware upload flow.""" import argparse import hashlib import json from pathlib import Path import re import shutil import struct project = Path(__file__).resolve().parents[1] parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--model', required=True, help='Exact inventory model, e.g. ECHOEAR-S3') parser.add_argument('--app', type=Path, default=project / 'build/VolcRTCDemo.bin') parser.add_argument('--out', type=Path, required=True) args = parser.parse_args() version = re.search(r'^#define DEVICE_FIRMWARE_VERSION "([^"]+)"', (project / 'main/firmware_version.h').read_text(), re.M).group(1) image = args.app.read_bytes() if not args.model or len(args.model.encode()) > 120: parser.error('Model must match the device inventory and fit 120 bytes') if not 1024 <= len(image) <= 4 * 1024 * 1024: parser.error('The application must fit the 4 MiB OTA slot') if image[0] != 0xE9 or struct.unpack_from('