Skip to content

Commit 077c720

Browse files
committed
sysbuild: add a hook to tie an app snippet to its MCUboot counterpart
Simplify the usage of Matter FOTA external flash snippet by allowing a single `SNIPPET=matter_fota_ext_flash` argument for building. Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
1 parent 7e6b042 commit 077c720

5 files changed

Lines changed: 54 additions & 21 deletions

File tree

docs/includes/matter_extension_activation.txt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,21 @@ This selects the :file:`prj_matter_fota.conf` configuration, which enables Matte
88

99
The same configuration is supported on ``nrf54lm20dk/nrf54lm20a/cpuapp`` and ``nrf54lm20dk/nrf54lm20b/cpuapp``.
1010

11-
To place the MCUboot secondary slot on external SPI NOR flash instead, apply the ``matter_fota_ext_flash`` and ``matter_fota_mcuboot_ext_flash`` snippets to the application and MCUboot images respectively.
1211
On the nRF54L15 DK, the combined Matter and Zigbee image requires this variant due to the available internal slot size.
12+
To place the MCUboot secondary slot on external SPI NOR flash instead, pass the ``matter_fota_ext_flash`` snippet.
1313

1414
.. parsed-literal::
1515
:class: highlight
1616

17-
west build |sample dir| -b nrf54l15dk/nrf54l15/cpuapp --sysbuild -- \\
18-
-DFILE_SUFFIX=matter_fota \\
19-
-D|sample|_SNIPPET=matter_fota_ext_flash \\
20-
-Dmcuboot_SNIPPET=matter_fota_mcuboot_ext_flash
21-
22-
Replace ``|sample|`` with ``light_bulb`` or ``light_switch``.
17+
west build |sample dir| -b nrf54l15dk/nrf54l15/cpuapp -S matter_fota_ext_flash -- -DFILE_SUFFIX=matter_fota
18+
west build |sample dir| -b nrf54lm20dk/nrf54lm20a/cpuapp -S matter_fota_ext_flash -- -DFILE_SUFFIX=matter_fota
2319

2420
To produce a size-optimized release build (no logging, console or shell), add :file:`matter_fota_release.conf` as an extra overlay:
2521

2622
.. parsed-literal::
2723
:class: highlight
2824

29-
west build |sample dir| -b nrf54l15dk/nrf54l15/cpuapp --sysbuild -- \\
30-
-DFILE_SUFFIX=matter_fota \\
31-
-D|sample|_SNIPPET=matter_fota_ext_flash \\
32-
-Dmcuboot_SNIPPET=matter_fota_mcuboot_ext_flash \\
33-
-DEXTRA_CONF_FILE='matter_fota_release.conf'
25+
west build |sample dir| -b nrf54l15dk/nrf54l15/cpuapp -S matter_fota_ext_flash -- -DFILE_SUFFIX=matter_fota -DEXTRA_CONF_FILE='matter_fota_release.conf'
3426

3527
Use ``nrf54lm20dk/nrf54lm20b/cpuapp`` as the board target for the nRF54LM20B SoC variant.
3628

docs/memory.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ The following table lists the available files, which targets they cover, and whe
7474
- | nRF54L15 DK (DK only)
7575
| nRF54LM20 DK (DK only)
7676
- Same as the Matter and Zigbee layout, but places ``slot1_partition`` on external flash and enlarges ``slot0_partition``.
77-
Build with ``FILE_SUFFIX=matter_fota``, the ``matter_fota_ext_flash`` snippet on the application image, and the ``matter_fota_mcuboot_ext_flash`` snippet on the MCUboot image.
77+
Build with ``FILE_SUFFIX=matter_fota`` and ``SNIPPET=matter_fota_ext_flash``.
7878

7979
* - External flash (FOTA)
8080
- :file:`dts/ext_flash/<board>_partitions.dtsi`

samples/light_bulb/sample.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ tests:
77
build_only: true
88
extra_args:
99
- FILE_SUFFIX=matter_fota
10-
- light_bulb_SNIPPET=matter_fota_ext_flash
11-
- mcuboot_SNIPPET=matter_fota_mcuboot_ext_flash
10+
- SNIPPET=matter_fota_ext_flash
1211
integration_platforms:
1312
- nrf54l15dk/nrf54l15/cpuapp
1413
- nrf54lm20dk/nrf54lm20a/cpuapp
@@ -41,8 +40,7 @@ tests:
4140
build_only: true
4241
extra_args:
4342
- FILE_SUFFIX=matter_fota
44-
- light_bulb_SNIPPET=matter_fota_ext_flash
45-
- mcuboot_SNIPPET=matter_fota_mcuboot_ext_flash
43+
- SNIPPET=matter_fota_ext_flash
4644
- EXTRA_CONF_FILE=matter_fota_release.conf
4745
integration_platforms:
4846
- nrf54l15dk/nrf54l15/cpuapp

