From cd8915e53239e2f950c558ac498c736e5554e603 Mon Sep 17 00:00:00 2001 From: James Walmsley Date: Thu, 27 Mar 2025 13:20:58 +0000 Subject: [PATCH 1/4] readme: Update build instructions to support python venv This is a necessary part of the build instructions, and not immediately obvious to a new user without looking through the seperate online getting started guide. This example should serve as a "one-place" to get started. Signed-off-by: James Walmsley --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index ceb2c51e..940cff9f 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: From 853c022f34734b26af70806ac1beb390dddd4563 Mon Sep 17 00:00:00 2001 From: James Walmsley Date: Thu, 27 Mar 2025 13:24:35 +0000 Subject: [PATCH 2/4] app: overlay: add support for nucleo_stm32f413zh Updating app to support more nucleo boards to help other's get started. Signed-off-by: James Walmsley --- app/boards/nucleo_f413zh.overlay | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 app/boards/nucleo_f413zh.overlay diff --git a/app/boards/nucleo_f413zh.overlay b/app/boards/nucleo_f413zh.overlay new file mode 100644 index 00000000..c99fc78e --- /dev/null +++ b/app/boards/nucleo_f413zh.overlay @@ -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"; +}; + + From 69357ca8c5bdd356d7b38b186cda76bac026e0ea Mon Sep 17 00:00:00 2001 From: James Walmsley Date: Thu, 27 Mar 2025 13:25:40 +0000 Subject: [PATCH 3/4] sysbuild: Adding other modules required for a sysbuild example --- west.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/west.yml b/west.yml index 6bb551cb..1ce0d50b 100644 --- a/west.yml +++ b/west.yml @@ -20,3 +20,4 @@ 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 From 519a6f6e330175c27bd2a0096c5fb2bd2add5b07 Mon Sep 17 00:00:00 2001 From: James Walmsley Date: Tue, 1 Apr 2025 14:31:32 +0100 Subject: [PATCH 4/4] sysbuild: full example of sysbuild with mcuboot and multiple images --- sysbuild-example/CMakeLists.txt | 12 ++++++++++++ sysbuild-example/README.md | 11 +++++++++++ sysbuild-example/dfu_app/CMakeLists.txt | 9 +++++++++ sysbuild-example/dfu_app/prj.conf | 9 +++++++++ sysbuild-example/dfu_app/src/main.c | 15 +++++++++++++++ sysbuild-example/mfg_image/CMakeLists.txt | 9 +++++++++ sysbuild-example/mfg_image/prj.conf | 1 + sysbuild-example/mfg_image/src/main.c | 14 ++++++++++++++ sysbuild-example/prj.conf | 0 sysbuild-example/sysbuild.cmake | 15 +++++++++++++++ sysbuild-example/sysbuild.conf | 1 + sysbuild-example/sysbuild/mcuboot.conf | 2 ++ west.yml | 1 + 13 files changed, 99 insertions(+) create mode 100644 sysbuild-example/CMakeLists.txt create mode 100644 sysbuild-example/README.md create mode 100644 sysbuild-example/dfu_app/CMakeLists.txt create mode 100644 sysbuild-example/dfu_app/prj.conf create mode 100644 sysbuild-example/dfu_app/src/main.c create mode 100644 sysbuild-example/mfg_image/CMakeLists.txt create mode 100644 sysbuild-example/mfg_image/prj.conf create mode 100644 sysbuild-example/mfg_image/src/main.c create mode 100644 sysbuild-example/prj.conf create mode 100644 sysbuild-example/sysbuild.cmake create mode 100644 sysbuild-example/sysbuild.conf create mode 100644 sysbuild-example/sysbuild/mcuboot.conf diff --git a/sysbuild-example/CMakeLists.txt b/sysbuild-example/CMakeLists.txt new file mode 100644 index 00000000..40063d71 --- /dev/null +++ b/sysbuild-example/CMakeLists.txt @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: Apache-2.0 +# Author: James Walmsley + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +test_sysbuild() + +project(hello_world) + +target_sources(app PRIVATE mfg_image/src/main.c) + diff --git a/sysbuild-example/README.md b/sysbuild-example/README.md new file mode 100644 index 00000000..fef6b668 --- /dev/null +++ b/sysbuild-example/README.md @@ -0,0 +1,11 @@ +# Example Sysbuild Project + +The aim of this folder is to demonstrate a typical sysbuild project from the ground-up. + +## Build + +``` +cd my-workspace/example-application +west build --sysbuild sysbuild +``` + diff --git a/sysbuild-example/dfu_app/CMakeLists.txt b/sysbuild-example/dfu_app/CMakeLists.txt new file mode 100644 index 00000000..ce1c4c99 --- /dev/null +++ b/sysbuild-example/dfu_app/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2025 James Walmsley +# 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) + diff --git a/sysbuild-example/dfu_app/prj.conf b/sysbuild-example/dfu_app/prj.conf new file mode 100644 index 00000000..3c0f8a65 --- /dev/null +++ b/sysbuild-example/dfu_app/prj.conf @@ -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 + diff --git a/sysbuild-example/dfu_app/src/main.c b/sysbuild-example/dfu_app/src/main.c new file mode 100644 index 00000000..11244a57 --- /dev/null +++ b/sysbuild-example/dfu_app/src/main.c @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2025 James Walmsley + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +int main(void) +{ + printk("Hello world from %s\n", CONFIG_BOARD_TARGET); + + return 0; +} + + diff --git a/sysbuild-example/mfg_image/CMakeLists.txt b/sysbuild-example/mfg_image/CMakeLists.txt new file mode 100644 index 00000000..e402fcda --- /dev/null +++ b/sysbuild-example/mfg_image/CMakeLists.txt @@ -0,0 +1,9 @@ +# Copyright (c) 2025 James Walmsley +# 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) + diff --git a/sysbuild-example/mfg_image/prj.conf b/sysbuild-example/mfg_image/prj.conf new file mode 100644 index 00000000..0608e7a8 --- /dev/null +++ b/sysbuild-example/mfg_image/prj.conf @@ -0,0 +1 @@ +CONFIG_BOOTLOADER_MCUBOOT=y diff --git a/sysbuild-example/mfg_image/src/main.c b/sysbuild-example/mfg_image/src/main.c new file mode 100644 index 00000000..36822190 --- /dev/null +++ b/sysbuild-example/mfg_image/src/main.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2025 James Walmsley + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +int main(void) +{ + printk("Manufacturing image on: %s\n", CONFIG_BOARD_TARGET); + + return 0; +} + diff --git a/sysbuild-example/prj.conf b/sysbuild-example/prj.conf new file mode 100644 index 00000000..e69de29b diff --git a/sysbuild-example/sysbuild.cmake b/sysbuild-example/sysbuild.cmake new file mode 100644 index 00000000..913f34b3 --- /dev/null +++ b/sysbuild-example/sysbuild.cmake @@ -0,0 +1,15 @@ +# Copyright (c) 2025 James Walmsley +# 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) diff --git a/sysbuild-example/sysbuild.conf b/sysbuild-example/sysbuild.conf new file mode 100644 index 00000000..47f00ff3 --- /dev/null +++ b/sysbuild-example/sysbuild.conf @@ -0,0 +1 @@ +SB_CONFIG_BOOTLOADER_MCUBOOT=y diff --git a/sysbuild-example/sysbuild/mcuboot.conf b/sysbuild-example/sysbuild/mcuboot.conf new file mode 100644 index 00000000..166d338f --- /dev/null +++ b/sysbuild-example/sysbuild/mcuboot.conf @@ -0,0 +1,2 @@ +CONFIG_BOOT_SWAP_USING_SCRATCH=y + diff --git a/west.yml b/west.yml index 1ce0d50b..be221a50 100644 --- a/west.yml +++ b/west.yml @@ -21,3 +21,4 @@ manifest: - hal_nordic # required by the custom_plank board (Nordic based) - hal_stm32 # required by the nucleo_f302r8 board (STM32 based) - mcuboot + - mbedtls