File
Blob: archive/flash.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Explicitly flash one archived experiment. This interrupts the running radio.""" |
| 3 | import argparse |
| 4 | from pathlib import Path |
| 5 | import subprocess |
| 6 | import sys |
| 7 | |
| 8 | ROOT = Path(__file__).resolve().parents[1] |
| 9 | sys.path.insert(0, str(ROOT / "scripts")) |
| 10 | from project import sdk_root |
| 11 | from serial_device import device_port |
| 12 | from flash_backup import require_backup |
| 13 | |
| 14 | parser = argparse.ArgumentParser(description=__doc__) |
| 15 | parser.add_argument("experiment", choices=["sfu-bringup", "fft-benchmark", "legacy-c"]) |
| 16 | args = parser.parse_args() |
| 17 | try: |
| 18 | require_backup() |
| 19 | except ValueError as error: |
| 20 | raise SystemExit(str(error)) from None |
| 21 | build = sdk_root() / f"archive-{args.experiment}-build" |
| 22 | name = "s3_hardware_check.bin" if args.experiment == "sfu-bringup" else "s3_radio.bin" |
| 23 | files = [("0x0", build / "bootloader/bootloader.bin"), |
| 24 | ("0x8000", build / "partition_table/partition-table.bin"), |
| 25 | ("0x10000", build / name)] |
| 26 | if args.experiment in {"fft-benchmark", "legacy-c"}: |
| 27 | music = ROOT / "artifacts/archive/music/music.bin" |
| 28 | header = music.read_bytes()[:64] |
| 29 | if len(header) != 64 or header[:8] != b"S3MUSIC\0" or int.from_bytes(header[8:12], "little") != 1 or music.stat().st_size > 4 * 1024 * 1024: |
| 30 | raise SystemExit("Prepare a version 1 pack with archive/prepare-music.py") |
| 31 | files.append(("0x410000", music)) |
| 32 | if any(not path.is_file() for _, path in files): |
| 33 | raise SystemExit("Build the selected archived experiment first") |
| 34 | port = device_port() |
| 35 | command = [sys.executable, "-m", "esptool", "--chip", "esp32s3", "--port", port, |
| 36 | "--baud", "460800", "--before", "default-reset", "--after", "hard-reset", |
| 37 | "write-flash", "--flash-mode", "dout", "--flash-size", "32MB", "--flash-freq", "80m"] |
| 38 | for address, path in files: |
| 39 | command.extend([address, str(path)]) |
| 40 | raise SystemExit(subprocess.run(command).returncode) |