Files
PlatformIO_Esp32C3Boilerplate/scripts/create_update_package.py

36 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import argparse
import struct
from pathlib import Path
MAGIC = b"TSLUPD1\0"
HEADER_SIZE = 32
def main():
parser = argparse.ArgumentParser(description="Create a combined ESP32 update package.")
parser.add_argument("--firmware", default=".pio/build/seeed_xiao_esp32c3/firmware.bin")
parser.add_argument("--filesystem", default=".pio/build/seeed_xiao_esp32c3/littlefs.bin")
parser.add_argument("--output", default=".pio/build/seeed_xiao_esp32c3/update.tslpkg")
args = parser.parse_args()
firmware_path = Path(args.firmware)
filesystem_path = Path(args.filesystem)
output_path = Path(args.output)
firmware = firmware_path.read_bytes()
filesystem = filesystem_path.read_bytes()
output_path.parent.mkdir(parents=True, exist_ok=True)
header = MAGIC + struct.pack("<III", HEADER_SIZE, len(filesystem), len(firmware)) + bytes(12)
output_path.write_bytes(header + filesystem + firmware)
print(f"Created {output_path}")
print(f" filesystem: {filesystem_path} ({len(filesystem)} bytes)")
print(f" firmware: {firmware_path} ({len(firmware)} bytes)")
print(f" total: {output_path.stat().st_size} bytes")
if __name__ == "__main__":
main()