esptool_py: use passed offset and image when template is given

esptool_py defines command `esptool_py_flash_project_args` that
generates arg file for esptool.py. Two of the arguments are the offset
and image, which are not being used when a template file is given.
This commit makes variables OFFSET and IMAGE available to the template
file, which will holds the value of the offset and image arguments to
`esptool_py_flash_project_args`.
This commit is contained in:
Renz Christian Bagaporo 2019-06-21 19:48:41 +08:00
parent d1da76e369
commit e8582e9aa4
3 changed files with 15 additions and 5 deletions

View file

@ -7,8 +7,7 @@ endif()
# Set values used in flash_bootloader_args.in and generate flash file
# for bootloader
set(BOOTLOADER_OFFSET 0x1000)
esptool_py_flash_project_args(bootloader ${BOOTLOADER_OFFSET}
esptool_py_flash_project_args(bootloader 0x1000
${BOOTLOADER_BUILD_DIR}/bootloader.bin
FLASH_IN_PROJECT
FLASH_FILE_TEMPLATE flash_bootloader_args.in)

View file

@ -1,4 +1,4 @@
--flash_mode ${ESPFLASHMODE}
--flash_size ${ESPFLASHSIZE}
--flash_freq ${ESPFLASHFREQ}
${BOOTLOADER_OFFSET} bootloader/bootloader.bin
${OFFSET} ${IMAGE}

View file

@ -148,7 +148,10 @@ add_custom_target(flash_project_args_target)
# esptool_py_flash_project_args
#
# Add file to the flasher args list, to be flashed at a particular offset
# 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
@ -172,8 +175,16 @@ function(esptool_py_flash_project_args entry offset image)
if(NOT __FLASH_FILE_TEMPLATE)
file(GENERATE OUTPUT ${entry_flash_args} CONTENT "${offset} ${image}")
else()
set(OFFSET ${offset})
set(IMAGE ${image})
get_filename_component(template "${__FLASH_FILE_TEMPLATE}" ABSOLUTE)
file(GENERATE OUTPUT ${entry_flash_args} INPUT ${template})
configure_file(${template} ${CMAKE_CURRENT_BINARY_DIR}/${template}.in2)
file(GENERATE OUTPUT ${entry_flash_args} INPUT ${CMAKE_CURRENT_BINARY_DIR}/${template}.in2)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
APPEND PROPERTY
ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/${template}.in2})
unset(OFFSET)
unset(IMAGE)
endif()
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}