Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

espressif: refactor after removing IDF submodule #1738

Merged
merged 4 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,3 @@
[submodule "boot/cypress/libs/cy-mbedtls-acceleration"]
path = boot/cypress/libs/cy-mbedtls-acceleration
url = https://github.com/cypresssemiconductorco/cy-mbedtls-acceleration.git
[submodule "boot/espressif/hal/esp-idf"]
path = boot/espressif/hal/esp-idf
url = https://github.com/espressif/esp-idf.git
branch = release/v4.4
35 changes: 26 additions & 9 deletions boot/espressif/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13)
cmake_policy(SET CMP0109 NEW)

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

Expand Down Expand Up @@ -36,13 +37,15 @@ 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")
elseif (DEFINED ENV{IDF_PATH})
set(IDF_PATH $ENV{IDF_PATH})
if (NOT DEFINED ESP_HAL_PATH)
if (DEFINED ENV{ESP_HAL_PATH})
set(ESP_HAL_PATH $ENV{ESP_HAL_PATH})
else()
message(FATAL_ERROR "IDF_PATH not found. Please update submodules or set IDF_PATH environment variable or pass -DIDF_PATH flag.")
message(WARNING "ESP_HAL_PATH not found. Please set -DESP_HAL_PATH parameter or define ESP_HAL_PATH environment variable.")
if (DEFINED ENV{IDF_PATH})
set(ESP_HAL_PATH $ENV{IDF_PATH})
message("IDF installation found in the system, using IDF_PATH as ESP_HAL_PATH.")
endif()
endif()
endif()

Expand Down Expand Up @@ -87,6 +90,20 @@ else()
set(imgtool_path "${IMGTOOL_COMMAND}")
endif()

# Find installed esptool, if not found falls to IDF's
find_program(ESPTOOL_COMMAND
NAMES esptool esptool.py
)
if ("${ESPTOOL_COMMAND}" MATCHES "ESPTOOL_COMMAND-NOTFOUND")
if (DEFINED ENV{IDF_PATH})
set(esptool_path "${IDF_PATH}/components/esptool_py/esptool/esptool.py")
else()
message(FATAL_ERROR "esptool.py not found. Please install it using \'pip install esptool\'.")
endif()
else()
set(esptool_path "${ESPTOOL_COMMAND}")
endif()

