Skip to content

Commit 6918a45

Browse files
committed
fix(esp_system): fix RTC reserved area alignment in the linker script
Make sure the size of the RTC reserved area complies with the alignment requirement. Closes #13082
1 parent 31a089c commit 6918a45

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

components/bootloader_support/src/bootloader_common_loader.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#define ESP_PARTITION_HASH_LEN 32 /* SHA-256 digest length */
3030
#define IS_FIELD_SET(rev_full) (((rev_full) != 65535) && ((rev_full) != 0))
31+
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
3132

3233
static const char* TAG = "boot_comm";
3334

@@ -264,7 +265,10 @@ rtc_retain_mem_t* bootloader_common_get_rtc_retain_mem(void)
264265
#if ESP_ROM_HAS_LP_ROM
265266
#define RTC_RETAIN_MEM_ADDR (SOC_RTC_DRAM_LOW)
266267
#else
267-
#define RTC_RETAIN_MEM_ADDR (SOC_RTC_DRAM_HIGH - sizeof(rtc_retain_mem_t))
268+
/* Since the structure containing the retain_mem_t is aligned on 8 by the linker, make sure we align this
269+
* structure size here too */
270+
#define RETAIN_MEM_SIZE ALIGN_UP(sizeof(rtc_retain_mem_t), 8)
271+
#define RTC_RETAIN_MEM_ADDR (SOC_RTC_DRAM_HIGH - RETAIN_MEM_SIZE)
268272
#endif //ESP_ROM_HAS_LP_ROM
269273
static rtc_retain_mem_t *const s_bootloader_retain_mem = (rtc_retain_mem_t *)RTC_RETAIN_MEM_ADDR;
270274
return s_bootloader_retain_mem;

components/esp_system/ld/ld.common

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "sdkconfig.h"
88

9+
#define ALIGN_UP(SIZE, AL) (((SIZE) + (AL - 1)) & ~(AL - 1))
10+
911
/* CPU instruction prefetch padding size for flash mmap scenario */
1012
#define _esp_flash_mmap_prefetch_pad_size 16
1113

@@ -45,10 +47,14 @@
4547

4648
#if CONFIG_SOC_RTC_MEM_SUPPORTED
4749
#if CONFIG_BOOTLOADER_RESERVE_RTC_MEM
50+
/**
51+
* The ESP_BOOTLOADER_RESERVE_RTC size must have the same alignment of RTC_TIMER_RESERVE_RTC, else
52+
* the segment will overflow at link time because not enough bytes are allocated for the RTC segment.
53+
*/
4854
#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
49-
#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE + CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE)
55+
#define ESP_BOOTLOADER_RESERVE_RTC ALIGN_UP(CONFIG_BOOTLOADER_RESERVE_RTC_SIZE + CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE, 8)
5056
#else
51-
#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE)
57+
#define ESP_BOOTLOADER_RESERVE_RTC ALIGN_UP(CONFIG_BOOTLOADER_RESERVE_RTC_SIZE, 8)
5258
#endif // not CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
5359
#else
5460
#define ESP_BOOTLOADER_RESERVE_RTC 0

0 commit comments

Comments
 (0)