Skip to content

Commit c366277

Browse files
committed
Merge branch 'fix/fetch_image_hdr_v5.4' into 'release/v5.4'
fix(esp_system): Correct address used to fetch application image header (v5.4) See merge request espressif/esp-idf!34627
2 parents dd8b4fa + e0e285b commit c366277

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

components/esp_system/port/cpu_start.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "esp_log.h"
1515
#include "esp_chip_info.h"
16+
#include "esp_app_format.h"
1617

1718
#include "esp_private/cache_err_int.h"
1819
#include "esp_clk_internal.h"
@@ -787,9 +788,13 @@ void IRAM_ATTR call_start_cpu0(void)
787788
// Read the application binary image header. This will also decrypt the header if the image is encrypted.
788789
__attribute__((unused)) esp_image_header_t fhdr = {0};
789790

790-
// This assumes that DROM is the first segment in the application binary, i.e. that we can read
791-
// the binary header through cache by accessing SOC_DROM_LOW address.
792-
hal_memcpy(&fhdr, (void *) SOC_DROM_LOW, sizeof(fhdr));
791+
// We can access the image header through the cache by reading from the memory-mapped virtual DROM start offset
792+
uint32_t fhdr_src_addr = (uint32_t)(&_rodata_reserved_start) - sizeof(esp_image_header_t) - sizeof(esp_image_segment_header_t);
793+
hal_memcpy(&fhdr, (void *) fhdr_src_addr, sizeof(fhdr));
794+
if (fhdr.magic != ESP_IMAGE_HEADER_MAGIC) {
795+
ESP_EARLY_LOGE(TAG, "Invalid app image header");
796+
abort();
797+
}
793798

794799
#if CONFIG_IDF_TARGET_ESP32
795800
#if !CONFIG_SPIRAM_BOOT_INIT

0 commit comments

Comments
 (0)