From 00cfcde3857cd95fbe62bb554448d8c824aa575b Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Sat, 16 Jan 2021 17:40:01 +1100 Subject: [PATCH 1/3] bootloader: Fix "skip validate on exit deep sleep" when "Use RTC fast memory as heap" is enabled RTC region used to store boot partition needs to remain reserved in the app. --- .../src/bootloader_common_loader.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/bootloader_support/src/bootloader_common_loader.c b/components/bootloader_support/src/bootloader_common_loader.c index 272035d597..3e8ddcf89d 100644 --- a/components/bootloader_support/src/bootloader_common_loader.c +++ b/components/bootloader_support/src/bootloader_common_loader.c @@ -30,6 +30,7 @@ #include "soc/gpio_periph.h" #include "soc/rtc.h" #include "soc/efuse_reg.h" +#include "soc/soc_memory_layout.h" #include "hal/gpio_ll.h" #include "esp_image_format.h" #include "bootloader_sha.h" @@ -138,7 +139,18 @@ esp_err_t bootloader_common_get_partition_description(const esp_partition_pos_t #if defined( CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP ) || defined( CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC ) -rtc_retain_mem_t *const rtc_retain_mem = (rtc_retain_mem_t *)(SOC_RTC_DRAM_HIGH - sizeof(rtc_retain_mem_t)); +#define RTC_RETAIN_MEM_ADDR (SOC_RTC_DATA_HIGH - sizeof(rtc_retain_mem_t)) + +rtc_retain_mem_t *const rtc_retain_mem = (rtc_retain_mem_t *)RTC_RETAIN_MEM_ADDR; + +#if !IS_BOOTLOADER_BUILD +/* The app needs to be told this memory is reserved, important if configured to use RTC memory as heap. + + Note that keeping this macro here only works when other symbols in this file are referenced by the app, as + this feature is otherwise 100% part of the bootloader. However this seems to happen in all apps. + */ +SOC_RESERVE_MEMORY_REGION(RTC_RETAIN_MEM_ADDR, RTC_RETAIN_MEM_ADDR + sizeof(rtc_retain_mem_t), rtc_retain_mem); +#endif static bool check_rtc_retain_mem(void) { From 17e30c9e89f101228d69dd0ef91205ec654ea96f Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Sat, 16 Jan 2021 17:42:45 +1100 Subject: [PATCH 2/3] esp32c3: Reserve RTC memory from bootloader in the app linker script --- components/esp32c3/ld/esp32c3.ld | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/esp32c3/ld/esp32c3.ld b/components/esp32c3/ld/esp32c3.ld index cbf54bc2b0..7f897a1c91 100644 --- a/components/esp32c3/ld/esp32c3.ld +++ b/components/esp32c3/ld/esp32c3.ld @@ -8,6 +8,14 @@ #include "sdkconfig.h" +#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC +#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE + CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE) +#elif defined(CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP) +#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE) +#else +#define ESP_BOOTLOADER_RESERVE_RTC 0 +#endif + #define SRAM_IRAM_START 0x4037C000 #define SRAM_DRAM_START 0x3FC7C000 #define ICACHE_SIZE 0x4000 /* ICache size is fixed to 16KB on ESP32-C3 */ @@ -65,7 +73,7 @@ MEMORY /** * RTC fast memory (executable). Persists over deep sleep. */ - rtc_iram_seg(RWX) : org = 0x50000000, len = 0x2000 + rtc_iram_seg(RWX) : org = 0x50000000, len = 0x2000 - ESP_BOOTLOADER_RESERVE_RTC } #if CONFIG_ESP32C3_USE_FIXED_STATIC_RAM_SIZE From 03b0540bc6420d6c15f364850b199552be109753 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 4 Mar 2021 09:50:56 +1100 Subject: [PATCH 3/3] esp32s3: Reserve RTC memory in bootloader in the app linker script --- components/esp32s3/ld/esp32s3.ld | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/esp32s3/ld/esp32s3.ld b/components/esp32s3/ld/esp32s3.ld index 821bf5f43a..1b7c3d1bb9 100644 --- a/components/esp32s3/ld/esp32s3.ld +++ b/components/esp32s3/ld/esp32s3.ld @@ -8,6 +8,14 @@ #include "sdkconfig.h" +#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC +#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE + CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE) +#elif defined(CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP) +#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE) +#else +#define ESP_BOOTLOADER_RESERVE_RTC 0 +#endif + #define SRAM_IRAM_START 0x40370000 #define SRAM_DRAM_START 0x3FC80000 #define I_D_SRAM_OFFSET (SRAM_IRAM_START - SRAM_DRAM_START) @@ -65,7 +73,7 @@ MEMORY /** * RTC fast memory (executable). Persists over deep sleep. */ - rtc_iram_seg(RWX) : org = 0x600fe000, len = 0x2000 + rtc_iram_seg(RWX) : org = 0x600fe000, len = 0x2000 - ESP_BOOTLOADER_RESERVE_RTC /** * RTC fast memory (same block as above), viewed from data bus