samples/light_switch/sample.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ tests:
77
build_only: true
88
extra_args:
99
- FILE_SUFFIX=matter_fota
10-
- light_switch_SNIPPET=matter_fota_ext_flash
11-
- mcuboot_SNIPPET=matter_fota_mcuboot_ext_flash
10+
- SNIPPET=matter_fota_ext_flash
1211
integration_platforms:
1312
- nrf54l15dk/nrf54l15/cpuapp
1413
- nrf54lm20dk/nrf54lm20a/cpuapp
@@ -41,8 +40,7 @@ tests:
4140
build_only: true
4241
extra_args:
4342
- FILE_SUFFIX=matter_fota
44-
- light_switch_SNIPPET=matter_fota_ext_flash
45-
- mcuboot_SNIPPET=matter_fota_mcuboot_ext_flash
43+
- SNIPPET=matter_fota_ext_flash
4644
- EXTRA_CONF_FILE=matter_fota_release.conf
4745
integration_platforms:
4846
- nrf54l15dk/nrf54l15/cpuapp

sysbuild/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,51 @@
44
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
#
66

7+
# Global SNIPPET/SB_SNIPPET is applied to every sysbuild image. Some addon
8+
# snippets target the application only and need a different MCUboot counterpart.
9+
# This hook remaps those pairs on the mcuboot image so builds can pass a single
10+
# -DSNIPPET=<app_snippet>. Extend the list below as <app_snippet> <mcuboot_snippet>.
11+
function(${SYSBUILD_CURRENT_MODULE_NAME}_pre_cmake)
12+
if(NOT SB_CONFIG_BOOTLOADER_MCUBOOT)
13+
return()
14+
endif()
15+
16+
zephyr_get(SB_SNIPPET)
17+
if(SB_SNIPPET)
18+
set(global_snippets ${SB_SNIPPET})
19+
else()
20+
zephyr_get(SNIPPET)
21+
set(global_snippets ${SNIPPET})
22+
endif()
23+
24+
# Extend this list as needed.
25+
set(app_mcuboot_snippet_pairs
26+
matter_fota_ext_flash matter_fota_mcuboot_ext_flash
27+
)
28+
29+
set(mcuboot_snippets ${global_snippets})
30+
set(remapped FALSE)
31+
list(LENGTH app_mcuboot_snippet_pairs pair_count)
32+
math(EXPR last_pair_idx "${pair_count} - 2")
33+
foreach(idx RANGE 0 ${last_pair_idx} 2)
34+
list(GET app_mcuboot_snippet_pairs ${idx} app_snippet)
35+
math(EXPR mcuboot_idx "${idx} + 1")
36+
list(GET app_mcuboot_snippet_pairs ${mcuboot_idx} mcuboot_snippet)
37+
38+
if(app_snippet IN_LIST global_snippets)
39+
set(remapped TRUE)
40+
list(REMOVE_ITEM mcuboot_snippets ${app_snippet})
41+
if(NOT mcuboot_snippet IN_LIST mcuboot_snippets)
42+
list(APPEND mcuboot_snippets ${mcuboot_snippet})
43+
endif()
44+
endif()
45+
endforeach()
46+
47+
if(remapped)
48+
set(mcuboot_SNIPPET ${mcuboot_snippets} CACHE STRING "" FORCE)
49+
endif()
50+
endfunction()
51+
752
function(${SYSBUILD_CURRENT_MODULE_NAME}_post_cmake)
853
sysbuild_get(CONFIG_ZIGBEE_ADD_ON IMAGE ${DEFAULT_IMAGE} VAR CONFIG_ZIGBEE_ADD_ON KCONFIG)
954
sysbuild_get(CONFIG_ZIGBEE_FOTA IMAGE ${DEFAULT_IMAGE} VAR CONFIG_ZIGBEE_FOTA KCONFIG)

0 commit comments

Comments
 (0)