]> granicus.if.org Git - esp-idf/commitdiff
OTA: Fall back to factory partition if ota data partition is invalid
authorAngus Gratton <angus@espressif.com>
Thu, 26 Jan 2017 05:19:45 +0000 (16:19 +1100)
committerAngus Gratton <angus@espressif.com>
Thu, 26 Jan 2017 05:20:06 +0000 (16:20 +1100)
components/app_update/esp_ota_ops.c
components/bootloader/src/main/bootloader_start.c

index 439117b596372c7c30db3bad720431baacb5a34b..8b1a43163e0515dc564ab4c3a05da99ff1b5d57e 100644 (file)
@@ -349,33 +349,34 @@ const esp_partition_t *esp_ota_get_boot_partition(void)
     }
     ota_app_count = get_ota_partition_count();
 
-    ESP_LOGD(TAG, "found ota bin max = %d", ota_app_count);
+    ESP_LOGD(TAG, "found ota app max = %d", ota_app_count);
+
     if (s_ota_select[0].ota_seq == 0xFFFFFFFF && s_ota_select[1].ota_seq == 0xFFFFFFFF) {
-        ESP_LOGD(TAG, "finding factory bin......");
+        ESP_LOGD(TAG, "finding factory app......");
 
         return esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
     } else if (ota_select_valid(&s_ota_select[0]) && ota_select_valid(&s_ota_select[1])) {
-        ESP_LOGD(TAG, "finding ota_%d bin......", \
+        ESP_LOGD(TAG, "finding ota_%d app......", \
                  ESP_PARTITION_SUBTYPE_APP_OTA_MIN + ((OTA_MAX(s_ota_select[0].ota_seq, s_ota_select[1].ota_seq) - 1) % ota_app_count));
 
         return esp_partition_find_first(ESP_PARTITION_TYPE_APP, \
                                         ESP_PARTITION_SUBTYPE_APP_OTA_MIN + ((OTA_MAX(s_ota_select[0].ota_seq, s_ota_select[1].ota_seq) - 1) % ota_app_count), NULL);
     } else if (ota_select_valid(&s_ota_select[0])) {
-        ESP_LOGD(TAG, "finding ota_%d bin......", \
+        ESP_LOGD(TAG, "finding ota_%d app......", \
                  ESP_PARTITION_SUBTYPE_APP_OTA_MIN + (s_ota_select[0].ota_seq - 1) % ota_app_count);
 
         return esp_partition_find_first(ESP_PARTITION_TYPE_APP, \
                                         ESP_PARTITION_SUBTYPE_APP_OTA_MIN + (s_ota_select[0].ota_seq - 1) % ota_app_count, NULL);
 
     } else if (ota_select_valid(&s_ota_select[1])) {
-        ESP_LOGD(TAG, "finding ota_%d bin......", \
+        ESP_LOGD(TAG, "finding ota_%d app......", \
                  ESP_PARTITION_SUBTYPE_APP_OTA_MIN + (s_ota_select[1].ota_seq - 1) % ota_app_count);
 
         return esp_partition_find_first(ESP_PARTITION_TYPE_APP, \
                                         ESP_PARTITION_SUBTYPE_APP_OTA_MIN + (s_ota_select[1].ota_seq - 1) % ota_app_count, NULL);
 
     } else {
-        ESP_LOGE(TAG, "not found current bin");
-        return NULL;
+        ESP_LOGE(TAG, "ota data invalid, no current app. Falling back to factory");
+        return esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
     }
 }
index a374c4306dc22b3c97a94d04814dd5d9f2fbfba9..43066aa3d7ed48201b55dabac91590fc4ceda557 100644 (file)
@@ -323,12 +323,15 @@ void bootloader_main()
         } else  {
             if(ota_select_valid(&sa) && ota_select_valid(&sb)) {
                 load_part_pos = bs.ota[(((sa.ota_seq > sb.ota_seq)?sa.ota_seq:sb.ota_seq) - 1)%bs.app_count];
-            }else if(ota_select_valid(&sa)) {
+            } else if(ota_select_valid(&sa)) {
                 load_part_pos = bs.ota[(sa.ota_seq - 1) % bs.app_count];
-            }else if(ota_select_valid(&sb)) {
+            } else if(ota_select_valid(&sb)) {
                 load_part_pos = bs.ota[(sb.ota_seq - 1) % bs.app_count];
-            }else {
-                ESP_LOGE(TAG, "ota data partition info error");
+            } else if (bs.factory.offset != 0) {
+                ESP_LOGE(TAG, "ota data partition invalid, falling back to factory");
+                load_part_pos = bs.factory;
+            } else {
+                ESP_LOGE(TAG, "ota data partition invalid and no factory, can't boot");
                 return;
             }
         }