7#include <esp_ota_ops.h>
8#include <esp_task_wdt.h>
9#include <spi_flash_mmap.h>
14std::unique_ptr<ota::OTABackend>
make_ota_backend() {
return make_unique<ota::IDFOTABackend>(); }
17 this->partition_ = esp_ota_get_next_update_partition(
nullptr);
18 if (this->partition_ ==
nullptr) {
22#if CONFIG_ESP_TASK_WDT_TIMEOUT_S < 15
24 esp_task_wdt_config_t wdtc;
25 wdtc.idle_core_mask = 0;
26#if CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0
27 wdtc.idle_core_mask |= (1 << 0);
29#if CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1
30 wdtc.idle_core_mask |= (1 << 1);
32 wdtc.timeout_ms = 15000;
33 wdtc.trigger_panic =
false;
34 esp_task_wdt_reconfigure(&wdtc);
37 esp_err_t err = esp_ota_begin(this->partition_, image_size, &this->update_handle_);
39#if CONFIG_ESP_TASK_WDT_TIMEOUT_S < 15
41 wdtc.timeout_ms = CONFIG_ESP_TASK_WDT_TIMEOUT_S * 1000;
42 esp_task_wdt_reconfigure(&wdtc);
46 esp_ota_abort(this->update_handle_);
47 this->update_handle_ = 0;
48 if (err == ESP_ERR_INVALID_SIZE) {
50 }
else if (err == ESP_ERR_FLASH_OP_TIMEOUT || err == ESP_ERR_FLASH_OP_FAIL) {
60 memcpy(this->expected_bin_md5_, expected_md5, 32);
61 this->md5_set_ =
true;
65 esp_err_t err = esp_ota_write(this->update_handle_, data,
len);
68 if (err == ESP_ERR_OTA_VALIDATE_FAILED) {
70 }
else if (err == ESP_ERR_FLASH_OP_TIMEOUT || err == ESP_ERR_FLASH_OP_FAIL) {
81 if (!this->md5_.
equals_hex(this->expected_bin_md5_)) {
86 esp_err_t err = esp_ota_end(this->update_handle_);
87 this->update_handle_ = 0;
89 err = esp_ota_set_boot_partition(this->partition_);
94 if (err == ESP_ERR_OTA_VALIDATE_FAILED) {
97 if (err == ESP_ERR_FLASH_OP_TIMEOUT || err == ESP_ERR_FLASH_OP_FAIL) {
104 esp_ota_abort(this->update_handle_);
105 this->update_handle_ = 0;
bool equals_hex(const char *expected)
Compare the digest against a provided hex-encoded digest (32 bytes).
void add(const uint8_t *data, size_t len)
Add bytes of data for the digest.
void init()
Initialize a new MD5 digest computation.
void calculate()
Compute the digest, based on the provided data.
OTAResponseTypes write(uint8_t *data, size_t len) override
void set_update_md5(const char *md5) override
OTAResponseTypes end() override
OTAResponseTypes begin(size_t image_size) override
std::unique_ptr< ota::OTABackend > make_ota_backend()
@ OTA_RESPONSE_ERROR_MD5_MISMATCH
@ OTA_RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE
@ OTA_RESPONSE_ERROR_WRITING_FLASH
@ OTA_RESPONSE_ERROR_UPDATE_END
@ OTA_RESPONSE_ERROR_UNKNOWN
@ OTA_RESPONSE_ERROR_NO_UPDATE_PARTITION
@ OTA_RESPONSE_ERROR_MAGIC
Providing packet encoding functions for exchanging data with a remote host.