diff --git a/boot/espressif/CMakeLists.txt b/boot/espressif/CMakeLists.txt index d1e18d2dab..05358839c1 100644 --- a/boot/espressif/CMakeLists.txt +++ b/boot/espressif/CMakeLists.txt @@ -14,6 +14,8 @@ endif() add_definitions(-DMCUBOOT_TARGET=${MCUBOOT_TARGET}) add_definitions(-D__ESPRESSIF__=1) +set(EXPECTED_IDF_HAL_VERSION "5.1.4") + if ("${MCUBOOT_TARGET}" STREQUAL "esp32" OR "${MCUBOOT_TARGET}" STREQUAL "esp32s2" OR "${MCUBOOT_TARGET}" STREQUAL "esp32s3") @@ -92,6 +94,25 @@ if (NOT DEFINED ESP_HAL_PATH) endif() endif() endif() +message(STATUS "Defined ESP_HAL_PATH: ${ESP_HAL_PATH}") + +# Verify from which IDF version the HAL is based on +set(IDF_VER_HEADER_FILE "${ESP_HAL_PATH}/components/esp_common/include/esp_idf_version.h") + +get_version_from_header("ESP_IDF_VERSION_MAJOR" ${IDF_VER_HEADER_FILE} IDF_VERSION_MAJOR) +get_version_from_header("ESP_IDF_VERSION_MINOR" ${IDF_VER_HEADER_FILE} IDF_VERSION_MINOR) +get_version_from_header("ESP_IDF_VERSION_PATCH" ${IDF_VER_HEADER_FILE} IDF_VERSION_PATCH) + +set(IDF_VERSION "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}.${IDF_VERSION_PATCH}") + +if (NOT IDF_VERSION VERSION_EQUAL ${EXPECTED_IDF_HAL_VERSION}) + message(FATAL_ERROR + "Unsupported HAL version ${IDF_VERSION}, expected ${EXPECTED_IDF_HAL_VERSION}. \ + Verify if the RTOS repository, where you are trying to build from, is up to date, \ + or check the installation pointed on ESP_HAL_PATH.") +else () + message(STATUS "HAL based on ESP-IDF version: ${IDF_VERSION}") +endif() execute_process( COMMAND git describe --tags diff --git a/boot/espressif/tools/utils.cmake b/boot/espressif/tools/utils.cmake index 238b30eb24..965571fda1 100644 --- a/boot/espressif/tools/utils.cmake +++ b/boot/espressif/tools/utils.cmake @@ -29,3 +29,16 @@ function(parse_and_set_config_file CONFIG_FILE) endif() endforeach() endfunction() + +# Auxiliar function to get IDF version from esp_idf_version.h file +function(get_version_from_header VAR_NAME HEADER_FILE VERSION_OUT) + # Read the header file and extract the value of the specified macro + file(READ "${HEADER_FILE}" CONTENTS) + string(REGEX MATCH "#define ${VAR_NAME}[ ]+([0-9]+)" MATCH "${CONTENTS}") + if(MATCH) + string(REGEX REPLACE "#define ${VAR_NAME}[ ]+([0-9]+)" "\\1" VERSION "${MATCH}") + set(${VERSION_OUT} "${VERSION}" PARENT_SCOPE) + else() + message(FATAL_ERROR "Could not find ${VAR_NAME} in ${HEADER_FILE}") + endif() +endfunction() diff --git a/ci/espressif_install.sh b/ci/espressif_install.sh index c2ec2c4edf..4ac52c9ab3 100755 --- a/ci/espressif_install.sh +++ b/ci/espressif_install.sh @@ -10,7 +10,7 @@ install_imgtool() { install_idf() { pushd $HOME - git clone --depth=1 https://github.com/espressif/esp-idf.git --branch release/v5.1 + git clone --depth=1 https://github.com/espressif/esp-idf.git --branch v5.1.4 [[ $? -ne 0 ]] && exit 1 $HOME/esp-idf/install.sh diff --git a/docs/release-notes.d/espressif-idf-version-checking.md b/docs/release-notes.d/espressif-idf-version-checking.md new file mode 100644 index 0000000000..8944a69594 --- /dev/null +++ b/docs/release-notes.d/espressif-idf-version-checking.md @@ -0,0 +1,2 @@ +- Added verification for supported IDF-based HAL version. +- Fixed missing macro for XMC flash devices on ESP32-S3