From faa4cf748308ece289a619ed99a90dd2bb636591 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 26 Dec 2025 20:19:25 -1000 Subject: [PATCH] fixes --- esphome/components/ota/ota_backend_esp8266.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/esphome/components/ota/ota_backend_esp8266.cpp b/esphome/components/ota/ota_backend_esp8266.cpp index b450babd38..861b8c5f0f 100644 --- a/esphome/components/ota/ota_backend_esp8266.cpp +++ b/esphome/components/ota/ota_backend_esp8266.cpp @@ -322,6 +322,19 @@ bool ESP8266OTABackend::verify_end_() { return false; } +// Check if new firmware's flash size fits (only when auto-detection is disabled) +// With FLASH_MAP_SUPPORT (modern cores), flash size is auto-detected from chip +#if !FLASH_MAP_SUPPORT + // NOLINTNEXTLINE(readability-static-accessed-through-instance) + uint32_t bin_flash_size = ESP.magicFlashChipSize((bytes[3] & 0xf0) >> 4); + // NOLINTNEXTLINE(readability-static-accessed-through-instance) + if (bin_flash_size > ESP.getFlashChipRealSize()) { + ESP_LOGE(TAG, "Firmware flash size (%" PRIu32 ") exceeds chip size (%" PRIu32 ")", bin_flash_size, + ESP.getFlashChipRealSize()); + return false; + } +#endif + return true; }