Create a proper flash image for QEMU ESP32. Args: firmware_path: Path to the firmware.bin file output_path: Path where to write the flash.bin flash_size_mb: Flash size in MB (must be 2, 4, 8, or 16)
(
self, firmware_path: Path, output_path: Path, flash_size_mb: int = 4
)
| 484 | raise e |
| 485 | |
| 486 | def _create_flash_image( |
| 487 | self, firmware_path: Path, output_path: Path, flash_size_mb: int = 4 |
| 488 | ): |
| 489 | """Create a proper flash image for QEMU ESP32. |
| 490 | |
| 491 | Args: |
| 492 | firmware_path: Path to the firmware.bin file |
| 493 | output_path: Path where to write the flash.bin |
| 494 | flash_size_mb: Flash size in MB (must be 2, 4, 8, or 16) |
| 495 | """ |
| 496 | if flash_size_mb not in [2, 4, 8, 16]: |
| 497 | raise ValueError( |
| 498 | f"Flash size must be 2, 4, 8, or 16 MB, got {flash_size_mb}" |
| 499 | ) |
| 500 | |
| 501 | flash_size = flash_size_mb * 1024 * 1024 |
| 502 | |
| 503 | # Read firmware content |
| 504 | firmware_data = firmware_path.read_bytes() |
| 505 | |
| 506 | # Create flash image: firmware at beginning, rest filled with 0xFF |
| 507 | flash_data = firmware_data + b"\xff" * (flash_size - len(firmware_data)) |
| 508 | |
| 509 | # Ensure we have exactly the right size |
| 510 | if len(flash_data) > flash_size: |
| 511 | raise ValueError( |
| 512 | f"Firmware size ({len(firmware_data)} bytes) exceeds flash size ({flash_size} bytes)" |
| 513 | ) |
| 514 | |
| 515 | flash_data = flash_data[:flash_size] # Truncate to exact size |
| 516 | |
| 517 | output_path.write_bytes(flash_data) |
| 518 | |
| 519 | def build_qemu_command( |
| 520 | self, |