diff --git a/components/esptool_py/project_include.cmake b/components/esptool_py/project_include.cmake index 8a1b610e8..6c2b2436b 100644 --- a/components/esptool_py/project_include.cmake +++ b/components/esptool_py/project_include.cmake @@ -194,6 +194,11 @@ esptool_py_custom_target(app-flash app "app") if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT) esptool_py_custom_target(encrypted-flash encrypted_project "app;partition_table;bootloader") esptool_py_custom_target(encrypted-app-flash encrypted_app "app") +else() + fail_target(encrypted-flash "Error: The target encrypted-flash requires" + "CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT to be enabled.") + fail_target(encrypted-app-flash "Error: The target encrypted-app-flash requires" + "CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT to be enabled.") endif() # esptool_py_flash_project_args diff --git a/components/partition_table/CMakeLists.txt b/components/partition_table/CMakeLists.txt index 65b1ff556..9b094876e 100644 --- a/components/partition_table/CMakeLists.txt +++ b/components/partition_table/CMakeLists.txt @@ -33,15 +33,24 @@ endif() idf_build_get_property(build_dir BUILD_DIR) idf_build_get_property(python PYTHON) +set(gen_partition_table "${python}" "${CMAKE_CURRENT_SOURCE_DIR}/gen_esp32part.py" "-q" + "--offset" "${PARTITION_TABLE_OFFSET}" "${md5_opt}" "${flashsize_opt}" + "${partition_secure_opt}" ) + add_custom_command(OUTPUT "${build_dir}/partition_table/${unsigned_partition_bin}" - COMMAND "${python}" "${CMAKE_CURRENT_SOURCE_DIR}/gen_esp32part.py" - -q --offset ${PARTITION_TABLE_OFFSET} ${md5_opt} ${flashsize_opt} - ${partition_secure_opt} ${partition_csv} ${build_dir}/partition_table/${unsigned_partition_bin} + COMMAND ${gen_partition_table} "${partition_csv}" "${build_dir}/partition_table/${unsigned_partition_bin}" DEPENDS ${partition_csv} "${CMAKE_CURRENT_SOURCE_DIR}/gen_esp32part.py" VERBATIM) if(EXISTS ${partition_csv}) - add_custom_target(partition_table ALL DEPENDS "${build_dir}/partition_table/${final_partition_bin}") + add_custom_target(partition_table ALL + DEPENDS "${build_dir}/partition_table/${unsigned_partition_bin}" + "${build_dir}/partition_table/${final_partition_bin}" + COMMAND ${CMAKE_COMMAND} -E echo "Partition table binary generated. Contents:" + COMMAND ${CMAKE_COMMAND} -E echo "*******************************************************************************" + COMMAND ${gen_partition_table} "${build_dir}/partition_table/${unsigned_partition_bin}" + COMMAND ${CMAKE_COMMAND} -E echo "*******************************************************************************" + VERBATIM) else() # If the partition input CSV is not found, create a phony partition_table target that # fails the build. fail_at_build_time also touches CMakeCache.txt to cause a cmake run next time @@ -68,7 +77,7 @@ if(CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME) add_custom_command(TARGET partition_table POST_BUILD COMMAND ${CMAKE_COMMAND} -E echo "Partition table built but not signed. Sign partition data before flashing:" - COMMAND ${CMAKE_COMMAND} -E echo + COMMAND ${CMAKE_COMMAND} -E echo "\t${espsecurepy} sign_data --keyfile KEYFILE ${build_dir}/partition_table/${final_partition_bin}" VERBATIM) endif() diff --git a/components/ulp/component_ulp_common.cmake b/components/ulp/component_ulp_common.cmake index ce207f802..30cbe44a7 100644 --- a/components/ulp/component_ulp_common.cmake +++ b/components/ulp/component_ulp_common.cmake @@ -15,4 +15,4 @@ foreach(ulp_exp_dep_src ${ULP_EXP_DEP_SRCS}) list(APPEND ulp_dep_srcs ${ulp_dep_src}) endforeach() -ulp_embed_binary(${ULP_APP_NAME} ${ulp_srcs} ${ulp_dep_srcs}) +ulp_embed_binary(${ULP_APP_NAME} "${ulp_srcs}" "${ulp_dep_srcs}") diff --git a/components/ulp/project_include.cmake b/components/ulp/project_include.cmake index 94afe208d..4647f8f7a 100644 --- a/components/ulp/project_include.cmake +++ b/components/ulp/project_include.cmake @@ -47,10 +47,9 @@ function(ulp_embed_binary app_name s_sources exp_dep_srcs) INSTALL_COMMAND "" CMAKE_ARGS -DCMAKE_GENERATOR=${CMAKE_GENERATOR} -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FLAG} - -DULP_S_SOURCES=${sources} -DULP_APP_NAME=${app_name} + -DULP_S_SOURCES=$ + -DULP_APP_NAME=${app_name} -DCOMPONENT_DIR=${COMPONENT_DIR} - # Even though this resolves to a ';' separated list, this is fine. This must be special behavior - # for generator expressions. -DCOMPONENT_INCLUDES=$ -DIDF_PATH=${idf_path} -DSDKCONFIG=${SDKCONFIG_HEADER} @@ -60,9 +59,10 @@ function(ulp_embed_binary app_name s_sources exp_dep_srcs) BUILD_BYPRODUCTS ${ulp_artifacts} ${ulp_artifacts_extras} ${ulp_ps_sources} ${CMAKE_CURRENT_BINARY_DIR}/${app_name}/${app_name} BUILD_ALWAYS 1 - LIST_SEPARATOR | ) + set_property(TARGET ${app_name} PROPERTY ULP_SOURCES "${sources}") + spaces2list(exp_dep_srcs) set_source_files_properties(${exp_dep_srcs} PROPERTIES OBJECT_DEPENDS ${ulp_artifacts}) diff --git a/components/ulp/test/CMakeLists.txt b/components/ulp/test/CMakeLists.txt index bbcb38f15..78c45d4fe 100644 --- a/components/ulp/test/CMakeLists.txt +++ b/components/ulp/test/CMakeLists.txt @@ -6,5 +6,5 @@ if(IDF_TARGET STREQUAL "esp32") set(ulp_app_name ulp_test_app) set(ulp_s_sources "ulp/test_jumps_esp32.S") set(ulp_exp_dep_srcs "esp32/test_ulp_as.c") - ulp_embed_binary(${ulp_app_name} ${ulp_s_sources} ${ulp_exp_dep_srcs}) + ulp_embed_binary(${ulp_app_name} "${ulp_s_sources}" "${ulp_exp_dep_srcs}") endif() diff --git a/docs/en/api-guides/ulp.rst b/docs/en/api-guides/ulp.rst index ad2509e0c..fb12f51bd 100644 --- a/docs/en/api-guides/ulp.rst +++ b/docs/en/api-guides/ulp.rst @@ -40,7 +40,7 @@ To compile the ULP code as part of the component, the following steps must be ta set(ulp_s_sources ulp/ulp_assembly_source_file.S) set(ulp_exp_dep_srcs "ulp_c_source_file.c") - ulp_embed_binary(${ulp_app_name} ${ulp_s_sources} ${ulp_exp_dep_srcs}) + ulp_embed_binary(${ulp_app_name} "${ulp_s_sources}" "${ulp_exp_dep_srcs}") The first argument to ``ulp_embed_binary`` specifies the ULP binary name. The name specified here will also be used by other generated artifacts such as the ELF file, map file, header file and linker export file. The second argument specifies the ULP assembly source files. diff --git a/docs/zh_CN/api-guides/ulp.rst b/docs/zh_CN/api-guides/ulp.rst index 5ad56a860..921577449 100644 --- a/docs/zh_CN/api-guides/ulp.rst +++ b/docs/zh_CN/api-guides/ulp.rst @@ -42,7 +42,7 @@ ULP 协处理器代码是用汇编语言编写的,并使用 `binutils-esp32ulp set(ulp_s_sources ulp/ulp_assembly_source_file.S) set(ulp_exp_dep_srcs "ulp_c_source_file.c") - ulp_embed_binary(${ulp_app_name} ${ulp_s_sources} ${ulp_exp_dep_srcs}) + ulp_embed_binary(${ulp_app_name} "${ulp_s_sources}" "${ulp_exp_dep_srcs}") 上述第一个参数到 ``ulp_embed_binary`` 为 ULP 二进制文件命名。此名称也用于生成的其他文件,如:ELF 文件、.map 文件、头文件和链接器导出文件。第二个参数设置 ULP 程序集源文件。最后,第三个参数设置组件源文件列表,其中包括被生成的头文件。此列表用以建立正确的依赖项,并确保在构建过程会先生成再编译包含头文件的源文件。请参考下文,查看为 ULP 应用程序生成的头文件等相关概念。 diff --git a/examples/system/ulp/README.md b/examples/system/ulp/README.md index 3c854043e..d76506a5d 100644 --- a/examples/system/ulp/README.md +++ b/examples/system/ulp/README.md @@ -2,7 +2,7 @@ This example demonstrates how to program the ULP coprocessor to count pulses on an IO while the main CPUs are either running some other code or are in deep sleep. See the README.md file in the upper level 'examples' directory for more information about examples. -ULP program written in assembly can be found in `ulp/pulse_cnt.S`. The build system assembles and links this program, converts it into binary format, and embeds it into the .rodata section of the ESP-IDF application. +ULP program written in assembly can be found across `ulp/pulse_cnt.S` and `ulp/wake_up.S` (demonstrating multiple ULP source files). The build system assembles and links this program, converts it into binary format, and embeds it into the .rodata section of the ESP-IDF application. At runtime, the main code running on the ESP32 (found in main.c) loads ULP program into the `RTC_SLOW_MEM` memory region using `ulp_load_binary` function. Main code configures the ULP program by setting up values of some variables and then starts it using `ulp_run`. Once the ULP program is started, it runs periodically, with the period set by the main program. The main program enables ULP wakeup source and puts the chip into deep sleep mode. diff --git a/examples/system/ulp/main/CMakeLists.txt b/examples/system/ulp/main/CMakeLists.txt index af7cb3f76..1ac5db257 100644 --- a/examples/system/ulp/main/CMakeLists.txt +++ b/examples/system/ulp/main/CMakeLists.txt @@ -10,7 +10,7 @@ set(ulp_app_name ulp_${COMPONENT_NAME}) # 2. Specify all assembly source files. # Files should be placed into a separate directory (in this case, ulp/), # which should not be added to COMPONENT_SRCS. -set(ulp_s_sources "ulp/pulse_cnt.S") +set(ulp_s_sources "ulp/pulse_cnt.S" "ulp/wake_up.S") # # 3. List all the component source files which include automatically # generated ULP export file, ${ulp_app_name}.h: @@ -18,4 +18,4 @@ set(ulp_exp_dep_srcs "ulp_example_main.c") # # 4. Call function to build ULP binary and embed in project using the argument # values above. -ulp_embed_binary(${ulp_app_name} ${ulp_s_sources} ${ulp_exp_dep_srcs}) +ulp_embed_binary(${ulp_app_name} "${ulp_s_sources}" "${ulp_exp_dep_srcs}") diff --git a/examples/system/ulp/main/component.mk b/examples/system/ulp/main/component.mk index 566757a56..55c5ba352 100644 --- a/examples/system/ulp/main/component.mk +++ b/examples/system/ulp/main/component.mk @@ -11,7 +11,7 @@ ULP_APP_NAME ?= ulp_$(COMPONENT_NAME) # Files should be placed into a separate directory (in this case, ulp/), # which should not be added to COMPONENT_SRCDIRS. ULP_S_SOURCES = $(addprefix $(COMPONENT_PATH)/ulp/, \ - pulse_cnt.S \ + pulse_cnt.S wake_up.S\ ) # # 3. List all the component object files which include automatically diff --git a/examples/system/ulp/main/ulp/pulse_cnt.S b/examples/system/ulp/main/ulp/pulse_cnt.S index 774375e2a..33e6ef686 100644 --- a/examples/system/ulp/main/ulp/pulse_cnt.S +++ b/examples/system/ulp/main/ulp/pulse_cnt.S @@ -144,14 +144,3 @@ edge_detected: jump wake_up, eq /* Not yet. End program */ halt - - .global wake_up -wake_up: - /* Check if the system can be woken up */ - READ_RTC_FIELD(RTC_CNTL_LOW_POWER_ST_REG, RTC_CNTL_RDY_FOR_WAKEUP) - and r0, r0, 1 - jump wake_up, eq - - /* Wake up the SoC, end program */ - wake - halt diff --git a/examples/system/ulp/main/ulp/wake_up.S b/examples/system/ulp/main/ulp/wake_up.S new file mode 100644 index 000000000..ec2e05da4 --- /dev/null +++ b/examples/system/ulp/main/ulp/wake_up.S @@ -0,0 +1,16 @@ +/* ULP assembly files are passed through C preprocessor first, so include directives + and C macros may be used in these files + */ +#include "soc/rtc_cntl_reg.h" +#include "soc/soc_ulp.h" + + .global wake_up +wake_up: + /* Check if the system can be woken up */ + READ_RTC_FIELD(RTC_CNTL_LOW_POWER_ST_REG, RTC_CNTL_RDY_FOR_WAKEUP) + and r0, r0, 1 + jump wake_up, eq + + /* Wake up the SoC, end program */ + wake + halt diff --git a/examples/system/ulp_adc/main/CMakeLists.txt b/examples/system/ulp_adc/main/CMakeLists.txt index ef85f9b2f..c2da07619 100644 --- a/examples/system/ulp_adc/main/CMakeLists.txt +++ b/examples/system/ulp_adc/main/CMakeLists.txt @@ -18,4 +18,4 @@ set(ulp_exp_dep_srcs "ulp_adc_example_main.c") # # 4. Call function to build ULP binary and embed in project using the argument # values above. -ulp_embed_binary(${ulp_app_name} ${ulp_s_sources} ${ulp_exp_dep_srcs}) +ulp_embed_binary(${ulp_app_name} "${ulp_s_sources}" "${ulp_exp_dep_srcs}") diff --git a/tools/ci/test_build_system_cmake.sh b/tools/ci/test_build_system_cmake.sh index 1a74a3d82..5be358c1d 100755 --- a/tools/ci/test_build_system_cmake.sh +++ b/tools/ci/test_build_system_cmake.sh @@ -445,6 +445,10 @@ function run_tests() (grep '"command"' build/compile_commands.json | grep -v mfix-esp32-psram-cache-issue) && failure "All commands in compile_commands.json should use PSRAM cache workaround" rm -r build + print_status "Displays partition table when executing target partition_table" + idf.py partition_table | grep -E "# Espressif .+ Partition Table" + rm -r build + print_status "Make sure a full build never runs '/usr/bin/env python' or similar" OLDPATH="$PATH" PYTHON="$(which python)" diff --git a/tools/cmake/scripts/fail.cmake b/tools/cmake/scripts/fail.cmake index 5ceddb3ca..b33aec4c3 100644 --- a/tools/cmake/scripts/fail.cmake +++ b/tools/cmake/scripts/fail.cmake @@ -1,4 +1,4 @@ # 'cmake -E' doesn't have a way to fail outright, so run this script # with 'cmake -P' to fail a build. -message(FATAL_ERROR "Failing the build (see errors on lines above)") +message(FATAL_ERROR "$ENV{FAIL_MESSAGE}") diff --git a/tools/cmake/utilities.cmake b/tools/cmake/utilities.cmake index 5d3a8ebc6..6cd1a5cd0 100644 --- a/tools/cmake/utilities.cmake +++ b/tools/cmake/utilities.cmake @@ -214,13 +214,37 @@ function(fail_at_build_time target_name message_line0) set(filename "${CMAKE_CURRENT_BINARY_DIR}/${filename}.cmake") file(WRITE "${filename}" "") include("${filename}") + set(fail_message "Failing the build (see errors on lines above)") add_custom_target(${target_name} ALL ${message_lines} COMMAND ${CMAKE_COMMAND} -E remove "${filename}" - COMMAND ${CMAKE_COMMAND} -P ${idf_path}/tools/cmake/scripts/fail.cmake + COMMAND ${CMAKE_COMMAND} -E env FAIL_MESSAGE=${fail_message} + ${CMAKE_COMMAND} -P ${idf_path}/tools/cmake/scripts/fail.cmake VERBATIM) endfunction() +# fail_target +# +# Creates a phony target which fails when invoked. This is used when the necessary conditions +# for a target are not met, such as configuration. Rather than ommitting the target altogether, +# we fail execution with a helpful message. +function(fail_target target_name message_line0) + idf_build_get_property(idf_path IDF_PATH) + set(message_lines COMMAND ${CMAKE_COMMAND} -E echo "${message_line0}") + foreach(message_line ${ARGN}) + set(message_lines ${message_lines} COMMAND ${CMAKE_COMMAND} -E echo "${message_line}") + endforeach() + # Generate a timestamp file that gets included. When deleted on build, this forces CMake + # to rerun. + set(fail_message "Failed executing target (see errors on lines above)") + add_custom_target(${target_name} + ${message_lines} + COMMAND ${CMAKE_COMMAND} -E env FAIL_MESSAGE=${fail_message} + ${CMAKE_COMMAND} -P ${idf_path}/tools/cmake/scripts/fail.cmake + VERBATIM) +endfunction() + + function(check_exclusive_args args prefix) set(_args ${args}) spaces2list(_args)