Skip to content

Commit 0d78271

Browse files
committed
sysbuild: full example of sysbuild with mcuboot and multiple images
1 parent d69b8cc commit 0d78271

19 files changed

+232
-0
lines changed

sysbuild-example/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Author: James Walmsley <[email protected]>
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
6+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
7+
test_sysbuild(REQUIRED)
8+
9+
project(sysbuild-example)
10+
11+
target_sources(app PRIVATE main_image/src/main.c)
12+

sysbuild-example/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Example Sysbuild Project
2+
3+
The aim of this folder is to demonstrate a typical sysbuild project from the ground-up.
4+
5+
## Build
6+
7+
```
8+
cd my-workspace/example-application
9+
west build --sysbuild sysbuild-example \
10+
-DEXTRA_DTC_OVERLAY_FILE=(pwd)/sysbuild-example/overlays/nucleo_f413zh_partitions.overlay \
11+
-Dmcuboot_EXTRA_DTC_OVERLAY_FILE=(pwd)/sysbuild-example/overlays/nucleo_f413zh_partitions.overlay \
12+
-Dmfg_image_EXTRA_DTC_OVERLAY_FILE=(pwd)/sysbuild-example/overlays/nucleo_f413zh_partitions.overlay \
13+
-Ddfu_app_EXTRA_DTC_OVERLAY_FILE=(pwd)/sysbuild-example/overlays/nucleo_f413zh_partitions.overlay
14+
```
15+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/ {
2+
chosen {
3+
zephyr,code-partition = &app_partition;
4+
};
5+
};
6+
7+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2025 James Walmsley <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
7+
project(dfu_app)
8+
target_sources(app PRIVATE src/main.c)
9+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/ {
2+
chosen {
3+
zephyr,code-partition = &app_partition;
4+
};
5+
};
6+
7+

sysbuild-example/dfu_app/prj.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CONFIG_BOOTLOADER_MCUBOOT=y
2+
CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/root-rsa-2048.pem"
3+
CONFIG_FLASH=y
4+
CONFIG_IMG_MANAGER=y
5+
CONFIG_STREAM_FLASH=y
6+
CONFIG_USB_DFU_CLASS=y
7+
CONFIG_USB_DEVICE_STACK=y
8+
CONFIG_FLASH_MAP=y
9+

sysbuild-example/dfu_app/src/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2025 James Walmsley
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/sys/printk.h>
7+
8+
int main(void)
9+
{
10+
printk("Hello world from 2 %s\n", CONFIG_BOARD_TARGET);
11+
12+
return 0;
13+
}
14+
15+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2025 James Walmsley
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/sys/printk.h>
7+
8+
int main(void)
9+
{
10+
printk("Main image on: %s\n", CONFIG_BOARD_TARGET);
11+
return 0;
12+
}
13+
14+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2025 James Walmsley <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZPEHYR_BASE})
6+
7+
project(mfg_image)
8+
target_sources(app PRIVATE src/main.c)
9+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/ {
2+
chosen {
3+
zephyr,code-partition = &app_partition;
4+
};
5+
};
6+
7+

sysbuild-example/mfg_image/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_BOOTLOADER_MCUBOOT=y
2+
CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/root-rsa-2048.pem"

sysbuild-example/mfg_image/src/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2025 James Walmsley
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/sys/printk.h>
7+
8+
int main(void)
9+
{
10+
printk("Manufacturing image on: %s\n", CONFIG_BOARD_TARGET);
11+
12+
return 0;
13+
}
14+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/delete-node/ &slot0_partition;
2+
/delete-node/ &slot1_partition;
3+
/delete-node/ &scratch_partition;
4+
5+
&flash0 {
6+
/*
7+
* Setting the erase/write block sizes for stm32f4xx
8+
* Its not defined in the main dts because the devices
9+
* have varying sector sizes.
10+
*
11+
* However we can use 128K as a working size across
12+
* the mcuboot slots.
13+
*/
14+
erase-block-size = <DT_SIZE_K(128)>;
15+
write-block-size = <1>;
16+
17+
partitions {
18+
/*
19+
*
20+
*/
21+
app_partition: app_partition@a {
22+
label = "app-max-size";
23+
reg = <0x00020000 DT_SIZE_K(512)>;
24+
};
25+
26+
/*
27+
* This paritition layout is for SWAP_WITH_MOVE,
28+
* Where the primary slot must be 1 sector bigger than the secondary slot!
29+
*/
30+
slot0_partition: partition@20000 {
31+
label = "image-0";
32+
reg = <0x00020000 DT_SIZE_K(512 + 128)>;
33+
34+
};
35+
36+
slot1_partition: partition@C0000 {
37+
label = "image-1";
38+
reg = <0x000C0000 DT_SIZE_K(512)>;
39+
};
40+
};
41+
};
42+

