Merge branch 'feature/use_underlying_cmake_targets_for_idf_py' into 'master'

CMake: Use underlying flash targets for idf.py

See merge request espressif/esp-idf!7067
This commit is contained in:
Ivan Grokhotkov 2020-01-21 17:05:47 +08:00
commit c11f77cb1a
16 changed files with 249 additions and 243 deletions

View file

@ -62,6 +62,11 @@ if(NOT BOOTLOADER_BUILD)
--partition-table-offset ${PARTITION_TABLE_OFFSET}
erase_otadata)
esptool_py_flash_project_args(otadata ${otadata_offset} "${blank_otadata_file}" FLASH_IN_PROJECT)
idf_component_get_property(main_args esptool_py FLASH_ARGS)
idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
esptool_py_flash_target(otadata-flash "${main_args}" "${sub_args}")
esptool_py_flash_target_image(otadata-flash otadata "${otadata_offset}" "${blank_otadata_file}")
esptool_py_flash_target_image(flash otadata "${otadata_offset}" "${blank_otadata_file}")
endif()
endif()

View file

@ -5,17 +5,12 @@ if(BOOTLOADER_BUILD OR NOT CONFIG_APP_BUILD_BOOTLOADER)
return()
endif()
# When secure boot is enabled, do not flash bootloader along with invocation of `idf.py flash`
if(NOT CONFIG_SECURE_BOOT_ENABLED)
set(flash_bootloader FLASH_IN_PROJECT)
endif()
# Set values used in flash_bootloader_args.in and generate flash file
# for bootloader
esptool_py_flash_project_args(bootloader 0x1000
${BOOTLOADER_BUILD_DIR}/bootloader.bin
${flash_bootloader}
FLASH_FILE_TEMPLATE flash_bootloader_args.in)
add_dependencies(bootloader partition_table)
esptool_py_custom_target(bootloader-flash bootloader "bootloader")
add_dependencies(bootloader partition_table)
esptool_py_flash_target_image(bootloader-flash bootloader "0x1000" "${BOOTLOADER_BUILD_DIR}/bootloader.bin")
# Also attach an image to the project flash target
if(NOT CONFIG_SECURE_BOOT_ENABLED)
esptool_py_flash_target_image(flash bootloader "0x1000" "${BOOTLOADER_BUILD_DIR}/bootloader.bin")
endif()

View file

@ -1,4 +0,0 @@
--flash_mode ${ESPFLASHMODE}
--flash_size ${ESPFLASHSIZE}
--flash_freq ${ESPFLASHFREQ}
${OFFSET} ${IMAGE}

View file

@ -29,9 +29,16 @@ project(bootloader)
idf_build_set_property(COMPILE_DEFINITIONS "-DBOOTLOADER_BUILD=1" APPEND)
idf_build_set_property(COMPILE_OPTIONS "-fno-stack-protector" APPEND)
idf_component_get_property(main_args esptool_py FLASH_ARGS)
idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
# String for printing flash command
string(REPLACE ";" " " esptoolpy_write_flash
"${ESPTOOLPY} --port=(PORT) --baud=(BAUD) ${main_args} "
"write_flash ${sub_args}")
string(REPLACE ";" " " espsecurepy "${ESPSECUREPY}")
string(REPLACE ";" " " espefusepy "${ESPEFUSEPY}")
set(esptoolpy_write_flash "${ESPTOOLPY_WRITE_FLASH_STR}")
if(CONFIG_SECURE_BOOTLOADER_REFLASHABLE)
if(CONFIG_SECURE_BOOTLOADER_KEY_ENCODING_192BIT)

View file