if (DEFINED CONFIG_ESP_SIGN_RSA)
include(${CMAKE_CURRENT_LIST_DIR}/include/crypto_config/rsa.cmake)
elseif (DEFINED CONFIG_ESP_SIGN_EC256)
Expand Down Expand Up @@ -169,7 +186,7 @@ set(CFLAGS
"-ggdb"
"-Os"
"-D_GNU_SOURCE"
"-std=gnu99"
"-std=gnu17"
"-Wno-old-style-declaration"
"-Wno-implicit-int"
"-Wno-declaration-after-statement"
Expand Down Expand Up @@ -275,7 +292,7 @@ target_link_libraries(
# 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
${esptool_path}
--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
Expand All @@ -296,7 +313,7 @@ add_custom_target(flash DEPENDS ${APP_NAME}.bin)
add_custom_command(TARGET flash
USES_TERMINAL
COMMAND
${IDF_PATH}/components/esptool_py/esptool/esptool.py
${esptool_path}
-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}
Expand Down
180 changes: 101 additions & 79 deletions boot/espressif/hal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,100 +6,115 @@ cmake_minimum_required(VERSION 3.13)

project(hal)

set(esp_idf_dir ${IDF_PATH})

set(esp_hal_dir ${ESP_HAL_PATH})
set(src_dir ${CMAKE_CURRENT_LIST_DIR}/src)
set(include_dirs
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/include/${MCUBOOT_TARGET}
)

list(APPEND include_dirs
${esp_idf_dir}/components/${MCUBOOT_ARCH}/include
${esp_idf_dir}/components/esp_common/include
${esp_idf_dir}/components/esp_rom/include
${esp_idf_dir}/components/esp_rom/include/${MCUBOOT_TARGET}
${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}
${esp_idf_dir}/components/spi_flash/include
${esp_idf_dir}/components/spi_flash/include/spi_flash
${esp_idf_dir}/components/esp_hw_support/include
${esp_idf_dir}/components/esp_hw_support/include/soc
${esp_idf_dir}/components/esp_hw_support/include/soc/${MCUBOOT_TARGET}
${esp_idf_dir}/components/esp_hw_support/port/include
${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}
${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/private_include
${esp_idf_dir}/components/soc/include
${esp_idf_dir}/components/soc/${MCUBOOT_TARGET}/include
${esp_idf_dir}/components/bootloader_support/include
${esp_idf_dir}/components/bootloader_support/include_bootloader
${esp_idf_dir}/components/hal/include
${esp_idf_dir}/components/hal/platform_port/include
${esp_idf_dir}/components/hal/${MCUBOOT_TARGET}/include
${esp_idf_dir}/components/hal/${MCUBOOT_TARGET}/include/hal
${esp_idf_dir}/components/heap/include
${esp_idf_dir}/components/efuse/include
${esp_idf_dir}/components/efuse/${MCUBOOT_TARGET}/include
${esp_idf_dir}/components/efuse/private_include
${esp_idf_dir}/components/efuse/${MCUBOOT_TARGET}/private_include
${esp_idf_dir}/components/esp_system/include
${esp_idf_dir}/components/newlib/platform_include
${esp_hal_dir}/components/bootloader_support/include
${esp_hal_dir}/components/bootloader_support/private_include
${esp_hal_dir}/components/bootloader_support/bootloader_flash/include
${esp_hal_dir}/components/spi_flash/include
${esp_hal_dir}/components/spi_flash/include/spi_flash
${esp_hal_dir}/components/esp_app_format/include
${esp_hal_dir}/components/newlib/platform_include
${esp_hal_dir}/components/esp_common/include
${esp_hal_dir}/components/${MCUBOOT_ARCH}/include
${esp_hal_dir}/components/esp_rom/include
${esp_hal_dir}/components/esp_rom/include/${MCUBOOT_TARGET}
${esp_hal_dir}/components/esp_rom/${MCUBOOT_TARGET}
${esp_hal_dir}/components/soc/include
${esp_hal_dir}/components/soc/${MCUBOOT_TARGET}
${esp_hal_dir}/components/soc/${MCUBOOT_TARGET}/include
${esp_hal_dir}/components/efuse/include
${esp_hal_dir}/components/efuse/${MCUBOOT_TARGET}/include
${esp_hal_dir}/components/efuse/private_include
${esp_hal_dir}/components/efuse/${MCUBOOT_TARGET}/private_include
${esp_hal_dir}/components/esp_hw_support/include
${esp_hal_dir}/components/esp_hw_support/include/soc
${esp_hal_dir}/components/esp_hw_support/include/soc/${MCUBOOT_TARGET}
${esp_hal_dir}/components/esp_hw_support/port/include
${esp_hal_dir}/components/esp_hw_support/include/esp_private
${esp_hal_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}
${esp_hal_dir}/components/hal/${MCUBOOT_TARGET}/include
${esp_hal_dir}/components/hal/include
${esp_hal_dir}/components/hal/platform_port/include
${esp_hal_dir}/components/esp_system/include
${esp_hal_dir}/components/log/include
)

if("${MCUBOOT_ARCH}" STREQUAL "xtensa")
list(APPEND include_dirs
${esp_idf_dir}/components/${MCUBOOT_ARCH}/${MCUBOOT_TARGET}/include
${esp_hal_dir}/components/${MCUBOOT_ARCH}/${MCUBOOT_TARGET}/include
${esp_hal_dir}/components/${MCUBOOT_ARCH}/include
)
endif()

set(hal_srcs
${src_dir}/bootloader_init_common.c
${esp_hal_dir}/components/bootloader_support/src/${MCUBOOT_TARGET}/bootloader_${MCUBOOT_TARGET}.c
${esp_hal_dir}/components/bootloader_support/src/bootloader_init.c
${esp_hal_dir}/components/bootloader_support/src/bootloader_common.c
${esp_hal_dir}/components/bootloader_support/src/bootloader_common_loader.c
${esp_hal_dir}/components/bootloader_support/src/bootloader_console.c
${esp_hal_dir}/components/bootloader_support/src/bootloader_console_loader.c
${esp_hal_dir}/components/bootloader_support/bootloader_flash/src/bootloader_flash.c
${esp_hal_dir}/components/bootloader_support/bootloader_flash/src/bootloader_flash_config_${MCUBOOT_TARGET}.c
${esp_hal_dir}/components/bootloader_support/src/bootloader_clock_init.c
${esp_hal_dir}/components/bootloader_support/src/bootloader_clock_loader.c
${esp_hal_dir}/components/bootloader_support/src/bootloader_efuse.c
${esp_hal_dir}/components/bootloader_support/src/bootloader_panic.c
${esp_hal_dir}/components/bootloader_support/src/bootloader_mem.c
${esp_hal_dir}/components/bootloader_support/src/bootloader_random.c
${esp_hal_dir}/components/bootloader_support/src/bootloader_random_${MCUBOOT_TARGET}.c
${esp_hal_dir}/components/bootloader_support/src/bootloader_utility.c
${esp_hal_dir}/components/bootloader_support/src/esp_image_format.c
${esp_hal_dir}/components/bootloader_support/src/secure_boot_v2/secure_boot_signatures_bootloader.c
${esp_hal_dir}/components/bootloader_support/src/${MCUBOOT_TARGET}/bootloader_soc.c
${esp_hal_dir}/components/bootloader_support/src/${MCUBOOT_TARGET}/bootloader_sha.c
${esp_hal_dir}/components/bootloader_support/src/${MCUBOOT_TARGET}/secure_boot_secure_features.c
${esp_hal_dir}/components/bootloader_support/src/${MCUBOOT_TARGET}/flash_encryption_secure_features.c
${esp_hal_dir}/components/hal/mpu_hal.c
${esp_hal_dir}/components/hal/efuse_hal.c
${esp_hal_dir}/components/hal/mmu_hal.c
${esp_hal_dir}/components/hal/wdt_hal_iram.c
${esp_hal_dir}/components/hal/${MCUBOOT_TARGET}/efuse_hal.c
${esp_hal_dir}/components/soc/${MCUBOOT_TARGET}/uart_periph.c
${esp_hal_dir}/components/soc/${MCUBOOT_TARGET}/gpio_periph.c
${esp_hal_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_time.c
${esp_hal_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_clk.c
${esp_hal_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_clk_init.c
${esp_hal_dir}/components/esp_rom/patches/esp_rom_uart.c
${esp_hal_dir}/components/esp_rom/patches/esp_rom_sys.c
${esp_hal_dir}/components/esp_rom/patches/esp_rom_spiflash.c
${esp_hal_dir}/components/efuse/${MCUBOOT_TARGET}/esp_efuse_table.c
${esp_hal_dir}/components/efuse/src/esp_efuse_fields.c
${esp_hal_dir}/components/efuse/${MCUBOOT_TARGET}/esp_efuse_fields.c
${esp_hal_dir}/components/efuse/src/esp_efuse_api.c
${esp_hal_dir}/components/efuse/src/esp_efuse_utility.c
${esp_hal_dir}/components/efuse/${MCUBOOT_TARGET}/esp_efuse_utility.c
${esp_hal_dir}/components/log/log_noos.c
${src_dir}/bootloader_banner.c
${src_dir}/bootloader_wdt.c
${src_dir}/secure_boot.c
${src_dir}/flash_encrypt.c
${src_dir}/${MCUBOOT_TARGET}/bootloader_init.c
${esp_idf_dir}/components/hal/mpu_hal.c
${esp_idf_dir}/components/hal/soc_hal.c
${esp_idf_dir}/components/soc/${MCUBOOT_TARGET}/uart_periph.c
${esp_idf_dir}/components/soc/${MCUBOOT_TARGET}/gpio_periph.c
${esp_idf_dir}/components/bootloader_support/src/bootloader_common_loader.c
${esp_idf_dir}/components/bootloader_support/src/bootloader_console.c
${esp_idf_dir}/components/bootloader_support/src/bootloader_console_loader.c
${esp_idf_dir}/components/bootloader_support/src/bootloader_flash.c
${esp_idf_dir}/components/bootloader_support/src/bootloader_flash_config_${MCUBOOT_TARGET}.c
${esp_idf_dir}/components/bootloader_support/src/bootloader_clock_init.c
${esp_idf_dir}/components/bootloader_support/src/bootloader_efuse_${MCUBOOT_TARGET}.c
${esp_idf_dir}/components/bootloader_support/src/bootloader_panic.c
${esp_idf_dir}/components/bootloader_support/src/bootloader_mem.c
${esp_idf_dir}/components/bootloader_support/src/bootloader_random.c
${esp_idf_dir}/components/bootloader_support/src/bootloader_random_${MCUBOOT_TARGET}.c
${esp_idf_dir}/components/bootloader_support/src/bootloader_utility.c
${esp_idf_dir}/components/bootloader_support/src/esp_image_format.c
${esp_idf_dir}/components/bootloader_support/src/secure_boot_v2/secure_boot_signatures_bootloader.c
${esp_idf_dir}/components/bootloader_support/src/${MCUBOOT_TARGET}/bootloader_soc.c
${esp_idf_dir}/components/bootloader_support/src/${MCUBOOT_TARGET}/bootloader_sha.c
${esp_idf_dir}/components/bootloader_support/src/${MCUBOOT_TARGET}/secure_boot_secure_features.c
${esp_idf_dir}/components/bootloader_support/src/${MCUBOOT_TARGET}/flash_encryption_secure_features.c
${esp_idf_dir}/components/spi_flash/${MCUBOOT_TARGET}/spi_flash_rom_patch.c
${esp_idf_dir}/components/esp_hw_support/esp_clk.c
${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_init.c
${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_time.c
${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_clk.c
${esp_idf_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_clk_init.c
${esp_idf_dir}/components/hal/wdt_hal_iram.c
${esp_idf_dir}/components/esp_hw_support/cpu_util.c
${esp_idf_dir}/components/esp_rom/patches/esp_rom_uart.c
${esp_idf_dir}/components/esp_rom/patches/esp_rom_sys.c
${esp_idf_dir}/components/efuse/${MCUBOOT_TARGET}/esp_efuse_table.c
${esp_idf_dir}/components/efuse/src/esp_efuse_fields.c
${esp_idf_dir}/components/efuse/${MCUBOOT_TARGET}/esp_efuse_fields.c
${esp_idf_dir}/components/efuse/src/esp_efuse_api.c
${esp_idf_dir}/components/efuse/src/esp_efuse_utility.c
${esp_idf_dir}/components/efuse/${MCUBOOT_TARGET}/esp_efuse_utility.c
)

if(DEFINED CONFIG_SECURE_BOOT_V2_ENABLED)
list(APPEND hal_srcs
${src_dir}/secure_boot.c
)
endif()

if(DEFINED CONFIG_SECURE_FLASH_ENC_ENABLED)
list(APPEND hal_srcs
${src_dir}/flash_encrypt.c
)
endif()

if("${MCUBOOT_ARCH}" STREQUAL "xtensa")
list(APPEND hal_srcs
${esp_idf_dir}/components/esp_rom/patches/esp_rom_longjmp.S
${esp_hal_dir}/components/esp_rom/patches/esp_rom_longjmp.S
)
endif()

Expand All @@ -125,7 +140,7 @@ set(CFLAGS
"-ggdb"
"-Os"
"-D_GNU_SOURCE"
"-std=gnu99"
"-std=gnu17"
"-Wno-old-style-declaration"
"-Wno-implicit-int"
)
Expand Down Expand Up @@ -153,16 +168,23 @@ if("${MCUBOOT_ARCH}" STREQUAL "xtensa")
endif()

set(LINKER_SCRIPTS
-T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.ld
-T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.libgcc.ld
-T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.api.ld
-T${esp_idf_dir}/components/soc/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.peripherals.ld
-T${esp_hal_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.ld
-T${esp_hal_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.libgcc.ld
-T${esp_hal_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.api.ld
-T${esp_hal_dir}/components/soc/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.peripherals.ld
)

include(${CMAKE_CURRENT_LIST_DIR}/include/${MCUBOOT_TARGET}/${MCUBOOT_TARGET}.cmake)

add_library(hal STATIC ${hal_srcs} ${include_dirs})

# Wrap for overriding the print banner function from bootloader_support
add_definitions(-DIDF_VER=0)
target_link_libraries(
hal
INTERFACE
"-Wl,--wrap=bootloader_print_banner")

target_include_directories(
hal
PUBLIC
Expand Down
1 change: 0 additions & 1 deletion boot/espressif/hal/esp-idf
Submodule esp-idf deleted from 8153bf
1 change: 0 additions & 1 deletion boot/espressif/hal/include/bootloader_wdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
#pragma once

void bootloader_wdt_feed(void);
void bootloader_config_wdt(void);
24 changes: 17 additions & 7 deletions boot/espressif/hal/include/esp32/esp32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@
#
# SPDX-License-Identifier: Apache-2.0

list(APPEND include_dirs
${esp_idf_dir}/components/${MCUBOOT_TARGET}/include
)

list(APPEND hal_srcs
${esp_idf_dir}/components/efuse/src/esp_efuse_api_key_esp32.c
${esp_hal_dir}/components/esp_hw_support/port/${MCUBOOT_TARGET}/rtc_init.c
${esp_hal_dir}/components/efuse/src/efuse_controller/keys/without_key_purposes/three_key_blocks/esp_efuse_api_key.c
)

if (DEFINED CONFIG_ESP_MULTI_PROCESSOR_BOOT)
list(APPEND hal_srcs
${src_dir}/${MCUBOOT_TARGET}/app_cpu_start.c
${esp_hal_dir}/components/esp_hw_support/cpu.c
)
endif()

if (DEFINED CONFIG_ESP_CONSOLE_UART_CUSTOM)
list(APPEND hal_srcs
${src_dir}/${MCUBOOT_TARGET}/console_uart_custom.c
)
endif()

list(APPEND LINKER_SCRIPTS
-T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.newlib-funcs.ld
-T${esp_idf_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.eco3.ld
-T${esp_hal_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.newlib-funcs.ld
-T${esp_hal_dir}/components/esp_rom/${MCUBOOT_TARGET}/ld/${MCUBOOT_TARGET}.rom.eco3.ld
)

set_source_files_properties(
${esp_hal_dir}/components/bootloader_support/src/esp32/bootloader_esp32.c
${esp_hal_dir}/components/bootloader_support/bootloader_flash/src/bootloader_flash.c
PROPERTIES COMPILE_FLAGS
"-Wno-unused-variable -Wno-unused-but-set-variable")
9 changes: 9 additions & 0 deletions boot/espressif/hal/include/esp32/sdkconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@
#define CONFIG_IDF_FIRMWARE_CHIP_ID 0x0000
#define CONFIG_IDF_TARGET_ESP32 1
#define CONFIG_ESP32_REV_MIN_3 1
#define CONFIG_ESP32_REV_MIN_FULL 300
#define CONFIG_ESP_REV_MIN_FULL CONFIG_ESP32_REV_MIN_FULL
#define CONFIG_ESP32_REV_MIN 3
#define CONFIG_ESP32_REV_MAX_FULL 399
#define CONFIG_ESP_REV_MAX_FULL CONFIG_ESP32_REV_MAX_FULL
#define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1
#define CONFIG_MMU_PAGE_SIZE 0x10000
#define CONFIG_ESP32_XTAL_FREQ 40
#define CONFIG_XTAL_FREQ 40
#define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_160 1
#define CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ 160
#define CONFIG_MCUBOOT 1
#define NDEBUG 1
#define CONFIG_BOOTLOADER_WDT_TIME_MS 9000
Expand All @@ -20,3 +28,4 @@
#define CONFIG_EFUSE_VIRTUAL_OFFSET 0x250000
#define CONFIG_EFUSE_VIRTUAL_SIZE 0x2000
#define CONFIG_EFUSE_MAX_BLK_LEN 192
#define CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT 1
Loading