zephyr/cmake/flash/CMakeLists.txt
Sebastian Bøe f0346bfac0 flash: Change type of FLASH_SCRIPT_ENV_VARS
The old way of constructing FLASH_SCRIPT_ENV_VARS was corrupting the
values that were passed to the flasher. This new method is the
standard way of creating a dictionary/hashmap in CMake and does not
suffer from the same problem.

This fixes
https://github.com/zephyrproject-rtos/zephyr/issues/4844#event-1334599401

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-10 07:54:54 -05:00

65 lines
1.7 KiB
CMake

get_property(ENV_VARS GLOBAL PROPERTY FLASH_SCRIPT_ENV_VARS)
set(ENV_VARS_FORMATTED "")
foreach(env_var ${ENV_VARS})
list(APPEND ENV_VARS_FORMATTED
${env_var}=${${env_var}}
)
endforeach()
list(APPEND ENV_VARS_FORMATTED
O=${PROJECT_BINARY_DIR}
KERNEL_ELF_NAME=${KERNEL_ELF_NAME}
KERNEL_HEX_NAME=${KERNEL_HEX_NAME}
KERNEL_BIN_NAME=${KERNEL_BIN_NAME}
ARCH=${ARCH}
BOARD_NAME=${BOARD}
GDB=${CMAKE_GDB}
OPENOCD_DEFAULT_PATH=${OPENOCD_DEFAULT_PATH}
OPENOCD=${OPENOCD}
)
foreach(target flash debug debugserver)
if(target STREQUAL flash)
set(comment "Flashing ${BOARD}")
set(script ${FLASH_SCRIPT})
elseif(target STREQUAL debug)
set(comment "Debugging ${BOARD}")
set(script ${DEBUG_SCRIPT})
elseif(target STREQUAL debugserver)
set(comment "Debugging ${BOARD}")
set(script ${DEBUG_SCRIPT})
if(EMU_PLATFORM)
# cmake/qemu/CMakeLists.txt will add a debugserver target for
# emulation platforms, so we don't add one here
continue()
endif()
endif()
if(script)
set(cmd
${CMAKE_COMMAND} -E env
${ENV_VARS_FORMATTED}
${PYTHON_EXECUTABLE}
$ENV{ZEPHYR_BASE}/scripts/support/zephyr_flash_debug.py
${target}
$ENV{ZEPHYR_BASE}/scripts/support/${script}
DEPENDS ${logical_target_for_zephyr_elf}
WORKING_DIRECTORY ${APPLICATION_BINARY_DIR}
)
else()
set(cmd
${CMAKE_COMMAND} -E echo
"'${target}' is not supported with this board."
"Please check the documentation for alternate instructions."
)
endif()
add_custom_target(${target}
COMMAND
${cmd}
COMMENT
${comment}
)
endforeach()