From 7f2edf8528f59de34a8713539e521f6a7af190e9 Mon Sep 17 00:00:00 2001 From: Konstantin Kondrashov Date: Tue, 24 Jul 2018 13:09:32 +0800 Subject: [PATCH] bootloader: Fix issue - bs->app_count is zero but ota_data have valid entry If we have the partition table without any ota_apps but in ota_data have valide entry, in this case we get an error(hang). This commit fix this case. If bs->app_count is zero when selecting the factory app. Closes https://github.com/espressif/esp-idf/issues/2218 --- components/bootloader_support/src/bootloader_utility.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/bootloader_support/src/bootloader_utility.c b/components/bootloader_support/src/bootloader_utility.c index 6b0145a629..4b23b14cb5 100644 --- a/components/bootloader_support/src/bootloader_utility.c +++ b/components/bootloader_support/src/bootloader_utility.c @@ -210,8 +210,8 @@ int bootloader_utility_get_selected_boot_partition(const bootloader_state_t *bs) bootloader_munmap(ota_select_map); ESP_LOGD(TAG, "OTA sequence values A 0x%08x B 0x%08x", sa.ota_seq, sb.ota_seq); - if(sa.ota_seq == UINT32_MAX && sb.ota_seq == UINT32_MAX) { - ESP_LOGD(TAG, "OTA sequence numbers both empty (all-0xFF)"); + if ((sa.ota_seq == UINT32_MAX && sb.ota_seq == UINT32_MAX) || (bs->app_count == 0)) { + ESP_LOGD(TAG, "OTA sequence numbers both empty (all-0xFF) or partition table does not have bootable ota_apps (app_count=%d)", bs->app_count); if (bs->factory.offset != 0) { ESP_LOGI(TAG, "Defaulting to factory image"); return FACTORY_INDEX;