Skip to content

Adding a sysbuild example #83

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ Before getting started, make sure you have a proper Zephyr development
environment. Follow the official
[Zephyr Getting Started Guide](https://docs.zephyrproject.org/latest/getting_started/index.html).


### Python VENV

To get started its recommended to initialize a virtual-environment for python.

```
mkdir -p my-workspace
cd my-workspace
python -m venv .venv
source .venv/bin/activate # note. activate.{fish,csh} etc for other shells!
```

From there you can install west and all the required python dependencies for zephyr's build system
without touching your system's python installation.

```
pip install west
```

### Initialization

The first step is to initialize the workspace folder (``my-workspace``) where
Expand All @@ -68,6 +87,12 @@ cd my-workspace
west update
```

Before building, ensure all required python packages are installed

```
west packages pip --install
```

### Building and running

To build the application, run the following command:
Expand Down
33 changes: 33 additions & 0 deletions app/boards/nucleo_f413zh.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
* SPDX-License-Identifier: Apache-2.0
*/

/* This devicetree overlay file will be automatically picked by the Zephyr
* build system when building the sample for the nucleo_f413zh board. It shows
* how the example-application can be built on sample boards already provided
* by Zephyr.
*/

/ {
example_sensor: example-sensor {
compatible = "zephyr,example-sensor";
input-gpios = <&gpioc 13 (GPIO_ACTIVE_HIGH)>;
};

blink_led: blink-led {
compatible = "blink-gpio-led";
led-gpios = <&gpiob 0 GPIO_ACTIVE_HIGH>;
blink-period-ms = <1000>;
};
};

&gpioc {
status = "okay";
};

&gpiob {
status = "okay";
};


12 changes: 12 additions & 0 deletions sysbuild-example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-License-Identifier: Apache-2.0
# Author: James Walmsley <[email protected]>

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
test_sysbuild(REQUIRED)

project(sysbuild-example)

target_sources(app PRIVATE main_image/src/main.c)

15 changes: 15 additions & 0 deletions sysbuild-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Example Sysbuild Project

The aim of this folder is to demonstrate a typical sysbuild project from the ground-up.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is the example application project, we want to explain as much as possible here. We should assume that the reader knows very little about Zephyr.

I would add more text here explaining what exactly sysbuild is (link to the docs), and explain what exactly will be built, and what the expected use-case for those build targets/aretifacts is.
Then, I would highlight the command line options on how to build all of the images, only one of them, how to debug (aka the --domain flag)

A newbie should be pointed into the correct direction, to the right docs, so they can learn further.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I'll try to write a "getting started" guide from my understanding, and simple explanations of the concepts.

I'll need you help to review, and correct any mis-understandings I have.

## Build

```
cd my-workspace/example-application
west build --sysbuild sysbuild-example \
-DEXTRA_DTC_OVERLAY_FILE=(pwd)/sysbuild-example/overlays/nucleo_f413zh_partitions.overlay \
-Dmcuboot_EXTRA_DTC_OVERLAY_FILE=(pwd)/sysbuild-example/overlays/nucleo_f413zh_partitions.overlay \
-Dmfg_image_EXTRA_DTC_OVERLAY_FILE=(pwd)/sysbuild-example/overlays/nucleo_f413zh_partitions.overlay \
-Ddfu_app_EXTRA_DTC_OVERLAY_FILE=(pwd)/sysbuild-example/overlays/nucleo_f413zh_partitions.overlay
```

7 changes: 7 additions & 0 deletions sysbuild-example/boards/nucleo_f413zh.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/ {
chosen {
zephyr,code-partition = &app_partition;
};
};


9 changes: 9 additions & 0 deletions sysbuild-example/dfu_app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2025 James Walmsley <[email protected]>
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(dfu_app)
target_sources(app PRIVATE src/main.c)

7 changes: 7 additions & 0 deletions sysbuild-example/dfu_app/boards/nucleo_f413zh.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/ {
chosen {
zephyr,code-partition = &app_partition;
};
};


9 changes: 9 additions & 0 deletions sysbuild-example/dfu_app/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/root-rsa-2048.pem"
CONFIG_FLASH=y
CONFIG_IMG_MANAGER=y
CONFIG_STREAM_FLASH=y
CONFIG_USB_DFU_CLASS=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_FLASH_MAP=y

15 changes: 15 additions & 0 deletions sysbuild-example/dfu_app/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2025 James Walmsley
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/sys/printk.h>

int main(void)
{
printk("Hello world from 2 %s\n", CONFIG_BOARD_TARGET);

return 0;
}


14 changes: 14 additions & 0 deletions sysbuild-example/main_image/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2025 James Walmsley
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/sys/printk.h>

int main(void)
{
printk("Main image on: %s\n", CONFIG_BOARD_TARGET);
return 0;
}


9 changes: 9 additions & 0 deletions sysbuild-example/mfg_image/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2025 James Walmsley <[email protected]>
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZPEHYR_BASE})

project(mfg_image)
target_sources(app PRIVATE src/main.c)

7 changes: 7 additions & 0 deletions sysbuild-example/mfg_image/boards/nucleo_f413zh.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/ {
chosen {
zephyr,code-partition = &app_partition;
};
};


2 changes: 2 additions & 0 deletions sysbuild-example/mfg_image/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/root-rsa-2048.pem"
14 changes: 14 additions & 0 deletions sysbuild-example/mfg_image/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2025 James Walmsley
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/sys/printk.h>

int main(void)
{
printk("Manufacturing image on: %s\n", CONFIG_BOARD_TARGET);

return 0;
}

42 changes: 42 additions & 0 deletions sysbuild-example/overlays/nucleo_f413zh_partitions.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/delete-node/ &slot0_partition;
/delete-node/ &slot1_partition;
/delete-node/ &scratch_partition;

&flash0 {
/*
* Setting the erase/write block sizes for stm32f4xx
* Its not defined in the main dts because the devices
* have varying sector sizes.
*
* However we can use 128K as a working size across
* the mcuboot slots.
*/
erase-block-size = <DT_SIZE_K(128)>;
write-block-size = <1>;

partitions {
/*
*
*/
app_partition: app_partition@a {
label = "app-max-size";
reg = <0x00020000 DT_SIZE_K(512)>;
};

/*
* This paritition layout is for SWAP_WITH_MOVE,
* Where the primary slot must be 1 sector bigger than the secondary slot!
*/
slot0_partition: partition@20000 {
label = "image-0";
reg = <0x00020000 DT_SIZE_K(512 + 128)>;

};

slot1_partition: partition@C0000 {
label = "image-1";
reg = <0x000C0000 DT_SIZE_K(512)>;
};
};
};

7 changes: 7 additions & 0 deletions sysbuild-example/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/root-rsa-2048.pem"
CONFIG_FLASH=y
CONFIG_IMG_MANAGER=y
CONFIG_STREAM_FLASH=y
CONFIG_FLASH_MAP=y

16 changes: 16 additions & 0 deletions sysbuild-example/sysbuild.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2025 James Walmsley <[email protected]>
# SPDX-License-Identifier: Apache-2.0

ExternalZephyrProject_Add(
APPLICATION mfg_image
SOURCE_DIR ${APP_DIR}/mfg_image
)

ExternalZephyrProject_Add(
APPLICATION dfu_app
SOURCE_DIR ${APP_DIR}/dfu_app
)

add_dependencies(${DEFAULT_IMAGE} mfg_image)
add_dependencies(${DEFAULT_IMAGE} dfu_app)

3 changes: 3 additions & 0 deletions sysbuild-example/sysbuild.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SB_CONFIG_BOOTLOADER_MCUBOOT=y
SB_CONFIG_MCUBOOT_MODE_SWAP_USING_MOVE=y

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/ {
chosen {
zephyr,code-partition = &boot_partition;
};
};


36 changes: 36 additions & 0 deletions sysbuild-example/sysbuild/mcuboot/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
CONFIG_PM=n

CONFIG_MAIN_STACK_SIZE=10240

CONFIG_BOOT_SWAP_SAVE_ENCTLV=n
CONFIG_BOOT_ENCRYPT_IMAGE=n

CONFIG_BOOT_UPGRADE_ONLY=n
CONFIG_BOOT_BOOTSTRAP=y

### mbedTLS has its own heap
# CONFIG_HEAP_MEM_POOL_SIZE is not set

### We never want Zephyr's copy of tinycrypt. If tinycrypt is needed,
### MCUboot has its own copy in tree.
# CONFIG_TINYCRYPT is not set
# CONFIG_TINYCRYPT_ECC_DSA is not set
# CONFIG_TINYCRYPT_SHA256 is not set

CONFIG_FLASH=y

### Various Zephyr boards enable features that we don't want.
# CONFIG_BT is not set
# CONFIG_BT_CTLR is not set
# CONFIG_I2C is not set

CONFIG_LOG=y
CONFIG_LOG_MODE_MINIMAL=y # former CONFIG_MODE_MINIMAL
### Ensure Zephyr logging changes don't use more resources
CONFIG_LOG_DEFAULT_LEVEL=0
### Use info log level by default
CONFIG_MCUBOOT_LOG_LEVEL_INF=y
### Decrease footprint by ~4 KB in comparison to CBPRINTF_COMPLETE=y
CONFIG_CBPRINTF_NANO=y
### Use the minimal C library to reduce flash usage
CONFIG_MINIMAL_LIBC=y
2 changes: 2 additions & 0 deletions west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ manifest:
- cmsis_6 # required by the ARM port for Cortex-M
- hal_nordic # required by the custom_plank board (Nordic based)
- hal_stm32 # required by the nucleo_f302r8 board (STM32 based)
- mcuboot
- mbedtls
Loading