Skip to content

Commit 36ea41f

Browse files
tejlmandcarlescufi
authored andcommitted
samples: introduce 'with_mcuboot' sample to show sysbuild feature
This sample is intended to show users how they can create a sample which has dedicated configuration files for extra images included in a build. MCUboot is used as example on how its default can be adjusted and MCUboot itself automatically be included in the build when using sysbuild. Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent d79d805 commit 36ea41f

File tree

7 files changed

+108
-0
lines changed

7 files changed

+108
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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(sample_with_mcuboot)
7+
8+
# Verify that this samnple is built through sysbuild to ensure MCUboot is
9+
# automatically included and that sample specific MCUboot configurations are
10+
# used when building MCUboot.
11+
test_sysbuild()
12+
13+
target_sources(app PRIVATE src/main.c)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.. _with_mcuboot:
2+
3+
Sample with MCUboot
4+
###################
5+
6+
Overview
7+
********
8+
A simple example that demonstrates how building a sample using sysbuild can
9+
automatically include MCUboot as the bootloader.
10+
It showcases how the sample can adjust the configuration of extra image by
11+
creating a image specific Kconfig fragment.
12+
13+
Sysbuild specific settings
14+
**************************
15+
16+
This sample automatically includes MCUboot as bootloader when built using
17+
sysbuild.
18+
19+
This is achieved with a sysbuild specific Kconfig configuration,
20+
:file:`sysbuild.conf`.
21+
22+
The `SB_CONFIG_BOOTLOADER_MCUBOOT=y` setting in the sysbuild Kconfig file
23+
enables the bootloader when building with sysbuild.
24+
25+
The :file:`sysbuild/mcuboot.conf` file will be used as an extra fragment that
26+
is merged together with the default configuration files used by MCUboot.
27+
28+
:file:`sysbuild/mcuboot.conf` adjusts the log level in MCUboot, as well as
29+
configures MCUboot to prevent downgrades and operate in upgrade-only mode.
30+
31+
To build both the sample and MCUboot with ``west`` for the ``reel_board``, run:
32+
33+
.. zephyr-app-commands::
34+
:tool: west
35+
:app: samples/application_development/sysbuild/with_mcuboot
36+
:board: reel_board
37+
:goals: build
38+
:west-args: --sysbuild
39+
:compact:
40+
41+
Execution output:
42+
43+
.. code-block:: console
44+
45+
*** Booting Zephyr OS build v3.2.0-rc3-209-gdcf4201d3573 ***
46+
*** Booting Zephyr OS build v3.2.0-rc3-209-gdcf4201d3573 ***
47+
Address of sample 0xc000
48+
Hello sysbuild with mcuboot! nrf52840dk_nrf52840
49+
50+
The first ``Booting Zephyr OS build`` is printed by MCUboot itself and the
51+
following lines are printed by the ``with_mcuboot`` sample.
52+
This sample also prints its flash location.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sample:
2+
description: Sample with MCUboot built through sysbuild
3+
name: with mcuboot
4+
tests:
5+
sample.application_development.sysbuild.with_mcuboot:
6+
sysbuild: True
7+
# Platform allowed is used as twister using sysbuild still lacks proper
8+
# filtering support, see discussion in #49552.
9+
platform_allow: reel_board nrf52840dk_nrf52840
10+
tags: mcuboot
11+
harness: console
12+
harness_config:
13+
type: multi_line
14+
regex:
15+
- "Address of sample(.*)"
16+
- "Hello sysbuild with mcuboot!(.*)"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2022 Nordic Semiconductor
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/linker/linker-defs.h>
9+
10+
void main(void)
11+
{
12+
printk("Address of sample %p\n", (void *)__rom_region_start);
13+
printk("Hello sysbuild with mcuboot! %s\n", CONFIG_BOARD);
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sysbuild configuration file.
2+
3+
# Enable MCUboot per default for this sample.
4+
SB_CONFIG_BOOTLOADER_MCUBOOT=y
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Example of sample specific Kconfig changes when building sample with MCUboot
2+
# when using sysbuild.
3+
CONFIG_MCUBOOT_LOG_LEVEL_WRN=y
4+
CONFIG_BOOT_UPGRADE_ONLY=y
5+
CONFIG_MCUBOOT_DOWNGRADE_PREVENTION=y

scripts/ci/check_compliance.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ def get_defined_syms(kconf):
561561
"ARMCLANG_STD_LIBC", # The ARMCLANG_STD_LIBC is defined in the toolchain
562562
# Kconfig which is sourced based on Zephyr toolchain
563563
# variant and therefore not visible to compliance.
564+
"BOOT_UPGRADE_ONLY", # Used in example adjusting MCUboot config, but symbol
565+
# is defined in MCUboot itself.
564566
"CDC_ACM_PORT_NAME_",
565567
"CLOCK_STM32_SYSCLK_SRC_",
566568
"CMU",
@@ -579,6 +581,8 @@ def get_defined_syms(kconf):
579581
"FOO_SETTING_1",
580582
"FOO_SETTING_2",
581583
"LSM6DSO_INT_PIN",
584+
"MCUBOOT_LOG_LEVEL_WRN", # Used in example adjusting MCUboot config,
585+
"MCUBOOT_DOWNGRADE_PREVENTION", # but symbols are defined in MCUboot itself.
582586
"MISSING",
583587
"MODULES",
584588
"MYFEATURE",

0 commit comments

Comments
 (0)