From b3d884740632692370e151b2e415f0c4d761518f Mon Sep 17 00:00:00 2001 From: Felipe Neves Date: Mon, 30 Mar 2020 10:07:16 -0300 Subject: [PATCH] flash_encryption: added wdt feed during encryption process to avoid undesired reset. --- components/bootloader/Kconfig.projbuild | 3 +-- components/bootloader_support/src/esp32s2/flash_encrypt.c | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/components/bootloader/Kconfig.projbuild b/components/bootloader/Kconfig.projbuild index 5bd1a0f42..e04913db6 100644 --- a/components/bootloader/Kconfig.projbuild +++ b/components/bootloader/Kconfig.projbuild @@ -180,8 +180,7 @@ menu "Bootloader config" config BOOTLOADER_WDT_TIME_MS int "Timeout for RTC watchdog (ms)" depends on BOOTLOADER_WDT_ENABLE - default 9000 if IDF_TARGET_ESP32 - default 40000 if IDF_TARGET_ESP32S2 + default 9000 range 0 120000 help Verify that this parameter is correct and more then the execution time. diff --git a/components/bootloader_support/src/esp32s2/flash_encrypt.c b/components/bootloader_support/src/esp32s2/flash_encrypt.c index 3204ebaa5..8cff97faa 100644 --- a/components/bootloader_support/src/esp32s2/flash_encrypt.c +++ b/components/bootloader_support/src/esp32s2/flash_encrypt.c @@ -27,6 +27,7 @@ #include "esp32s2/rom/efuse.h" #include "esp_efuse.h" #include "esp_efuse_table.h" +#include "hal/wdt_hal.h" static const char *TAG = "flash_encrypt"; @@ -324,7 +325,13 @@ esp_err_t esp_flash_encrypt_region(uint32_t src_addr, size_t data_length) return ESP_FAIL; } + wdt_hal_context_t rtc_wdt_ctx = {.inst = WDT_RWDT, .rwdt_dev = &RTCCNTL}; for (size_t i = 0; i < data_length; i += FLASH_SECTOR_SIZE) { + + wdt_hal_write_protect_disable(&rtc_wdt_ctx); + wdt_hal_feed(&rtc_wdt_ctx); + wdt_hal_write_protect_enable(&rtc_wdt_ctx); + uint32_t sec_start = i + src_addr; err = bootloader_flash_read(sec_start, buf, FLASH_SECTOR_SIZE, false); if (err != ESP_OK) {