1# Copyright 2022 NXP
2# SPDX-License-Identifier: Apache-2.0
3
4# Add the mcuboot key file to the secondary swapped app
5# This must be done here to ensure that the same key file is used for signing
6# both the primary and secondary apps
7set(swapped_app_CONFIG_MCUBOOT_SIGNATURE_KEY_FILE
8    \"${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}\" CACHE STRING
9    "Signature key file for signing" FORCE)
10
11# Add the swapped app to the build
12ExternalZephyrProject_Add(
13  APPLICATION swapped_app
14  SOURCE_DIR ${APP_DIR}/swapped_app
15)
16
17# This section ensures that sysbuild-related configurations, such as the MCUBOOT swap type,
18# are passed down to the swapped_app image.
19set_target_properties(swapped_app PROPERTIES
20  IMAGE_CONF_SCRIPT ${ZEPHYR_BASE}/share/sysbuild/image_configurations/MAIN_image_default.cmake
21)
22
23# Add the swapped app to the list of images to flash
24# Ensure the flashing order of images is as follows:
25# - mcuboot
26# - swapped app
27# - primary app (test_mcuboot)
28# This order means that if the debugger resets the MCU in between flash
29# iterations, the MCUBoot swap won't be triggered until the secondary app
30# is actually present in flash.
31sysbuild_add_dependencies(FLASH test_mcuboot swapped_app)
32sysbuild_add_dependencies(FLASH swapped_app mcuboot)
33