Skip to content

sysbuild: Add firmware loader application type support #86089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions boards/nordic/nrf52840dk/nrf52840dk_nrf52840.dts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
zephyr,bt-mon-uart = &uart0;
zephyr,bt-c2h-uart = &uart0;
zephyr,ieee802154 = &ieee802154;
zephyr,boot-mode = &boot_mode0;
};

leds {
Expand Down Expand Up @@ -276,3 +277,13 @@ zephyr_udc0: &usbd {
compatible = "nordic,nrf-usbd";
status = "okay";
};

&gpregret1 {
status = "okay";

boot_mode0: boot_mode@0 {
compatible = "zephyr,retention";
status = "okay";
reg = <0x0 0x1>;
};
};
11 changes: 11 additions & 0 deletions boards/nordic/nrf5340dk/nrf5340dk_nrf5340_cpuapp.dts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,16 @@
zephyr,code-partition = &slot0_partition;
zephyr,sram-secure-partition = &sram0_s;
zephyr,sram-non-secure-partition = &sram0_ns;
zephyr,boot-mode = &boot_mode0;
};
};

&gpregret1 {
status = "okay";

boot_mode0: boot_mode@0 {
compatible = "zephyr,retention";
status = "okay";
reg = <0x0 0x1>;
};
};
11 changes: 11 additions & 0 deletions boards/nordic/nrf54l15dk/nrf54l_05_10_15_cpuapp_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
zephyr,flash-controller = &rram_controller;
zephyr,flash = &cpuapp_rram;
zephyr,ieee802154 = &ieee802154;
zephyr,boot-mode = &boot_mode0;
};
};

Expand Down Expand Up @@ -91,6 +92,16 @@
status = "okay";
};

&gpregret1 {
status = "okay";

boot_mode0: boot_mode@0 {
compatible = "zephyr,retention";
status = "okay";
reg = <0x0 0x1>;
};
};

&spi00 {
status = "okay";
cs-gpios = <&gpio2 5 GPIO_ACTIVE_LOW>;
Expand Down
3 changes: 3 additions & 0 deletions doc/build/dts/api/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,6 @@ device.
:kconfig:option:`CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP_RAM_LOAD`,
this property is used to tell MCUboot the load address of the image, which
will be the ``reg`` of the chosen node.
* - zephyr,boot-mode
- Used for :ref:`boot_mode_api` selection, part of :ref:`retention_api`, which specifies
what image on a device should be booted.
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
&gpregret1 {
/delete-node/ boot_mode@0;
};

/ {
chosen {
/delete-property/ zephyr,boot-mode;
};

sram@2003FC00 {
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x2003FC00 DT_SIZE_K(1)>;
Expand Down
1 change: 1 addition & 0 deletions scripts/ci/check_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ def check_no_undef_outside_kconfig(self, kconf):
"BOOT_ENCRYPTION_KEY_FILE", # Used in sysbuild
"BOOT_ENCRYPT_IMAGE", # Used in sysbuild
"BOOT_FIRMWARE_LOADER", # Used in sysbuild for MCUboot configuration
"BOOT_FIRMWARE_LOADER_BOOT_MODE", # Used in sysbuild for MCUboot configuration
"BOOT_MAX_IMG_SECTORS_AUTO", # Used in sysbuild
"BOOT_RAM_LOAD", # Used in sysbuild for MCUboot configuration
"BOOT_SERIAL_BOOT_MODE", # Used in (sysbuild-based) test/
Expand Down
2 changes: 1 addition & 1 deletion share/sysbuild/cmake/modules/sysbuild_extensions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ endfunction()
# and debugging.
#
function(ExternalZephyrProject_Add)
set(app_types MAIN BOOTLOADER)
set(app_types MAIN BOOTLOADER FIRMWARE_LOADER)
cmake_parse_arguments(ZBUILD "" "APPLICATION;BOARD;BOARD_REVISION;SOURCE_DIR;APP_TYPE;BUILD_ONLY" "" ${ARGN})

if(ZBUILD_UNPARSED_ARGUMENTS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@ elseif(SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP OR SB_CONFIG_MCUBOOT_MODE_DIRECT_XIP_WI
set(bootmode CONFIG_BOOT_DIRECT_XIP)
elseif(SB_CONFIG_MCUBOOT_MODE_RAM_LOAD)
set(bootmode CONFIG_BOOT_RAM_LOAD)
elseif(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER)
set(bootmode CONFIG_BOOT_FIRMWARE_LOADER)
elseif(SB_CONFIG_MCUBOOT_MODE_SINGLE_APP_RAM_LOAD)
set(bootmode CONFIG_SINGLE_APPLICATION_SLOT_RAM_LOAD)
elseif(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER)
set(bootmode CONFIG_BOOT_FIRMWARE_LOADER)

if(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER_BOOT_MODE_ENTRANCE)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETAINED_MEM y)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETENTION y)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETENTION_BOOT_MODE y)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOT_FIRMWARE_LOADER_BOOT_MODE y)
endif()
endif()

foreach(loopbootmode ${bootmodes})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2025 Nordic Semiconductor
#
# SPDX-License-Identifier: Apache-2.0

# This sysbuild CMake file sets the sysbuild controlled settings as properties
# on a firmware updater image.

set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOTLOADER_MCUBOOT "${SB_CONFIG_BOOTLOADER_MCUBOOT}")
set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_SIGNATURE_KEY_FILE
"${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}"
)
set_config_string(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE
"${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}"
)

