2023-01-04 00:30:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								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 ===")
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-30 10:55:27 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    string(FIND "${log}" ${prefix_str} pos)
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-04 00:30:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if(${pos} GREATER -1)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        string(LENGTH ${prefix_str} len_of_prefix_str)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        math(EXPR pos "${pos} + ${len_of_prefix_str}")
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-30 10:55:27 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        string(SUBSTRING "${log}" ${pos} -1 final_log)
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-04 00:30:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    else()
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-30 10:55:27 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        set(final_log "${log}")
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-04 00:30:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    endif()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-30 10:55:27 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    set(${output_log} "${final_log}" PARENT_SCOPE)
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-04 00:30:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								endfunction()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# Reads efuses "espefuse.py summary" and returns JSON string
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								function(espefuse_get_json_summary json_str)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    espefuse_cmd("summary;--format;json" output_log)
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-30 10:55:27 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    set(${json_str} "${output_log}" PARENT_SCOPE)
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-04 00:30:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								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")
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-30 10:55:27 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        string(REGEX MATCH "\"${efuse_name}\":[ \t\n\r]*\{[^\}]*\}" cur_efuse "${efuse_json}")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        string(REGEX MATCH "\"${efuse_property}\":[ \t\n\r]*\"?([^,\"]*)\"?," ret_value "${cur_efuse}")
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-04 00:30:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        set(${result} ${CMAKE_MATCH_1} PARENT_SCOPE)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    else()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        # The JSON feature has been supported by Cmake since 3.19.0
							 | 
						
					
						
							
								
									
										
										
										
											2023-05-30 10:55:27 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        string(JSON cur_efuse GET "${efuse_json}" ${efuse_name})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        string(JSON ret_value GET "${cur_efuse}" ${efuse_property})
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-04 00:30:38 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        set(${result} ${ret_value} PARENT_SCOPE)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    endif()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								endfunction()
							 |