From 234c5ea1705609f2744de9694d40b9295e8d8d0a Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Mon, 17 Mar 2025 13:59:25 +0100 Subject: [PATCH] check fw size against partition (#23160) --- pio-tools/post_esp32.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pio-tools/post_esp32.py b/pio-tools/post_esp32.py index e986a5021..28066bf95 100644 --- a/pio-tools/post_esp32.py +++ b/pio-tools/post_esp32.py @@ -26,7 +26,7 @@ platform = env.PioPlatform() from genericpath import exists import os import sys -from os.path import join +from os.path import join, getsize import csv import requests import shutil @@ -272,6 +272,13 @@ def esp32_create_combined_bin(source, target, env): "--flash_size", flash_size, ] + # platformio estimates the flash space used to store the firmware. + # the estimation is inaccurate. perform a final check on the firmware + # size by comparing it against the partition size. + max_size = env.BoardConfig().get("upload.maximum_size", 1) + fw_size = getsize(firmware_name) + if (fw_size > max_size): + raise Exception(Fore.RED + "firmware binary too large: %d > %d" % (fw_size, max_size)) print(" Offset | File") for section in sections: