fix: Add conflict detection for concurrent OTA operations on same partition

This change adds conflict detection to prevent multiple OTA operations from
being initiated on the same partition simultaneously.

Closes https://github.com/espressif/esp-idf/issues/18127
This commit is contained in:
nilesh.kale
2026-02-04 12:04:50 +05:30
parent 5de0c45dd6
commit 5f80b77b55
3 changed files with 33 additions and 1 deletions
+24
View File
@@ -61,6 +61,18 @@ const static char *TAG = "esp_ota_ops";
static ota_ops_entry_t *get_ota_ops_entry(esp_ota_handle_t handle);
/* Check if there's already an ongoing OTA operation on the same staging or final partition */
static bool esp_ota_check_partition_conflict(const esp_partition_t *partition)
{
ota_ops_entry_t *it;
for (it = LIST_FIRST(&s_ota_ops_entries_head); it != NULL; it = LIST_NEXT(it, entries)) {
if (it->partition.staging == partition || it->partition.final == partition) {
return true;
}
}
return false;
}
/* Return true if this is an OTA app partition */
static bool is_ota_partition(const esp_partition_t *p)
{
@@ -172,6 +184,12 @@ esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp
#endif
}
// Check if there's already an ongoing OTA operation on this partition
if (esp_ota_check_partition_conflict(partition)) {
ESP_LOGE(TAG, "OTA operation already in progress on partition %s", partition->label);
return ESP_ERR_OTA_ALREADY_IN_PROGRESS;
}
new_entry = esp_ota_init_entry(partition);
if (new_entry == NULL) {
return ESP_ERR_NO_MEM;
@@ -238,6 +256,12 @@ esp_err_t esp_ota_resume(const esp_partition_t *partition, const size_t erase_si
return ESP_ERR_OTA_PARTITION_CONFLICT;
}
// Check if there's already an ongoing OTA operation on this partition
if (esp_ota_check_partition_conflict(partition)) {
ESP_LOGE(TAG, "OTA operation already in progress on partition %s", partition->label);
return ESP_ERR_OTA_ALREADY_IN_PROGRESS;
}
new_entry = esp_ota_init_entry(partition);
if (new_entry == NULL) {
return ESP_ERR_NO_MEM;