@ -83,16 +83,23 @@ if(CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION)
add_custom_target(phy_init_data ALL DEPENDS ${phy_init_data_bin})
add_dependencies(flash phy_init_data)
idf_component_get_property(main_args esptool_py FLASH_ARGS)
idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
# ToDo: remove once MP chip is supported
if(CONFIG_IDF_TARGET_ESP32)
esptool_py_flash_project_args(phy ${phy_partition_offset} ${phy_init_data_bin} FLASH_IN_PROJECT)
set(phy_name "phy")
elseif(CONFIG_IDF_TARGET_ESP32S2BETA)
if(CONFIG_ESP32S2BETA_VERSION_A)
esptool_py_flash_project_args(phyA ${phy_partition_offset} ${phy_init_data_bin} FLASH_IN_PROJECT)
set(phy_name "phyA")
elseif(CONFIG_ESP32S2BETA_VERSION_B)
esptool_py_flash_project_args(phyB ${phy_partition_offset} ${phy_init_data_bin} FLASH_IN_PROJECT)
set(phy_name "phyB")
elseif(CONFIG_ESP32S2BETA_VERSION_MARLIN3)
esptool_py_flash_project_args(phy_marlin3 ${phy_partition_offset} ${phy_init_data_bin} FLASH_IN_PROJECT)
set(phy_name "phy_marlin3")
endif()
endif()
esptool_py_flash_target(${phy_name}-flash "${main_args}" "${sub_args}")
esptool_py_flash_target_image(${phy_name}-flash ${phy_name} "${phy_partition_offset}" "${phy_init_data_bin}")
esptool_py_flash_target_image(flash ${phy_name} "${phy_partition_offset}" "${phy_init_data_bin}")
endif()

View file