sysbuild-example/prj.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CONFIG_BOOTLOADER_MCUBOOT=y
2+
CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/root-rsa-2048.pem"
3+
CONFIG_FLASH=y
4+
CONFIG_IMG_MANAGER=y
5+
CONFIG_STREAM_FLASH=y
6+
CONFIG_FLASH_MAP=y
7+

sysbuild-example/sysbuild.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2025 James Walmsley <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
ExternalZephyrProject_Add(
5+
APPLICATION mfg_image
6+
SOURCE_DIR ${APP_DIR}/mfg_image
7+
)
8+
9+
ExternalZephyrProject_Add(
10+
APPLICATION dfu_app
11+
SOURCE_DIR ${APP_DIR}/dfu_app
12+
)
13+
14+
add_dependencies(${DEFAULT_IMAGE} mfg_image)
15+
add_dependencies(${DEFAULT_IMAGE} dfu_app)
16+

sysbuild-example/sysbuild.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SB_CONFIG_BOOTLOADER_MCUBOOT=y
2+
SB_CONFIG_MCUBOOT_MODE_SWAP_USING_MOVE=y
3+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/ {
2+
chosen {
3+
zephyr,code-partition = &boot_partition;
4+
};
5+
};
6+
7+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
CONFIG_PM=n
2+
3+
CONFIG_MAIN_STACK_SIZE=10240
4+
5+
CONFIG_BOOT_SWAP_SAVE_ENCTLV=n
6+
CONFIG_BOOT_ENCRYPT_IMAGE=n
7+
8+
CONFIG_BOOT_UPGRADE_ONLY=n
9+
CONFIG_BOOT_BOOTSTRAP=y
10+
11+
### mbedTLS has its own heap
12+
# CONFIG_HEAP_MEM_POOL_SIZE is not set
13+
14+
### We never want Zephyr's copy of tinycrypt. If tinycrypt is needed,
15+
### MCUboot has its own copy in tree.
16+
# CONFIG_TINYCRYPT is not set
17+
# CONFIG_TINYCRYPT_ECC_DSA is not set
18+
# CONFIG_TINYCRYPT_SHA256 is not set
19+
20+
CONFIG_FLASH=y
21+
22+
### Various Zephyr boards enable features that we don't want.
23+
# CONFIG_BT is not set
24+
# CONFIG_BT_CTLR is not set
25+
# CONFIG_I2C is not set
26+
27+
CONFIG_LOG=y
28+
CONFIG_LOG_MODE_MINIMAL=y # former CONFIG_MODE_MINIMAL
29+
### Ensure Zephyr logging changes don't use more resources
30+
CONFIG_LOG_DEFAULT_LEVEL=0
31+
### Use info log level by default
32+
CONFIG_MCUBOOT_LOG_LEVEL_INF=y
33+
### Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y
34+
CONFIG_CBPRINTF_NANO=y
35+
### Use the minimal C library to reduce flash usage
36+
CONFIG_MINIMAL_LIBC=y

west.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ manifest:
2121
- hal_nordic # required by the custom_plank board (Nordic based)
2222
- hal_stm32 # required by the nucleo_f302r8 board (STM32 based)
2323
- mcuboot
24+
- mbedtls

0 commit comments

Comments
 (0)