Merge branch 'feature/support_serial_port_env_args_in_tools' into 'master'

Support port and baud env args for otatool targets

Closes IDFGH-3289

See merge request espressif/esp-idf!10812
pull/6416/head
Angus Gratton 2021-01-14 07:51:45 +08:00
commit 92ae75f955
8 zmienionych plików z 88 dodań i 82 usunięć

Wyświetl plik

@ -48,19 +48,32 @@ if(NOT BOOTLOADER_BUILD)
set(otatool_py ${python} ${COMPONENT_DIR}/otatool.py)
set(esptool_args --esptool-args before=${CONFIG_ESPTOOLPY_BEFORE} after=${CONFIG_ESPTOOLPY_AFTER})
set(esptool_args "--esptool-args;before=${CONFIG_ESPTOOLPY_BEFORE};after=${CONFIG_ESPTOOLPY_AFTER}")
set(otatool_args "--partition-table-file;${PARTITION_CSV_PATH}"
"--partition-table-offset;${PARTITION_TABLE_OFFSET}")
idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR)
add_custom_target(read_otadata DEPENDS "${PARTITION_CSV_PATH}"
COMMAND ${otatool_py} ${esptool_args}
--partition-table-file ${PARTITION_CSV_PATH}
--partition-table-offset ${PARTITION_TABLE_OFFSET}
read_otadata)
COMMAND ${CMAKE_COMMAND}
-D IDF_PATH="${idf_path}"
-D SERIAL_TOOL="${otatool_py}"
-D SERIAL_TOOL_ARGS="${esptool_args};${otatool_args};read_otadata"
-D WORKING_DIRECTORY="${build_dir}"
-P ${esptool_py_dir}/run_serial_tool.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
USES_TERMINAL
)
add_custom_target(erase_otadata DEPENDS "${PARTITION_CSV_PATH}"
COMMAND ${otatool_py} ${esptool_args}
--partition-table-file ${PARTITION_CSV_PATH}
--partition-table-offset ${PARTITION_TABLE_OFFSET}
erase_otadata)
COMMAND ${CMAKE_COMMAND}
-D IDF_PATH="${idf_path}"
-D SERIAL_TOOL="${otatool_py}"
-D SERIAL_TOOL_ARGS="${esptool_args};${otatool_args};erase_otadata"
-D WORKING_DIRECTORY="${build_dir}"
-P ${esptool_py_dir}/run_serial_tool.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
USES_TERMINAL
)
idf_component_get_property(main_args esptool_py FLASH_ARGS)
idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)

Wyświetl plik

@ -63,8 +63,6 @@ class OtatoolTarget():
self.target.read_partition(OtatoolTarget.OTADATA_PARTITION, temp_file.name)
with open(temp_file.name, "rb") as f:
self.otadata = f.read()
except Exception:
self.otadata = None
finally:
os.unlink(temp_file.name)

Wyświetl plik

@ -3,14 +3,15 @@
# without needing a CMake re-run)
set(ESPPORT $ENV{ESPPORT})
if(NOT ESPPORT)
message("Note: ${TOOL} will search for a serial port. To specify a port, set the ESPPORT environment variable.")
message("Note: ${SERIAL_TOOL} will search for a serial port. "
"To specify a port, set the ESPPORT environment variable.")
else()
set(port_arg "-p ${ESPPORT}")
endif()
set(ESPBAUD $ENV{ESPBAUD})
if(NOT ESPBAUD)
message("Note: ${TOOL} will attempt to set baud rate automatically. "
message("Note: ${SERIAL_TOOL} will attempt to set baud rate automatically. "
"To specify a baud rate, set the ESPBAUD environment variable.")
else()
set(baud_arg "-b ${ESPBAUD}")

Wyświetl plik

@ -133,9 +133,9 @@ endif()
add_custom_target(erase_flash
COMMAND ${CMAKE_COMMAND}
-D IDF_PATH="${idf_path}"
-D ESPTOOLPY="${ESPTOOLPY}"
-D ESPTOOL_ARGS="erase_flash"
-P run_esptool.cmake
-D SERIAL_TOOL="${ESPTOOLPY}"
-D SERIAL_TOOL_ARGS="erase_flash"
-P run_serial_tool.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
USES_TERMINAL
)
@ -143,10 +143,10 @@ add_custom_target(erase_flash
add_custom_target(monitor
COMMAND ${CMAKE_COMMAND}
-D IDF_PATH="${idf_path}"
-D IDF_MONITOR="${idf_path}/tools/idf_monitor.py"
-D ELF_FILE="${elf_dir}/${elf}"
-D SERIAL_TOOL="${idf_path}/tools/idf_monitor.py"
-D SERIAL_TOOL_ARGS="${elf_dir}/${elf}"
-D WORKING_DIRECTORY="${build_dir}"
-P run_idf_monitor.cmake
-P run_serial_tool.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
USES_TERMINAL
)
@ -332,10 +332,10 @@ function(esptool_py_flash_target target_name main_args sub_args)
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 SERIAL_TOOL="${ESPTOOLPY}"
-D SERIAL_TOOL_ARGS="${main_args};write_flash;@${target_name}_args"
-D WORKING_DIRECTORY="${build_dir}"
-P ${esptool_py_dir}/run_esptool.cmake
-P ${esptool_py_dir}/run_serial_tool.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
USES_TERMINAL
)
@ -373,10 +373,10 @@ $<JOIN:$<TARGET_PROPERTY:${target_name},IMAGES>,\n>")
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 SERIAL_TOOL="${ESPTOOLPY}"
-D SERIAL_TOOL_ARGS="${main_args};write_flash;@encrypted_${target_name}_args"
-D WORKING_DIRECTORY="${build_dir}"
-P ${esptool_py_dir}/run_esptool.cmake
-P ${esptool_py_dir}/run_serial_tool.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
USES_TERMINAL
)

