Skip to content

Commit db1fe60

Browse files
sylvioalveskartben
authored andcommitted
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>
1 parent 747bf7b commit db1fe60

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

soc/espressif/Kconfig.defconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@ if SOC_FAMILY_ESPRESSIF_ESP32
55

66
rsource "*/Kconfig.defconfig"
77

8+
config HAS_FLASH_LOAD_OFFSET
9+
default y
10+
11+
config FLASH_LOAD_OFFSET
12+
default $(dt_node_reg_addr_hex,$(dt_nodelabel_path,boot_partition)) if ESP_SIMPLE_BOOT
13+
814
endif # SOC_FAMILY_ESPRESSIF_ESP32

soc/espressif/common/CMakeLists.txt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,23 @@ endif()
4141

4242
set_property(TARGET bintools PROPERTY disassembly_flag_inline_source)
4343

44-
# Select the image origin depending on the boot configuration
45-
if(CONFIG_SOC_ESP32_APPCPU OR CONFIG_SOC_ESP32S3_APPCPU)
46-
dt_nodelabel(dts_partition_path NODELABEL "slot0_appcpu_partition")
47-
elseif(CONFIG_SOC_ESP32C6_LPCORE)
48-
dt_nodelabel(dts_partition_path NODELABEL "slot0_lpcore_partition")
49-
elseif(CONFIG_MCUBOOT OR CONFIG_ESP_SIMPLE_BOOT)
50-
dt_nodelabel(dts_partition_path NODELABEL "boot_partition")
51-
else()
52-
dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")
44+
set(image_off ${CONFIG_FLASH_LOAD_OFFSET})
45+
46+
# If CONFIG_BUILD_OUTPUT_ADJUST_LMA is defined, adjust the image offset
47+
# to account for the additional load memory address offset.
48+
# This is useful for cases where the image needs to be loaded at a specific
49+
# address in flash, such as when using MCUBoot and flashing secondary images.
50+
if(DEFINED CONFIG_BUILD_OUTPUT_ADJUST_LMA)
51+
math(EXPR image_off "${CONFIG_FLASH_LOAD_OFFSET} + ${CONFIG_BUILD_OUTPUT_ADJUST_LMA}")
5352
endif()
5453

55-
dt_reg_addr(image_off PATH ${dts_partition_path})
5654
board_runner_args(esp32 "--esp-app-address=${image_off}")
5755
board_runner_args(esp32 "--esp-flash-size=${esptoolpy_flashsize}MB")
5856
board_runner_args(esp32 "--esp-flash-freq=${CONFIG_ESPTOOLPY_FLASHFREQ}")
5957
board_runner_args(esp32 "--esp-flash-mode=${CONFIG_ESPTOOLPY_FLASHMODE}")
6058
board_finalize_runner_args(esp32 "--esp-monitor-baud=${monitor_baud}")
6159

62-
message("-- Image partition ${dts_partition_path}")
60+
message(STATUS "Image partition address: ${image_off}")
6361

6462
# Look for cross references between bootloader sections
6563
if(CONFIG_MCUBOOT)

soc/espressif/common/Kconfig.defconfig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ config SOC_FLASH_ESP32
4343

4444
if BOOTLOADER_MCUBOOT
4545

46-
config HAS_FLASH_LOAD_OFFSET
47-
default y
48-
4946
config MCUBOOT_GENERATE_UNSIGNED_IMAGE
5047
default y
5148

@@ -91,9 +88,6 @@ config MINIMAL_LIBC_OPTIMIZE_STRING_FOR_SIZE
9188

9289
if BOOTLOADER_MCUBOOT
9390

94-
config HAS_FLASH_LOAD_OFFSET
95-
default y
96-
9791
config MCUBOOT_GENERATE_UNSIGNED_IMAGE
9892
default y
9993

soc/espressif/esp32c6/Kconfig.defconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ config MULTITHREADING
3737
config NUM_PREEMPT_PRIORITIES
3838
default 0
3939

40+
# Workaround for not being able to have commas in macro arguments
41+
DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition
42+
43+
config FLASH_LOAD_OFFSET
44+
default $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION))
45+
4046
endif

0 commit comments

Comments
 (0)