if("${SB_CONFIG_SIGNATURE_TYPE}" STREQUAL "NONE")
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE y)
else()
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE n)
endif()

set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER y)
11 changes: 9 additions & 2 deletions share/sysbuild/image_configurations/MAIN_image_default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ if(SB_CONFIG_BOOTLOADER_MCUBOOT)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_RAM_LOAD y)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_XIP n)
set_config_int(${ZCMAKE_APPLICATION} CONFIG_FLASH_SIZE 0)
elseif(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER y)
elseif(SB_CONFIG_MCUBOOT_MODE_SINGLE_APP_RAM_LOAD)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_SINGLE_APP_RAM_LOAD y)
elseif(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_BOOTLOADER_MODE_FIRMWARE_UPDATER y)

if(SB_CONFIG_MCUBOOT_MODE_FIRMWARE_UPDATER_BOOT_MODE_ENTRANCE)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_REBOOT y)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETAINED_MEM y)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETENTION y)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETENTION_BOOT_MODE y)
endif()
endif()
endif()
1 change: 1 addition & 0 deletions share/sysbuild/images/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ExternalZephyrProject_Add(

# This allows for MCUboot to be included.
sysbuild_add_subdirectory(bootloader)
sysbuild_add_subdirectory(firmware_loader)

# Include zephyr modules generated sysbuild CMake file.
foreach(SYSBUILD_CURRENT_MODULE_NAME ${SYSBUILD_MODULE_NAMES})
Expand Down
1 change: 1 addition & 0 deletions share/sysbuild/images/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# SPDX-License-Identifier: Apache-2.0

rsource "bootloader/Kconfig"
rsource "firmware_loader/Kconfig"
8 changes: 8 additions & 0 deletions share/sysbuild/images/bootloader/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ config MCUBOOT_MODE_SINGLE_APP_RAM_LOAD

endchoice

config MCUBOOT_MODE_FIRMWARE_UPDATER_BOOT_MODE_ENTRANCE
bool "Firmware updater retention boot mode entrance"
depends on MCUBOOT_MODE_FIRMWARE_UPDATER
help
Will enable retained memory, retention and the boot mode module in MCUboot and the main
application so that it can be used to force booting the firmware loader application
image. This needs the ``zephyr,boot-mode`` chosen node to be correctly configured.

config SIGNATURE_TYPE
string
default "NONE" if BOOT_SIGNATURE_TYPE_NONE
Expand Down
11 changes: 11 additions & 0 deletions share/sysbuild/images/firmware_loader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2025 Nordic Semiconductor
#
# SPDX-License-Identifier: Apache-2.0

if(SB_CONFIG_FIRMWARE_LOADER_IMAGE_PATH)
ExternalZephyrProject_Add(
APPLICATION ${SB_CONFIG_FIRMWARE_LOADER_IMAGE_NAME}
SOURCE_DIR ${SB_CONFIG_FIRMWARE_LOADER_IMAGE_PATH}
APP_TYPE FIRMWARE_LOADER
)
endif()
37 changes: 37 additions & 0 deletions share/sysbuild/images/firmware_loader/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2025 Nordic Semiconductor
#
# SPDX-License-Identifier: Apache-2.0

config SUPPORT_FIRMWARE_LOADER_SMP_SVR
bool
default y

choice FIRMWARE_LOADER
prompt "Firmware loader image"
default FIRMWARE_LOADER_IMAGE_NONE
depends on MCUBOOT_MODE_FIRMWARE_UPDATER

config FIRMWARE_LOADER_IMAGE_NONE
bool "None"
help
Do not Include a firmware loader image in the build.

config FIRMWARE_LOADER_IMAGE_SMP_SVR
bool "smp_svr"
depends on SUPPORT_FIRMWARE_LOADER_SMP_SVR
help
Include the MCUmgr ``smp_svr`` sample as the firmware loader image to use.

endchoice

config FIRMWARE_LOADER_IMAGE_NAME
string
default "smp_svr" if FIRMWARE_LOADER_IMAGE_SMP_SVR
help
Name of firmware loader image.

config FIRMWARE_LOADER_IMAGE_PATH
string
default "${ZEPHYR_BASE}/samples/subsys/mgmt/mcumgr/smp_svr" if FIRMWARE_LOADER_IMAGE_SMP_SVR
help
Source directory of firmware loader image.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* SPDX-License-Identifier: Apache-2.0 */

/ {
chosen {
/delete-property/ zephyr,boot-mode;
};

sram@2003FC00 {
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x2003FC00 DT_SIZE_K(1)>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@

/ {
chosen {
zephyr,boot-mode = &boot_mode0;
zephyr,uart-mcumgr = &cdc_acm_uart;
};
};

&gpregret1 {
status = "okay";

boot_mode0: boot_mode@0 {
compatible = "zephyr,retention";
status = "okay";
reg = <0x0 0x1>;
};
};

&zephyr_udc0 {
status = "okay";

Expand Down
Loading