diff --git a/components/app_update/esp_ota_ops.c b/components/app_update/esp_ota_ops.c index cabfe87cff..ae164f3011 100644 --- a/components/app_update/esp_ota_ops.c +++ b/components/app_update/esp_ota_ops.c @@ -302,16 +302,33 @@ esp_err_t esp_ota_write_with_offset(esp_ota_handle_t handle, const void *data, s return ESP_ERR_INVALID_ARG; } -esp_err_t esp_ota_end(esp_ota_handle_t handle) +static ota_ops_entry_t *get_ota_ops_entry(esp_ota_handle_t handle) { - ota_ops_entry_t *it; - esp_err_t ret = ESP_OK; - + ota_ops_entry_t *it = NULL; for (it = LIST_FIRST(&s_ota_ops_entries_head); it != NULL; it = LIST_NEXT(it, entries)) { if (it->handle == handle) { break; } } + return it; +} + +esp_err_t esp_ota_abort(esp_ota_handle_t handle) +{ + ota_ops_entry_t *it = get_ota_ops_entry(handle); + + if (it == NULL) { + return ESP_ERR_NOT_FOUND; + } + LIST_REMOVE(it, entries); + free(it); + return ESP_OK; +} + +esp_err_t esp_ota_end(esp_ota_handle_t handle) +{ + ota_ops_entry_t *it = get_ota_ops_entry(handle); + esp_err_t ret = ESP_OK; if (it == NULL) { return ESP_ERR_NOT_FOUND; diff --git a/components/app_update/include/esp_ota_ops.h b/components/app_update/include/esp_ota_ops.h index f16ed6b1f6..c37f96f931 100644 --- a/components/app_update/include/esp_ota_ops.h +++ b/components/app_update/include/esp_ota_ops.h @@ -157,6 +157,18 @@ esp_err_t esp_ota_write_with_offset(esp_ota_handle_t handle, const void *data, s */ esp_err_t esp_ota_end(esp_ota_handle_t handle); +/** + * @brief Abort OTA update, free the handle and memory associated with it. + * + * @param handle obtained from esp_ota_begin(). + * + * @return + * - ESP_OK: Handle and its associated memory is freed successfully. + * - ESP_ERR_NOT_FOUND: OTA handle was not found. + */ +esp_err_t esp_ota_abort(esp_ota_handle_t handle); + + /** * @brief Configure OTA data for a new boot partition *