@ -1,74 +1,16 @@
idf_component_register(REQUIRES bootloader)
if(NOT BOOTLOADER_BUILD AND CONFIG_APP_BUILD_GENERATE_BINARIES)
string(REPLACE ";" " " ESPTOOLPY_FLASH_PROJECT_OPTIONS "${ESPTOOLPY_FLASH_OPTIONS}")
set(ESPTOOLPY_FLASH_PROJECT_OPTIONS
"${ESPTOOLPY_FLASH_PROJECT_OPTIONS}"
)
if(CONFIG_SECURE_BOOT_ENABLED)
set(ESPTOOLPY_FLASH_PROJECT_OPTIONS "")
endif()
# FLASH_PROJECT_ARGS, FLASH_PROJECT_ARGS_JSON, FLASH_PROJECT_ARGS_ENTRY_JSON
# are used in the flasher args input files (flash_project_args.in, flasher_args.json.in)
idf_component_get_property(FLASH_PROJECT_ARGS ${COMPONENT_NAME}
FLASH_PROJECT_ARGS GENERATOR_EXPRESSION)
idf_component_get_property(FLASH_PROJECT_ARGS_JSON ${COMPONENT_NAME}
FLASH_PROJECT_ARGS_JSON GENERATOR_EXPRESSION)
idf_component_get_property(FLASH_PROJECT_ARGS_ENTRY_JSON ${COMPONENT_NAME}
FLASH_PROJECT_ARGS_ENTRY_JSON GENERATOR_EXPRESSION)
# Generate the flash project args and the flasher args json file using the accumulated values
# from esptool_py_flash_project_args calls. The file is first configured using configure_file() for all variable values,
# and then generated using file(GENERATE... for generator expressions.
configure_file(${COMPONENT_DIR}/flash_project_args.in
${CMAKE_CURRENT_BINARY_DIR}/flash_project_args.in)
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/flash_project_args.in2
INPUT ${CMAKE_CURRENT_BINARY_DIR}/flash_project_args.in)
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/flash_project_args
INPUT ${CMAKE_CURRENT_BINARY_DIR}/flash_project_args.in2)
if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT)
configure_file(${COMPONENT_DIR}/flash_encrypted_project_args.in
${CMAKE_CURRENT_BINARY_DIR}/flash_encrypted_project_args.in)
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/flash_encrypted_project_args.in2
INPUT ${CMAKE_CURRENT_BINARY_DIR}/flash_encrypted_project_args.in)
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/flash_encrypted_project_args
INPUT ${CMAKE_CURRENT_BINARY_DIR}/flash_encrypted_project_args.in2)
endif()
configure_file(${COMPONENT_DIR}/flasher_args.json.in
${CMAKE_CURRENT_BINARY_DIR}/flasher_args.json.in)
file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/flasher_args.json.in2
INPUT ${CMAKE_CURRENT_BINARY_DIR}/flasher_args.json.in)
file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/flasher_args.json
INPUT ${CMAKE_CURRENT_BINARY_DIR}/flasher_args.json.in2)
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
"${CMAKE_CURRENT_BINARY_DIR}/flash_project_args.in"
"${CMAKE_CURRENT_BINARY_DIR}/flash_project_args.in2"
"${CMAKE_BINARY_DIR}/flash_project_args"
"${CMAKE_CURRENT_BINARY_DIR}/flasher_args.json.in"
"${CMAKE_CURRENT_BINARY_DIR}/flasher_args.json.in2"
"${CMAKE_BINARY_DIR}/flasher_args.json")
if(NOT BOOTLOADER_BUILD)
idf_build_get_property(build_dir BUILD_DIR)
partition_table_get_partition_info(app_partition_offset "--partition-boot-default" "offset")
esptool_py_flash_project_args(app ${app_partition_offset} ${build_dir}/${PROJECT_BIN} FLASH_IN_PROJECT)
if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/flash_encrypted_app_args.in "--encrypt ${app_partition_offset} ${PROJECT_BIN}")
esptool_py_flash_project_args(encrypted_app ${app_partition_offset} ${build_dir}/${PROJECT_BIN}
FLASH_FILE_TEMPLATE ${CMAKE_CURRENT_BINARY_DIR}/flash_encrypted_app_args.in)
if(CONFIG_APP_BUILD_GENERATE_BINARIES)
partition_table_get_partition_info(app_partition_offset "--partition-boot-default" "offset")
esptool_py_custom_target(app-flash app "app")
esptool_py_flash_target_image(app-flash app "${app_partition_offset}" "${build_dir}/${PROJECT_BIN}")
esptool_py_flash_target_image(flash app "${app_partition_offset}" "${build_dir}/${PROJECT_BIN}")
endif()
add_dependencies(flash partition_table)
# If anti-rollback option is set then factory partition should not be in Partition Table.
# In this case, should be used the partition table with two ota app without the factory.
partition_table_get_partition_info(factory_offset "--partition-type app --partition-subtype factory" "offset")
@ -77,5 +19,35 @@ if(NOT BOOTLOADER_BUILD AND CONFIG_APP_BUILD_GENERATE_BINARIES)
"ERROR: Anti-rollback option is enabled. Partition table should consist of two ota app without factory partition.")
add_dependencies(app check_table_contents)
endif()
# Generate flasher_args.json for tools that need it. The variables below are used
# in configuring the template flasher_args.json.in.
set(ESPFLASHMODE ${CONFIG_ESPTOOLPY_FLASHMODE})
set(ESPFLASHFREQ ${CONFIG_ESPTOOLPY_FLASHFREQ})
set(ESPFLASHSIZE ${CONFIG_ESPTOOLPY_FLASHSIZE})
set(ESPTOOLPY_FLASH_OPTIONS
--flash_mode ${ESPFLASHMODE}
--flash_freq ${ESPFLASHFREQ}
--flash_size ${ESPFLASHSIZE}
)
set(ESPTOOLPY_BEFORE "${CONFIG_ESPTOOLPY_BEFORE}")
set(ESPTOOLPY_AFTER "${CONFIG_ESPTOOLPY_AFTER}")
set(ESPTOOLPY_CHIP "${target}")
set(ESPTOOLPY_WITH_STUB TRUE)
if(CONFIG_SECURE_BOOT_ENABLED OR CONFIG_SECURE_FLASH_ENC_ENABLED)
# If security enabled then override post flash option
set(ESPTOOLPY_AFTER "no_reset")
endif()
file(READ "flasher_args.json.in" flasher_args_content)
string(CONFIGURE "${flasher_args_content}" flasher_args_content)
file_generate("${CMAKE_CURRENT_BINARY_DIR}/flasher_args.json.in"
CONTENT "${flasher_args_content}")
file_generate("${CMAKE_BINARY_DIR}/flasher_args.json"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/flasher_args.json.in")
endif()

View file

@ -1,3 +0,0 @@
--encrypt ${ESPTOOLPY_FLASH_PROJECT_OPTIONS}
$<JOIN:${FLASH_PROJECT_ARGS},
>

View file

@ -1,3 +0,0 @@
${ESPTOOLPY_FLASH_PROJECT_OPTIONS}
$<JOIN:${FLASH_PROJECT_ARGS},
>

View file

@ -8,10 +8,10 @@
"flash_freq": "${ESPFLASHFREQ}"
},
"flash_files" : {
$<JOIN:${FLASH_PROJECT_ARGS_JSON},,
$<JOIN:$<TARGET_PROPERTY:flash,FLASH_FILE>,,
>
},
$<JOIN:${FLASH_PROJECT_ARGS_ENTRY_JSON},,
$<JOIN:$<TARGET_PROPERTY:flash,FLASH_ENTRY>,,
>,
"extra_esptool_args" : {
"after" : "${ESPTOOLPY_AFTER}",

View file

@ -3,60 +3,23 @@
# Many of these are read when generating flash_app_args & flash_project_args
idf_build_get_property(target IDF_TARGET)
idf_build_get_property(python PYTHON)
set(ESPTOOLPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/esptool.py" --chip ${target})
set(ESPSECUREPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/espsecure.py")
set(ESPEFUSEPY ${python} "${CMAKE_CURRENT_LIST_DIR}/esptool/espefuse.py")
set(ESPFLASHMODE ${CONFIG_ESPTOOLPY_FLASHMODE})
set(ESPFLASHFREQ ${CONFIG_ESPTOOLPY_FLASHFREQ})
set(ESPFLASHSIZE ${CONFIG_ESPTOOLPY_FLASHSIZE})
set(ESPTOOLPY_BEFORE "${CONFIG_ESPTOOLPY_BEFORE}")
set(ESPTOOLPY_AFTER "${CONFIG_ESPTOOLPY_AFTER}")
set(ESPTOOLPY_CHIP "${target}")
set(ESPTOOLPY_WITH_STUB TRUE)
if(CONFIG_SECURE_BOOT_ENABLED OR CONFIG_SECURE_FLASH_ENC_ENABLED)
# If security enabled then override post flash option
set(ESPTOOLPY_AFTER "no_reset")
endif()
set(ESPTOOLPY_SERIAL "${ESPTOOLPY}"
--port "${ESPPORT}"
--baud ${ESPBAUD}
--before "${ESPTOOLPY_BEFORE}"
--after "${ESPTOOLPY_AFTER}"
)
if(CONFIG_ESPTOOLPY_COMPRESSED)
set(ESPTOOLPY_COMPRESSED_OPT -z)
else()
set(ESPTOOLPY_COMPRESSED_OPT -u)
endif()
set(ESPTOOLPY_FLASH_OPTIONS
--flash_mode ${ESPFLASHMODE}
--flash_freq ${ESPFLASHFREQ}
--flash_size ${ESPFLASHSIZE}
)
# String for printing flash command
string(REPLACE ";" " " ESPTOOLPY_WRITE_FLASH_STR
"${ESPTOOLPY} --port (PORT) --baud (BAUD) --before ${ESPTOOLPY_BEFORE} --after ${ESPTOOLPY_AFTER} "
"write_flash ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_EXTRA_FLASH_OPTIONS} ${ESPTOOLPY_COMPRESSED_OPT}")
if(NOT BOOTLOADER_BUILD)
set(ESPTOOLPY_ELF2IMAGE_OPTIONS --elf-sha256-offset 0xb0)
set(esptool_elf2image_args --elf-sha256-offset 0xb0)
endif()
if(CONFIG_SECURE_BOOT_ENABLED AND
NOT CONFIG_SECURE_BOOT_ALLOW_SHORT_APP_PARTITION
AND NOT BOOTLOADER_BUILD)
set(ESPTOOLPY_ELF2IMAGE_OPTIONS ${ESPTOOLPY_ELF2IMAGE_OPTIONS} --secure-pad)
list(APPEND esptool_elf2image_args --secure-pad)
endif()
if(CONFIG_ESP32_REV_MIN)
set(ESPTOOLPY_ELF2IMAGE_OPTIONS ${ESPTOOLPY_ELF2IMAGE_OPTIONS} --min-rev ${CONFIG_ESP32_REV_MIN})
list(APPEND esptool_elf2image_args --min-rev ${CONFIG_ESP32_REV_MIN})
endif()
if(CONFIG_ESPTOOLPY_FLASHSIZE_DETECT)
@ -83,7 +46,7 @@ set(PROJECT_BIN "${elf_name}.bin")
#
if(CONFIG_APP_BUILD_GENERATE_BINARIES)
add_custom_command(OUTPUT "${build_dir}/.bin_timestamp"
COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${ESPTOOLPY_ELF2IMAGE_OPTIONS}
COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_FLASH_OPTIONS} ${esptool_elf2image_args}
-o "${build_dir}/${unsigned_project_binary}" "${elf}"
COMMAND ${CMAKE_COMMAND} -E echo "Generated ${build_dir}/${unsigned_project_binary}"
COMMAND ${CMAKE_COMMAND} -E md5sum "${build_dir}/${unsigned_project_binary}" > "${build_dir}/.bin_timestamp"
@ -135,24 +98,6 @@ if(NOT BOOTLOADER_BUILD AND CONFIG_SECURE_SIGNED_APPS)
endif()
endif()
#
# Add 'flash' target - not all build systems can run this directly
#
function(esptool_py_custom_target target_name flasher_filename dependencies)
idf_build_get_property(idf_path IDF_PATH)
idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR)
add_custom_target(${target_name} DEPENDS ${dependencies}
COMMAND ${CMAKE_COMMAND}
-D IDF_PATH="${idf_path}"
-D ESPTOOLPY="${ESPTOOLPY}"
-D ESPTOOL_ARGS="write_flash;@flash_${flasher_filename}_args"
-D WORKING_DIRECTORY="${build_dir}"
-P ${esptool_py_dir}/run_esptool.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
USES_TERMINAL
)
endfunction()
add_custom_target(erase_flash
COMMAND ${CMAKE_COMMAND}
-D IDF_PATH="${idf_path}"
@ -174,69 +119,128 @@ add_custom_target(monitor
USES_TERMINAL
)
esptool_py_custom_target(flash project "app;partition_table;bootloader")
esptool_py_custom_target(app-flash app "app")
set(esptool_flash_main_args "--before=${CONFIG_ESPTOOLPY_BEFORE}")
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")
if(CONFIG_SECURE_BOOT_ENABLED OR CONFIG_SECURE_FLASH_ENC_ENABLED)
# If security enabled then override post flash option
list(APPEND esptool_flash_main_args "--after=no_reset")
else()
list(APPEND esptool_flash_main_args "--after=${CONFIG_ESPTOOLPY_AFTER}")
endif()
# esptool_py_flash_project_args
#
# Add file to the flasher args list, to be flashed at a particular offset.
#
# When a template FLASH_FILE_TEMPLATE is given, the variables OFFSET and IMAGE
# hold the value of arguments offset and image, respectively.
function(esptool_py_flash_project_args entry offset image)
set(options FLASH_IN_PROJECT) # flash the image when flashing the project
set(single_value FLASH_FILE_TEMPLATE) # template file to use to be able to
# flash the image individually using esptool
cmake_parse_arguments(_ "${options}" "${single_value}" "" "${ARGN}")
set(esptool_flash_sub_args "--flash_mode=${CONFIG_ESPTOOLPY_FLASHMODE}"
"--flash_freq=${CONFIG_ESPTOOLPY_FLASHFREQ}"
"--flash_size=${CONFIG_ESPTOOLPY_FLASHSIZE}")
if(${entry} IN_LIST flash_project_entries)
message(FATAL_ERROR "entry '${entry}' has already been added to flash project entries")
endif()
idf_component_set_property(esptool_py FLASH_PROJECT_ENTRIES "${entry}" APPEND)
idf_component_set_property(esptool_py FLASH_ARGS "${esptool_flash_main_args}")
idf_component_set_property(esptool_py FLASH_SUB_ARGS "${esptool_flash_sub_args}")
function(esptool_py_flash_target_image target_name image_name offset image)
idf_build_get_property(build_dir BUILD_DIR)
file(RELATIVE_PATH image ${build_dir} ${image})
# Generate the standalone flash file to flash the image individually using esptool
set(entry_flash_args ${build_dir}/flash_${entry}_args)
if(NOT __FLASH_FILE_TEMPLATE)
file(GENERATE OUTPUT ${entry_flash_args} CONTENT "${offset} ${image}")
else()
set(OFFSET ${offset})
set(IMAGE ${image})
set_property(TARGET ${target_name} APPEND PROPERTY FLASH_FILE
"\"${offset}\" : \"${image}\"")
set_property(TARGET ${target_name} APPEND PROPERTY FLASH_ENTRY
"\"${image_name}\" : { \"offset\" : \"${offset}\", \"file\" : \"${image}\" }")
set_property(TARGET ${target_name} APPEND PROPERTY IMAGES "${offset} ${image}")
get_filename_component(template_in "${__FLASH_FILE_TEMPLATE}" ABSOLUTE)
get_filename_component(template_name "${template_in}" NAME)
set(template_partial "${CMAKE_CURRENT_BINARY_DIR}/${template_name}.in2")
configure_file("${template_in}" "${template_partial}")
file(GENERATE OUTPUT ${entry_flash_args} INPUT "${template_partial}")
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
APPEND PROPERTY
ADDITIONAL_MAKE_CLEAN_FILES "${template_partial}")
unset(OFFSET)
unset(IMAGE)
endif()
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${entry_flash_args})
# Generate standalone entries in the flasher args json file
idf_component_set_property(esptool_py FLASH_PROJECT_ARGS_ENTRY_JSON
"\"${entry}\" : { \"offset\" : \"${offset}\", \"file\" : \"${image}\" }" APPEND)
# Generate entries in the flasher args json file
if(__FLASH_IN_PROJECT)
idf_component_set_property(esptool_py FLASH_PROJECT_ARGS
"${offset} ${image}" APPEND)
idf_component_set_property(esptool_py FLASH_PROJECT_ARGS_JSON
"\"${offset}\" : \"${image}\"" APPEND)
if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT)
set_property(TARGET encrypted-${target_name} APPEND PROPERTY FLASH_FILE
"\"${offset}\" : \"${image}\"")
set_property(TARGET encrypted-${target_name} APPEND PROPERTY FLASH_ENTRY
"\"${image_name}\" : { \"offset\" : \"${offset}\", \"file\" : \"${image}\" }")
set_property(TARGET encrypted-${target_name} APPEND PROPERTY IMAGES "${offset} ${image}")
endif()
endfunction()
function(esptool_py_flash_target target_name main_args sub_args)
set(single_value OFFSET IMAGE) # template file to use to be able to
# flash the image individually using esptool
cmake_parse_arguments(_ "" "${single_value}" "" "${ARGN}")
idf_build_get_property(idf_path IDF_PATH)
idf_build_get_property(build_dir BUILD_DIR)
idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR)
add_custom_target(${target_name}
COMMAND ${CMAKE_COMMAND}
-D IDF_PATH="${idf_path}"
-D ESPTOOLPY="${ESPTOOLPY}"
-D ESPTOOL_ARGS="${main_args};write_flash;@${target_name}_args"
-D WORKING_DIRECTORY="${build_dir}"
-P ${esptool_py_dir}/run_esptool.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
USES_TERMINAL
)
set_target_properties(${target_name} PROPERTIES SUB_ARGS "${sub_args}")
set(flash_args_content "$<JOIN:$<TARGET_PROPERTY:${target_name},SUB_ARGS>, >\n\
$<JOIN:$<TARGET_PROPERTY:${target_name},IMAGES>,\n>")
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${target_name}_args.in"
CONTENT "${flash_args_content}")
file(GENERATE OUTPUT "${build_dir}/${target_name}_args"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/${target_name}_args.in")
if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT)
add_custom_target(encrypted-${target_name}
COMMAND ${CMAKE_COMMAND}
-D IDF_PATH="${idf_path}"
-D ESPTOOLPY="${ESPTOOLPY}"
-D ESPTOOL_ARGS="${main_args};write_flash;@encrypted_${target_name}_args"
-D WORKING_DIRECTORY="${build_dir}"
-P ${esptool_py_dir}/run_esptool.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
USES_TERMINAL
)
set_target_properties(encrypted-${target_name} PROPERTIES SUB_ARGS "${sub_args};--encrypt")
set(flash_args_content "$<JOIN:$<TARGET_PROPERTY:encrypted-${target_name},SUB_ARGS>, >\n\
$<JOIN:$<TARGET_PROPERTY:encrypted-${target_name},IMAGES>,\n>")
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/encrypted_${target_name}_args.in"
CONTENT "${flash_args_content}")
file(GENERATE OUTPUT "${build_dir}/encrypted_${target_name}_args"
INPUT "${CMAKE_CURRENT_BINARY_DIR}/encrypted_${target_name}_args.in")
endif()
endfunction()
function(esptool_py_custom_target target_name flasher_filename dependencies)
idf_component_get_property(main_args esptool_py FLASH_ARGS)
idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
idf_build_get_property(build_dir BUILD_DIR)
esptool_py_flash_target(${target_name} "${main_args}" "${sub_args}")
# Copy the file to flash_xxx_args for compatibility for select target
file_generate("${build_dir}/flash_${flasher_filename}_args"
INPUT "${build_dir}/${target_name}_args")
add_dependencies(${target_name} ${dependencies})
if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT)
file_generate("${build_dir}/flash_encrypted_${flasher_filename}_args"
INPUT "${build_dir}/encrypted_${target_name}_args")
add_dependencies(encrypted-${target_name} ${dependencies})
endif()
endfunction()
if(NOT BOOTLOADER_BUILD)
set(flash_deps "partition_table")
if(CONFIG_APP_BUILD_GENERATE_BINARIES)
list(APPEND flash_deps "app")
endif()
if(CONFIG_APP_BUILD_BOOTLOADER)
list(APPEND flash_deps "bootloader")
endif()
esptool_py_custom_target(flash project "${flash_deps}")
endif()

