diff --git a/esphome/components/ota/ota_backend_esp_idf.cpp b/esphome/components/ota/ota_backend_esp_idf.cpp index 2952cc3b12..6f45fb75e4 100644 --- a/esphome/components/ota/ota_backend_esp_idf.cpp +++ b/esphome/components/ota/ota_backend_esp_idf.cpp @@ -6,7 +6,6 @@ #include #include -#include #if ESP_IDF_VERSION_MAJOR >= 5 #include @@ -18,9 +17,6 @@ namespace ota { std::unique_ptr make_ota_backend() { return make_unique(); } OTAResponseTypes IDFOTABackend::begin(size_t image_size) { - // Reset MD5 validation state - this->md5_set_ = false; - this->partition_ = esp_ota_get_next_update_partition(nullptr); if (this->partition_ == nullptr) { return OTA_RESPONSE_ERROR_NO_UPDATE_PARTITION; @@ -71,10 +67,7 @@ OTAResponseTypes IDFOTABackend::begin(size_t image_size) { return OTA_RESPONSE_OK; } -void IDFOTABackend::set_update_md5(const char *expected_md5) { - memcpy(this->expected_bin_md5_, expected_md5, 32); - this->md5_set_ = true; -} +void IDFOTABackend::set_update_md5(const char *expected_md5) { memcpy(this->expected_bin_md5_, expected_md5, 32); } OTAResponseTypes IDFOTABackend::write(uint8_t *data, size_t len) { esp_err_t err = esp_ota_write(this->update_handle_, data, len); @@ -92,15 +85,10 @@ OTAResponseTypes IDFOTABackend::write(uint8_t *data, size_t len) { OTAResponseTypes IDFOTABackend::end() { this->md5_.calculate(); - - // Only validate MD5 if one was provided - if (this->md5_set_) { - if (!this->md5_.equals_hex(this->expected_bin_md5_)) { - this->abort(); - return OTA_RESPONSE_ERROR_MD5_MISMATCH; - } + if (!this->md5_.equals_hex(this->expected_bin_md5_)) { + this->abort(); + return OTA_RESPONSE_ERROR_MD5_MISMATCH; } - esp_err_t err = esp_ota_end(this->update_handle_); this->update_handle_ = 0; if (err == ESP_OK) { diff --git a/esphome/components/ota/ota_backend_esp_idf.h b/esphome/components/ota/ota_backend_esp_idf.h index 51d9563112..ed66d9b970 100644 --- a/esphome/components/ota/ota_backend_esp_idf.h +++ b/esphome/components/ota/ota_backend_esp_idf.h @@ -12,7 +12,6 @@ namespace ota { class IDFOTABackend : public OTABackend { public: - IDFOTABackend() : expected_bin_md5_{}, md5_set_(false) {} OTAResponseTypes begin(size_t image_size) override; void set_update_md5(const char *md5) override; OTAResponseTypes write(uint8_t *data, size_t len) override; @@ -25,7 +24,6 @@ class IDFOTABackend : public OTABackend { const esp_partition_t *partition_; md5::MD5Digest md5_{}; char expected_bin_md5_[32]; - bool md5_set_; }; } // namespace ota diff --git a/esphome/components/web_server_base/web_server_base.cpp b/esphome/components/web_server_base/web_server_base.cpp index 78c4b6b57a..9ad88e09f4 100644 --- a/esphome/components/web_server_base/web_server_base.cpp +++ b/esphome/components/web_server_base/web_server_base.cpp @@ -31,6 +31,9 @@ static const char *const TAG = "web_server_base"; // that both web_server and ota components can depend on, avoiding code duplication // while keeping the components independent. This would allow both ESP-IDF and Arduino // implementations to share the base OTA functionality without requiring the full OTA component. +// The IDFWebServerOTABackend class is intentionally designed with the same interface +// as OTABackend to make it easy to swap to using OTABackend when the ota component +// is split into ota and ota_base in the future. class IDFWebServerOTABackend { public: bool begin() {