Browse Source

soc: espressif: align flashing address with DTS configuration

The current CMakeLists.txt uses hardcoded flash addresses for the
bootloader and application, which may not match the slot defined
in the DTS file. This can lead to inconsistencies when flashing
and running images.

This update introduces support for using CONFIG_FLASH_LOAD_OFFSET
and applies CONFIG_BUILD_OUTPUT_ADJUST_LMA if specified,
ensuring that the final image address aligns with the DTS
and runtime expectations.

Note: For ESP32-C6, a custom workaround is included since the
LPCORE does not support MCUboot images.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
pull/91972/head
Sylvio Alves 3 weeks ago committed by Benjamin Cabé
parent
commit
db1fe6005a
  1. 6
      soc/espressif/Kconfig.defconfig
  2. 20
      soc/espressif/common/CMakeLists.txt
  3. 6
      soc/espressif/common/Kconfig.defconfig
  4. 6
      soc/espressif/esp32c6/Kconfig.defconfig

6
soc/espressif/Kconfig.defconfig

@ -5,4 +5,10 @@ if SOC_FAMILY_ESPRESSIF_ESP32 @@ -5,4 +5,10 @@ if SOC_FAMILY_ESPRESSIF_ESP32
rsource "*/Kconfig.defconfig"
config HAS_FLASH_LOAD_OFFSET
default y
config FLASH_LOAD_OFFSET
default $(dt_node_reg_addr_hex,$(dt_nodelabel_path,boot_partition)) if ESP_SIMPLE_BOOT
endif # SOC_FAMILY_ESPRESSIF_ESP32

20
soc/espressif/common/CMakeLists.txt

@ -41,25 +41,23 @@ endif() @@ -41,25 +41,23 @@ endif()
set_property(TARGET bintools PROPERTY disassembly_flag_inline_source)
# Select the image origin depending on the boot configuration
if(CONFIG_SOC_ESP32_APPCPU OR CONFIG_SOC_ESP32S3_APPCPU)
dt_nodelabel(dts_partition_path NODELABEL "slot0_appcpu_partition")
elseif(CONFIG_SOC_ESP32C6_LPCORE)
dt_nodelabel(dts_partition_path NODELABEL "slot0_lpcore_partition")
elseif(CONFIG_MCUBOOT OR CONFIG_ESP_SIMPLE_BOOT)
dt_nodelabel(dts_partition_path NODELABEL "boot_partition")
else()
dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")
set(image_off ${CONFIG_FLASH_LOAD_OFFSET})
# If CONFIG_BUILD_OUTPUT_ADJUST_LMA is defined, adjust the image offset
# to account for the additional load memory address offset.
# This is useful for cases where the image needs to be loaded at a specific
# address in flash, such as when using MCUBoot and flashing secondary images.
if(DEFINED CONFIG_BUILD_OUTPUT_ADJUST_LMA)
math(EXPR image_off "${CONFIG_FLASH_LOAD_OFFSET} + ${CONFIG_BUILD_OUTPUT_ADJUST_LMA}")
endif()
dt_reg_addr(image_off PATH ${dts_partition_path})
board_runner_args(esp32 "--esp-app-address=${image_off}")
board_runner_args(esp32 "--esp-flash-size=${esptoolpy_flashsize}MB")
board_runner_args(esp32 "--esp-flash-freq=${CONFIG_ESPTOOLPY_FLASHFREQ}")
board_runner_args(esp32 "--esp-flash-mode=${CONFIG_ESPTOOLPY_FLASHMODE}")
board_finalize_runner_args(esp32 "--esp-monitor-baud=${monitor_baud}")
message("-- Image partition ${dts_partition_path}")
message(STATUS "Image partition address: ${image_off}")
# Look for cross references between bootloader sections
if(CONFIG_MCUBOOT)

6
soc/espressif/common/Kconfig.defconfig

@ -43,9 +43,6 @@ config SOC_FLASH_ESP32 @@ -43,9 +43,6 @@ config SOC_FLASH_ESP32
if BOOTLOADER_MCUBOOT
config HAS_FLASH_LOAD_OFFSET
default y
config MCUBOOT_GENERATE_UNSIGNED_IMAGE
default y
@ -91,9 +88,6 @@ config MINIMAL_LIBC_OPTIMIZE_STRING_FOR_SIZE @@ -91,9 +88,6 @@ config MINIMAL_LIBC_OPTIMIZE_STRING_FOR_SIZE
if BOOTLOADER_MCUBOOT
config HAS_FLASH_LOAD_OFFSET
default y
config MCUBOOT_GENERATE_UNSIGNED_IMAGE
default y

6
soc/espressif/esp32c6/Kconfig.defconfig

@ -37,4 +37,10 @@ config MULTITHREADING @@ -37,4 +37,10 @@ config MULTITHREADING
config NUM_PREEMPT_PRIORITIES
default 0
# Workaround for not being able to have commas in macro arguments
DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition
config FLASH_LOAD_OFFSET
default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION))
endif

Loading…
Cancel
Save