Commit fa173df3 authored by Almir Okato's avatar Almir Okato Committed by Gustavo Henrique Nihei
Browse files

espressif: Add warning for unsupported chip revision



Added checking and warning for ESP32, ESP32-S2, ESP32-C3, ESP32-S3
unsupported chip revisions on their initialization.

Made respectively changes for build system and documentation.

Signed-off-by: default avatarAlmir Okato <almir.okato@espressif.com>
parent 1dc71368
Loading
Loading
Loading
Loading
+56 −20
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@

cmake_minimum_required(VERSION 3.13)

include(${CMAKE_CURRENT_LIST_DIR}/tools/utils.cmake)

if (NOT DEFINED MCUBOOT_TARGET)
    message(FATAL_ERROR "MCUBOOT_TARGET not defined. Please pass -DMCUBOOT_TARGET flag.")
endif()
@@ -20,6 +22,19 @@ elseif("${MCUBOOT_TARGET}" STREQUAL "esp32c3")
    set(MCUBOOT_ARCH "riscv")
endif()

# Set the minimum revision for each supported chip
if ("${MCUBOOT_TARGET}" STREQUAL "esp32")
    set(ESP_MIN_REVISION 3)
elseif("${MCUBOOT_TARGET}" STREQUAL "esp32s2")
    set(ESP_MIN_REVISION 0)
elseif("${MCUBOOT_TARGET}" STREQUAL "esp32s3")
    set(ESP_MIN_REVISION 0)
elseif("${MCUBOOT_TARGET}" STREQUAL "esp32c3")
    set(ESP_MIN_REVISION 3)
else()
    message(FATAL_ERROR "Unsupported target ${MCUBOOT_TARGET}")
endif()

if (NOT DEFINED IDF_PATH)
    if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/hal/esp-idf")
        set(IDF_PATH "${CMAKE_CURRENT_LIST_DIR}/hal/esp-idf")
@@ -38,29 +53,16 @@ execute_process(
    )
