7 #include <esp_ota_ops.h> 8 #include <esp_task_wdt.h> 10 #if ESP_IDF_VERSION_MAJOR >= 5 11 #include <spi_flash_mmap.h> 17 std::unique_ptr<ota::OTABackend>
make_ota_backend() {
return make_unique<ota::IDFOTABackend>(); }
20 this->partition_ = esp_ota_get_next_update_partition(
nullptr);
21 if (this->partition_ ==
nullptr) {
25 #if CONFIG_ESP_TASK_WDT_TIMEOUT_S < 15 27 #if ESP_IDF_VERSION_MAJOR >= 5 28 esp_task_wdt_config_t wdtc;
29 wdtc.idle_core_mask = 0;
30 #if CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0 31 wdtc.idle_core_mask |= (1 << 0);
33 #if CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1 34 wdtc.idle_core_mask |= (1 << 1);
36 wdtc.timeout_ms = 15000;
37 wdtc.trigger_panic =
false;
38 esp_task_wdt_reconfigure(&wdtc);
40 esp_task_wdt_init(15,
false);
44 esp_err_t err = esp_ota_begin(this->partition_, image_size, &this->update_handle_);
46 #if CONFIG_ESP_TASK_WDT_TIMEOUT_S < 15 48 #if ESP_IDF_VERSION_MAJOR >= 5 49 wdtc.timeout_ms = CONFIG_ESP_TASK_WDT_TIMEOUT_S * 1000;
50 esp_task_wdt_reconfigure(&wdtc);
52 esp_task_wdt_init(CONFIG_ESP_TASK_WDT_TIMEOUT_S,
false);
57 esp_ota_abort(this->update_handle_);
58 this->update_handle_ = 0;
59 if (err == ESP_ERR_INVALID_SIZE) {
61 }
else if (err == ESP_ERR_FLASH_OP_TIMEOUT || err == ESP_ERR_FLASH_OP_FAIL) {
73 esp_err_t err = esp_ota_write(this->update_handle_, data, len);
74 this->md5_.
add(data, len);
76 if (err == ESP_ERR_OTA_VALIDATE_FAILED) {
78 }
else if (err == ESP_ERR_FLASH_OP_TIMEOUT || err == ESP_ERR_FLASH_OP_FAIL) {
88 if (!this->md5_.
equals_hex(this->expected_bin_md5_)) {
92 esp_err_t err = esp_ota_end(this->update_handle_);
93 this->update_handle_ = 0;
95 err = esp_ota_set_boot_partition(this->partition_);
100 if (err == ESP_ERR_OTA_VALIDATE_FAILED) {
103 if (err == ESP_ERR_FLASH_OP_TIMEOUT || err == ESP_ERR_FLASH_OP_FAIL) {
110 esp_ota_abort(this->update_handle_);
111 this->update_handle_ = 0;
void init()
Initialize a new MD5 digest computation.
bool equals_hex(const char *expected)
Compare the digest against a provided hex-encoded digest (32 bytes).
OTAResponseTypes begin(size_t image_size) override
void add(const uint8_t *data, size_t len)
Add bytes of data for the digest.
std::unique_ptr< ota::OTABackend > make_ota_backend()
Implementation of SPI Controller mode.
OTAResponseTypes write(uint8_t *data, size_t len) override
void calculate()
Compute the digest, based on the provided data.
void set_update_md5(const char *md5) override
OTAResponseTypes end() override