Browse Source

app_update: Add definition for esp_ota_abort

Closes: https://github.com/espressif/esp-idf/issues/5329
Merges: https://github.com/espressif/esp-idf/pull/5331

Signed-off-by: Shubham Kulkarni <shubham.kulkarni@espressif.com>
lucastcox 5 years ago
parent
commit
d5d722c66f
2 changed files with 33 additions and 4 deletions
  1. 21 4
      components/app_update/esp_ota_ops.c
  2. 12 0
      components/app_update/include/esp_ota_ops.h

+ 21 - 4
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;

+ 12 - 0
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
  *