Wyświetl plik

@ -1,15 +0,0 @@
if(NOT IDF_PATH)
message(FATAL_ERROR "IDF_PATH not set.")
endif()
include("${IDF_PATH}/tools/cmake/utilities.cmake")
spaces2list(CMD)
execute_process(COMMAND ${CMD}
WORKING_DIRECTORY "${WORKING_DIRECTORY}"
RESULT_VARIABLE result
)
if(${result})
# No way to have CMake silently fail, unfortunately
message(FATAL_ERROR "${TOOL} failed")
endif()

Wyświetl plik

@ -1,21 +0,0 @@
# A CMake script to run esptool commands from within ninja or make
# or another cmake-based build runner
#
# (Needed to expand environment variables, for backwards compatibility.)
#
# It is recommended to NOT USE this CMake script if you have the option of
# running esptool.py directly. This script exists only for use inside CMake builds.
#
cmake_minimum_required(VERSION 3.5)
set(TOOL "esptool.py")
if(NOT ESPTOOLPY OR NOT ESPTOOL_ARGS)
message(FATAL_ERROR "ESPTOOLPY and ESPTOOL_ARGS must "
"be specified on the CMake command line. For direct execution, it is "
"strongly recommended to run ${TOOL} directly.")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/get_port_args.cmake")
set(CMD "${ESPTOOLPY} ${port_arg} ${baud_arg} ${ESPTOOL_ARGS}")
include("${CMAKE_CURRENT_LIST_DIR}/run_cmd.cmake")

Wyświetl plik

@ -1,21 +0,0 @@
# A CMake script to run idf_monitor from within ninja or make
# or another cmake-based build runner
#
# (Needed to expand environment variables, for backwards compatibility.)
#
# It is recommended to NOT USE this CMake script if you have the option of
# running idf_monitor.py directly. This script exists only for use inside CMake builds.
#
cmake_minimum_required(VERSION 3.5)
set(TOOL "idf_monitor.py")
if(NOT IDF_MONITOR OR NOT ELF_FILE)
message(FATAL_ERROR "IDF_MONITOR and ELF_FILE must "
"be specified on the CMake command line. For direct execution, it is "
"strongly recommended to run ${TOOL} directly.")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/get_port_args.cmake")
set(CMD "${IDF_MONITOR} ${port_arg} ${baud_arg} ${ELF_FILE}")
include("${CMAKE_CURRENT_LIST_DIR}/run_cmd.cmake")

Wyświetl plik

@ -0,0 +1,51 @@
# A CMake script to run serial tool commands supporting ESPPORT and
# ESPBAUD environment variables from within ninja or make or another
# cmake-based build runner.
#
# It is recommended to NOT USE this CMake script if you have the option of
# running the tool directly. This script exists only for use inside CMake builds.
cmake_minimum_required(VERSION 3.5)
if(NOT IDF_PATH)
message(FATAL_ERROR "IDF_PATH not set.")
endif()
if(NOT SERIAL_TOOL OR NOT SERIAL_TOOL_ARGS)
message(FATAL_ERROR "SERIAL_TOOL and SERIAL_TOOL_ARGS must "
"be specified on the CMake command line. For direct execution, it is "
"strongly recommended to run ${SERIAL_TOOL} directly.")
endif()
# Main purpose of this script: we can't expand these environment variables in the main IDF CMake build,
# because we want to expand them at flashing time not at CMake runtime (so they can change
# without needing a CMake re-run)
set(ESPPORT $ENV{ESPPORT})
if(NOT ESPPORT)
message("Note: ${SERIAL_TOOL} will search for a serial port. "
"To specify a port, set the ESPPORT environment variable.")
else()
set(port_arg "-p ${ESPPORT}")
endif()
set(ESPBAUD $ENV{ESPBAUD})
if(NOT ESPBAUD)
message("Note: ${SERIAL_TOOL} will attempt to set baud rate automatically. "
"To specify a baud rate, set the ESPBAUD environment variable.")
else()
set(baud_arg "-b ${ESPBAUD}")
endif()
set(serial_tool_cmd "${SERIAL_TOOL} ${port_arg} ${baud_arg} ${SERIAL_TOOL_ARGS}")
include("${IDF_PATH}/tools/cmake/utilities.cmake")
spaces2list(serial_tool_cmd)
execute_process(COMMAND ${serial_tool_cmd}
WORKING_DIRECTORY "${WORKING_DIRECTORY}"
RESULT_VARIABLE result
)
if(${result})
# No way to have CMake silently fail, unfortunately
message(FATAL_ERROR "${SERIAL_TOOL} failed")
endif()