23
23
#include "app_cpu_start.h"
24
24
#endif
25
25
26
+ #include "esp_rom_sys.h"
27
+ #include "esp_cpu.h"
28
+
29
+ #if CONFIG_IDF_TARGET_ESP32
30
+ #define LP_RTC_PREFIX "RTC"
31
+ #elif CONFIG_IDF_TARGET_ESP32S2
32
+ #define LP_RTC_PREFIX "RTC"
33
+ #elif CONFIG_IDF_TARGET_ESP32S3
34
+ #define LP_RTC_PREFIX "RTC"
35
+ #elif CONFIG_IDF_TARGET_ESP32C2
36
+ #elif CONFIG_IDF_TARGET_ESP32C3
37
+ #define LP_RTC_PREFIX "RTC"
38
+ #elif CONFIG_IDF_TARGET_ESP32C6
39
+ #define LP_RTC_PREFIX "LP"
40
+ #elif CONFIG_IDF_TARGET_ESP32H2
41
+ #define LP_RTC_PREFIX "LP"
42
+ #endif
43
+
26
44
static int load_segment (const struct flash_area * fap , uint32_t data_addr , uint32_t data_len , uint32_t load_addr )
27
45
{
28
46
const uint32_t * data = (const uint32_t * )bootloader_mmap ((fap -> fa_off + data_addr ), data_len );
@@ -69,6 +87,26 @@ void esp_app_image_load(int image_index, int slot, unsigned int hdr_offset, unsi
69
87
FIH_PANIC ;
70
88
}
71
89
90
+ #if SOC_RTC_FAST_MEM_SUPPORTED
91
+ if (load_header .lp_rtc_iram_size > 0 ) {
92
+ if (!esp_ptr_in_rtc_iram_fast ((void * )load_header .lp_rtc_iram_dest_addr ) ||
93
+ !esp_ptr_in_rtc_iram_fast ((void * )(load_header .lp_rtc_iram_dest_addr + load_header .lp_rtc_iram_size ))) {
94
+ BOOT_LOG_ERR ("%s_IRAM region in load header is not valid. Aborting" , LP_RTC_PREFIX );
95
+ FIH_PANIC ;
96
+ }
97
+ }
98
+ #endif
99
+
100
+ #if SOC_RTC_SLOW_MEM_SUPPORTED
101
+ if (load_header .lp_rtc_dram_size > 0 ) {
102
+ if (!esp_ptr_in_rtc_slow ((void * )load_header .lp_rtc_dram_dest_addr ) ||
103
+ !esp_ptr_in_rtc_slow ((void * )(load_header .lp_rtc_dram_dest_addr + load_header .lp_rtc_dram_size ))) {
104
+ BOOT_LOG_ERR ("%s_RAM region in load header is not valid. Aborting %p" , LP_RTC_PREFIX , load_header .lp_rtc_dram_dest_addr );
105
+ FIH_PANIC ;
106
+ }
107
+ }
108
+ #endif
109
+
72
110
if (!esp_ptr_in_iram ((void * )load_header .entry_addr )) {
73
111
BOOT_LOG_ERR ("Application entry point (0x%x) is not in IRAM. Aborting" , load_header .entry_addr );
74
112
FIH_PANIC ;
@@ -80,6 +118,33 @@ void esp_app_image_load(int image_index, int slot, unsigned int hdr_offset, unsi
80
118
BOOT_LOG_INF ("IRAM segment: start=0x%x, size=0x%x, vaddr=0x%x" , fap -> fa_off + load_header .iram_flash_offset , load_header .iram_size , load_header .iram_dest_addr );
81
119
load_segment (fap , load_header .iram_flash_offset , load_header .iram_size , load_header .iram_dest_addr );
82
120
121
+ #if SOC_RTC_FAST_MEM_SUPPORTED || SOC_RTC_SLOW_MEM_SUPPORTED
122
+ if (load_header .lp_rtc_dram_size > 0 ) {
123
+ soc_reset_reason_t reset_reason = esp_rom_get_reset_reason (0 );
124
+
125
+ /* Unless waking from deep sleep (implying RTC memory is intact), load its segments */
126
+ if (reset_reason != RESET_REASON_CORE_DEEP_SLEEP ) {
127
+ BOOT_LOG_INF ("%s_RAM segment: paddr=%08xh, vaddr=%08xh, size=%05xh (%6d) load" , LP_RTC_PREFIX ,
128
+ (fap -> fa_off + load_header .lp_rtc_dram_flash_offset ), load_header .lp_rtc_dram_dest_addr ,
129
+ load_header .lp_rtc_dram_size , load_header .lp_rtc_dram_size );
130
+ load_segment (fap , load_header .lp_rtc_dram_flash_offset ,
131
+ load_header .lp_rtc_dram_size , load_header .lp_rtc_dram_dest_addr );
132
+ } else {
133
+ BOOT_LOG_INF ("%s_RAM segment: paddr=%08xh, vaddr=%08xh, size=%05xh (%6d) noload" , LP_RTC_PREFIX ,
134
+ load_header .lp_rtc_dram_flash_offset , load_header .lp_rtc_dram_dest_addr ,
135
+ load_header .lp_rtc_dram_size , load_header .lp_rtc_dram_size );
136
+ }
137
+ }
138
+
139
+ if (load_header .lp_rtc_iram_size > 0 ) {
140
+ BOOT_LOG_INF ("%s_IRAM segment: paddr=%08xh, vaddr=%08xh, size=%05xh (%6d) load" , LP_RTC_PREFIX ,
141
+ (fap -> fa_off + load_header .lp_rtc_iram_flash_offset ), load_header .lp_rtc_iram_dest_addr ,
142
+ load_header .lp_rtc_iram_size , load_header .lp_rtc_iram_size );
143
+ load_segment (fap , load_header .lp_rtc_iram_flash_offset ,
144
+ load_header .lp_rtc_iram_size , load_header .lp_rtc_iram_dest_addr );
145
+ }
146
+ #endif
147
+
83
148
BOOT_LOG_INF ("start=0x%x" , load_header .entry_addr );
84
149
uart_tx_wait_idle (0 );
85
150
0 commit comments