53 lines
1.7 KiB
Python
Executable File
53 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Verify the merged ESP32-C3 firmware layout produced by idf.py merge-bin."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
EXPECTED_IMAGES = (
|
|
(0x0000, "bootloader/bootloader.bin"),
|
|
(0x8000, "partition_table/partition-table.bin"),
|
|
(0x10000, "FoloToy-AI-Passport.bin"),
|
|
)
|
|
|
|
|
|
def main() -> int:
|
|
build_dir = Path(sys.argv[1] if len(sys.argv) > 1 else "build").resolve()
|
|
merged_path = build_dir / "FoloToy-AI-Passport-full.bin"
|
|
flash_args_path = build_dir / "flash_args"
|
|
|
|
if not merged_path.is_file() or not flash_args_path.is_file():
|
|
print("ERROR: merged firmware or flash_args is missing", file=sys.stderr)
|
|
return 1
|
|
|
|
flash_args = flash_args_path.read_text(encoding="utf-8")
|
|
if "--flash_size 8MB" not in flash_args:
|
|
print("ERROR: flash_args does not select the required 8 MB flash size", file=sys.stderr)
|
|
return 1
|
|
|
|
merged = merged_path.read_bytes()
|
|
for offset, relative_name in EXPECTED_IMAGES:
|
|
image_path = build_dir / relative_name
|
|
if not image_path.is_file():
|
|
print(f"ERROR: missing image {image_path}", file=sys.stderr)
|
|
return 1
|
|
image = image_path.read_bytes()
|
|
if merged[offset : offset + len(image)] != image:
|
|
print(f"ERROR: {relative_name} differs at merged offset 0x{offset:x}", file=sys.stderr)
|
|
return 1
|
|
print(f"Verified {relative_name}: {len(image)} bytes at 0x{offset:x}")
|
|
|
|
if len(merged) > 8 * 1024 * 1024:
|
|
print("ERROR: merged firmware exceeds 8 MB", file=sys.stderr)
|
|
return 1
|
|
|
|
print(f"Merged firmware: PASS ({len(merged)} bytes, flash at 0x0)")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|