Skip to content

Commit

Permalink
espressif: add checking for supported IDF version
Browse files Browse the repository at this point in the history
Verify if IDF-based HAL version is supported

Signed-off-by: Almir Okato <[email protected]>
  • Loading branch information
almir-okato committed Jan 10, 2025
1 parent 9286264 commit 59e9f03
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
21 changes: 21 additions & 0 deletions boot/espressif/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions boot/espressif/tools/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion ci/espressif_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/release-notes.d/espressif-idf-version-checking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added verification for supported IDF-based HAL version.
- Fixed missing macro for XMC flash devices on ESP32-S3

0 comments on commit 59e9f03

Please sign in to comment.