64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
import json
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def main():
|
|
root = Path(__file__).resolve().parent.parent
|
|
config_file = root / "settings.json"
|
|
|
|
if not config_file.exists():
|
|
print(f"[ERROR] settings.json not found at {config_file}")
|
|
sys.exit(1)
|
|
|
|
with open(config_file) as f:
|
|
cfg = json.load(f)
|
|
|
|
project = cfg["project_name"]
|
|
chip = cfg.get("chip", "esp32")
|
|
port = cfg.get("port", "COM3")
|
|
baud = cfg.get("flash_baud", 460800)
|
|
flash_mode = cfg.get("flash_mode", "dio")
|
|
flash_freq = cfg.get("flash_freq", "40m")
|
|
flash_size = cfg.get("flash_size", "4MB")
|
|
before = cfg.get("before", "default_reset")
|
|
after = cfg.get("after", "hard_reset")
|
|
|
|
# Define binaries and offsets
|
|
bootloader = root / "build" / "bootloader" / "bootloader.bin"
|
|
firmware = root / "build" / f"{project}.bin"
|
|
ota_intitial = root / "build" / "ota_data_initial.bin"
|
|
partition = root / "build" / "partition_table" / "partition-table.bin"
|
|
|
|
|
|
# Verify binaries exist
|
|
for f in [bootloader, firmware, partition]:
|
|
if not f.exists():
|
|
print(f"[ERROR] File not found: {f}")
|
|
sys.exit(1)
|
|
|
|
# Build esptool command
|
|
cmd = [
|
|
sys.executable, "-m", "esptool",
|
|
"--chip", chip,
|
|
"--port", port,
|
|
"--baud", str(baud),
|
|
"--before", before,
|
|
"--after", after,
|
|
"write-flash", # ✅ hyphenated command
|
|
"--flash-mode", flash_mode, # ✅ hyphenated flags
|
|
"--flash-freq", flash_freq,
|
|
"--flash-size", flash_size,
|
|
"0x1000", str(bootloader),
|
|
"0x20000", str(firmware),
|
|
"0x11000", str(ota_intitial),
|
|
"0x8000", str(partition)
|
|
]
|
|
|
|
|
|
print(f"[Flashing] Running: {' '.join(cmd)}")
|
|
subprocess.run(cmd, check=True)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|