From 90aafe2cbf8853044b04ce0f18443873f474c1be Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Sat, 1 Jun 2024 20:35:19 +0200 Subject: [PATCH] check FW bin file size when creating factory.bin --- pio-scripts/create_factory_bin.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pio-scripts/create_factory_bin.py b/pio-scripts/create_factory_bin.py index 56f71c4b1..d394998b2 100644 --- a/pio-scripts/create_factory_bin.py +++ b/pio-scripts/create_factory_bin.py @@ -21,7 +21,7 @@ platform = env.PioPlatform() import sys -from os.path import join +from os.path import join, getsize sys.path.append(join(platform.get_package_dir("tool-esptoolpy"))) import esptool @@ -60,6 +60,14 @@ def esp32_create_combined_bin(source, target, env): flash_size, ] + # platformio estimates the amount of flash used to store the firmware. this + # estimate is not accurate. we perform a final check on the firmware bin + # size by comparing it against the respective partition size. + max_size = env.BoardConfig().get("upload.maximum_size", 1) + fw_size = getsize(firmware_name) + if (fw_size > max_size): + raise Exception("firmware binary too large: %d > %d" % (fw_size, max_size)) + print(" Offset | File") for section in sections: sect_adr, sect_file = section.split(" ", 1)