mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user