From 65bd54852175d8f6a167c2ecdf3663073ef22349 Mon Sep 17 00:00:00 2001 From: Tiago Medicci Serrano Date: Tue, 2 Apr 2024 16:36:04 -0300 Subject: [PATCH] esp32[c3|c6|h2]: Fix RTC data placement RTC data was not being correctly placed on RTC's memory data due to linker issues. Also, the image's RTC memory segment was not being properly parsed by the bootloader. --- arch/risc-v/src/common/espressif/Make.defs | 2 +- arch/risc-v/src/common/espressif/esp_start.c | 67 ++++++++++++++----- .../scripts/esp32c3_simple_boot_sections.ld | 2 + .../scripts/esp32c6_simple_boot_sections.ld | 2 + .../scripts/esp32h2_simple_boot_sections.ld | 2 + 5 files changed, 59 insertions(+), 16 deletions(-) diff --git a/arch/risc-v/src/common/espressif/Make.defs b/arch/risc-v/src/common/espressif/Make.defs index 5bf479843d..d2679aaf12 100644 --- a/arch/risc-v/src/common/espressif/Make.defs +++ b/arch/risc-v/src/common/espressif/Make.defs @@ -95,7 +95,7 @@ endif ESP_HAL_3RDPARTY_REPO = esp-hal-3rdparty ifndef ESP_HAL_3RDPARTY_VERSION - ESP_HAL_3RDPARTY_VERSION = 09219a0103984369f56482f2a2fd92b26512e381 + ESP_HAL_3RDPARTY_VERSION = 54aca80daef2002b0169e67bcde36f19f59cf6cf endif ifndef ESP_HAL_3RDPARTY_URL diff --git a/arch/risc-v/src/common/espressif/esp_start.c b/arch/risc-v/src/common/espressif/esp_start.c index 1d84219a78..cbbeffe58e 100644 --- a/arch/risc-v/src/common/espressif/esp_start.c +++ b/arch/risc-v/src/common/espressif/esp_start.c @@ -24,6 +24,7 @@ #include +#include #include #include @@ -90,15 +91,39 @@ EXTMEM_ICACHE_SHUT_DBUS_M) # define CHECKSUM_ALIGN 16 -# define IS_PADD(addr) (addr == 0) -# define IS_DRAM(addr) (addr >= SOC_DRAM_LOW && addr < SOC_DRAM_HIGH) -# define IS_IRAM(addr) (addr >= SOC_IRAM_LOW && addr < SOC_IRAM_HIGH) -# define IS_IROM(addr) (addr >= SOC_IROM_LOW && addr < SOC_IROM_HIGH) -# define IS_DROM(addr) (addr >= SOC_DROM_LOW && addr < SOC_DROM_HIGH) +# define IS_PADD(addr) ((addr) == 0) +# define IS_DRAM(addr) ((addr) >= SOC_DRAM_LOW && (addr) < SOC_DRAM_HIGH) +# define IS_IRAM(addr) ((addr) >= SOC_IRAM_LOW && (addr) < SOC_IRAM_HIGH) +# define IS_IROM(addr) ((addr) >= SOC_IROM_LOW && (addr) < SOC_IROM_HIGH) +# define IS_DROM(addr) ((addr) >= SOC_DROM_LOW && (addr) < SOC_DROM_HIGH) # define IS_SRAM(addr) (IS_IRAM(addr) || IS_DRAM(addr)) # define IS_MMAP(addr) (IS_IROM(addr) || IS_DROM(addr)) -# define IS_NONE(addr) (!IS_IROM(addr) && !IS_DROM(addr) \ - && !IS_IRAM(addr) && !IS_DRAM(addr) && !IS_PADD(addr)) +# ifdef SOC_RTC_FAST_MEM_SUPPORTED +# define IS_RTC_FAST_IRAM(addr) \ + ((addr) >= SOC_RTC_IRAM_LOW \ + && (addr) < SOC_RTC_IRAM_HIGH) +# define IS_RTC_FAST_DRAM(addr) \ + ((addr) >= SOC_RTC_DRAM_LOW \ + && (addr) < SOC_RTC_DRAM_HIGH) +# else +# define IS_RTC_FAST_IRAM(addr) false +# define IS_RTC_FAST_DRAM(addr) false +# endif +# ifdef SOC_RTC_SLOW_MEM_SUPPORTED +# define IS_RTC_SLOW_DRAM(addr) \ + ((addr) >= SOC_RTC_DATA_LOW \ + && (addr) < SOC_RTC_DATA_HIGH) +# else +# define IS_RTC_SLOW_DRAM(addr) false +# endif +# define IS_NONE(addr) (!IS_IROM(addr) \ + && !IS_DROM(addr) \ + && !IS_IRAM(addr) \ + && !IS_DRAM(addr) \ + && !IS_RTC_FAST_IRAM(addr) \ + && !IS_RTC_FAST_DRAM(addr) \ + && !IS_RTC_SLOW_DRAM(addr) \ + && !IS_PADD(addr)) # define IS_MAPPING(addr) IS_IROM(addr) || IS_DROM(addr) #endif @@ -262,15 +287,27 @@ static int map_rom_segments(uint32_t app_drom_start, uint32_t app_drom_vaddr, break; } + if (IS_RTC_FAST_IRAM(segment_hdr.load_addr) || + IS_RTC_FAST_DRAM(segment_hdr.load_addr) || + IS_RTC_SLOW_DRAM(segment_hdr.load_addr)) + { + /* RTC segment is loaded by ROM bootloader */ + + ram_segments++; + } + ets_printf("%s: lma 0x%08x vma 0x%08lx len 0x%-6lx (%lu)\n", - IS_NONE(segment_hdr.load_addr) ? "???" : - IS_MMAP(segment_hdr.load_addr) ? - IS_IROM(segment_hdr.load_addr) ? "imap" : "dmap" : - IS_PADD(segment_hdr.load_addr) ? "padd" : - IS_DRAM(segment_hdr.load_addr) ? "dram" : "iram", - offset + sizeof(esp_image_segment_header_t), - segment_hdr.load_addr, segment_hdr.data_len, - segment_hdr.data_len); + IS_NONE(segment_hdr.load_addr) ? "???" : + IS_RTC_FAST_IRAM(segment_hdr.load_addr) || + IS_RTC_FAST_DRAM(segment_hdr.load_addr) || + IS_RTC_SLOW_DRAM(segment_hdr.load_addr) ? "rtc" : + IS_MMAP(segment_hdr.load_addr) ? + IS_IROM(segment_hdr.load_addr) ? "imap" : "dmap" : + IS_PADD(segment_hdr.load_addr) ? "padd" : + IS_DRAM(segment_hdr.load_addr) ? "dram" : "iram", + offset + sizeof(esp_image_segment_header_t), + segment_hdr.load_addr, segment_hdr.data_len, + segment_hdr.data_len); /* Fix drom and irom produced be the linker, as this * is later invalidated by the elf2image command. diff --git a/boards/risc-v/esp32c3/common/scripts/esp32c3_simple_boot_sections.ld b/boards/risc-v/esp32c3/common/scripts/esp32c3_simple_boot_sections.ld index c9266e26a3..e5a5bfd70a 100644 --- a/boards/risc-v/esp32c3/common/scripts/esp32c3_simple_boot_sections.ld +++ b/boards/risc-v/esp32c3/common/scripts/esp32c3_simple_boot_sections.ld @@ -372,7 +372,9 @@ SECTIONS .rtc.data : { *(.rtc.data) + *(.rtc.data.*) *(.rtc.rodata) + *(.rtc.rodata.*) } >rtc_iram_seg /* This section holds RTC data that should have fixed addresses. diff --git a/boards/risc-v/esp32c6/common/scripts/esp32c6_simple_boot_sections.ld b/boards/risc-v/esp32c6/common/scripts/esp32c6_simple_boot_sections.ld index fc903daf01..98cdfa765b 100644 --- a/boards/risc-v/esp32c6/common/scripts/esp32c6_simple_boot_sections.ld +++ b/boards/risc-v/esp32c6/common/scripts/esp32c6_simple_boot_sections.ld @@ -384,7 +384,9 @@ SECTIONS .rtc.data : { *(.rtc.data) + *(.rtc.data.*) *(.rtc.rodata) + *(.rtc.rodata.*) } >rtc_iram_seg /* This section holds RTC data that should have fixed addresses. diff --git a/boards/risc-v/esp32h2/common/scripts/esp32h2_simple_boot_sections.ld b/boards/risc-v/esp32h2/common/scripts/esp32h2_simple_boot_sections.ld index 9c64b93d74..910842b133 100644 --- a/boards/risc-v/esp32h2/common/scripts/esp32h2_simple_boot_sections.ld +++ b/boards/risc-v/esp32h2/common/scripts/esp32h2_simple_boot_sections.ld @@ -384,7 +384,9 @@ SECTIONS .rtc.data : { *(.rtc.data) + *(.rtc.data.*) *(.rtc.rodata) + *(.rtc.rodata.*) } >rtc_iram_seg /* This section holds RTC data that should have fixed addresses.