Merge branch 'idf_webserver_ota' into integration

This commit is contained in:
J. Nick Koston 2025-06-30 09:56:30 -05:00
commit da189da9ae
No known key found for this signature in database
3 changed files with 7 additions and 18 deletions

View File

@ -6,7 +6,6 @@
#include <esp_ota_ops.h> #include <esp_ota_ops.h>
#include <esp_task_wdt.h> #include <esp_task_wdt.h>
#include <cstring>
#if ESP_IDF_VERSION_MAJOR >= 5 #if ESP_IDF_VERSION_MAJOR >= 5
#include <spi_flash_mmap.h> #include <spi_flash_mmap.h>
@ -18,9 +17,6 @@ namespace ota {
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::IDFOTABackend>(); } std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::IDFOTABackend>(); }
OTAResponseTypes IDFOTABackend::begin(size_t image_size) { OTAResponseTypes IDFOTABackend::begin(size_t image_size) {
// Reset MD5 validation state
this->md5_set_ = false;
this->partition_ = esp_ota_get_next_update_partition(nullptr); this->partition_ = esp_ota_get_next_update_partition(nullptr);
if (this->partition_ == nullptr) { if (this->partition_ == nullptr) {
return OTA_RESPONSE_ERROR_NO_UPDATE_PARTITION; return OTA_RESPONSE_ERROR_NO_UPDATE_PARTITION;
@ -71,10 +67,7 @@ OTAResponseTypes IDFOTABackend::begin(size_t image_size) {
return OTA_RESPONSE_OK; return OTA_RESPONSE_OK;
} }
void IDFOTABackend::set_update_md5(const char *expected_md5) { void IDFOTABackend::set_update_md5(const char *expected_md5) { memcpy(this->expected_bin_md5_, expected_md5, 32); }
memcpy(this->expected_bin_md5_, expected_md5, 32);
this->md5_set_ = true;
}
OTAResponseTypes IDFOTABackend::write(uint8_t *data, size_t len) { OTAResponseTypes IDFOTABackend::write(uint8_t *data, size_t len) {
esp_err_t err = esp_ota_write(this->update_handle_, data, 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() { OTAResponseTypes IDFOTABackend::end() {
this->md5_.calculate(); this->md5_.calculate();
// Only validate MD5 if one was provided
if (this->md5_set_) {
if (!this->md5_.equals_hex(this->expected_bin_md5_)) { if (!this->md5_.equals_hex(this->expected_bin_md5_)) {
this->abort(); this->abort();
return OTA_RESPONSE_ERROR_MD5_MISMATCH; return OTA_RESPONSE_ERROR_MD5_MISMATCH;
} }
}
esp_err_t err = esp_ota_end(this->update_handle_); esp_err_t err = esp_ota_end(this->update_handle_);
this->update_handle_ = 0; this->update_handle_ = 0;
if (err == ESP_OK) { if (err == ESP_OK) {

View File

@ -12,7 +12,6 @@ namespace ota {
class IDFOTABackend : public OTABackend { class IDFOTABackend : public OTABackend {
public: public:
IDFOTABackend() : expected_bin_md5_{}, md5_set_(false) {}
OTAResponseTypes begin(size_t image_size) override; OTAResponseTypes begin(size_t image_size) override;
void set_update_md5(const char *md5) override; void set_update_md5(const char *md5) override;
OTAResponseTypes write(uint8_t *data, size_t len) override; OTAResponseTypes write(uint8_t *data, size_t len) override;
@ -25,7 +24,6 @@ class IDFOTABackend : public OTABackend {
const esp_partition_t *partition_; const esp_partition_t *partition_;
md5::MD5Digest md5_{}; md5::MD5Digest md5_{};
char expected_bin_md5_[32]; char expected_bin_md5_[32];
bool md5_set_;
}; };
} // namespace ota } // namespace ota

View File

@ -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 // 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 // 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. // 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 { class IDFWebServerOTABackend {
public: public:
bool begin() { bool begin() {