""" PlatformIO post-build script: merge bootloader + partitions + firmware + SPIFFS into a single flashable binary. Includes a pre-formatted empty SPIFFS image so first-boot doesn't need to format the partition (which takes 1-2 minutes on 16MB flash). Output: .pio/build//firmware_merged.bin Flash: esptool.py --chip esp32s3 write_flash 0x0 firmware_merged.bin Place this file in the project root alongside platformio.ini. Add to each environment (or the base section): extra_scripts = post:merge_firmware.py """ Import("env") def find_spiffs_partition(partitions_bin): """Parse compiled partitions.bin to find SPIFFS partition offset and size. ESP32 partition entry format (32 bytes each): 0xAA50 magic, type, subtype, offset(u32le), size(u32le), label(16), flags(u32le) SPIFFS: type=0x01(data), subtype=0x82(spiffs) """ import struct with open(partitions_bin, "rb") as f: data = f.read() for i in range(0, len(data) - 32, 32): magic = struct.unpack_from("