Skip to content

Commit 130fdc7

Browse files
committed
Merge branch 'fix/fix_bootloader_skip_validate_in_deep_sleep' into 'master'
fix(bootloader): fix signature verification skip in deep sleep scenarios Closes IDFGH-14871 See merge request espressif/esp-idf!43067
2 parents 461c0d8 + 32da6e0 commit 130fdc7

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

components/bootloader_support/src/esp_image_format.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "hal/cache_ll.h"
2525
#include "spi_flash_mmap.h"
2626
#include "hal/efuse_hal.h"
27+
#include "sdkconfig.h"
2728

2829
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
2930

@@ -141,6 +142,22 @@ static bool is_bootloader(uint32_t offset)
141142
);
142143
}
143144

145+
#if BOOTLOADER_BUILD && (SECURE_BOOT_CHECK_SIGNATURE == 1)
146+
#if CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP
147+
static bool skip_verify(esp_image_load_mode_t mode, bool verify_sha)
148+
{
149+
// Multi level check to ensure that its a legit exit from deep sleep case
150+
return (esp_rom_get_reset_reason(0) == RESET_REASON_CORE_DEEP_SLEEP &&
151+
mode == ESP_IMAGE_LOAD_NO_VALIDATE &&
152+
!verify_sha) ? true : false;
153+
}
154+
#else
155+
156+
#define skip_verify(mode, verify_sha) (false)
157+
158+
#endif
159+
#endif // BOOTLOADER_BUILD && (SECURE_BOOT_CHECK_SIGNATURE == 1)
160+
144161
static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data)
145162
{
146163
#ifdef BOOTLOADER_BUILD
@@ -236,9 +253,9 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
236253
"only verify signature in bootloader" into the macro so it's tested multiple times.
237254
*/
238255
#if CONFIG_SECURE_BOOT_V2_ENABLED
239-
ESP_FAULT_ASSERT(!esp_secure_boot_enabled() || memcmp(image_digest, verified_digest, ESP_SECURE_BOOT_DIGEST_LEN) == 0);
256+
ESP_FAULT_ASSERT(!esp_secure_boot_enabled() || skip_verify(mode, verify_sha) || memcmp(image_digest, verified_digest, ESP_SECURE_BOOT_DIGEST_LEN) == 0);
240257
#else // Secure Boot V1 on ESP32, only verify signatures for apps not bootloaders
241-
ESP_FAULT_ASSERT(is_bootloader(data->start_addr) || memcmp(image_digest, verified_digest, HASH_LEN) == 0);
258+
ESP_FAULT_ASSERT(is_bootloader(data->start_addr) || skip_verify(mode, verify_sha) || memcmp(image_digest, verified_digest, HASH_LEN) == 0);
242259
#endif
243260

244261
#endif // SECURE_BOOT_CHECK_SIGNATURE

0 commit comments

Comments
 (0)