from pathlib import Path BASE = Path("/home/andre/ESP32_Build/home/build/micropython/ports/esp32/build-GENERIC/") START = 0x1000 FILES = ( (BASE / "bootloader/bootloader.bin", 0), (BASE / "partition_table/partition-table.bin", 0x8000 - START), (BASE / "micropython.bin", 0x10000 - START) ) TARGET = Path.home().joinpath("micropython_esp32.bin") with TARGET.open("w+b") as fd_out: for file, offset in FILES: print(f"Writing {file.name} as offset {offset:x}") fd_out.seek(offset) with file.open("rb") as fd_in: while chunk := fd_in.read(65 * 1024 ** 1): fd_out.write(chunk) # start flashing at 0x1000