File tree Expand file tree Collapse file tree 11 files changed +123
-0
lines changed Expand file tree Collapse file tree 11 files changed +123
-0
lines changed Original file line number Diff line number Diff line change 1+ # SPDX-License-Identifier: Apache-2.0
2+
3+ cmake_minimum_required (VERSION 3.20.0)
4+
5+ find_package (Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} )
6+ project (test_mcuboot)
7+
8+ FILE (GLOB app_sources src/*.c)
9+ target_sources (app PRIVATE ${app_sources} )
Original file line number Diff line number Diff line change 1+ MCUBoot Swap Testing
2+ #####################
3+
4+ Tests MCUBoot's image swap support. This application is built in three parts
5+ using sysbuild. The first application is the MCUBoot bootloader. The second
6+ application is the main sysbuild target, and will request an image swap
7+ from MCUBoot when booted. The third application is build with a load address
8+ adjustment using CONFIG_BUILD_OUTPUT_ADJUST_LMA, and will be the application
9+ that MCUBoot swaps to when the image swap is requested.
10+
11+ This sequence of applications allows the test to verify support for the MCUBoot
12+ upgrade process on any platform supporting it.
Original file line number Diff line number Diff line change 1+ # Enable zephyr dfu boot utility library
2+ CONFIG_IMG_MANAGER=y
3+ # Enable flash drivers for MCUBoot
4+ CONFIG_FLASH=y
5+ # Enable reboot API to reset board after selecting new image
6+ CONFIG_REBOOT=y
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2022 NXP
3+ *
4+ * SPDX-License-Identifier: Apache-2.0
5+ */
6+
7+ #include <zephyr/kernel.h>
8+ #include <zephyr/sys/reboot.h>
9+ #include <zephyr/dfu/mcuboot.h>
10+
11+ /* Main entry point */
12+ void main (void )
13+ {
14+ printk ("Launching primary slot application on %s\n" , CONFIG_BOARD );
15+ /* Perform a permanent swap of MCUBoot application */
16+ boot_request_upgrade (1 );
17+ printk ("Secondary application ready for swap, rebooting\n" );
18+ sys_reboot (SYS_REBOOT_COLD );
19+ }
Original file line number Diff line number Diff line change 1+ # SPDX-License-Identifier: Apache-2.0
2+
3+ cmake_minimum_required (VERSION 3.20.0)
4+
5+ find_package (Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} )
6+ project (test_mcuboot)
7+
8+ FILE (GLOB app_sources src/*.c)
9+ target_sources (app PRIVATE ${app_sources} )
Original file line number Diff line number Diff line change 1+ # Copyright 2022 NXP
2+ # SPDX-License-Identifier: Apache-2.0
3+ source "Kconfig.zephyr"
4+ # Workaround for not being able to have commas in macro arguments
5+ DT_CHOSEN_Z_CODE_PARTITION := zephyr,code-partition
6+
7+ config BUILD_OUTPUT_ADJUST_LMA
8+ default "$(dt_node_reg_addr_hex,$(dt_nodelabel_path,slot1_partition))-\
9+ $(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_CODE_PARTITION))"
Original file line number Diff line number Diff line change 1+ # Since LMA adjustment is used to move the image location to the secondary
2+ # slot, we need to enable hex build output. Otherwise, some debuggers will not
3+ # flash the binary to the second image slot.
4+ CONFIG_BUILD_OUTPUT_HEX=y
5+ CONFIG_BOOTLOADER_MCUBOOT=y
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2022 NXP
3+ *
4+ * SPDX-License-Identifier: Apache-2.0
5+ */
6+
7+ #include <zephyr/kernel.h>
8+
9+ /* Main entry point */
10+ void main (void )
11+ {
12+ printk ("Swapped application booted on %s\n" , CONFIG_BOARD );
13+ }
Original file line number Diff line number Diff line change 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
7+ set (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
12+ ExternalZephyrProject_Add(
13+ APPLICATION swapped_app
14+ SOURCE_DIR ${APP_DIR} /swapped_app
15+ )
16+
17+ # Add the swapped app to the list of images to flash
18+ # Ensure the order of images is as follows:
19+ # - mcuboot
20+ # - swapped app
21+ # - primary app (test_mcuboot)
22+ # This order means that if the debugger resets the MCU in between flash
23+ # iterations, the MCUBoot swap won't be triggered until the secondary app
24+ # is actually present in flash.
25+ set (IMAGES "mcuboot" "swapped_app" "test_mcuboot" )
Original file line number Diff line number Diff line change 1+ SB_CONFIG_BOOTLOADER_MCUBOOT=y
You can’t perform that action at this time.
0 commit comments