From 0227e541989b455048bca3368e008d3f0b121880 Mon Sep 17 00:00:00 2001 From: Eduard Iten Date: Fri, 11 Jul 2025 15:10:10 +0200 Subject: [PATCH] bootloader somehow working Signed-off-by: Eduard Iten --- software/apps/bl_test/CMakeLists.txt | 7 ++ software/apps/bl_test/VERSION | 5 + software/apps/bl_test/prj.conf | 46 +++++++++ software/apps/bl_test/src/main.c | 11 +++ software/apps/bl_test/sysbuild.conf | 1 + .../apps/bl_test/sysbuild/bl_test.overlay | 9 ++ software/apps/bl_test/sysbuild/common.dtsi | 94 +++++++++++++++++++ software/apps/bl_test/sysbuild/mcuboot.conf | 23 +++++ .../apps/bl_test/sysbuild/mcuboot.overlay | 8 ++ software/apps/firmware_node/CMakeLists.txt | 0 software/apps/firmware_node/README.md | 0 .../boards/flash_partitions_128kb.dtsi | 0 .../boards/weact_stm32g431_core.overlay | 0 software/apps/firmware_node/pm.yml | 0 software/apps/firmware_node/prj.conf | 0 software/apps/firmware_node/src/main.c | 0 software/apps/firmware_node/sysbuild.cmake | 0 software/apps/firmware_node/sysbuild.conf | 0 .../sysbuild/firmware_node.overlay | 0 .../apps/firmware_node/sysbuild/mcuboot.conf | 0 .../firmware_node/sysbuild/mcuboot.overlay | 0 .../boards/weact_stm32g431_core.overlay | 0 22 files changed, 204 insertions(+) create mode 100644 software/apps/bl_test/CMakeLists.txt create mode 100644 software/apps/bl_test/VERSION create mode 100644 software/apps/bl_test/prj.conf create mode 100644 software/apps/bl_test/src/main.c create mode 100644 software/apps/bl_test/sysbuild.conf create mode 100644 software/apps/bl_test/sysbuild/bl_test.overlay create mode 100644 software/apps/bl_test/sysbuild/common.dtsi create mode 100644 software/apps/bl_test/sysbuild/mcuboot.conf create mode 100644 software/apps/bl_test/sysbuild/mcuboot.overlay delete mode 100644 software/apps/firmware_node/CMakeLists.txt delete mode 100644 software/apps/firmware_node/README.md delete mode 100644 software/apps/firmware_node/boards/flash_partitions_128kb.dtsi delete mode 100644 software/apps/firmware_node/boards/weact_stm32g431_core.overlay delete mode 100644 software/apps/firmware_node/pm.yml delete mode 100644 software/apps/firmware_node/prj.conf delete mode 100644 software/apps/firmware_node/src/main.c delete mode 100644 software/apps/firmware_node/sysbuild.cmake delete mode 100644 software/apps/firmware_node/sysbuild.conf delete mode 100644 software/apps/firmware_node/sysbuild/firmware_node.overlay delete mode 100644 software/apps/firmware_node/sysbuild/mcuboot.conf delete mode 100644 software/apps/firmware_node/sysbuild/mcuboot.overlay delete mode 100644 software/apps/firmware_node/sysbuild/mcuboot/boards/weact_stm32g431_core.overlay diff --git a/software/apps/bl_test/CMakeLists.txt b/software/apps/bl_test/CMakeLists.txt new file mode 100644 index 0000000..47c912e --- /dev/null +++ b/software/apps/bl_test/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(bl_test) + +# Add application source files +target_sources(app PRIVATE src/main.c) diff --git a/software/apps/bl_test/VERSION b/software/apps/bl_test/VERSION new file mode 100644 index 0000000..2bdb1ca --- /dev/null +++ b/software/apps/bl_test/VERSION @@ -0,0 +1,5 @@ +VERSION_MAJOR = 0 +VERSION_MINOR = 0 +PATCHLEVEL = 1 +VERSION_TWEAK = 1 +EXTRAVERSION = devel \ No newline at end of file diff --git a/software/apps/bl_test/prj.conf b/software/apps/bl_test/prj.conf new file mode 100644 index 0000000..2ee34b9 --- /dev/null +++ b/software/apps/bl_test/prj.conf @@ -0,0 +1,46 @@ +# Enable Console and printk for logging via UART +CONFIG_CONSOLE=y +CONFIG_LOG=y +CONFIG_UART_CONSOLE=y + +# Enable more detailed MCUMGR logging +CONFIG_MCUMGR_LOG_LEVEL_DBG=y +CONFIG_IMG_MANAGER_LOG_LEVEL_DBG=y +CONFIG_STREAM_FLASH_LOG_LEVEL_DBG=y + +# Enable USB for MCUMGR only +CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_CDC_ACM=y +CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y + +# USB CDC ACM buffer configuration for better MCUMGR performance +CONFIG_USB_CDC_ACM_RINGBUF_SIZE=1024 + +# Set log level to info for reasonable size +CONFIG_LOG_DEFAULT_LEVEL=3 + +# Enable MCUMGR info logging (not debug to save space) +CONFIG_MCUMGR_LOG_LEVEL_INF=y + +# Enable USB CDC info logging +CONFIG_USB_CDC_ACM_LOG_LEVEL_INF=y + +# STEP 5.2 - Enable mcumgr DFU in application +# Enable MCUMGR +CONFIG_MCUMGR=y # Enable MCUMGR management for both OS and Images +CONFIG_MCUMGR_GRP_OS=y +CONFIG_MCUMGR_GRP_IMG=y + +# Configure MCUMGR transport to UART (will use USB-CDC via chosen device) +CONFIG_MCUMGR_TRANSPORT_UART=y + +# Dependencies +# Configure dependencies for CONFIG_MCUMGR +CONFIG_NET_BUF=y +CONFIG_ZCBOR=y +CONFIG_CRC=y # Configure dependencies for CONFIG_MCUMGR_GRP_IMG +CONFIG_FLASH=y +CONFIG_IMG_MANAGER=y # Configure dependencies for CONFIG_IMG_MANAGER +CONFIG_STREAM_FLASH=y +CONFIG_FLASH_MAP=y # Configure dependencies for CONFIG_MCUMGR_TRANSPORT_USB_CDC +CONFIG_BASE64=y diff --git a/software/apps/bl_test/src/main.c b/software/apps/bl_test/src/main.c new file mode 100644 index 0000000..1ebfc46 --- /dev/null +++ b/software/apps/bl_test/src/main.c @@ -0,0 +1,11 @@ +#include +#include +#include + +LOG_MODULE_REGISTER(bl_test_app, LOG_LEVEL_INF); + +int main(void) +{ + LOG_INF("Hello World from bl_test! This is version %s", APP_VERSION_EXTENDED_STRING); + return 0; +} diff --git a/software/apps/bl_test/sysbuild.conf b/software/apps/bl_test/sysbuild.conf new file mode 100644 index 0000000..721a76f --- /dev/null +++ b/software/apps/bl_test/sysbuild.conf @@ -0,0 +1 @@ +SB_CONFIG_BOOTLOADER_MCUBOOT=y \ No newline at end of file diff --git a/software/apps/bl_test/sysbuild/bl_test.overlay b/software/apps/bl_test/sysbuild/bl_test.overlay new file mode 100644 index 0000000..458afc8 --- /dev/null +++ b/software/apps/bl_test/sysbuild/bl_test.overlay @@ -0,0 +1,9 @@ +#include "common.dtsi" + +/* Application Configuration - Firmware wird in slot0_partition geschrieben */ +/ { + chosen { + zephyr,code-partition = &slot0_partition; + zephyr,uart-mcumgr = &cdc_acm_uart0; + }; +}; \ No newline at end of file diff --git a/software/apps/bl_test/sysbuild/common.dtsi b/software/apps/bl_test/sysbuild/common.dtsi new file mode 100644 index 0000000..5199a2f --- /dev/null +++ b/software/apps/bl_test/sysbuild/common.dtsi @@ -0,0 +1,94 @@ +/* + * Common Devicetree Configuration für weact_stm32g431_core + * - Konfiguriert einen W25Q128 Flash-Speicher auf SPI2 + * - Konfiguriert USB-CDC für MCUMGR + * - Setzt den Chip Select (CS) Pin auf PA5 + * - Weist das Label "flash1" zu + */ + +/* Partitions für internes Flash (STM32G431) */ +&flash0 { + /delete-node/ partitions; /* Entferne die Standard-Partitionen */ + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + /* MCUboot bootloader - 48 KB */ + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0x0000C000>; + }; + + /* Slot0 partition für primäres Application Image - 80 KB (20 sectors @ 4KB) */ + slot0_partition: partition@C000 { + label = "image-0"; + reg = <0x0000C000 0x00014000>; + }; + }; +}; + +/* USB-CDC Konfiguration für MCUMGR */ +&usb { + status = "okay"; + cdc_acm_uart0: cdc_acm_uart0 { + compatible = "zephyr,cdc-acm-uart"; + }; +}; + +/ { + chosen { + zephyr,uart-mcumgr = &cdc_acm_uart0; + }; +}; + +&spi2 { + /* Definiere die Pins für SCK, MISO, MOSI auf Port B */ + pinctrl-0 = <&spi2_sck_pb13 &spi2_miso_pb14 &spi2_mosi_pb15>; + pinctrl-names = "default"; + status = "okay"; + + /* === Chip Select (CS) auf PA5 gesetzt === */ + cs-gpios = <&gpioa 5 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; + + /* Definiere den Flash-Chip als SPI NOR Gerät */ + flash1: flash@0 { + compatible = "jedec,spi-nor"; + reg = <0>; + label = "flash1"; + + /* JEDEC ID für einen Winbond W25Q128 (16 MBytes) */ + jedec-id = [ef 40 18]; + + /* Speichergröße in Bytes (16 MBytes) */ + size = ; + + /* Maximale Taktfrequenz - angepasst an STM32G431 Limits */ + spi-max-frequency = <1000000>; + + /* Partitions für externes Flash */ + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + /* Slot1 partition für MCUboot (sekundäres Image) - 80 KB (20 sectors @ 4KB) */ + slot1_partition: partition@0 { + label = "image-1"; + reg = <0x00000000 0x00014000>; + }; + + /* Scratch partition für MCUboot - 80 KB (20 sectors @ 4KB) */ + scratch_partition: partition@14000 { + label = "scratch"; + reg = <0x00014000 0x00014000>; + }; + + /* Speicher partition für LittleFS - ~15.83 MB */ + storage_partition: partition@28000 { + label = "storage"; + reg = <0x00028000 0x00FD8000>; + }; + }; + }; +}; diff --git a/software/apps/bl_test/sysbuild/mcuboot.conf b/software/apps/bl_test/sysbuild/mcuboot.conf new file mode 100644 index 0000000..2547ccf --- /dev/null +++ b/software/apps/bl_test/sysbuild/mcuboot.conf @@ -0,0 +1,23 @@ +CONFIG_LOG=y +CONFIG_MCUBOOT_LOG_LEVEL_INF=y + +# Enable UART console for MCUboot debug output +CONFIG_UART_CONSOLE=y +CONFIG_CONSOLE=y +CONFIG_MCUBOOT_INDICATION_LED=y + +# Enable external SPI flash support +CONFIG_SPI=y +CONFIG_SPI_NOR=y +CONFIG_SPI_NOR_SFDP_DEVICETREE=n +CONFIG_FLASH=y +CONFIG_FLASH_MAP=y +CONFIG_GPIO=y + +# Add SPI NOR specific configurations - use 4KB page size (required by driver) +CONFIG_SPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096 +CONFIG_SPI_NOR_INIT_PRIORITY=80 + +# Set maximum image sectors manually since auto doesn't work with external flash +CONFIG_BOOT_MAX_IMG_SECTORS_AUTO=n +CONFIG_BOOT_MAX_IMG_SECTORS=80 diff --git a/software/apps/bl_test/sysbuild/mcuboot.overlay b/software/apps/bl_test/sysbuild/mcuboot.overlay new file mode 100644 index 0000000..4206680 --- /dev/null +++ b/software/apps/bl_test/sysbuild/mcuboot.overlay @@ -0,0 +1,8 @@ +#include "common.dtsi" + +/* MCUboot Configuration - Bootloader wird in boot_partition geschrieben */ +/ { + chosen { + zephyr,code-partition = &boot_partition; + }; +}; diff --git a/software/apps/firmware_node/CMakeLists.txt b/software/apps/firmware_node/CMakeLists.txt deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/firmware_node/README.md b/software/apps/firmware_node/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/firmware_node/boards/flash_partitions_128kb.dtsi b/software/apps/firmware_node/boards/flash_partitions_128kb.dtsi deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/firmware_node/boards/weact_stm32g431_core.overlay b/software/apps/firmware_node/boards/weact_stm32g431_core.overlay deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/firmware_node/pm.yml b/software/apps/firmware_node/pm.yml deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/firmware_node/prj.conf b/software/apps/firmware_node/prj.conf deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/firmware_node/src/main.c b/software/apps/firmware_node/src/main.c deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/firmware_node/sysbuild.cmake b/software/apps/firmware_node/sysbuild.cmake deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/firmware_node/sysbuild.conf b/software/apps/firmware_node/sysbuild.conf deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/firmware_node/sysbuild/firmware_node.overlay b/software/apps/firmware_node/sysbuild/firmware_node.overlay deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/firmware_node/sysbuild/mcuboot.conf b/software/apps/firmware_node/sysbuild/mcuboot.conf deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/firmware_node/sysbuild/mcuboot.overlay b/software/apps/firmware_node/sysbuild/mcuboot.overlay deleted file mode 100644 index e69de29..0000000 diff --git a/software/apps/firmware_node/sysbuild/mcuboot/boards/weact_stm32g431_core.overlay b/software/apps/firmware_node/sysbuild/mcuboot/boards/weact_stm32g431_core.overlay deleted file mode 100644 index e69de29..0000000