6 #include <esp_ota_ops.h> 13 this->partition_ = esp_ota_get_next_update_partition(
nullptr);
14 if (this->partition_ ==
nullptr) {
17 esp_err_t err = esp_ota_begin(this->partition_, image_size, &this->update_handle_);
19 esp_ota_abort(this->update_handle_);
20 this->update_handle_ = 0;
21 if (err == ESP_ERR_INVALID_SIZE) {
23 }
else if (err == ESP_ERR_FLASH_OP_TIMEOUT || err == ESP_ERR_FLASH_OP_FAIL) {
35 esp_err_t err = esp_ota_write(this->update_handle_, data, len);
36 this->md5_.
add(data, len);
38 if (err == ESP_ERR_OTA_VALIDATE_FAILED) {
40 }
else if (err == ESP_ERR_FLASH_OP_TIMEOUT || err == ESP_ERR_FLASH_OP_FAIL) {
50 if (!this->md5_.
equals_hex(this->expected_bin_md5_)) {
54 esp_err_t err = esp_ota_end(this->update_handle_);
55 this->update_handle_ = 0;
57 err = esp_ota_set_boot_partition(this->partition_);
62 if (err == ESP_ERR_OTA_VALIDATE_FAILED) {
65 if (err == ESP_ERR_FLASH_OP_TIMEOUT || err == ESP_ERR_FLASH_OP_FAIL) {
72 esp_ota_abort(this->update_handle_);
73 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.
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