|
24 | 24 | #include "hal/cache_ll.h" |
25 | 25 | #include "spi_flash_mmap.h" |
26 | 26 | #include "hal/efuse_hal.h" |
| 27 | +#include "sdkconfig.h" |
27 | 28 |
|
28 | 29 | #define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1)) |
29 | 30 |
|
@@ -141,6 +142,22 @@ static bool is_bootloader(uint32_t offset) |
141 | 142 | ); |
142 | 143 | } |
143 | 144 |
|
| 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 | + |
144 | 161 | static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data) |
145 | 162 | { |
146 | 163 | #ifdef BOOTLOADER_BUILD |
@@ -236,9 +253,9 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_ |
236 | 253 | "only verify signature in bootloader" into the macro so it's tested multiple times. |
237 | 254 | */ |
238 | 255 | #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); |
240 | 257 | #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); |
242 | 259 | #endif |
243 | 260 |
|
244 | 261 | #endif // SECURE_BOOT_CHECK_SIGNATURE |
|
0 commit comments