mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-03 19:41:55 +02:00
esptool_py: Adds funcs to read eFuses from Cmake during a build stage
Closes https://github.com/espressif/esp-idf/issues/10311
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
# Executes a espefuse.py command and returns a cleaned log
|
||||
function(espefuse_cmd cmd output_log)
|
||||
set(SERIAL_TOOL ${ESPEFUSEPY})
|
||||
if(${ESPEFUSEPY_OFFLINE})
|
||||
set(VIRT_OPTION "--virt")
|
||||
endif()
|
||||
set(SERIAL_TOOL_ARGS ${VIRT_OPTION} "--chip;${IDF_TARGET};${cmd}")
|
||||
set(SERIAL_TOOL_SILENT 1)
|
||||
include(${esptool_py_dir}/run_serial_tool.cmake)
|
||||
set(log ${SERIAL_TOOL_OUTPUT_LOG})
|
||||
|
||||
set(prefix_str " command ===")
|
||||
string(FIND ${log} ${prefix_str} pos)
|
||||
if(${pos} GREATER -1)
|
||||
string(LENGTH ${prefix_str} len_of_prefix_str)
|
||||
math(EXPR pos "${pos} + ${len_of_prefix_str}")
|
||||
string(SUBSTRING ${log} ${pos} -1 final_log)
|
||||
else()
|
||||
set(final_log ${log})
|
||||
endif()
|
||||
|
||||
set(${output_log} ${final_log} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Reads efuses "espefuse.py summary" and returns JSON string
|
||||
function(espefuse_get_json_summary json_str)
|
||||
espefuse_cmd("summary;--format;json" output_log)
|
||||
set(${json_str} ${output_log} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# See the esp-idf/docs/en/api-reference/system/efuse.rst "Get eFuses During Build".
|
||||
#
|
||||
# It takes the efuse json string and returns a value of property for a given efuse name
|
||||
function(espefuse_get_efuse result efuse_json efuse_name efuse_property)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.19.0")
|
||||
string(REGEX MATCH "\"${efuse_name}\":[ \t\n\r]*\{[^\}]*\}" cur_efuse ${efuse_json})
|
||||
string(REGEX MATCH "\"${efuse_property}\":[ \t\n\r]*\"?([^,\"]*)\"?," ret_value ${cur_efuse})
|
||||
set(${result} ${CMAKE_MATCH_1} PARENT_SCOPE)
|
||||
else()
|
||||
# The JSON feature has been supported by Cmake since 3.19.0
|
||||
string(JSON cur_efuse GET ${efuse_json} ${efuse_name})
|
||||
string(JSON ret_value GET ${cur_efuse} ${efuse_property})
|
||||
set(${result} ${ret_value} PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -494,3 +494,7 @@ if(NOT BOOTLOADER_BUILD)
|
||||
|
||||
esptool_py_custom_target(flash project "${flash_deps}")
|
||||
endif()
|
||||
|
||||
# Adds espefuse functions for global use
|
||||
idf_component_get_property(esptool_py_dir esptool_py COMPONENT_DIR)
|
||||
include(${esptool_py_dir}/espefuse.cmake)
|
||||
|
||||
@@ -45,12 +45,20 @@ endif()
|
||||
|
||||
list(APPEND serial_tool_cmd ${SERIAL_TOOL_ARGS})
|
||||
|
||||
execute_process(COMMAND ${serial_tool_cmd}
|
||||
WORKING_DIRECTORY "${WORKING_DIRECTORY}"
|
||||
RESULT_VARIABLE result
|
||||
if(${SERIAL_TOOL_SILENT})
|
||||
execute_process(COMMAND ${serial_tool_cmd}
|
||||
WORKING_DIRECTORY "${WORKING_DIRECTORY}"
|
||||
RESULT_VARIABLE result
|
||||
OUTPUT_VARIABLE SERIAL_TOOL_OUTPUT_LOG
|
||||
)
|
||||
else()
|
||||
execute_process(COMMAND ${serial_tool_cmd}
|
||||
WORKING_DIRECTORY "${WORKING_DIRECTORY}"
|
||||
RESULT_VARIABLE result
|
||||
)
|
||||
endif()
|
||||
|
||||
if(${result})
|
||||
# No way to have CMake silently fail, unfortunately
|
||||
message(FATAL_ERROR "${SERIAL_TOOL} failed")
|
||||
message(FATAL_ERROR "${SERIAL_TOOL} failed. \n${SERIAL_TOOL_OUTPUT_LOG}")
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user