Skip to content

Commit

Permalink
mcuboot: loader: enable loading RTC segments
Browse files Browse the repository at this point in the history
Load RTC/LP RAM/IRAM segments during load phase of MCUBoot
startup.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
  • Loading branch information
sylvioalves authored and LucasTambor committed Jan 8, 2025
1 parent ae55849 commit 05b1eb3
Showing 1 changed file with 56 additions and 7 deletions.
63 changes: 56 additions & 7 deletions zephyr/port/boot/esp_image_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,22 @@
#if CONFIG_SOC_SERIES_ESP32
#include "esp32/rom/uart.h"
#include "esp32/rom/cache.h"
#define LP_RTC_PREFIX "RTC"
#elif CONFIG_SOC_SERIES_ESP32S2
#include "esp32s2/rom/uart.h"
#define LP_RTC_PREFIX "RTC"
#elif CONFIG_SOC_SERIES_ESP32S3
#include "esp32s3/rom/uart.h"
#include "esp32s3/rom/cache.h"
#define LP_RTC_PREFIX "RTC"
#elif CONFIG_SOC_SERIES_ESP32C2
#include "esp32c2/rom/uart.h"
#elif CONFIG_SOC_SERIES_ESP32C3
#include "esp32c3/rom/uart.h"
#define LP_RTC_PREFIX "RTC"
#elif CONFIG_SOC_SERIES_ESP32C6
#include "esp32c6/rom/uart.h"
#define LP_RTC_PREFIX "LP"
#endif

#include "esp_mcuboot_image.h"
Expand Down Expand Up @@ -84,7 +89,7 @@ void esp_app_image_load(int image_index, int slot,
image_index, slot, area_id);

const uint32_t *data = (const uint32_t *)bootloader_mmap((fap->fa_off + hdr_offset),
sizeof(esp_image_load_header_t));
sizeof(esp_image_load_header_t));
esp_image_load_header_t load_header = {0};
memcpy((void *)&load_header, data, sizeof(esp_image_load_header_t));
bootloader_munmap(data);
Expand All @@ -106,24 +111,68 @@ void esp_app_image_load(int image_index, int slot,
FIH_PANIC;
}

#if SOC_RTC_FAST_MEM_SUPPORTED
if (!esp_ptr_in_rtc_iram_fast((void *)load_header.lp_rtc_iram_dest_addr) ||
!esp_ptr_in_rtc_iram_fast((void *)(load_header.lp_rtc_iram_dest_addr + load_header.lp_rtc_iram_size))) {
BOOT_LOG_ERR("%s_IRAM region in load header is not valid. Aborting", LP_RTC_PREFIX);
FIH_PANIC;
}
#endif

#if SOC_RTC_SLOW_MEM_SUPPORTED
if (!esp_ptr_in_rtc_slow((void *)load_header.lp_rtc_dram_dest_addr) ||
!esp_ptr_in_rtc_slow((void *)(load_header.lp_rtc_dram_dest_addr + load_header.lp_rtc_dram_size))) {
BOOT_LOG_ERR("%s_RAM region in load header is not valid. Aborting %p", LP_RTC_PREFIX, load_header.lp_rtc_dram_dest_addr);
FIH_PANIC;
}
#endif

if (!esp_ptr_in_iram((void *)load_header.entry_addr)) {
BOOT_LOG_ERR("Application entry point (%xh) is not in IRAM. Aborting",
load_header.entry_addr);
FIH_PANIC;
}

BOOT_LOG_INF("Application start=%xh", load_header.entry_addr);

#if SOC_RTC_FAST_MEM_SUPPORTED || SOC_RTC_SLOW_MEM_SUPPORTED
if (load_header.lp_rtc_dram_size > 0) {
soc_reset_reason_t reset_reason = esp_rom_get_reset_reason(0);

/* Unless waking from deep sleep (implying RTC memory is intact), load its segments */
if (reset_reason != RESET_REASON_CORE_DEEP_SLEEP) {
BOOT_LOG_INF("%s_RAM segment: paddr=%08xh, vaddr=%08xh, size=%05xh (%6d) load", LP_RTC_PREFIX,
(fap->fa_off + load_header.lp_rtc_dram_flash_offset), load_header.lp_rtc_dram_dest_addr,
load_header.lp_rtc_dram_size, load_header.lp_rtc_dram_size);
load_segment(fap, load_header.lp_rtc_dram_flash_offset,
load_header.lp_rtc_dram_size, load_header.lp_rtc_dram_dest_addr);
} else {
BOOT_LOG_INF("%s_RAM segment: paddr=%08xh, vaddr=%08xh, size=%05xh (%6d) noload", LP_RTC_PREFIX,
load_header.lp_rtc_dram_flash_offset, load_header.lp_rtc_dram_dest_addr,
load_header.lp_rtc_dram_size, load_header.lp_rtc_dram_size);
}
}

if (load_header.lp_rtc_iram_size > 0) {
BOOT_LOG_INF("%s_IRAM segment: paddr=%08xh, vaddr=%08xh, size=%05xh (%6d) load", LP_RTC_PREFIX,
(fap->fa_off + load_header.lp_rtc_iram_flash_offset), load_header.lp_rtc_iram_dest_addr,
load_header.lp_rtc_iram_size, load_header.lp_rtc_iram_size);
load_segment(fap, load_header.lp_rtc_iram_flash_offset,
load_header.lp_rtc_iram_size, load_header.lp_rtc_iram_dest_addr);
}
#endif

BOOT_LOG_INF("DRAM segment: paddr=%08xh, vaddr=%08xh, size=%05xh (%6d) load",
(fap->fa_off + load_header.dram_flash_offset), load_header.dram_dest_addr,
load_header.dram_size, load_header.dram_size);
(fap->fa_off + load_header.dram_flash_offset), load_header.dram_dest_addr,
load_header.dram_size, load_header.dram_size);
load_segment(fap, load_header.dram_flash_offset,
load_header.dram_size, load_header.dram_dest_addr);
load_header.dram_size, load_header.dram_dest_addr);

BOOT_LOG_INF("IRAM segment: paddr=%08xh, vaddr=%08xh, size=%05xh (%6d) load",
(fap->fa_off + load_header.iram_flash_offset), load_header.iram_dest_addr,
load_header.iram_size, load_header.iram_size);
(fap->fa_off + load_header.iram_flash_offset), load_header.iram_dest_addr,
load_header.iram_size, load_header.iram_size);
load_segment(fap, load_header.iram_flash_offset,
load_header.iram_size, load_header.iram_dest_addr);
load_header.iram_size, load_header.iram_dest_addr);

uart_tx_wait_idle(0);

Expand Down

0 comments on commit 05b1eb3

Please sign in to comment.