From 8f397e040715fea84686070a7f2d3e8ba803c7ce Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Tue, 28 Jul 2026 21:50:51 +0800 Subject: [PATCH] fix(bootloader_support): fix RTC retain mem offset for secure boot fast wakeup Pointer arithmetic on rtc_retain_mem_t* subtracted ESP_SECURE_BOOT_DIGEST_LEN in struct units instead of bytes. Cast through uintptr_t so retain mem stays below the ROM verified-image digest region on deep-sleep wake. Partial backport of !51265 (bootloader_common_loader.c only). --- components/bootloader_support/src/bootloader_common_loader.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/bootloader_support/src/bootloader_common_loader.c b/components/bootloader_support/src/bootloader_common_loader.c index 909a35732ce..f8c40d29cf3 100644 --- a/components/bootloader_support/src/bootloader_common_loader.c +++ b/components/bootloader_support/src/bootloader_common_loader.c @@ -5,6 +5,7 @@ */ #include "string.h" +#include #include "sdkconfig.h" #include "esp_err.h" #include "esp_log.h" @@ -253,7 +254,9 @@ rtc_retain_mem_t* bootloader_common_get_rtc_retain_mem(void) #endif //ESP_ROM_HAS_LP_ROM #if CONFIG_SECURE_BOOT && ESP_ROM_SUPPORT_SECURE_BOOT_FAST_WAKEUP - static rtc_retain_mem_t *const s_bootloader_retain_mem = (rtc_retain_mem_t *)RTC_RETAIN_MEM_ADDR - ESP_SECURE_BOOT_DIGEST_LEN; + /* ROM stores the verified image digest in the last ESP_SECURE_BOOT_DIGEST_LEN + * bytes of LP/RTC RAM on deep-sleep wake. Keep retain mem below that region. */ + static rtc_retain_mem_t *const s_bootloader_retain_mem = (rtc_retain_mem_t *)((uintptr_t)RTC_RETAIN_MEM_ADDR - ESP_SECURE_BOOT_DIGEST_LEN); #else static rtc_retain_mem_t *const s_bootloader_retain_mem = (rtc_retain_mem_t *)RTC_RETAIN_MEM_ADDR; #endif