This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 151ebd71c4d1402932b7b9fbbace4c75e91945e8 Author: Max Kriegleder <[email protected]> AuthorDate: Thu Oct 29 17:54:48 2026 +0100 tools/espressif: Make the CMake image and flash steps work with esptool 4.x. * find_program(ESPTOOL esptool esptool.py) takes esptool.py as a search path, not as a second name, so with esptool 4.x (which installs only esptool.py) ESPTOOL was ESPTOOL-NOTFOUND and the image step failed with "esptool.py elf2image failed". Use NAMES (also for espsecure and espefuse), and stop with a clear error when esptool is missing. * write-flash, merge-bin and --pad-to-size exist only in esptool 5, while the scripts ask for 4.8.0 or later: use write_flash, merge_bin and --fill-flash-size, as tools/espressif/Config.mk; esptool 5 takes them too (same merged image). * The ESP32 and ESP32-S2 boot the second stage from 0x1000 (tools/esp32*/Config.mk APP_OFFSET), not 0x0: the flash target wrote their simple boot image to the wrong address. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Max Kriegleder <[email protected]> --- .../common/espressif/hal_xtensa_espressif.cmake | 96 ---------------------- tools/espressif/espressif_burn_enc_key.cmake | 2 +- tools/espressif/espressif_esptool_common.cmake | 5 +- tools/espressif/espressif_flash.cmake | 6 +- tools/espressif/espressif_mkimage.cmake | 22 +++-- 5 files changed, 22 insertions(+), 109 deletions(-) diff --git a/arch/xtensa/src/common/espressif/hal_xtensa_espressif.cmake b/arch/xtensa/src/common/espressif/hal_xtensa_espressif.cmake deleted file mode 100644 index 7f566f64a5d..00000000000 --- a/arch/xtensa/src/common/espressif/hal_xtensa_espressif.cmake +++ /dev/null @@ -1,96 +0,0 @@ -# ############################################################################## -# arch/xtensa/src/common/espressif/hal_xtensa_espressif.cmake -# -# SPDX-License-Identifier: Apache-2.0 -# ############################################################################## - -if(NOT EXISTS ${ESP_HAL_3RDPARTY_REPO}) - message( - FATAL_ERROR - "ESP_HAL_3RDPARTY_REPO does not exist: ${ESP_HAL_3RDPARTY_REPO}. Please ensure the HAL 3rd party repository is cloned correctly." - ) -endif() - -target_include_directories( - arch - PRIVATE - ${ESP_HAL_3RDPARTY_REPO}/nuttx/include - ${ESP_HAL_3RDPARTY_REPO}/nuttx/include/mbedtls - ${ESP_HAL_3RDPARTY_REPO}/nuttx/${CHIP_SERIES}/include - ${ESP_HAL_3RDPARTY_REPO}/components/bootloader_support/include - ${ESP_HAL_3RDPARTY_REPO}/components/bootloader_support/private_include - ${ESP_HAL_3RDPARTY_REPO}/components/bootloader_support/bootloader_flash/include - ${ESP_HAL_3RDPARTY_REPO}/components/efuse/include - ${ESP_HAL_3RDPARTY_REPO}/components/efuse/private_include - ${ESP_HAL_3RDPARTY_REPO}/components/efuse/${CHIP_SERIES}/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_common/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_event/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_adc/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_adc/interface - ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/include/esp_private - ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/include/soc - ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/include/soc/${CHIP_SERIES} - ${ESP_HAL_3RDPARTY_REPO}/components/esp_mm/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_phy/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_phy/${CHIP_SERIES}/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_pm/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_rom/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_rom/${CHIP_SERIES} - ${ESP_HAL_3RDPARTY_REPO}/components/esp_rom/${CHIP_SERIES}/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_system/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_system/port/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_timer/include - ${ESP_HAL_3RDPARTY_REPO}/components/esp_timer/private_include - ${ESP_HAL_3RDPARTY_REPO}/components/hal/include - ${ESP_HAL_3RDPARTY_REPO}/components/hal/${CHIP_SERIES}/include - ${ESP_HAL_3RDPARTY_REPO}/components/log/include - ${ESP_HAL_3RDPARTY_REPO}/components/mbedtls/port/include - ${ESP_HAL_3RDPARTY_REPO}/components/mbedtls/mbedtls/include - ${ESP_HAL_3RDPARTY_REPO}/components/soc/include - ${ESP_HAL_3RDPARTY_REPO}/components/soc/${CHIP_SERIES}/include - ${ESP_HAL_3RDPARTY_REPO}/components/soc/${CHIP_SERIES}/register - ${ESP_HAL_3RDPARTY_REPO}/components/spi_flash/include - ${ESP_HAL_3RDPARTY_REPO}/components/spi_flash/include/esp_flash_chips - ${ESP_HAL_3RDPARTY_REPO}/components/xtensa/include - ${ESP_HAL_3RDPARTY_REPO}/components/xtensa/${CHIP_SERIES}/include - ${ESP_HAL_3RDPARTY_REPO}/components/upper_hal_gpio/include - ${ESP_HAL_3RDPARTY_REPO}/components/upper_hal_rmt/include - ${ESP_HAL_3RDPARTY_REPO}/components/upper_hal_rmt/src - ${ESP_HAL_3RDPARTY_REPO}/nuttx/src/components/esp_libc/platform_include) - -set(ESP_ROM_LD_DIR - ${ESP_HAL_3RDPARTY_REPO}/components/esp_rom/${CHIP_SERIES}/ld) -set(ESP_SOC_LD_DIR ${ESP_HAL_3RDPARTY_REPO}/components/soc/${CHIP_SERIES}/ld) -set_property( - GLOBAL APPEND - PROPERTY LD_SCRIPT ${ESP_ROM_LD_DIR}/${CHIP_SERIES}.rom.api.ld - ${ESP_ROM_LD_DIR}/${CHIP_SERIES}.rom.ld - ${ESP_SOC_LD_DIR}/${CHIP_SERIES}.peripherals.ld) - -set(HAL_SRCS) -list( - APPEND - HAL_SRCS - ${ESP_HAL_3RDPARTY_REPO}/components/esp_common/src/esp_err_to_name.c - ${ESP_HAL_3RDPARTY_REPO}/components/esp_system/esp_system.c - ${ESP_HAL_3RDPARTY_REPO}/components/esp_system/esp_err.c - ${ESP_HAL_3RDPARTY_REPO}/components/esp_system/startup.c - ${ESP_HAL_3RDPARTY_REPO}/components/esp_system/startup_funcs.c - ${ESP_HAL_3RDPARTY_REPO}/components/esp_timer/src/esp_timer.c - ${ESP_HAL_3RDPARTY_REPO}/components/esp_timer/src/esp_timer_impl_common.c - ${ESP_HAL_3RDPARTY_REPO}/components/efuse/src/esp_efuse_api.c - ${ESP_HAL_3RDPARTY_REPO}/components/efuse/src/esp_efuse_utility.c - ${ESP_HAL_3RDPARTY_REPO}/components/efuse/${CHIP_SERIES}/esp_efuse_fields.c - ${ESP_HAL_3RDPARTY_REPO}/components/bootloader_support/src/flash_encrypt.c - ${ESP_HAL_3RDPARTY_REPO}/components/bootloader_support/bootloader_flash/src/bootloader_flash.c - ${ESP_HAL_3RDPARTY_REPO}/components/esp_rom/patches/esp_rom_sys.c - ${ESP_HAL_3RDPARTY_REPO}/components/esp_rom/patches/esp_rom_print.c - ${ESP_HAL_3RDPARTY_REPO}/components/spi_flash/esp_flash_api.c - ${ESP_HAL_3RDPARTY_REPO}/components/spi_flash/spi_flash_wrap.c - ${ESP_HAL_3RDPARTY_REPO}/components/log/src/log.c - ${ESP_HAL_3RDPARTY_REPO}/components/upper_hal_gpio/src/gpio.c - ${ESP_HAL_3RDPARTY_REPO}/nuttx/src/platform/os.c - ${ESP_HAL_3RDPARTY_REPO}/nuttx/src/heap_caps.c) - -target_sources(arch PRIVATE ${HAL_SRCS}) diff --git a/tools/espressif/espressif_burn_enc_key.cmake b/tools/espressif/espressif_burn_enc_key.cmake index dec33025fa7..1f24d28bd71 100644 --- a/tools/espressif/espressif_burn_enc_key.cmake +++ b/tools/espressif/espressif_burn_enc_key.cmake @@ -30,7 +30,7 @@ # # ############################################################################## -find_program(ESPEFUSE espefuse espefuse.py) +find_program(ESPEFUSE NAMES espefuse espefuse.py) if(NOT ESPEFUSE) message(FATAL_ERROR "espefuse.py not found (required for burn_enc_key)") endif() diff --git a/tools/espressif/espressif_esptool_common.cmake b/tools/espressif/espressif_esptool_common.cmake index 60c3d0a2086..914f2d23398 100644 --- a/tools/espressif/espressif_esptool_common.cmake +++ b/tools/espressif/espressif_esptool_common.cmake @@ -53,9 +53,12 @@ if(NOT DEFINED CHIP_SERIES) string(REPLACE "\"" "" CHIP_SERIES "${CONFIG_ESPRESSIF_CHIP_SERIES}") endif() -# Bootloader base (MCUboot placement; simple boot app start on ESP32-P4) +# Bootloader base (MCUboot placement; simple boot app start): where the ROM +# loads the second stage from (tools/<chip>/Config.mk APP_OFFSET) if(CONFIG_ARCH_CHIP_ESP32P4) set(BL_OFFSET 0x2000) +elseif(CONFIG_ARCH_CHIP_ESP32 OR CONFIG_ARCH_CHIP_ESP32S2) + set(BL_OFFSET 0x1000) else() set(BL_OFFSET 0x0000) endif() diff --git a/tools/espressif/espressif_flash.cmake b/tools/espressif/espressif_flash.cmake index cc9305a4492..cedcc1ca156 100644 --- a/tools/espressif/espressif_flash.cmake +++ b/tools/espressif/espressif_flash.cmake @@ -80,7 +80,7 @@ if((NOT DEFINED ESPTOOL_PORT) OR ("${ESPTOOL_PORT}" STREQUAL "")) set(ESPTOOL_PORT "$ENV{ESPTOOL_PORT}") endif() -find_program(ESPTOOL esptool esptool.py) +find_program(ESPTOOL NAMES esptool esptool.py) find_program(PYTHON3 python3) if(NOT ESPTOOL) @@ -188,12 +188,12 @@ else() endif() execute_process( - COMMAND ${ESPTOOL} ${ESPTOOL_OPTS} write-flash ${WRITEFLASH_ARGS} + COMMAND ${ESPTOOL} ${ESPTOOL_OPTS} write_flash ${WRITEFLASH_ARGS} WORKING_DIRECTORY ${BINARY_DIR} RESULT_VARIABLE FLASH_RESULT) if(NOT FLASH_RESULT EQUAL 0) - message(FATAL_ERROR "esptool write-flash failed (exit ${FLASH_RESULT})") + message(FATAL_ERROR "esptool write_flash failed (exit ${FLASH_RESULT})") endif() message(STATUS "Flash completed successfully.") diff --git a/tools/espressif/espressif_mkimage.cmake b/tools/espressif/espressif_mkimage.cmake index c967ccd7732..7405836bca6 100644 --- a/tools/espressif/espressif_mkimage.cmake +++ b/tools/espressif/espressif_mkimage.cmake @@ -82,7 +82,7 @@ endif() # Find required tools for the post build process # ############################################################################## -find_program(ESPTOOL esptool esptool.py) +find_program(ESPTOOL NAMES esptool esptool.py) find_program(IMGTOOL imgtool) find_program(PYTHON3 python3) @@ -181,6 +181,10 @@ else() message(FATAL_ERROR "nuttx ELF not found in ${BINARY_DIR}") endif() + if(NOT ESPTOOL) + message(FATAL_ERROR "esptool / esptool.py not found in PATH") + endif() + # Build elf2image options set(ELF2IMAGE_OPTS -fs ${FLASH_SIZE} -fm ${FLASH_MODE} -ff ${FLASH_FREQ}) @@ -213,7 +217,7 @@ file(APPEND "${BINARY_DIR}/nuttx.manifest" "nuttx.bin\n") if(CONFIG_ESPRESSIF_SECURE_FLASH_ENC_ENABLED) message(STATUS "Flash Encryption is enabled!") - find_program(ESPSECURE espsecure espsecure.py) + find_program(ESPSECURE NAMES espsecure espsecure.py) if(CONFIG_ESPRESSIF_EFUSE_VIRTUAL) message(WARNING "Virtual E-Fuses are enabled! E-Fuses will not be burned.") @@ -330,7 +334,8 @@ if(CONFIG_ESPRESSIF_BOOTLOADER_MCUBOOT) endif() elseif(CONFIG_ESPRESSIF_SIMPLE_BOOT) - # Simple boot: same base offset as BL_OFFSET (0x2000 on ESP32-P4, else 0x0) + # Simple boot: at BL_OFFSET (0x1000 on ESP32/ESP32-S2, 0x2000 on ESP32-P4, + # else 0x0) list(APPEND ESPTOOL_BINS ${BL_OFFSET} "${BINARY_DIR}/nuttx.bin") else() @@ -353,13 +358,14 @@ if(CONFIG_ESPRESSIF_MERGE_BINS) # Execute merge_bin execute_process( - COMMAND ${ESPTOOL} -c ${CHIP_SERIES} merge-bin --pad-to-size ${FLASH_SIZE} - --output ${BINARY_DIR}/nuttx.merged.bin ${ESPTOOL_BINS} + COMMAND + ${ESPTOOL} -c ${CHIP_SERIES} merge_bin --fill-flash-size ${FLASH_SIZE} + --output ${BINARY_DIR}/nuttx.merged.bin ${ESPTOOL_BINS} RESULT_VARIABLE MERGEBIN_RESULT WORKING_DIRECTORY ${BINARY_DIR}) if(NOT MERGEBIN_RESULT EQUAL 0) - message(FATAL_ERROR "esptool merge-bin failed") + message(FATAL_ERROR "esptool merge_bin failed") endif() message(STATUS "Generated: nuttx.merged.bin") @@ -375,14 +381,14 @@ if(UF2_ENABLED) execute_process( COMMAND - ${ESPTOOL} -c ${CHIP_SERIES} merge-bin --format uf2 -o + ${ESPTOOL} -c ${CHIP_SERIES} merge_bin --format uf2 -o ${BINARY_DIR}/nuttx.merged.uf2 -fs ${FLASH_SIZE} -fm ${FLASH_MODE} ${ESPTOOL_BINS} RESULT_VARIABLE MAKEUF2_RESULT WORKING_DIRECTORY ${BINARY_DIR}) if(NOT MAKEUF2_RESULT EQUAL 0) - message(FATAL_ERROR "esptool merge-bin --format uf2 failed") + message(FATAL_ERROR "esptool merge_bin --format uf2 failed") endif() message(STATUS "Generated: nuttx.merged.uf2")
