From 657cb626a49ac8885af3bbf55e27829287889c23 Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Tue, 4 Oct 2022 13:47:23 -0400 Subject: [PATCH] [nrfconnect] Make flashing_script hex selection reliable (#23003) When building via west build -b nrf52840dk_nrf52840 -t flashing_script the wrong hex file is flashed, and doesn't boot. We need to flash zephyr/merged.hex, not zephyr/zephyr.hex. The copy step attempts to do this, but does so incorrectly based upon a file existence test for which it has no declared dependency. This does not work reliably. It's a bit tricky to figure out which file we need to use, but for nRF Connect there is a global variable ${merged_hex_to_flash} that suffices. --- .../app/copy-flashbundle-firmware.cmake | 25 ------------------- config/nrfconnect/app/flashing.cmake | 11 +++++--- config/zephyr/app/flashing.cmake | 11 +++++--- 3 files changed, 16 insertions(+), 31 deletions(-) delete mode 100644 config/nrfconnect/app/copy-flashbundle-firmware.cmake diff --git a/config/nrfconnect/app/copy-flashbundle-firmware.cmake b/config/nrfconnect/app/copy-flashbundle-firmware.cmake deleted file mode 100644 index 93464f7aceb837..00000000000000 --- a/config/nrfconnect/app/copy-flashbundle-firmware.cmake +++ /dev/null @@ -1,25 +0,0 @@ -# -# Copyright (c) 2022 Project CHIP Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# Copy the merged.hex file if it exists, otherwise copy zephyr.hex - -set(HEX_NAME merged.hex) - -if(EXISTS "zephyr/${HEX_NAME}") - configure_file("zephyr/${HEX_NAME}" "${FLASHBUNDLE_FIRMWARE}" COPYONLY) -else() - configure_file("zephyr/${KERNEL_HEX_NAME}" "${FLASHBUNDLE_FIRMWARE}" COPYONLY) -endif() diff --git a/config/nrfconnect/app/flashing.cmake b/config/nrfconnect/app/flashing.cmake index b70e166ff28cfe..7937d99d887799 100644 --- a/config/nrfconnect/app/flashing.cmake +++ b/config/nrfconnect/app/flashing.cmake @@ -39,10 +39,15 @@ add_custom_command(OUTPUT "${FLASHBUNDLE_FLASHER_PLATFORM}" COMMAND ${CMAKE_COMMAND} ARGS -E copy "${PROJECT_SOURCE_DIR}/third_party/connectedhomeip/scripts/flashing/nrfconnect_firmware_utils.py" "${FLASHBUNDLE_FLASHER_PLATFORM}" VERBATIM) +if (merged_hex_to_flash) + set(flashbundle_hex_to_copy "${merged_hex_to_flash}") +else() + set(flashbundle_hex_to_copy "zephyr/${KERNEL_HEX_NAME}") +endif() + add_custom_command(OUTPUT "${FLASHBUNDLE_FIRMWARE}" - DEPENDS zephyr/${KERNEL_HEX_NAME} - COMMAND ${CMAKE_COMMAND} ARGS -DFLASHBUNDLE_FIRMWARE=${FLASHBUNDLE_FIRMWARE} -DKERNEL_HEX_NAME=${KERNEL_HEX_NAME} -P "${CHIP_ROOT}/config/nrfconnect/app/copy-flashbundle-firmware.cmake" - VERBATIM) + DEPENDS ${flashbundle_hex_to_copy} + COMMAND ${CMAKE_COMMAND} -E copy "${flashbundle_hex_to_copy}" "${FLASHBUNDLE_FIRMWARE}") add_custom_command(OUTPUT "${CMAKE_PROJECT_NAME}/${CMAKE_PROJECT_NAME}.flash.py" COMMAND ${python} diff --git a/config/zephyr/app/flashing.cmake b/config/zephyr/app/flashing.cmake index b70e166ff28cfe..7937d99d887799 100644 --- a/config/zephyr/app/flashing.cmake +++ b/config/zephyr/app/flashing.cmake @@ -39,10 +39,15 @@ add_custom_command(OUTPUT "${FLASHBUNDLE_FLASHER_PLATFORM}" COMMAND ${CMAKE_COMMAND} ARGS -E copy "${PROJECT_SOURCE_DIR}/third_party/connectedhomeip/scripts/flashing/nrfconnect_firmware_utils.py" "${FLASHBUNDLE_FLASHER_PLATFORM}" VERBATIM) +if (merged_hex_to_flash) + set(flashbundle_hex_to_copy "${merged_hex_to_flash}") +else() + set(flashbundle_hex_to_copy "zephyr/${KERNEL_HEX_NAME}") +endif() + add_custom_command(OUTPUT "${FLASHBUNDLE_FIRMWARE}" - DEPENDS zephyr/${KERNEL_HEX_NAME} - COMMAND ${CMAKE_COMMAND} ARGS -DFLASHBUNDLE_FIRMWARE=${FLASHBUNDLE_FIRMWARE} -DKERNEL_HEX_NAME=${KERNEL_HEX_NAME} -P "${CHIP_ROOT}/config/nrfconnect/app/copy-flashbundle-firmware.cmake" - VERBATIM) + DEPENDS ${flashbundle_hex_to_copy} + COMMAND ${CMAKE_COMMAND} -E copy "${flashbundle_hex_to_copy}" "${FLASHBUNDLE_FIRMWARE}") add_custom_command(OUTPUT "${CMAKE_PROJECT_NAME}/${CMAKE_PROJECT_NAME}.flash.py" COMMAND ${python}