From 928a176e7cfd420dabc0b38c6de9ba3d35a9f7fe Mon Sep 17 00:00:00 2001 From: Eduard Iten Date: Mon, 7 Jul 2025 15:59:41 +0200 Subject: [PATCH] Step 2 complete: MCUboot integration with single-slot configuration - Created sysbuild configuration for MCUboot bootloader - Added device tree overlays for correct partition layout (32KB MCUboot, 96KB app) - Fixed MCUboot partition addressing to use boot_partition instead of slot0_partition - MCUboot successfully boots and chains to application - Application runs with shell and custom reset command - Disabled signature validation for testing purposes --- .../boards/weact_stm32g431_core.overlay | 30 +++++++++++++++++++ .../weact_stm32g431_core_mcuboot.overlay | 18 +++++++++++ software/apps/firmware_node/pm.yml | 25 ++++++++++++++++ software/apps/firmware_node/prj.conf | 5 ++++ software/apps/firmware_node/sysbuild.cmake | 12 -------- software/apps/firmware_node/sysbuild.conf | 5 ++++ .../sysbuild/firmware_node.overlay | 30 +++++++++++++++++++ .../apps/firmware_node/sysbuild/mcuboot.conf | 11 +++++++ .../firmware_node/sysbuild/mcuboot.overlay | 30 +++++++++++++++++++ 9 files changed, 154 insertions(+), 12 deletions(-) create mode 100644 software/apps/firmware_node/boards/weact_stm32g431_core.overlay create mode 100644 software/apps/firmware_node/boards/weact_stm32g431_core_mcuboot.overlay create mode 100644 software/apps/firmware_node/pm.yml delete mode 100644 software/apps/firmware_node/sysbuild.cmake create mode 100644 software/apps/firmware_node/sysbuild.conf create mode 100644 software/apps/firmware_node/sysbuild/firmware_node.overlay create mode 100644 software/apps/firmware_node/sysbuild/mcuboot.conf create mode 100644 software/apps/firmware_node/sysbuild/mcuboot.overlay diff --git a/software/apps/firmware_node/boards/weact_stm32g431_core.overlay b/software/apps/firmware_node/boards/weact_stm32g431_core.overlay new file mode 100644 index 0000000..521d20d --- /dev/null +++ b/software/apps/firmware_node/boards/weact_stm32g431_core.overlay @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x00008000>; /* 32 KB */ + read-only; + }; + + slot0_partition: partition@8000 { + label = "image-0"; + reg = <0x00008000 0x00018000>; /* 96 KB */ + }; + }; +}; + +/ { + chosen { + zephyr,code-partition = &slot0_partition; + }; +}; diff --git a/software/apps/firmware_node/boards/weact_stm32g431_core_mcuboot.overlay b/software/apps/firmware_node/boards/weact_stm32g431_core_mcuboot.overlay new file mode 100644 index 0000000..673e79e --- /dev/null +++ b/software/apps/firmware_node/boards/weact_stm32g431_core_mcuboot.overlay @@ -0,0 +1,18 @@ +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x00008000>; /* 32 KB */ + read-only; + }; + + slot0_partition: partition@8000 { + label = "image-0"; + reg = <0x00008000 0x00018000>; /* 96 KB */ + }; + }; +}; diff --git a/software/apps/firmware_node/pm.yml b/software/apps/firmware_node/pm.yml new file mode 100644 index 0000000..fe5d814 --- /dev/null +++ b/software/apps/firmware_node/pm.yml @@ -0,0 +1,25 @@ +# Partition manager configuration for firmware_node + +# Boot partition (MCUboot) +mcuboot_primary: + address: 0x00000000 + size: 0x8000 + region: flash_primary + +# Application partition (primary slot) +mcuboot_primary_app: + address: 0x00008000 + size: 0x18000 + region: flash_primary + +# Secondary slot for updates +mcuboot_secondary: + address: 0x00020000 + size: 0x18000 + region: flash_primary + +# Settings partition +settings_partition: + address: 0x00038000 + size: 0x8000 + region: flash_primary diff --git a/software/apps/firmware_node/prj.conf b/software/apps/firmware_node/prj.conf index 7609528..4bc36b8 100644 --- a/software/apps/firmware_node/prj.conf +++ b/software/apps/firmware_node/prj.conf @@ -8,3 +8,8 @@ CONFIG_REBOOT=y # Enable the reset command CONFIG_KERNEL_SHELL=y + +# Enable settings for persistent storage +CONFIG_SETTINGS=y +CONFIG_SETTINGS_NVS=y +CONFIG_NVS=y diff --git a/software/apps/firmware_node/sysbuild.cmake b/software/apps/firmware_node/sysbuild.cmake deleted file mode 100644 index 53e3311..0000000 --- a/software/apps/firmware_node/sysbuild.cmake +++ /dev/null @@ -1,12 +0,0 @@ -# Enable MCUboot -set(SB_CONFIG_BOOTLOADER_MCUBOOT y) - -# MCUboot configuration -set(SB_CONFIG_MCUBOOT_BOOTLOADER_MODE_OVERWRITE_ONLY y) -set(SB_CONFIG_MCUBOOT_SIGNATURE_KEY_FILE "bootloader/mcuboot/root-rsa-2048.pem") -set(SB_CONFIG_MCUBOOT_GENERATE_UNSIGNED_IMAGE y) -set(SB_CONFIG_MCUBOOT_GENERATE_CONFIRMED_IMAGE y) - -# Enable USB CDC ACM for MCUboot console -set(SB_CONFIG_MCUBOOT_USB_SUPPORT y) -set(SB_CONFIG_MCUBOOT_SERIAL y) diff --git a/software/apps/firmware_node/sysbuild.conf b/software/apps/firmware_node/sysbuild.conf new file mode 100644 index 0000000..288d889 --- /dev/null +++ b/software/apps/firmware_node/sysbuild.conf @@ -0,0 +1,5 @@ +# Sysbuild configuration for firmware_node with MCUboot + +# Enable MCUboot as bootloader +SB_CONFIG_BOOTLOADER_MCUBOOT=y +SB_CONFIG_MCUBOOT_MODE_SINGLE_APP=y \ No newline at end of file diff --git a/software/apps/firmware_node/sysbuild/firmware_node.overlay b/software/apps/firmware_node/sysbuild/firmware_node.overlay new file mode 100644 index 0000000..521d20d --- /dev/null +++ b/software/apps/firmware_node/sysbuild/firmware_node.overlay @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x00008000>; /* 32 KB */ + read-only; + }; + + slot0_partition: partition@8000 { + label = "image-0"; + reg = <0x00008000 0x00018000>; /* 96 KB */ + }; + }; +}; + +/ { + chosen { + zephyr,code-partition = &slot0_partition; + }; +}; diff --git a/software/apps/firmware_node/sysbuild/mcuboot.conf b/software/apps/firmware_node/sysbuild/mcuboot.conf new file mode 100644 index 0000000..851897b --- /dev/null +++ b/software/apps/firmware_node/sysbuild/mcuboot.conf @@ -0,0 +1,11 @@ +# MCUboot configuration for firmware_node +CONFIG_LOG=y +CONFIG_BOOT_BANNER=y +CONFIG_MCUBOOT_LOG_LEVEL_DBG=y +# Enable console in MCUboot to see debug output +CONFIG_CONSOLE=y +# Single slot configuration (no upgrades) +CONFIG_SINGLE_APPLICATION_SLOT=y + +# Disable signature validation for testing +CONFIG_BOOT_SIGNATURE_TYPE_NONE=y diff --git a/software/apps/firmware_node/sysbuild/mcuboot.overlay b/software/apps/firmware_node/sysbuild/mcuboot.overlay new file mode 100644 index 0000000..d31c4cb --- /dev/null +++ b/software/apps/firmware_node/sysbuild/mcuboot.overlay @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x00008000>; /* 32 KB */ + read-only; + }; + + slot0_partition: partition@8000 { + label = "image-0"; + reg = <0x00008000 0x00018000>; /* 96 KB */ + }; + }; +}; + +/ { + chosen { + zephyr,code-partition = &boot_partition; + }; +};