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 <james@fullfat-fs.co.uk>

cmake_minimum_required(VERSION 3.20.0)

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

Choose a reason for hiding this comment

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

Suggested change
test_sysbuild()
test_sysbuild(REQUIRED)

Maybe add the required flag, since the whole point is to show sysbuild?
If not, the the README should highlight what happens when building with sysbuild and when building without.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks. Yes sysbuild() is REQUIRED.


project(hello_world)

target_sources(app PRIVATE mfg_image/src/main.c)
Copy link

@TjazVracko TjazVracko Apr 16, 2025

Choose a reason for hiding this comment

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

I think this will confuse people a lot.
Both the "main" image and the mfg_image use the same main.c file, and will thus print the same thing when booted.

I feel like the main image should have its own source files, so that all 3 images will do something distinct, even if it is just printing different logs. The README and possibly some comments in the code can then highlight what the images could do in a "full" implementation.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I was also confused that the top-level CMake generates an app. And the others are just extra.
I'll ensure the apps are distinct.


11 changes: 11 additions & 0 deletions sysbuild-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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

Choose a reason for hiding this comment

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

Should this not be

Suggested change
west build --sysbuild sysbuild
west build --sysbuild sysbuild-example

?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, yes I renamed the folder from sysbuild to not have sysbuild/sysbuild

```

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 <james@fullfat-fs.co.uk>
# SPDX-License-Identifier: Apache-2.0

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

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

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 %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 <james@fullfat-fs.co.uk>
# 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)

1 change: 1 addition & 0 deletions sysbuild-example/mfg_image/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_BOOTLOADER_MCUBOOT=y
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;
}

Empty file added sysbuild-example/prj.conf
Empty file.
15 changes: 15 additions & 0 deletions sysbuild-example/sysbuild.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2025 James Walmsley <james@fullfat-fs.co.uk>
# 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)
1 change: 1 addition & 0 deletions sysbuild-example/sysbuild.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SB_CONFIG_BOOTLOADER_MCUBOOT=y
2 changes: 2 additions & 0 deletions sysbuild-example/sysbuild/mcuboot.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_BOOT_SWAP_USING_SCRATCH=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 # required by the ARM port
- hal_nordic # required by the custom_plank board (Nordic based)
- hal_stm32 # required by the nucleo_f302r8 board (STM32 based)
- mcuboot
- mbedtls
Loading