(board: str, example: str | None = None)
| 142 | |
| 143 | |
| 144 | def check_firmware_size(board: str, example: str | None = None) -> int: |
| 145 | build_info_json = _find_build_info(board, example) |
| 146 | board_info = _create_board_info(build_info_json) |
| 147 | assert board_info, f"Board {board} not found in {build_info_json}" |
| 148 | |
| 149 | # PRIORITY 1: Use PlatformIO's size command for accurate flash usage |
| 150 | # This is essential for AVR boards where .hex files are ASCII format |
| 151 | # and their file size is much larger than actual flash usage |
| 152 | build_dir = build_info_json.parent |
| 153 | size = _run_pio_size(build_dir) |
| 154 | if size is not None: |
| 155 | return size |
| 156 | |
| 157 | # PRIORITY 2: Only use .bin or .uf2 files (which have accurate file sizes) |
| 158 | # DO NOT use .hex files - they're ASCII Intel HEX format |
| 159 | prog_path = Path(board_info["prog_path"]) |
| 160 | base_path = prog_path.parent |
| 161 | suffixes = [".bin", ".uf2"] |
| 162 | for suffix in suffixes: |
| 163 | candidate = base_path / f"firmware{suffix}" |
| 164 | if candidate.exists(): |
| 165 | return candidate.stat().st_size |
| 166 | |
| 167 | # Unable to determine size accurately |
| 168 | raise FileNotFoundError( |
| 169 | f"Unable to determine firmware size for {board}. " |
| 170 | f"PlatformIO size command failed and no .bin/.uf2 file found in {base_path}" |
| 171 | ) |
| 172 | |
| 173 | |
| 174 | def main(board: str, example: str | None = None): |
no test coverage detected