MCPcopy Create free account
hub / github.com/FastLED/FastLED / check_firmware_size

Function check_firmware_size

ci/compiled_size.py:144–171  ·  view source on GitHub ↗
(board: str, example: str | None = None)

Source from the content-addressed store, hash-verified

142
143
144def 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
174def main(board: str, example: str | None = None):

Callers 1

mainFunction · 0.85

Calls 3

_create_board_infoFunction · 0.85
_run_pio_sizeFunction · 0.85
_find_build_infoFunction · 0.70

Tested by

no test coverage detected