add_definitions(-DMCUBOOT_VER=\"${MCUBOOT_VER}\")

if (DEFINED MCUBOOT_CONFIG_FILE)
    set(mcuboot_config_file ${MCUBOOT_CONFIG_FILE})
else()
    set(mcuboot_config_file "${CMAKE_CURRENT_LIST_DIR}/bootloader.conf")
endif()

if (NOT EXISTS "${mcuboot_config_file}")
    message(FATAL_ERROR "MCUboot configuration file does not exist at ${mcuboot_config_file}")
if (NOT DEFINED MCUBOOT_CONFIG_FILE)
    set(MCUBOOT_CONFIG_FILE "${CMAKE_CURRENT_LIST_DIR}/port/${MCUBOOT_TARGET}/bootloader.conf")
endif()

configure_file(${mcuboot_config_file} dummy.conf)
file(STRINGS ${mcuboot_config_file} BOOTLOADER_CONF)
foreach(config ${BOOTLOADER_CONF})
    if (NOT (${config} MATCHES "#"))
        string(REGEX REPLACE "^[ ]+" "" config ${config})
        string(REGEX MATCH "^[^=]+" CONFIG_NAME ${config})
        string(REPLACE "${CONFIG_NAME}=" "" CONFIG_VALUE ${config})
        if (NOT ("${CONFIG_VALUE}" STREQUAL "n"
            OR "${CONFIG_VALUE}" STREQUAL "N"))
            add_definitions(-D${CONFIG_NAME}=${CONFIG_VALUE})
            set(${CONFIG_NAME} ${CONFIG_VALUE})
        endif()
string(REPLACE " " ";" MCUBOOT_CONFIG_FILE_LIST "${MCUBOOT_CONFIG_FILE}")
foreach(CONFIG_FILE ${MCUBOOT_CONFIG_FILE_LIST})
    if (NOT EXISTS "${CONFIG_FILE}")
        message(FATAL_ERROR "MCUboot configuration file does not exist at ${CONFIG_FILE}")
    endif()
    parse_and_set_config_file(${CONFIG_FILE})
endforeach()

set(APP_NAME mcuboot_${MCUBOOT_TARGET})
@@ -235,3 +237,37 @@ target_link_libraries(
    PUBLIC
    hal
    )

# This step uses esptool.py for generating the final bootloader binary in
# Espressif compatible format.
# Note: Both binary generation and flash steps still have some default arguments
add_custom_command(TARGET ${APP_EXECUTABLE} POST_BUILD
    COMMAND
    ${IDF_PATH}/components/esptool_py/esptool/esptool.py
    --chip ${MCUBOOT_TARGET} elf2image --min-rev ${ESP_MIN_REVISION}
    --flash_mode dio --flash_freq 40m --flash_size ${CONFIG_ESP_FLASH_SIZE}
    -o ${APP_NAME}.bin ${APP_NAME}.elf
    )

if (DEFINED MCUBOOT_FLASH_PORT)
    set(FLASH_PORT ${MCUBOOT_FLASH_PORT})
else()
    # Defaults to the first USB serial port
    set(FLASH_PORT "/dev/ttyUSB0")
endif()

if (NOT EXISTS "${FLASH_PORT}")
    message(WARNING "Could not open ${FLASH_PORT}, serial port does not exist")
endif()

add_custom_target(flash DEPENDS ${APP_NAME}.bin)
add_custom_command(TARGET flash
    USES_TERMINAL
    COMMAND
    ${IDF_PATH}/components/esptool_py/esptool/esptool.py
    -p ${FLASH_PORT} -b 2000000 --before default_reset --after no_reset
    --chip ${MCUBOOT_TARGET} write_flash
    --flash_mode dio --flash_size ${CONFIG_ESP_FLASH_SIZE}
    --flash_freq 40m ${CONFIG_ESP_BOOTLOADER_OFFSET}
    ${APP_NAME}.bin
    )
+4 −0
Original line number Diff line number Diff line
@@ -172,6 +172,10 @@ esp_err_t bootloader_init(void)
    if ((ret = bootloader_read_bootloader_header()) != ESP_OK) {
        goto err;
    }
    // read chip revision and check if it's compatible to bootloader
    if ((ret = bootloader_check_bootloader_validity()) != ESP_OK) {
        goto err;
    }
    /* initialize spi flash */
    if ((ret = bootloader_init_spi_flash()) != ESP_OK) {
        goto err;
+4 −0
Original line number Diff line number Diff line
@@ -197,6 +197,10 @@ esp_err_t bootloader_init(void)
    if ((ret = bootloader_read_bootloader_header()) != ESP_OK) {
        goto err;
    }
    // read chip revision and check if it's compatible to bootloader
    if ((ret = bootloader_check_bootloader_validity()) != ESP_OK) {
        goto err;
    }
    // initialize spi flash
    if ((ret = bootloader_init_spi_flash()) != ESP_OK) {
        goto err;
+4 −0
Original line number Diff line number Diff line
@@ -163,6 +163,10 @@ esp_err_t bootloader_init(void)
    if ((ret = bootloader_read_bootloader_header()) != ESP_OK) {
        goto err;
    }
    // read chip revision and check if it's compatible to bootloader
    if ((ret = bootloader_check_bootloader_validity()) != ESP_OK) {
        goto err;
    }
    /* initialize spi flash */
    if ((ret = bootloader_init_spi_flash()) != ESP_OK) {
        goto err;
+4 −0
Original line number Diff line number Diff line
@@ -270,6 +270,10 @@ esp_err_t bootloader_init(void)
    if ((ret = bootloader_read_bootloader_header()) != ESP_OK) {
        goto err;
    }
    // read chip revision and check if it's compatible to bootloader
    if ((ret = bootloader_check_bootloader_validity()) != ESP_OK) {
        goto err;
    }
    // initialize spi flash
    if ((ret = bootloader_init_spi_flash()) != ESP_OK) {
        goto err;
Loading