View file

@ -74,11 +74,12 @@ if(CONFIG_SECURE_SIGNED_APPS)
endif()
endif()
# Use global properties ESPTOOL_WRITE_FLASH_ARGS to pass this info to build
# the list of esptool write arguments for flashing
set_property(GLOBAL APPEND_STRING PROPERTY
ESPTOOL_WRITE_FLASH_ARGS
"${PARTITION_TABLE_OFFSET} ${build_dir}/partition_table/${final_partition_bin} ")
idf_component_get_property(main_args esptool_py FLASH_ARGS)
idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
esptool_py_flash_target(partition_table-flash "${main_args}" "${sub_args}")
esptool_py_flash_target_image(partition_table-flash partition_table "${PARTITION_TABLE_OFFSET}"
"${build_dir}/partition_table/partition-table.bin")
esptool_py_flash_target_image(flash partition_table "${PARTITION_TABLE_OFFSET}"
"${build_dir}/partition_table/partition-table.bin")
esptool_py_flash_project_args(partition_table ${PARTITION_TABLE_OFFSET}
${build_dir}/partition_table/partition-table.bin FLASH_IN_PROJECT)

View file

@ -47,10 +47,14 @@ function(spiffs_create_partition_image partition base_dir)
ADDITIONAL_MAKE_CLEAN_FILES
${image_file})
idf_component_get_property(main_args esptool_py FLASH_ARGS)
idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
esptool_py_flash_target(${partition}-flash "${main_args}" "${sub_args}")
esptool_py_flash_target_image(${partition}-flash "${partition}" "${offset}" "${image_file}")
if(arg_FLASH_IN_PROJECT)
esptool_py_flash_project_args("${partition}" "${offset}" "${image_file}" FLASH_IN_PROJECT)
else()
esptool_py_flash_project_args("${partition}" "${offset}" "${image_file}")
esptool_py_flash_target_image(flash "${partition}" "${offset}" "${image_file}")
endif()
else()
set(message "Failed to create SPIFFS image for partition '${partition}'. "

View file

@ -260,6 +260,9 @@ function(add_c_compile_options)
endfunction()
# add_prebuild_library
#
# Add prebuilt library with support for adding dependencies on ESP-IDF components.
function(add_prebuilt_library target_name lib_path)
cmake_parse_arguments(_ "" "" "REQUIRES;PRIV_REQUIRES" ${ARGN})
@ -280,4 +283,23 @@ function(add_prebuilt_library target_name lib_path)
set_property(TARGET ${target_name} APPEND PROPERTY LINK_LIBRARIES "${req_lib}")
set_property(TARGET ${target_name} APPEND PROPERTY INTERFACE_LINK_LIBRARIES "$<LINK_ONLY:${req_lib}>")
endforeach()
endfunction()
# file_generate
#
# Utility to generate file and have the output automatically added to cleaned files.
function(file_generate output)
cmake_parse_arguments(_ "" "INPUT;CONTENT" "" ${ARGN})
if(__INPUT)
file(GENERATE OUTPUT "${output}" INPUT "${__INPUT}")
elseif(__CONTENT)
file(GENERATE OUTPUT "${output}" CONTENT "${__CONTENT}")
else()
message(FATAL_ERROR "Content to generate not specified.")
endif()
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${output}")
endfunction()

View file

@ -8,17 +8,10 @@ import click
from idf_py_actions.constants import GENERATORS, SUPPORTED_TARGETS
from idf_py_actions.errors import FatalError
from idf_py_actions.global_options import global_options
from idf_py_actions.tools import ensure_build_directory, idf_version, merge_action_lists, realpath, run_tool
from idf_py_actions.tools import ensure_build_directory, idf_version, merge_action_lists, realpath, run_target
def action_extensions(base_actions, project_path):
def run_target(target_name, args):
generator_cmd = GENERATORS[args.generator]["command"]
if args.verbose:
generator_cmd += [GENERATORS[args.generator]["verbose_flag"]]
run_tool(generator_cmd[0], generator_cmd + [target_name], args.build_dir)
def build_target(target_name, ctx, args):
"""

View file

@ -4,7 +4,7 @@ import sys
from idf_py_actions.errors import FatalError
from idf_py_actions.global_options import global_options
from idf_py_actions.tools import ensure_build_directory, run_tool
from idf_py_actions.tools import ensure_build_directory, run_tool, run_target
PYTHON = sys.executable
@ -99,18 +99,11 @@ def action_extensions(base_actions, project_path):
"""
Run esptool to flash the entire project, from an argfile generated by the build system
"""
flasher_args_path = {
# action -> name of flasher args file generated by build system
"bootloader-flash": "flash_bootloader_args",
"partition_table-flash": "flash_partition_table_args",
"app-flash": "flash_app_args",
"flash": "flash_project_args",
"encrypted-app-flash": "flash_encrypted_app_args",
"encrypted-flash": "flash_encrypted_project_args",
}[action]
esptool_args = _get_esptool_args(args)
esptool_args += ["write_flash", "@" + flasher_args_path]
run_tool("esptool.py", esptool_args, args.build_dir)
if args.port is None:
args.port = _get_default_serial_port()
run_target(action, args, {"ESPPORT": args.port,
"ESPBAUD": str(args.baud)})
def erase_flash(action, ctx, args):
esptool_args = _get_esptool_args(args)

View file

@ -63,7 +63,7 @@ def idf_version():
return version
def run_tool(tool_name, args, cwd):
def run_tool(tool_name, args, cwd, env=dict()):
def quote_arg(arg):
" Quote 'arg' if necessary "
if " " in arg and not (arg.startswith('"') or arg.startswith("'")):
@ -73,13 +73,26 @@ def run_tool(tool_name, args, cwd):
display_args = " ".join(quote_arg(arg) for arg in args)
print("Running %s in directory %s" % (tool_name, quote_arg(cwd)))
print('Executing "%s"...' % str(display_args))
env_copy = dict(os.environ)
env_copy.update(env)
try:
# Note: we explicitly pass in os.environ here, as we may have set IDF_PATH there during startup
subprocess.check_call(args, env=os.environ, cwd=cwd)
subprocess.check_call(args, env=env_copy, cwd=cwd)
except subprocess.CalledProcessError as e:
raise FatalError("%s failed with exit code %d" % (tool_name, e.returncode))
def run_target(target_name, args, env=dict()):
generator_cmd = GENERATORS[args.generator]["command"]
if args.verbose:
generator_cmd += [GENERATORS[args.generator]["verbose_flag"]]
run_tool(generator_cmd[0], generator_cmd + [target_name], args.build_dir, env)
def _strip_quotes(value, regexp=re.compile(r"^\"(.*)\"$|^'(.*)'$|^(.*)$")):
"""
Strip quotes like CMake does during parsing cache entries