mirror of
https://github.com/esphome/esphome.git
synced 2025-08-06 18:37:47 +00:00
Merge branch 'idf_webserver_ota' into integration
This commit is contained in:
commit
da189da9ae
@ -6,7 +6,6 @@
|
||||
|
||||
#include <esp_ota_ops.h>
|
||||
#include <esp_task_wdt.h>
|
||||
#include <cstring>
|
||||
|
||||
#if ESP_IDF_VERSION_MAJOR >= 5
|
||||
#include <spi_flash_mmap.h>
|
||||
@ -18,9 +17,6 @@ namespace ota {
|
||||
std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::IDFOTABackend>(); }
|
||||
|
||||
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) {
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user