2018-01-18 23:47:49 -05:00
|
|
|
# Set some global esptool.py variables
|
2018-01-23 01:08:28 -05:00
|
|
|
#
|
|
|
|
# Many of these are read when generating flash_app_args & flash_project_args
|
2018-01-18 23:47:49 -05:00
|
|
|
set(ESPTOOLPY "${PYTHON}" "${CMAKE_CURRENT_LIST_DIR}/esptool/esptool.py" --chip esp32)
|
|
|
|
set(ESPSECUREPY "${PYTHON}" "${CMAKE_CURRENT_LIST_DIR}/esptool/espsecure.py")
|
|
|
|
|
|
|
|
set(ESPFLASHMODE ${CONFIG_ESPTOOLPY_FLASHMODE})
|
|
|
|
set(ESPFLASHFREQ ${CONFIG_ESPTOOLPY_FLASHFREQ})
|
|
|
|
set(ESPFLASHSIZE ${CONFIG_ESPTOOLPY_FLASHSIZE})
|
|
|
|
|
|
|
|
set(ESPTOOLPY_SERIAL "${ESPTOOLPY}" --port "${ESPPORT}" --baud ${ESPBAUD})
|
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
set(ESPTOOLPY_ELF2IMAGE_FLASH_OPTIONS
|
|
|
|
--flash_mode ${ESPFLASHMODE}
|
|
|
|
--flash_freq ${ESPFLASHFREQ}
|
|
|
|
--flash_size ${ESPFLASHSIZE}
|
|
|
|
)
|
2018-01-18 23:47:49 -05:00
|
|
|
|
2019-09-18 01:25:50 -04:00
|
|
|
if(CONFIG_ESP32_REV_MIN)
|
|
|
|
set(ESPTOOLPY_ELF2IMAGE_OPTIONS ${ESPTOOLPY_ELF2IMAGE_OPTIONS} --min-rev ${CONFIG_ESP32_REV_MIN})
|
|
|
|
endif()
|
|
|
|
|
2018-01-23 01:08:28 -05:00
|
|
|
if(CONFIG_ESPTOOLPY_FLASHSIZE_DETECT)
|
2018-02-26 23:45:30 -05:00
|
|
|
# Set ESPFLASHSIZE to 'detect' *after* elf2image options are generated,
|
|
|
|
# as elf2image can't have 'detect' as an option...
|
|
|
|
set(ESPFLASHSIZE detect)
|
2018-01-23 01:08:28 -05:00
|
|
|
endif()
|
2018-01-18 23:47:49 -05:00
|
|
|
|
2018-01-23 01:08:28 -05:00
|
|
|
# Set variables if the PHY data partition is in the flash
|
2018-02-26 23:45:30 -05:00
|
|
|
if(CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION)
|
|
|
|
set(PHY_PARTITION_OFFSET ${CONFIG_PHY_DATA_OFFSET})
|
|
|
|
set(PHY_PARTITION_BIN_FILE "esp32/phy_init_data.bin")
|
2018-01-23 01:08:28 -05:00
|
|
|
endif()
|
2018-01-18 23:47:49 -05:00
|
|
|
|
|
|
|
#
|
2018-01-23 01:08:28 -05:00
|
|
|
# Add 'app.bin' target - generates with elf2image
|
2018-01-18 23:47:49 -05:00
|
|
|
#
|
|
|
|
add_custom_command(OUTPUT "${PROJECT_NAME}.bin"
|
2018-02-26 23:45:30 -05:00
|
|
|
COMMAND ${ESPTOOLPY} elf2image ${ESPTOOLPY_ELF2IMAGE_FLASH_OPTIONS} -o "${PROJECT_NAME}.bin" "${PROJECT_NAME}.elf"
|
|
|
|
DEPENDS ${PROJECT_NAME}.elf
|
|
|
|
VERBATIM
|
|
|
|
)
|
2018-01-23 01:08:28 -05:00
|
|
|
add_custom_target(app ALL DEPENDS "${PROJECT_NAME}.bin")
|
2018-01-18 23:47:49 -05:00
|
|
|
|
|
|
|
#
|
|
|
|
# Add 'flash' target - not all build systems can run this directly
|
|
|
|
#
|
2018-01-23 01:08:28 -05:00
|
|
|
function(esptool_py_custom_target target_name flasher_filename dependencies)
|
2018-02-26 23:45:30 -05:00
|
|
|
add_custom_target(${target_name} DEPENDS ${dependencies}
|
2018-09-13 00:13:20 -04:00
|
|
|
COMMAND ${CMAKE_COMMAND}
|
|
|
|
-D IDF_PATH="${IDF_PATH}"
|
|
|
|
-D ESPTOOLPY="${ESPTOOLPY}"
|
|
|
|
-D ESPTOOL_ARGS="write_flash;@flash_${flasher_filename}_args"
|
|
|
|
-D ESPTOOL_WORKING_DIR="${CMAKE_CURRENT_BINARY_DIR}"
|
2019-12-04 08:13:48 -05:00
|
|
|
-P ${IDF_PATH}/components/esptool_py/run_esptool.cmake
|
2018-09-13 00:13:20 -04:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
|
|
|
USES_TERMINAL
|
2018-02-26 23:45:30 -05:00
|
|
|
)
|
2018-01-23 01:08:28 -05:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
esptool_py_custom_target(flash project "app;partition_table;bootloader")
|
|
|
|
esptool_py_custom_target(app-flash app "app")
|
|
|
|
esptool_py_custom_target(bootloader-flash bootloader "bootloader")
|