From 118462a1f989dab5b313f1e2a91e12ab1a839ca8 Mon Sep 17 00:00:00 2001 From: M Starch Date: Sat, 15 Nov 2025 15:36:19 -0800 Subject: [PATCH 01/18] Bump to Zephyr v4.3.0 --- .codespell-ignore-words.txt | 1 + .../ReferenceDeployment/Top/instances.fpp | 2 +- .../proves_flight_control_board_v5.dtsi | 30 +------------------ .../Kconfig.proves_flight_control_board_v5c | 2 +- ...ht_control_board_v5c_rp2350a_m33_defconfig | 12 ++++++-- .../Kconfig.proves_flight_control_board_v5d | 2 +- ...ht_control_board_v5d_rp2350a_m33_defconfig | 12 ++++++-- lib/fprime | 2 +- lib/fprime-zephyr | 2 +- lib/zephyr-workspace/zephyr | 2 +- prj.conf | 12 +++----- west.yml | 29 ++++++------------ 12 files changed, 39 insertions(+), 69 deletions(-) diff --git a/.codespell-ignore-words.txt b/.codespell-ignore-words.txt index c72c89e9..3d64f1a1 100644 --- a/.codespell-ignore-words.txt +++ b/.codespell-ignore-words.txt @@ -1,2 +1,3 @@ comIn Ines +rsource diff --git a/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp b/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp index 099fdb45..f6a1c069 100644 --- a/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp +++ b/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp @@ -38,7 +38,7 @@ module ReferenceDeployment { priority 3 instance cmdSeq: Svc.CmdSequencer base id 0x10006000 \ - queue size Default.QUEUE_SIZE \ + queue size Default.QUEUE_SIZE * 2 \ stack size Default.STACK_SIZE \ priority 15 diff --git a/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5.dtsi b/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5.dtsi index 1141469b..78eb6a54 100644 --- a/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5.dtsi +++ b/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5.dtsi @@ -11,7 +11,6 @@ zephyr,flash = &flash0; zephyr,console = &cdc_acm_uart0; zephyr,shell-uart = &cdc_acm_uart0; - zephyr,code-partition = &code_partition; }; fstab { @@ -58,34 +57,7 @@ zephyr_udc0: &usbd { }; &flash0 { - reg = <0x10000000 DT_SIZE_M(4)>; - - partitions { - compatible = "fixed-partitions"; - #address-cells = <1>; - #size-cells = <1>; - - /* Reserved memory for an image definition block. The block is much - * smaller than 256 bytes, but in practice the linker places the vector - * table at a much larger alignment offset. - */ - image_def: partition@0 { - label = "image_def"; - reg = <0x00000000 0x100>; - read-only; - }; - - /* - * Usable flash. Starts at 0x100, after the image definition block. - * The partition size is 4MB minus the 0x100 bytes taken by the - * image definition. - */ - code_partition: partition@100 { - label = "code-partition"; - reg = <0x100 (DT_SIZE_M(4) - 0x100)>; - read-only; - }; - }; + reg = <0x10000000 DT_SIZE_M(4)>; }; &timer0 { diff --git a/boards/bronco_space/proves_flight_control_board_v5c/Kconfig.proves_flight_control_board_v5c b/boards/bronco_space/proves_flight_control_board_v5c/Kconfig.proves_flight_control_board_v5c index ce2e6e17..e121c9a2 100644 --- a/boards/bronco_space/proves_flight_control_board_v5c/Kconfig.proves_flight_control_board_v5c +++ b/boards/bronco_space/proves_flight_control_board_v5c/Kconfig.proves_flight_control_board_v5c @@ -1 +1 @@ -source "../../../boards/bronco_space/proves_flight_control_board_v5/Kconfig.defconfig" +rsource "../../../boards/bronco_space/proves_flight_control_board_v5/Kconfig.defconfig" diff --git a/boards/bronco_space/proves_flight_control_board_v5c/proves_flight_control_board_v5c_rp2350a_m33_defconfig b/boards/bronco_space/proves_flight_control_board_v5c/proves_flight_control_board_v5c_rp2350a_m33_defconfig index 02bb4603..176cb4e4 100644 --- a/boards/bronco_space/proves_flight_control_board_v5c/proves_flight_control_board_v5c_rp2350a_m33_defconfig +++ b/boards/bronco_space/proves_flight_control_board_v5c/proves_flight_control_board_v5c_rp2350a_m33_defconfig @@ -8,9 +8,15 @@ CONFIG_SERIAL=y CONFIG_UART_CONSOLE=y CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_USE_DT_CODE_PARTITION=y -CONFIG_USB_DEVICE_STACK=y -CONFIG_USB_DEVICE_PRODUCT="PROVES Flight Control Board v5c" -CONFIG_USB_DEVICE_VID=0x0028 + +# USB Next Stack +CONFIG_USBD_CDC_ACM_CLASS=y +CONFIG_USB_DEVICE_STACK_NEXT=y +CONFIG_CDC_ACM_SERIAL_ENABLE_AT_BOOT=y +CONFIG_CDC_ACM_SERIAL_INITIALIZE_AT_BOOT=y +CONFIG_CDC_ACM_SERIAL_PID=0x000F +CONFIG_CDC_ACM_SERIAL_VID=0x0028 +CONFIG_CDC_ACM_SERIAL_PRODUCT_STRING="PROVES Flight Control Board v5c" # Sensors CONFIG_LSM6DSO=y diff --git a/boards/bronco_space/proves_flight_control_board_v5d/Kconfig.proves_flight_control_board_v5d b/boards/bronco_space/proves_flight_control_board_v5d/Kconfig.proves_flight_control_board_v5d index b3bd39fa..2fb77af4 100644 --- a/boards/bronco_space/proves_flight_control_board_v5d/Kconfig.proves_flight_control_board_v5d +++ b/boards/bronco_space/proves_flight_control_board_v5d/Kconfig.proves_flight_control_board_v5d @@ -2,4 +2,4 @@ config BOARD_PROVES_FLIGHT_CONTROL_BOARD_V5D bool "PROVES Flight Control Board v5d" default y -source "../../../boards/bronco_space/proves_flight_control_board_v5/Kconfig.defconfig" +rsource "../../../boards/bronco_space/proves_flight_control_board_v5/Kconfig.defconfig" diff --git a/boards/bronco_space/proves_flight_control_board_v5d/proves_flight_control_board_v5d_rp2350a_m33_defconfig b/boards/bronco_space/proves_flight_control_board_v5d/proves_flight_control_board_v5d_rp2350a_m33_defconfig index fccf5b0f..12f07e11 100644 --- a/boards/bronco_space/proves_flight_control_board_v5d/proves_flight_control_board_v5d_rp2350a_m33_defconfig +++ b/boards/bronco_space/proves_flight_control_board_v5d/proves_flight_control_board_v5d_rp2350a_m33_defconfig @@ -8,9 +8,15 @@ CONFIG_SERIAL=y CONFIG_UART_CONSOLE=y CONFIG_UART_INTERRUPT_DRIVEN=y CONFIG_USE_DT_CODE_PARTITION=y -CONFIG_USB_DEVICE_STACK=y -CONFIG_USB_DEVICE_PRODUCT="PROVES Flight Control Board v5d" -CONFIG_USB_DEVICE_VID=0x0028 + +# USB Next Stack +CONFIG_USBD_CDC_ACM_CLASS=y +CONFIG_USB_DEVICE_STACK_NEXT=y +CONFIG_CDC_ACM_SERIAL_ENABLE_AT_BOOT=y +CONFIG_CDC_ACM_SERIAL_INITIALIZE_AT_BOOT=y +CONFIG_CDC_ACM_SERIAL_PID=0x000F +CONFIG_CDC_ACM_SERIAL_VID=0x0028 +CONFIG_CDC_ACM_SERIAL_PRODUCT_STRING="PROVES Flight Control Board v5d" # Sensors CONFIG_LSM6DSO=y diff --git a/lib/fprime b/lib/fprime index 146f0edc..589871a9 160000 --- a/lib/fprime +++ b/lib/fprime @@ -1 +1 @@ -Subproject commit 146f0edc486159ada15591587d22bcc4315a1341 +Subproject commit 589871a957802bb0ea96a98122418a514440cb5b diff --git a/lib/fprime-zephyr b/lib/fprime-zephyr index 3b2775dc..66ea1412 160000 --- a/lib/fprime-zephyr +++ b/lib/fprime-zephyr @@ -1 +1 @@ -Subproject commit 3b2775dc284073685752d046be899b9d47709934 +Subproject commit 66ea141240a6cb0f4abab2815a8e41bc4b144b81 diff --git a/lib/zephyr-workspace/zephyr b/lib/zephyr-workspace/zephyr index 413b789d..3568e1b6 160000 --- a/lib/zephyr-workspace/zephyr +++ b/lib/zephyr-workspace/zephyr @@ -1 +1 @@ -Subproject commit 413b789deb391d3a37d06b463288a5fe765ee57e +Subproject commit 3568e1b6d5cdd51a6b964a2a1d6d29200fea2056 diff --git a/prj.conf b/prj.conf index a422ba52..016c5884 100644 --- a/prj.conf +++ b/prj.conf @@ -1,9 +1,5 @@ #### Configure Device VID and PID --> Uncomment the desired device definitions #### -#### From Raspberry Pi Pico2 USB Definitions #### -CONFIG_USB_DEVICE_PID=0x000F -CONFIG_USB_DEVICE_VID=0x2E8A - #### F Prime C++ Dependencies #### CONFIG_CPP=y CONFIG_REQUIRES_FULL_LIBCPP=y @@ -15,9 +11,9 @@ CONFIG_POSIX_API=y CONFIG_REBOOT=y #### Native USB #### -CONFIG_USB_DEVICE_STACK=y -CONFIG_USB_CDC_ACM=y -CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y +#CONFIG_USB_DEVICE_STACK=y +#CONFIG_USB_CDC_ACM=y +#CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y CONFIG_UART_INTERRUPT_DRIVEN=y #### Serial and I/O #### @@ -36,7 +32,7 @@ CONFIG_DYNAMIC_THREAD=y CONFIG_KERNEL_MEM_POOL=y CONFIG_DYNAMIC_THREAD_ALLOC=n CONFIG_DYNAMIC_THREAD_PREFER_POOL=y -CONFIG_DYNAMIC_THREAD_POOL_SIZE=20 +CONFIG_DYNAMIC_THREAD_POOL_SIZE=30 # Num threads in the thread pool CONFIG_DYNAMIC_THREAD_STACK_SIZE=8192 # Size of thread stack in thread pool, must be >= Thread Pool size in F' diff --git a/west.yml b/west.yml index c1a61d83..05c4dc99 100644 --- a/west.yml +++ b/west.yml @@ -17,18 +17,25 @@ manifest: # Zephyr RTOS core - name: zephyr repo-path: zephyr - revision: v4.2.0 + revision: v4.3.0 path: lib/zephyr-workspace/zephyr west-commands: scripts/west-commands.yml import: # Import specific submanifests only (instead of all submanifests) name-allowlist: - cmsis # ARM CMSIS support (required for Cortex-M) + - cmsis_6 # ARM CMSIS 6 support (required for RPI) - hal_rpi_pico # Raspberry Pi Pico HAL (REQUIRED for RP2040/RP2350) - picolibc # C library - mbedtls # Crypto library - tinycrypt # Lightweight crypto library - mcuboot # Bootloader support + - fatfs # FatFS (file system) support + - hal_st # Required for certain sensors + + - name: loramac-node + revision: fb00b383072518c918e2258b0916c996f2d4eebe + path: lib/zephyr-workspace/modules/lib/loramac-node # Core modules required for RP2040/RP2350 - name: cmsis @@ -46,7 +53,7 @@ manifest: - name: hal_rpi_pico path: lib/zephyr-workspace/modules/hal/rpi_pico - revision: 7b57b24588797e6e7bf18b6bda168e6b96374264 + revision: 09e957522da60581cf7958b31f8e625d969c69a5 groups: - hal @@ -60,10 +67,6 @@ manifest: path: lib/zephyr-workspace/modules/lib/picolibc revision: 560946f26db075c296beea5b39d99e6de43c9010 - - name: loramac-node - revision: fb00b383072518c918e2258b0916c996f2d4eebe - path: lib/zephyr-workspace/modules/lib/loramac-node - # Crypto libraries (commonly used) - name: mbedtls revision: 85440ef5fffa95d0e9971e9163719189cf34d979 @@ -77,20 +80,6 @@ manifest: groups: - crypto - # Bootloader support (optional - remove if not needed) - - name: mcuboot - revision: 4eba8087fa606db801455f14d185255bc8c49467 - path: lib/zephyr-workspace/bootloader/mcuboot - groups: - - bootloader - - # FAT Filesystem support - - name: fatfs - revision: 16245c7c41d2b79e74984f49b5202551786b8a9b - path: lib/zephyr-workspace/modules/fs/fatfs - groups: - - fs - self: path: . west-commands: west-commands.yml From 946b2245440bbb869adef981b953e02e12f064f1 Mon Sep 17 00:00:00 2001 From: M Starch Date: Fri, 21 Nov 2025 20:41:27 -0800 Subject: [PATCH 02/18] Add bootloader changes --- .../Kconfig.defconfig | 3 ++ .../proves_flight_control_board_v5.dtsi | 38 ++++++++++++++++++- ..._flight_control_board_v5d_rp2350a_m33.yaml | 2 +- prj.conf | 5 +++ west.yml | 4 ++ 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/boards/bronco_space/proves_flight_control_board_v5/Kconfig.defconfig b/boards/bronco_space/proves_flight_control_board_v5/Kconfig.defconfig index 53c0c734..c3b08ffe 100644 --- a/boards/bronco_space/proves_flight_control_board_v5/Kconfig.defconfig +++ b/boards/bronco_space/proves_flight_control_board_v5/Kconfig.defconfig @@ -3,10 +3,13 @@ config SOC_RP2350A_M33 default y config USB_SELF_POWERED + bool "Enable USB_SELF_POWERED" default n config USB_CDC_ACM_LOG_LEVEL + int "Log level" default 0 config USB_DEVICE_LOG_LEVEL + int "Log level" default 1 diff --git a/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5.dtsi b/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5.dtsi index 78eb6a54..5793f36b 100644 --- a/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5.dtsi +++ b/boards/bronco_space/proves_flight_control_board_v5/proves_flight_control_board_v5.dtsi @@ -9,8 +9,10 @@ chosen { zephyr,sram = &sram0; zephyr,flash = &flash0; + zephyr,flash-controller = &qmi; zephyr,console = &cdc_acm_uart0; zephyr,shell-uart = &cdc_acm_uart0; + zephyr,code-partition = &slot0_partition; }; fstab { @@ -56,8 +58,42 @@ zephyr_udc0: &usbd { }; }; +&qmi { + status = "okay"; +}; + &flash0 { - reg = <0x10000000 DT_SIZE_M(4)>; + reg = <0x10000000 DT_SIZE_M(4)>; + partitions { + compatible = "fixed-partitions"; + #address-cells = <0x1>; + #size-cells = <0x1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x0 0x100000>; + }; + + slot0_partition: partition@100000 { + label = "current"; + reg = <0x100000 0x100000>; + }; + + slot1_partition: partition@200000 { + label = "golden"; + reg = <0x200000 0x100000>; + }; + + slot2_partition: partition@300000 { + label = "test"; + reg = <0x300000 0x100000>; + }; + + storage_partition: partition@400000 { + label = "storage"; + reg = <0x400000 0xC00000>; + }; + }; }; &timer0 { diff --git a/boards/bronco_space/proves_flight_control_board_v5d/proves_flight_control_board_v5d_rp2350a_m33.yaml b/boards/bronco_space/proves_flight_control_board_v5d/proves_flight_control_board_v5d_rp2350a_m33.yaml index 6880c0c1..2de6ad15 100644 --- a/boards/bronco_space/proves_flight_control_board_v5d/proves_flight_control_board_v5d_rp2350a_m33.yaml +++ b/boards/bronco_space/proves_flight_control_board_v5d/proves_flight_control_board_v5d_rp2350a_m33.yaml @@ -2,7 +2,7 @@ identifier: proves_flight_control_board_v5d/rp2350a/m33 name: PROVES Flight Control Board v5d (RP2350, Cortex-M33) type: mcu arch: arm -flash: 4096 +flash: 16384 ram: 520 toolchain: - zephyr diff --git a/prj.conf b/prj.conf index 016c5884..066af249 100644 --- a/prj.conf +++ b/prj.conf @@ -61,3 +61,8 @@ CONFIG_FAT_FILESYSTEM_ELM=y CONFIG_FS_FATFS_EXFAT=y CONFIG_FS_FATFS_MOUNT_MKFS=y CONFIG_FS_FATFS_FSTAB_AUTOMOUNT=y +CONFIG_BOOTLOADER_MCUBOOT=y +CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="/home/starchmd/code/fprime-projects/bootloader/mcuboot/root-rsa-2048.pem" +CONFIG_FLASH=y +CONFIG_STREAM_FLASH=y +CONFIG_IMG_MANAGER=y diff --git a/west.yml b/west.yml index 05c4dc99..64e95a62 100644 --- a/west.yml +++ b/west.yml @@ -80,6 +80,10 @@ manifest: groups: - crypto + - name: mcuboot + revision: 96576b341ee19f1c3af6622256b0d4f3d408e1e3 + path: lib/zephyr-workspace/bootloader/mcuboot + self: path: . west-commands: west-commands.yml From 9904caa2abdfe4d5e0d6467df7461ffa3aaf26b7 Mon Sep 17 00:00:00 2001 From: M Starch Date: Fri, 21 Nov 2025 21:17:58 -0800 Subject: [PATCH 03/18] Add boot tools and instructions --- .gitignore | 2 +- README.md | 19 +++++++++++++++++++ tools/bin/build-with-proves | 11 +++++++++++ tools/bin/make-loadable-image | 12 ++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 tools/bin/build-with-proves create mode 100755 tools/bin/make-loadable-image diff --git a/.gitignore b/.gitignore index 35c3901a..2549b294 100644 --- a/.gitignore +++ b/.gitignore @@ -23,5 +23,5 @@ settings.ini **/__pycache__/ **/*.egg-info/ -bin/ +/bin/ _codeql_detected_source_root diff --git a/README.md b/README.md index d70a075e..315e4fee 100644 --- a/README.md +++ b/README.md @@ -109,3 +109,22 @@ Depending on the comdelay, the gds should turn green every time a packet is sent ## Sequences You can control the specific command lists of the satellite by writing a sequence file. Sequence files are contained in /sequences. For details on how to attack the startup sequence check the sdd in Startup Manager. + +## MCUBootloader + +First, build the bootloader with west. This is easiest accomplished by building the `sysbuild` example "with_mcuboot" in zephyr. + +``` +cd /samples/sysbuild/with_mcubuild +/tools/bin/build-with-proves --sysbuild +``` + +Once built, upload `build/mcuboot/zephyr/zephyr.uf2` like normally done. + +Then build Proves like normal. This will make a UF2, but not for the second flash region. To build a bootable image, use: + +``` +/tools/bin/build-bootable-image ./build-artifacts/zephyr.signed.bin ./bootable.uf2 +``` + +Now upload `bootable.uf2`. This should chain from MCUBoot to the bootable software image diff --git a/tools/bin/build-with-proves b/tools/bin/build-with-proves new file mode 100755 index 00000000..7bad6a60 --- /dev/null +++ b/tools/bin/build-with-proves @@ -0,0 +1,11 @@ +#!/bin/bash +DIRNAME="$(cd "$(dirname $BASH_SOURCE)"; pwd)" +PROVES_ROOT="$(cd ${DIRNAME}/../..; pwd)" + +which west +if (( $? != 0 )) +then + echo "[ERROR] 'west' not found. Source your virtual environment/" + exit 1 +fi +west build -p -b proves_flight_control_board_v5d/rp2350a/m33 "$@" -- -DBOARD_ROOT="${PROVES_ROOT}" diff --git a/tools/bin/make-loadable-image b/tools/bin/make-loadable-image new file mode 100755 index 00000000..887b5807 --- /dev/null +++ b/tools/bin/make-loadable-image @@ -0,0 +1,12 @@ +#!/bin/bash +DIRNAME="$(cd "$(dirname $BASH_SOURCE)"; pwd)" +ZEPHYR="${ZEPHYR_BASE:-${DIRNAME}/../../lib/zephyr-workspace/zephyr}" + +# Check arguments +if (( $# == 2 )) +then + echo "$0 " + exit 0 +fi + +python3 ${ZEPHYR}/scripts/build/uf2conv.py -c -f 0xe48bff57 -b 0x10100000 -o "$2" "$1" From a2fbea223810b670a4f50b00a269fa4a31e8de82 Mon Sep 17 00:00:00 2001 From: M Starch Date: Sat, 22 Nov 2025 18:03:32 -0800 Subject: [PATCH 04/18] Fix modules installation --- .west/config | 6 ++++++ prj.conf | 2 +- requirements.txt | 2 ++ west.yml | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .west/config diff --git a/.west/config b/.west/config new file mode 100644 index 00000000..8d67d99f --- /dev/null +++ b/.west/config @@ -0,0 +1,6 @@ +[manifest] +path = . +file = west.yml + +[zephyr] +base = ./lib/zephyr-workspace/zephyr diff --git a/prj.conf b/prj.conf index 066af249..2e57ebc1 100644 --- a/prj.conf +++ b/prj.conf @@ -62,7 +62,7 @@ CONFIG_FS_FATFS_EXFAT=y CONFIG_FS_FATFS_MOUNT_MKFS=y CONFIG_FS_FATFS_FSTAB_AUTOMOUNT=y CONFIG_BOOTLOADER_MCUBOOT=y -CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="/home/starchmd/code/fprime-projects/bootloader/mcuboot/root-rsa-2048.pem" +CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="/home/starchmd/code/fprime-projects/proves-core-reference/lib/zephyr-workspace/bootloader/mcuboot/root-rsa-2048.pem" CONFIG_FLASH=y CONFIG_STREAM_FLASH=y CONFIG_IMG_MANAGER=y diff --git a/requirements.txt b/requirements.txt index f6c91b4f..19f6df6b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,5 @@ pip west -r lib/fprime/requirements.txt +-r lib/zephyr-workspace/zephyr/scripts/requirements.txt +-r lib/zephyr-workspace/bootloader/mcuboot/zephyr/requirements.txt diff --git a/west.yml b/west.yml index 64e95a62..051b91be 100644 --- a/west.yml +++ b/west.yml @@ -84,6 +84,10 @@ manifest: revision: 96576b341ee19f1c3af6622256b0d4f3d408e1e3 path: lib/zephyr-workspace/bootloader/mcuboot + - name: fatfs + revision: f4ead3bf4a6dab3a07d7b5f5315795c073db568d + path: lib/zephyr-workspace/modules/fatfs + self: path: . west-commands: west-commands.yml From 4c41a63c136bef3299bf91e8203da0e91a451649 Mon Sep 17 00:00:00 2001 From: M Starch Date: Sat, 22 Nov 2025 19:57:56 -0800 Subject: [PATCH 05/18] Fix bad link --- prj.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/prj.conf b/prj.conf index 2e57ebc1..70becbdd 100644 --- a/prj.conf +++ b/prj.conf @@ -66,3 +66,4 @@ CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="/home/starchmd/code/fprime-projects/proves-co CONFIG_FLASH=y CONFIG_STREAM_FLASH=y CONFIG_IMG_MANAGER=y +CONFIG_MCUBOOT_BOOTUTIL_LIB=y From a5a44aa311d3d4d4c2d08e47197b35e0e9ea7d88 Mon Sep 17 00:00:00 2001 From: M Starch Date: Sat, 22 Nov 2025 13:12:20 -0800 Subject: [PATCH 06/18] Add updater --- .../Components/CMakeLists.txt | 1 + .../Components/Updater/CMakeLists.txt | 36 ++++++++++ .../Components/Updater/Updater.cpp | 43 ++++++++++++ .../Components/Updater/Updater.fpp | 36 ++++++++++ .../Components/Updater/Updater.hpp | 49 ++++++++++++++ .../Components/Updater/docs/sdd.md | 66 +++++++++++++++++++ .../ReferenceDeployment/Top/instances.fpp | 6 ++ .../ReferenceDeployment/Top/topology.fpp | 1 + 8 files changed, 238 insertions(+) create mode 100644 FprimeZephyrReference/Components/Updater/CMakeLists.txt create mode 100644 FprimeZephyrReference/Components/Updater/Updater.cpp create mode 100644 FprimeZephyrReference/Components/Updater/Updater.fpp create mode 100644 FprimeZephyrReference/Components/Updater/Updater.hpp create mode 100644 FprimeZephyrReference/Components/Updater/docs/sdd.md diff --git a/FprimeZephyrReference/Components/CMakeLists.txt b/FprimeZephyrReference/Components/CMakeLists.txt index 0190a9cb..a47cd3de 100644 --- a/FprimeZephyrReference/Components/CMakeLists.txt +++ b/FprimeZephyrReference/Components/CMakeLists.txt @@ -14,3 +14,4 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PowerMonitor/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ResetManager/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/StartupManager/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog") +add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Updater/") diff --git a/FprimeZephyrReference/Components/Updater/CMakeLists.txt b/FprimeZephyrReference/Components/Updater/CMakeLists.txt new file mode 100644 index 00000000..611a59e5 --- /dev/null +++ b/FprimeZephyrReference/Components/Updater/CMakeLists.txt @@ -0,0 +1,36 @@ +#### +# F Prime CMakeLists.txt: +# +# SOURCES: list of source files (to be compiled) +# AUTOCODER_INPUTS: list of files to be passed to the autocoders +# DEPENDS: list of libraries that this module depends on +# +# More information in the F´ CMake API documentation: +# https://fprime.jpl.nasa.gov/latest/docs/reference/api/cmake/API/ +# +#### + +# Module names are derived from the path from the nearest project/library/framework +# root when not specifically overridden by the developer. i.e. The module defined by +# `Ref/SignalGen/CMakeLists.txt` will be named `Ref_SignalGen`. + +register_fprime_library( + AUTOCODER_INPUTS + "${CMAKE_CURRENT_LIST_DIR}/Updater.fpp" + SOURCES + "${CMAKE_CURRENT_LIST_DIR}/Updater.cpp" +# DEPENDS +# MyPackage_MyOtherModule +) + +### Unit Tests ### +# register_fprime_ut( +# AUTOCODER_INPUTS +# "${CMAKE_CURRENT_LIST_DIR}/Updater.fpp" +# SOURCES +# "${CMAKE_CURRENT_LIST_DIR}/test/ut/UpdaterTestMain.cpp" +# "${CMAKE_CURRENT_LIST_DIR}/test/ut/UpdaterTester.cpp" +# DEPENDS +# STest # For rules-based testing +# UT_AUTO_HELPERS +# ) diff --git a/FprimeZephyrReference/Components/Updater/Updater.cpp b/FprimeZephyrReference/Components/Updater/Updater.cpp new file mode 100644 index 00000000..f9fa95ca --- /dev/null +++ b/FprimeZephyrReference/Components/Updater/Updater.cpp @@ -0,0 +1,43 @@ +// ====================================================================== +// \title Updater.cpp +// \author starchmd +// \brief cpp file for Updater component implementation class +// ====================================================================== + +#include "FprimeZephyrReference/Components/Updater/Updater.hpp" + +#include + +namespace Zephyr { + +// ---------------------------------------------------------------------- +// Component construction and destruction +// ---------------------------------------------------------------------- + +Updater ::Updater(const char* const compName) : UpdaterComponentBase(compName) {} + +Updater ::~Updater() {} + +// ---------------------------------------------------------------------- +// Handler implementations for commands +// ---------------------------------------------------------------------- + +void Updater ::NEXT_BOOT_TEST_IMAGE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) { + int return_code = boot_request_upgrade(BOOT_UPGRADE_TEST); + if (return_code != 0) { + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); + } else { + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); + } +} + +void Updater ::CONFIRM_NEXT_BOOT_IMAGE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) { + int return_code = boot_write_img_confirmed(); + if (return_code != 0) { + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); + } else { + this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); + } +} + +} // namespace Zephyr diff --git a/FprimeZephyrReference/Components/Updater/Updater.fpp b/FprimeZephyrReference/Components/Updater/Updater.fpp new file mode 100644 index 00000000..e2b38fef --- /dev/null +++ b/FprimeZephyrReference/Components/Updater/Updater.fpp @@ -0,0 +1,36 @@ +module Zephyr { + @ Update firmware images + active component Updater { + + @ Set the image for the next boot in test boot mode + async command NEXT_BOOT_TEST_IMAGE() + + @ Confirm this image for future boots + async command CONFIRM_NEXT_BOOT_IMAGE() + + ############################################################################### + # Standard AC Ports: Required for Channels, Events, Commands, and Parameters # + ############################################################################### + @ Port for requesting the current time + time get port timeCaller + + @ Port for sending command registrations + command reg port cmdRegOut + + @ Port for receiving commands + command recv port cmdIn + + @ Port for sending command responses + command resp port cmdResponseOut + + @ Port for sending textual representation of events + text event port logTextOut + + @ Port for sending events to downlink + event port logOut + + @ Port for sending telemetry channels to downlink + telemetry port tlmOut + + } +} diff --git a/FprimeZephyrReference/Components/Updater/Updater.hpp b/FprimeZephyrReference/Components/Updater/Updater.hpp new file mode 100644 index 00000000..20b8250d --- /dev/null +++ b/FprimeZephyrReference/Components/Updater/Updater.hpp @@ -0,0 +1,49 @@ +// ====================================================================== +// \title Updater.hpp +// \author starchmd +// \brief hpp file for Updater component implementation class +// ====================================================================== + +#ifndef Zephyr_Updater_HPP +#define Zephyr_Updater_HPP + +#include "FprimeZephyrReference/Components/Updater/UpdaterComponentAc.hpp" + +namespace Zephyr { + +class Updater final : public UpdaterComponentBase { + public: + // ---------------------------------------------------------------------- + // Component construction and destruction + // ---------------------------------------------------------------------- + + //! Construct Updater object + Updater(const char* const compName //!< The component name + ); + + //! Destroy Updater object + ~Updater(); + + private: + // ---------------------------------------------------------------------- + // Handler implementations for commands + // ---------------------------------------------------------------------- + + //! Handler implementation for command NEXT_BOOT_TEST_IMAGE + //! + //! Set the image for the next boot in test boot mode + void NEXT_BOOT_TEST_IMAGE_cmdHandler(FwOpcodeType opCode, //!< The opcode + U32 cmdSeq //!< The command sequence number + ) override; + + //! Handler implementation for command CONFIRM_NEXT_BOOT_IMAGE + //! + //! Confirm this image for future boots + void CONFIRM_NEXT_BOOT_IMAGE_cmdHandler(FwOpcodeType opCode, //!< The opcode + U32 cmdSeq //!< The command sequence number + ) override; +}; + +} // namespace Zephyr + +#endif diff --git a/FprimeZephyrReference/Components/Updater/docs/sdd.md b/FprimeZephyrReference/Components/Updater/docs/sdd.md new file mode 100644 index 00000000..401f2a1a --- /dev/null +++ b/FprimeZephyrReference/Components/Updater/docs/sdd.md @@ -0,0 +1,66 @@ +# Zephyr::Updater + +Update firmware images + +## Usage Examples +Add usage examples here + +### Diagrams +Add diagrams here + +### Typical Usage +And the typical usage of the component here + +## Class Diagram +Add a class diagram here + +## Port Descriptions +| Name | Description | +|---|---| +|---|---| + +## Component States +Add component states in the chart below +| Name | Description | +|---|---| +|---|---| + +## Sequence Diagrams +Add sequence diagrams here + +## Parameters +| Name | Description | +|---|---| +|---|---| + +## Commands +| Name | Description | +|---|---| +|---|---| + +## Events +| Name | Description | +|---|---| +|---|---| + +## Telemetry +| Name | Description | +|---|---| +|---|---| + +## Unit Tests +Add unit test descriptions in the chart below +| Name | Description | Output | Coverage | +|---|---|---|---| +|---|---|---|---| + +## Requirements +Add requirements in the chart below +| Name | Description | Validation | +|---|---|---| +|---|---|---| + +## Change Log +| Date | Description | +|---|---| +|---| Initial Draft | diff --git a/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp b/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp index f6a1c069..46cf1918 100644 --- a/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp +++ b/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp @@ -47,6 +47,12 @@ module ReferenceDeployment { stack size Default.STACK_SIZE \ priority 14 +instance updater: Zephyr.Updater base id 0x1000C000 \ + queue size Default.QUEUE_SIZE \ + stack size Default.STACK_SIZE \ + priority 15 + + # ---------------------------------------------------------------------- # Queued component instances # ---------------------------------------------------------------------- diff --git a/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp b/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp index 62099f02..15f9d7f1 100644 --- a/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp +++ b/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp @@ -67,6 +67,7 @@ module ReferenceDeployment { instance ina219SysManager instance ina219SolManager instance resetManager + instance updater # ---------------------------------------------------------------------- From a436c4d5b9cd1dc3b3f93cca7bb808362bf71768 Mon Sep 17 00:00:00 2001 From: M Starch Date: Thu, 27 Nov 2025 20:54:13 -0800 Subject: [PATCH 07/18] Add flash worker --- .gitmodules | 3 + .../Components/CMakeLists.txt | 1 + .../Components/FlashWorker/CMakeLists.txt | 37 ++++++ .../Components/FlashWorker/FlashWorker.cpp | 115 ++++++++++++++++++ .../Components/FlashWorker/FlashWorker.fpp | 34 ++++++ .../Components/FlashWorker/FlashWorker.hpp | 69 +++++++++++ .../FlashWorker/UpdateStatus/CMakeLists.txt | 4 + .../FlashWorker/UpdateStatus/UpdateStatus.fpp | 20 +++ .../Components/FlashWorker/docs/sdd.md | 66 ++++++++++ .../ReferenceDeployment/Top/topology.fpp | 1 + .../project/config/CMakeLists.txt | 2 + .../project/config/UpdateConfig.fpp | 32 +++++ .../project/config/UpdateStatus.fpp | 11 ++ lib/fprime-extras | 1 + prj.conf | 3 + settings.ini | 2 +- 16 files changed, 400 insertions(+), 1 deletion(-) create mode 100644 FprimeZephyrReference/Components/FlashWorker/CMakeLists.txt create mode 100644 FprimeZephyrReference/Components/FlashWorker/FlashWorker.cpp create mode 100644 FprimeZephyrReference/Components/FlashWorker/FlashWorker.fpp create mode 100644 FprimeZephyrReference/Components/FlashWorker/FlashWorker.hpp create mode 100644 FprimeZephyrReference/Components/FlashWorker/UpdateStatus/CMakeLists.txt create mode 100644 FprimeZephyrReference/Components/FlashWorker/UpdateStatus/UpdateStatus.fpp create mode 100644 FprimeZephyrReference/Components/FlashWorker/docs/sdd.md create mode 100644 FprimeZephyrReference/project/config/UpdateConfig.fpp create mode 100644 FprimeZephyrReference/project/config/UpdateStatus.fpp create mode 160000 lib/fprime-extras diff --git a/.gitmodules b/.gitmodules index ef179827..84800847 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "lib/fprime-zephyr"] path = lib/fprime-zephyr url = https://github.com/fprime-community/fprime-zephyr.git +[submodule "lib/fprime-extras"] + path = lib/fprime-extras + url = https://github.com/LeStarch/fprime-extras diff --git a/FprimeZephyrReference/Components/CMakeLists.txt b/FprimeZephyrReference/Components/CMakeLists.txt index a47cd3de..2738df46 100644 --- a/FprimeZephyrReference/Components/CMakeLists.txt +++ b/FprimeZephyrReference/Components/CMakeLists.txt @@ -6,6 +6,7 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Burnwire/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ComDelay/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Drv/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FatalHandler") +add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FlashWorker/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FsSpace/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ImuManager/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LoadSwitch/") diff --git a/FprimeZephyrReference/Components/FlashWorker/CMakeLists.txt b/FprimeZephyrReference/Components/FlashWorker/CMakeLists.txt new file mode 100644 index 00000000..7f9dda2f --- /dev/null +++ b/FprimeZephyrReference/Components/FlashWorker/CMakeLists.txt @@ -0,0 +1,37 @@ +#### +# F Prime CMakeLists.txt: +# +# SOURCES: list of source files (to be compiled) +# AUTOCODER_INPUTS: list of files to be passed to the autocoders +# DEPENDS: list of libraries that this module depends on +# +# More information in the F´ CMake API documentation: +# https://fprime.jpl.nasa.gov/latest/docs/reference/api/cmake/API/ +# +#### +add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/UpdateStatus/") + +# Module names are derived from the path from the nearest project/library/framework +# root when not specifically overridden by the developer. i.e. The module defined by +# `Ref/SignalGen/CMakeLists.txt` will be named `Ref_SignalGen`. + +register_fprime_library( + AUTOCODER_INPUTS + "${CMAKE_CURRENT_LIST_DIR}/FlashWorker.fpp" + SOURCES + "${CMAKE_CURRENT_LIST_DIR}/FlashWorker.cpp" +# DEPENDS +# MyPackage_MyOtherModule +) + +### Unit Tests ### +# register_fprime_ut( +# AUTOCODER_INPUTS +# "${CMAKE_CURRENT_LIST_DIR}/FlashWorker.fpp" +# SOURCES +# "${CMAKE_CURRENT_LIST_DIR}/test/ut/FlashWorkerTestMain.cpp" +# "${CMAKE_CURRENT_LIST_DIR}/test/ut/FlashWorkerTester.cpp" +# DEPENDS +# STest # For rules-based testing +# UT_AUTO_HELPERS +# ) diff --git a/FprimeZephyrReference/Components/FlashWorker/FlashWorker.cpp b/FprimeZephyrReference/Components/FlashWorker/FlashWorker.cpp new file mode 100644 index 00000000..4d18d3eb --- /dev/null +++ b/FprimeZephyrReference/Components/FlashWorker/FlashWorker.cpp @@ -0,0 +1,115 @@ +// ====================================================================== +// \title FlashWorker.cpp +// \author starchmd +// \brief cpp file for FlashWorker component implementation class +// ====================================================================== + +#include "FprimeZephyrReference/Components/FlashWorker/FlashWorker.hpp" +#include "Os/File.hpp" +#include +#include + +namespace Components { + +// ---------------------------------------------------------------------- +// Component construction and destruction +// ---------------------------------------------------------------------- + +FlashWorker ::FlashWorker(const char* const compName) : FlashWorkerComponentBase(compName), m_last_successful(IDLE) {} + +FlashWorker ::~FlashWorker() {} + +// ---------------------------------------------------------------------- +// Flash helpers +// ---------------------------------------------------------------------- + +Update::UpdateStatus FlashWorker ::writeImage(const Fw::StringBase& file_name, Os::File& file) { + const FwSizeType CHUNK = static_cast(sizeof(this->m_data)); + FW_ASSERT(file.isOpen()); + FwSizeType size = 0; + Update::UpdateStatus return_status = Update::UpdateStatus::OP_OK; + int status = flash_img_init_id(&this->m_flash_context, FlashWorker::REGION_NUMBER); + // Read file size, and default to 0 if unavailable + Os::File::Status file_status = file.size(size); + // Loop through file chunk by chunk + for (FwSizeType i = 0; i < size && status == 0 && file_status == Os::File::Status::OP_OK; i += CHUNK) { + FwSizeType read_size = CHUNK; + file_status = file.read(this->m_data, read_size); + if (file_status != Os::File::Status::OP_OK) { + break; + } + status = flash_img_buffered_write(&this->m_flash_context, this->m_data, read_size, true); + if (status != 0) { + break; + } + } + if (file_status != Os::File::Status::OP_OK) { + this->log_WARNING_LO_ImageFileReadError(file_name, + Os::FileStatus(static_cast(file_status))); + } + if (status != 0) { + //TODO image op error + } + return return_status; +} + + +// ---------------------------------------------------------------------- +// Handler implementations for typed input ports +// ---------------------------------------------------------------------- + +Update::UpdateStatus FlashWorker ::confirmImage_handler(FwIndexType portNum) { + int status = boot_write_img_confirmed(); + if (status != 0) { + this->log_WARNING_LO_ConfirmImageFailed(static_cast(-1 * status)); + return Update::UpdateStatus::NEXT_BOOT_ERROR; + } + return Update::UpdateStatus::OP_OK; +} + +Update::UpdateStatus FlashWorker ::nextBoot_handler(FwIndexType portNum, const Update::NextBootMode& mode) { + int permanent = (mode == Update::NextBootMode::PERMANENT) ? BOOT_UPGRADE_PERMANENT : BOOT_UPGRADE_TEST; + + int status = boot_request_upgrade(permanent); + if (status != 0) { + this->log_WARNING_LO_NextBootSetFailed(mode, static_cast(-1 * status)); + return Update::UpdateStatus::NEXT_BOOT_ERROR; + } + return Update::UpdateStatus::OP_OK; +} + +void FlashWorker ::prepareImage_handler(FwIndexType portNum) { + Update::UpdateStatus return_status = Update::UpdateStatus::OP_OK; + int status = boot_erase_img_bank(FlashWorker::REGION_NUMBER); + if (status != 0) { + this->log_WARNING_LO_FlashEraseFailed(static_cast(-1 * status)); + return_status = Update::UpdateStatus::PREPARATION_ERROR; + } else { + this->m_last_successful = PREPARE; + } + this->prepareImageDone_out(0, return_status); +} + +void FlashWorker ::updateImage_handler(FwIndexType portNum, const Fw::StringBase& file) { + Os::File image_file; + Update::UpdateStatus return_status = Update::UpdateStatus::OP_OK; + + if (this->m_last_successful != PREPARE) { + return_status = Update::UpdateStatus::UNPREPARED; + this->m_last_successful = IDLE; + this->log_WARNING_LO_NoImagePrepared(); + } else { + Os::File::Status file_status = image_file.open(file.toChar(), Os::File::Mode::OPEN_READ); + if (file_status == Os::File::Status::OP_OK) { + return_status = this->writeImage(file, image_file); + this->m_last_successful = UPDATE; + } else { + return_status = Update::UpdateStatus::IMAGE_FILE_READ_ERROR; + this->m_last_successful = IDLE; + this->log_WARNING_LO_ImageFileReadError(file, static_cast(file_status)); + } + } + this->updateImageDone_out(0, return_status); +} + +} // namespace Components diff --git a/FprimeZephyrReference/Components/FlashWorker/FlashWorker.fpp b/FprimeZephyrReference/Components/FlashWorker/FlashWorker.fpp new file mode 100644 index 00000000..871a2c6b --- /dev/null +++ b/FprimeZephyrReference/Components/FlashWorker/FlashWorker.fpp @@ -0,0 +1,34 @@ +module Components { + @ Performs long-running operations for the flash subsystem + active component FlashWorker { + import Update.UpdateWorker + + event NoImagePrepared() severity warning low \ + format "No image has been prepared for update" + + event NextBootSetFailed(mode: Update.NextBootMode, error_number: I32) severity warning low \ + format "Set next boot mode to {} failed (errno: {})" + + event ConfirmImageFailed(error_number: I32) severity warning low \ + format "Confirm image failed (errno: {})" + + event FlashEraseFailed(error_number: I32) severity warning low \ + format "Flash erase failed (errno: {})" + + event ImageFileReadError(file_name: string, error: Os.FileStatus) severity warning low \ + format "Failed to read {} with error {}" + + ############################################################################### + # Standard AC Ports: Required for Channels, Events, Commands, and Parameters # + ############################################################################### + @ Port for requesting the current time + time get port timeCaller + + @ Port for sending textual representation of events + text event port logTextOut + + @ Port for sending events to downlink + event port logOut + + } +} \ No newline at end of file diff --git a/FprimeZephyrReference/Components/FlashWorker/FlashWorker.hpp b/FprimeZephyrReference/Components/FlashWorker/FlashWorker.hpp new file mode 100644 index 00000000..2d182110 --- /dev/null +++ b/FprimeZephyrReference/Components/FlashWorker/FlashWorker.hpp @@ -0,0 +1,69 @@ +// ====================================================================== +// \title FlashWorker.hpp +// \author starchmd +// \brief hpp file for FlashWorker component implementation class +// ====================================================================== + +#ifndef Update_FlashWorker_HPP +#define Update_FlashWorker_HPP +#include "Os/File.hpp" + +#include "FprimeZephyrReference/Components/FlashWorker/FlashWorkerComponentAc.hpp" +#include +namespace Components { + +class FlashWorker final : public FlashWorkerComponentBase { + public: + constexpr static U8 REGION_NUMBER = 1; // slot1 + enum Step { + IDLE, + PREPARE, + UPDATE + }; + // ---------------------------------------------------------------------- + // Component construction and destruction + // ---------------------------------------------------------------------- + + //! Construct FlashWorker object + FlashWorker(const char* const compName //!< The component name + ); + + //! Destroy FlashWorker object + ~FlashWorker(); + private: + Update::UpdateStatus writeImage(const Fw::StringBase& file_name, Os::File& image_file); + + private: + // ---------------------------------------------------------------------- + // Handler implementations for typed input ports + // ---------------------------------------------------------------------- + + //! Handler implementation for confirmImage + //! + //! Confirm that the currently running image is good + Update::UpdateStatus confirmImage_handler(FwIndexType portNum //!< The port number + ) override; + + //! Handler implementation for nextBoot + //! + //! Set the next boot image and mode + Update::UpdateStatus nextBoot_handler(FwIndexType portNum, //!< The port number + const Update::NextBootMode& mode) override; + + //! Handler implementation for prepareImage + void prepareImage_handler(FwIndexType portNum //!< The port number + ) override; + + //! Handler implementation for updateImage + void updateImage_handler(FwIndexType portNum, //!< The port number + const Fw::StringBase& file) override; + private: + Step m_last_successful; + U8 m_data[CONFIG_IMG_BLOCK_BUF_SIZE]; + struct flash_img_context m_flash_context; + +}; + +} // namespace Components + +#endif diff --git a/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/CMakeLists.txt b/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/CMakeLists.txt new file mode 100644 index 00000000..d88b3559 --- /dev/null +++ b/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/CMakeLists.txt @@ -0,0 +1,4 @@ +register_fprime_library( + AUTOCODER_INPUTS + "${CMAKE_CURRENT_LIST_DIR}/UpdateStatus.fpp" +) \ No newline at end of file diff --git a/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/UpdateStatus.fpp b/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/UpdateStatus.fpp new file mode 100644 index 00000000..3c935d00 --- /dev/null +++ b/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/UpdateStatus.fpp @@ -0,0 +1,20 @@ +# UpdateStatus/UpdateStatus.fpp: +# +# File provided by the UpdateWorker component to report status codes back to the Updater component. This is configured +# specifically for the FlashWorker implementation supplied by Proves. +# +# Copyright (c) 2025 Michael Starch +# +# Licensed under the Apache License, Version 2.0. See LICENSE for details. +# +module Update { + @ Status codes used by the Update subsystem. + enum FlashWorkerUpdateStatus { + OP_OK, @< REQUIRED: operation successful + BUSY, @< REQUIRED: operation could not be started because another operation is in-progress + UNPREPARED, @< Preparation step was not completed and not optional + PREPARATION_ERROR, @< An error occurred during the preparation step + IMAGE_FILE_READ_ERROR, @< An error occurred reading the image file + NEXT_BOOT_ERROR @< An error occurred setting the next boot image + } +} \ No newline at end of file diff --git a/FprimeZephyrReference/Components/FlashWorker/docs/sdd.md b/FprimeZephyrReference/Components/FlashWorker/docs/sdd.md new file mode 100644 index 00000000..4c24e238 --- /dev/null +++ b/FprimeZephyrReference/Components/FlashWorker/docs/sdd.md @@ -0,0 +1,66 @@ +# Components::FlashWorker + +Performs long-running operations for the flash subsystem + +## Usage Examples +Add usage examples here + +### Diagrams +Add diagrams here + +### Typical Usage +And the typical usage of the component here + +## Class Diagram +Add a class diagram here + +## Port Descriptions +| Name | Description | +|---|---| +|---|---| + +## Component States +Add component states in the chart below +| Name | Description | +|---|---| +|---|---| + +## Sequence Diagrams +Add sequence diagrams here + +## Parameters +| Name | Description | +|---|---| +|---|---| + +## Commands +| Name | Description | +|---|---| +|---|---| + +## Events +| Name | Description | +|---|---| +|---|---| + +## Telemetry +| Name | Description | +|---|---| +|---|---| + +## Unit Tests +Add unit test descriptions in the chart below +| Name | Description | Output | Coverage | +|---|---|---|---| +|---|---|---|---| + +## Requirements +Add requirements in the chart below +| Name | Description | Validation | +|---|---|---| +|---|---|---| + +## Change Log +| Date | Description | +|---|---| +|---| Initial Draft | \ No newline at end of file diff --git a/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp b/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp index 15f9d7f1..c4bcd87f 100644 --- a/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp +++ b/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp @@ -18,6 +18,7 @@ module ReferenceDeployment { import ComCcsds.FramingSubtopology import ComCcsdsUart.Subtopology import FileHandling.Subtopology + import Update.Subtopology # ---------------------------------------------------------------------- # Instances used in the topology diff --git a/FprimeZephyrReference/project/config/CMakeLists.txt b/FprimeZephyrReference/project/config/CMakeLists.txt index df855eb8..13b518c2 100644 --- a/FprimeZephyrReference/project/config/CMakeLists.txt +++ b/FprimeZephyrReference/project/config/CMakeLists.txt @@ -18,5 +18,7 @@ register_fprime_config( "${CMAKE_CURRENT_LIST_DIR}/LoRaCfg.hpp" "${CMAKE_CURRENT_LIST_DIR}/PlatformCfg.fpp" "${CMAKE_CURRENT_LIST_DIR}/TlmPacketizerCfg.hpp" + "${CMAKE_CURRENT_LIST_DIR}/UpdateConfig.fpp" + "${CMAKE_CURRENT_LIST_DIR}/UpdateStatus.fpp" INTERFACE ) diff --git a/FprimeZephyrReference/project/config/UpdateConfig.fpp b/FprimeZephyrReference/project/config/UpdateConfig.fpp new file mode 100644 index 00000000..4c507f91 --- /dev/null +++ b/FprimeZephyrReference/project/config/UpdateConfig.fpp @@ -0,0 +1,32 @@ +# Update/Subtopology/UpdateConfig/UpdateConfig.fpp: +# +# Update Subtopology configuration +# +# Copyright (c) 2025 Michael Starch +# +# Licensed under the Apache License, Version 2.0. See LICENSE for details. +# +module Update { + # Base ID for instance IDs in this subtopology + constant BASE_ID = 0xA0000000 + + module QueueSizes { + constant updater = 5 # Updater should process quickly; small queue + constant worker = 1 # Worker only handles one item at a time + } + + module StackSizes { + constant updater = 8 * 1024 # Minimal stack size, not much processing + constant worker = 8 * 1024 # Minimal stack size, not much processing + } + + module Priorities { + constant updater = 90 # Updater does real-time tasks; higher priority + constant worker = 15 # Worker does slow-running tasks; lower priority + } + + instance worker: Components.FlashWorker base id BASE_ID + 0x1000 \ + queue size QueueSizes.worker \ + stack size StackSizes.worker \ + priority Priorities.worker +} diff --git a/FprimeZephyrReference/project/config/UpdateStatus.fpp b/FprimeZephyrReference/project/config/UpdateStatus.fpp new file mode 100644 index 00000000..fb81a25b --- /dev/null +++ b/FprimeZephyrReference/project/config/UpdateStatus.fpp @@ -0,0 +1,11 @@ +# Update/UpdateStatus/UpdateStatus.fpp: +# +# UpdateStatus configuration +# +# Copyright (c) 2025 Michael Starch +# +# Licensed under the Apache License, Version 2.0. See LICENSE for details. +# +module Update { + type UpdateStatus = Update.FlashWorkerUpdateStatus +} diff --git a/lib/fprime-extras b/lib/fprime-extras new file mode 160000 index 00000000..db80e48d --- /dev/null +++ b/lib/fprime-extras @@ -0,0 +1 @@ +Subproject commit db80e48d71f50a04c0f0d8bf340443f49e2f8368 diff --git a/prj.conf b/prj.conf index 70becbdd..60179a2b 100644 --- a/prj.conf +++ b/prj.conf @@ -64,6 +64,9 @@ CONFIG_FS_FATFS_FSTAB_AUTOMOUNT=y CONFIG_BOOTLOADER_MCUBOOT=y CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="/home/starchmd/code/fprime-projects/proves-core-reference/lib/zephyr-workspace/bootloader/mcuboot/root-rsa-2048.pem" CONFIG_FLASH=y +CONFIG_FLASH_MAP=y CONFIG_STREAM_FLASH=y CONFIG_IMG_MANAGER=y CONFIG_MCUBOOT_BOOTUTIL_LIB=y +CONFIG_MCUBOOT_BOOTLOADER_MODE_SWAP_USING_OFFSET=y +CONFIG_MCUBOOT_BOOTLOADER_NO_DOWNGRADE=n diff --git a/settings.ini b/settings.ini index 3672f58f..1305a6ba 100644 --- a/settings.ini +++ b/settings.ini @@ -1,7 +1,7 @@ [fprime] project_root: . framework_path: ./lib/fprime -library_locations: ./lib/fprime-zephyr +library_locations: ./lib/fprime-zephyr:./lib/fprime-extras default_toolchain: zephyr default_cmake_options: FPRIME_ENABLE_FRAMEWORK_UTS=OFF From d6914b301e37f126b3b876a2d652f3a11b084b30 Mon Sep 17 00:00:00 2001 From: M Starch Date: Tue, 2 Dec 2025 22:42:27 -0800 Subject: [PATCH 08/18] Add file uplink over LoRa --- .../ReferenceDeployment/Top/instances.fpp | 8 +++----- .../ReferenceDeployment/Top/topology.fpp | 14 ++++++++++---- .../project/config/ComCcsdsConfig.fpp | 4 ++-- lib/fprime-extras | 2 +- tools/bin/make-loadable-image | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp b/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp index 46cf1918..bb132e66 100644 --- a/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp +++ b/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp @@ -47,11 +47,6 @@ module ReferenceDeployment { stack size Default.STACK_SIZE \ priority 14 -instance updater: Zephyr.Updater base id 0x1000C000 \ - queue size Default.QUEUE_SIZE \ - stack size Default.STACK_SIZE \ - priority 15 - # ---------------------------------------------------------------------- # Queued component instances @@ -143,4 +138,7 @@ instance updater: Zephyr.Updater base id 0x1000C000 \ instance startupManager: Components.StartupManager base id 0x1003F000 + instance fileUplinkCollector: Utilities.BufferCollector base id 0x10040000 + + } diff --git a/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp b/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp index c4bcd87f..22c586c9 100644 --- a/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp +++ b/FprimeZephyrReference/ReferenceDeployment/Top/topology.fpp @@ -68,8 +68,7 @@ module ReferenceDeployment { instance ina219SysManager instance ina219SolManager instance resetManager - instance updater - + instance fileUplinkCollector # ---------------------------------------------------------------------- # Pattern graph specifiers @@ -213,10 +212,17 @@ module ReferenceDeployment { # File Downlink <-> ComQueue FileHandling.fileDownlink.bufferSendOut -> ComCcsdsUart.comQueue.bufferQueueIn[ComCcsds.Ports_ComBufferQueue.FILE] ComCcsdsUart.comQueue.bufferReturnOut[ComCcsds.Ports_ComBufferQueue.FILE] -> FileHandling.fileDownlink.bufferReturn + } + connections FileUplinkCollecting { # Router <-> FileUplink - ComCcsdsUart.fprimeRouter.fileOut -> FileHandling.fileUplink.bufferSendIn - FileHandling.fileUplink.bufferSendOut -> ComCcsdsUart.fprimeRouter.fileBufferReturnIn + fileUplinkCollector.singleOut -> FileHandling.fileUplink.bufferSendIn + FileHandling.fileUplink.bufferSendOut -> fileUplinkCollector.singleIn + + ComCcsdsUart.fprimeRouter.fileOut -> fileUplinkCollector.multiIn[1] + fileUplinkCollector.multiOut[1] -> ComCcsdsUart.fprimeRouter.fileBufferReturnIn + ComCcsds.fprimeRouter.fileOut -> fileUplinkCollector.multiIn[0] + fileUplinkCollector.multiOut[0] -> ComCcsds.fprimeRouter.fileBufferReturnIn } diff --git a/FprimeZephyrReference/project/config/ComCcsdsConfig.fpp b/FprimeZephyrReference/project/config/ComCcsdsConfig.fpp index c39d3778..72f93416 100644 --- a/FprimeZephyrReference/project/config/ComCcsdsConfig.fpp +++ b/FprimeZephyrReference/project/config/ComCcsdsConfig.fpp @@ -35,9 +35,9 @@ module ComCcsdsConfig { module BuffMgr { constant frameAccumulatorSize = 1024 # Must be at least as large as the comm buffer size constant commsBuffSize = 1024 # Size of ring buffer - constant commsFileBuffSize = 1 + constant commsFileBuffSize = 1024 constant commsBuffCount = 5 - constant commsFileBuffCount = 1 + constant commsFileBuffCount = 5 constant commsBuffMgrId = 200 } } diff --git a/lib/fprime-extras b/lib/fprime-extras index db80e48d..bb4410af 160000 --- a/lib/fprime-extras +++ b/lib/fprime-extras @@ -1 +1 @@ -Subproject commit db80e48d71f50a04c0f0d8bf340443f49e2f8368 +Subproject commit bb4410af69ded5c9f2d5d9c180fdc6f01ced526d diff --git a/tools/bin/make-loadable-image b/tools/bin/make-loadable-image index 887b5807..8fc230cb 100755 --- a/tools/bin/make-loadable-image +++ b/tools/bin/make-loadable-image @@ -3,7 +3,7 @@ DIRNAME="$(cd "$(dirname $BASH_SOURCE)"; pwd)" ZEPHYR="${ZEPHYR_BASE:-${DIRNAME}/../../lib/zephyr-workspace/zephyr}" # Check arguments -if (( $# == 2 )) +if (( $# != 2 )) then echo "$0 " exit 0 From 95dcbf0c5b8d3bca005cfa7bca121e4a33091a53 Mon Sep 17 00:00:00 2001 From: M Starch Date: Tue, 2 Dec 2025 22:51:19 -0800 Subject: [PATCH 09/18] Remove Updater from proves --- .../Components/CMakeLists.txt | 1 - .../Components/Updater/CMakeLists.txt | 36 ---------- .../Components/Updater/Updater.cpp | 43 ------------ .../Components/Updater/Updater.fpp | 36 ---------- .../Components/Updater/Updater.hpp | 49 -------------- .../Components/Updater/docs/sdd.md | 66 ------------------- 6 files changed, 231 deletions(-) delete mode 100644 FprimeZephyrReference/Components/Updater/CMakeLists.txt delete mode 100644 FprimeZephyrReference/Components/Updater/Updater.cpp delete mode 100644 FprimeZephyrReference/Components/Updater/Updater.fpp delete mode 100644 FprimeZephyrReference/Components/Updater/Updater.hpp delete mode 100644 FprimeZephyrReference/Components/Updater/docs/sdd.md diff --git a/FprimeZephyrReference/Components/CMakeLists.txt b/FprimeZephyrReference/Components/CMakeLists.txt index 2738df46..5e1a69b0 100644 --- a/FprimeZephyrReference/Components/CMakeLists.txt +++ b/FprimeZephyrReference/Components/CMakeLists.txt @@ -15,4 +15,3 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PowerMonitor/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ResetManager/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/StartupManager/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog") -add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Updater/") diff --git a/FprimeZephyrReference/Components/Updater/CMakeLists.txt b/FprimeZephyrReference/Components/Updater/CMakeLists.txt deleted file mode 100644 index 611a59e5..00000000 --- a/FprimeZephyrReference/Components/Updater/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -#### -# F Prime CMakeLists.txt: -# -# SOURCES: list of source files (to be compiled) -# AUTOCODER_INPUTS: list of files to be passed to the autocoders -# DEPENDS: list of libraries that this module depends on -# -# More information in the F´ CMake API documentation: -# https://fprime.jpl.nasa.gov/latest/docs/reference/api/cmake/API/ -# -#### - -# Module names are derived from the path from the nearest project/library/framework -# root when not specifically overridden by the developer. i.e. The module defined by -# `Ref/SignalGen/CMakeLists.txt` will be named `Ref_SignalGen`. - -register_fprime_library( - AUTOCODER_INPUTS - "${CMAKE_CURRENT_LIST_DIR}/Updater.fpp" - SOURCES - "${CMAKE_CURRENT_LIST_DIR}/Updater.cpp" -# DEPENDS -# MyPackage_MyOtherModule -) - -### Unit Tests ### -# register_fprime_ut( -# AUTOCODER_INPUTS -# "${CMAKE_CURRENT_LIST_DIR}/Updater.fpp" -# SOURCES -# "${CMAKE_CURRENT_LIST_DIR}/test/ut/UpdaterTestMain.cpp" -# "${CMAKE_CURRENT_LIST_DIR}/test/ut/UpdaterTester.cpp" -# DEPENDS -# STest # For rules-based testing -# UT_AUTO_HELPERS -# ) diff --git a/FprimeZephyrReference/Components/Updater/Updater.cpp b/FprimeZephyrReference/Components/Updater/Updater.cpp deleted file mode 100644 index f9fa95ca..00000000 --- a/FprimeZephyrReference/Components/Updater/Updater.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// ====================================================================== -// \title Updater.cpp -// \author starchmd -// \brief cpp file for Updater component implementation class -// ====================================================================== - -#include "FprimeZephyrReference/Components/Updater/Updater.hpp" - -#include - -namespace Zephyr { - -// ---------------------------------------------------------------------- -// Component construction and destruction -// ---------------------------------------------------------------------- - -Updater ::Updater(const char* const compName) : UpdaterComponentBase(compName) {} - -Updater ::~Updater() {} - -// ---------------------------------------------------------------------- -// Handler implementations for commands -// ---------------------------------------------------------------------- - -void Updater ::NEXT_BOOT_TEST_IMAGE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) { - int return_code = boot_request_upgrade(BOOT_UPGRADE_TEST); - if (return_code != 0) { - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); - } else { - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); - } -} - -void Updater ::CONFIRM_NEXT_BOOT_IMAGE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) { - int return_code = boot_write_img_confirmed(); - if (return_code != 0) { - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR); - } else { - this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK); - } -} - -} // namespace Zephyr diff --git a/FprimeZephyrReference/Components/Updater/Updater.fpp b/FprimeZephyrReference/Components/Updater/Updater.fpp deleted file mode 100644 index e2b38fef..00000000 --- a/FprimeZephyrReference/Components/Updater/Updater.fpp +++ /dev/null @@ -1,36 +0,0 @@ -module Zephyr { - @ Update firmware images - active component Updater { - - @ Set the image for the next boot in test boot mode - async command NEXT_BOOT_TEST_IMAGE() - - @ Confirm this image for future boots - async command CONFIRM_NEXT_BOOT_IMAGE() - - ############################################################################### - # Standard AC Ports: Required for Channels, Events, Commands, and Parameters # - ############################################################################### - @ Port for requesting the current time - time get port timeCaller - - @ Port for sending command registrations - command reg port cmdRegOut - - @ Port for receiving commands - command recv port cmdIn - - @ Port for sending command responses - command resp port cmdResponseOut - - @ Port for sending textual representation of events - text event port logTextOut - - @ Port for sending events to downlink - event port logOut - - @ Port for sending telemetry channels to downlink - telemetry port tlmOut - - } -} diff --git a/FprimeZephyrReference/Components/Updater/Updater.hpp b/FprimeZephyrReference/Components/Updater/Updater.hpp deleted file mode 100644 index 20b8250d..00000000 --- a/FprimeZephyrReference/Components/Updater/Updater.hpp +++ /dev/null @@ -1,49 +0,0 @@ -// ====================================================================== -// \title Updater.hpp -// \author starchmd -// \brief hpp file for Updater component implementation class -// ====================================================================== - -#ifndef Zephyr_Updater_HPP -#define Zephyr_Updater_HPP - -#include "FprimeZephyrReference/Components/Updater/UpdaterComponentAc.hpp" - -namespace Zephyr { - -class Updater final : public UpdaterComponentBase { - public: - // ---------------------------------------------------------------------- - // Component construction and destruction - // ---------------------------------------------------------------------- - - //! Construct Updater object - Updater(const char* const compName //!< The component name - ); - - //! Destroy Updater object - ~Updater(); - - private: - // ---------------------------------------------------------------------- - // Handler implementations for commands - // ---------------------------------------------------------------------- - - //! Handler implementation for command NEXT_BOOT_TEST_IMAGE - //! - //! Set the image for the next boot in test boot mode - void NEXT_BOOT_TEST_IMAGE_cmdHandler(FwOpcodeType opCode, //!< The opcode - U32 cmdSeq //!< The command sequence number - ) override; - - //! Handler implementation for command CONFIRM_NEXT_BOOT_IMAGE - //! - //! Confirm this image for future boots - void CONFIRM_NEXT_BOOT_IMAGE_cmdHandler(FwOpcodeType opCode, //!< The opcode - U32 cmdSeq //!< The command sequence number - ) override; -}; - -} // namespace Zephyr - -#endif diff --git a/FprimeZephyrReference/Components/Updater/docs/sdd.md b/FprimeZephyrReference/Components/Updater/docs/sdd.md deleted file mode 100644 index 401f2a1a..00000000 --- a/FprimeZephyrReference/Components/Updater/docs/sdd.md +++ /dev/null @@ -1,66 +0,0 @@ -# Zephyr::Updater - -Update firmware images - -## Usage Examples -Add usage examples here - -### Diagrams -Add diagrams here - -### Typical Usage -And the typical usage of the component here - -## Class Diagram -Add a class diagram here - -## Port Descriptions -| Name | Description | -|---|---| -|---|---| - -## Component States -Add component states in the chart below -| Name | Description | -|---|---| -|---|---| - -## Sequence Diagrams -Add sequence diagrams here - -## Parameters -| Name | Description | -|---|---| -|---|---| - -## Commands -| Name | Description | -|---|---| -|---|---| - -## Events -| Name | Description | -|---|---| -|---|---| - -## Telemetry -| Name | Description | -|---|---| -|---|---| - -## Unit Tests -Add unit test descriptions in the chart below -| Name | Description | Output | Coverage | -|---|---|---|---| -|---|---|---|---| - -## Requirements -Add requirements in the chart below -| Name | Description | Validation | -|---|---|---| -|---|---|---| - -## Change Log -| Date | Description | -|---|---| -|---| Initial Draft | From 46eda0edb94f452e8b04e3eb7762647e2e8abefd Mon Sep 17 00:00:00 2001 From: M Starch Date: Tue, 2 Dec 2025 23:09:44 -0800 Subject: [PATCH 10/18] Fix fatal handler timing --- .../Components/FatalHandler/FatalHandler.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/FprimeZephyrReference/Components/FatalHandler/FatalHandler.cpp b/FprimeZephyrReference/Components/FatalHandler/FatalHandler.cpp index ff0ad029..cea51119 100644 --- a/FprimeZephyrReference/Components/FatalHandler/FatalHandler.cpp +++ b/FprimeZephyrReference/Components/FatalHandler/FatalHandler.cpp @@ -27,23 +27,14 @@ FatalHandler ::FatalHandler(const char* const compName) : FatalHandlerComponentB FatalHandler ::~FatalHandler() {} void FatalHandler::reboot() { -// When running in CI failsafe mode and the board is a teensy, -// then we should invoke bkpt #251 to trigger the soft reboot enabling a -// flash of new software -#if defined(FPRIME_CI_FAILSAFE_CYCLE_COUNT) - // Magic bootloader breakpoint, provided by PRJC - if (strncmp(CONFIG_BOARD, "teensy", 6) == 0) { - asm("bkpt #251"); - } -#endif // Otherwise, use Zephyr to reboot the system sys_reboot(SYS_REBOOT_COLD); } void FatalHandler::FatalReceive_handler(const FwIndexType portNum, FwEventIdType Id) { - Fw::Logger::log("FATAL %" PRI_FwEventIdType "handled.\n", Id); - Os::Task::delay(Fw::TimeInterval(0, 1000)); // Delay to allow log to be processed - this->reboot(); // Reboot the system + Fw::Logger::log("FATAL %" PRI_FwEventIdType " handled.\n", Id); + Os::Task::delay(Fw::TimeInterval(1, 0)); // Delay to allow log to be processed + this->reboot(); // Reboot the system } } // namespace Components From 11c13fc3c9d8d998adbe1c0c62da80f7bbcb66ac Mon Sep 17 00:00:00 2001 From: ineskhou Date: Wed, 3 Dec 2025 22:30:11 -0800 Subject: [PATCH 11/18] lint! --- .../Components/FlashWorker/FlashWorker.cpp | 15 ++++++------- .../Components/FlashWorker/FlashWorker.fpp | 6 ++--- .../Components/FlashWorker/FlashWorker.hpp | 22 ++++++++----------- .../FlashWorker/UpdateStatus/CMakeLists.txt | 2 +- .../FlashWorker/UpdateStatus/UpdateStatus.fpp | 4 ++-- .../Components/FlashWorker/docs/sdd.md | 2 +- .../ReferenceDeployment/Top/instances.fpp | 2 +- .../project/config/UpdateConfig.fpp | 8 +++---- .../project/config/UpdateStatus.fpp | 2 +- 9 files changed, 29 insertions(+), 34 deletions(-) diff --git a/FprimeZephyrReference/Components/FlashWorker/FlashWorker.cpp b/FprimeZephyrReference/Components/FlashWorker/FlashWorker.cpp index 4d18d3eb..dac22382 100644 --- a/FprimeZephyrReference/Components/FlashWorker/FlashWorker.cpp +++ b/FprimeZephyrReference/Components/FlashWorker/FlashWorker.cpp @@ -5,9 +5,10 @@ // ====================================================================== #include "FprimeZephyrReference/Components/FlashWorker/FlashWorker.hpp" + #include "Os/File.hpp" -#include #include +#include namespace Components { @@ -25,9 +26,9 @@ FlashWorker ::~FlashWorker() {} Update::UpdateStatus FlashWorker ::writeImage(const Fw::StringBase& file_name, Os::File& file) { const FwSizeType CHUNK = static_cast(sizeof(this->m_data)); - FW_ASSERT(file.isOpen()); + FW_ASSERT(file.isOpen()); FwSizeType size = 0; - Update::UpdateStatus return_status = Update::UpdateStatus::OP_OK; + Update::UpdateStatus return_status = Update::UpdateStatus::OP_OK; int status = flash_img_init_id(&this->m_flash_context, FlashWorker::REGION_NUMBER); // Read file size, and default to 0 if unavailable Os::File::Status file_status = file.size(size); @@ -44,16 +45,14 @@ Update::UpdateStatus FlashWorker ::writeImage(const Fw::StringBase& file_name, O } } if (file_status != Os::File::Status::OP_OK) { - this->log_WARNING_LO_ImageFileReadError(file_name, - Os::FileStatus(static_cast(file_status))); + this->log_WARNING_LO_ImageFileReadError(file_name, Os::FileStatus(static_cast(file_status))); } if (status != 0) { - //TODO image op error + // TODO image op error } return return_status; } - // ---------------------------------------------------------------------- // Handler implementations for typed input ports // ---------------------------------------------------------------------- @@ -69,7 +68,7 @@ Update::UpdateStatus FlashWorker ::confirmImage_handler(FwIndexType portNum) { Update::UpdateStatus FlashWorker ::nextBoot_handler(FwIndexType portNum, const Update::NextBootMode& mode) { int permanent = (mode == Update::NextBootMode::PERMANENT) ? BOOT_UPGRADE_PERMANENT : BOOT_UPGRADE_TEST; - + int status = boot_request_upgrade(permanent); if (status != 0) { this->log_WARNING_LO_NextBootSetFailed(mode, static_cast(-1 * status)); diff --git a/FprimeZephyrReference/Components/FlashWorker/FlashWorker.fpp b/FprimeZephyrReference/Components/FlashWorker/FlashWorker.fpp index 871a2c6b..57e0a0be 100644 --- a/FprimeZephyrReference/Components/FlashWorker/FlashWorker.fpp +++ b/FprimeZephyrReference/Components/FlashWorker/FlashWorker.fpp @@ -8,10 +8,10 @@ module Components { event NextBootSetFailed(mode: Update.NextBootMode, error_number: I32) severity warning low \ format "Set next boot mode to {} failed (errno: {})" - + event ConfirmImageFailed(error_number: I32) severity warning low \ format "Confirm image failed (errno: {})" - + event FlashEraseFailed(error_number: I32) severity warning low \ format "Flash erase failed (errno: {})" @@ -31,4 +31,4 @@ module Components { event port logOut } -} \ No newline at end of file +} diff --git a/FprimeZephyrReference/Components/FlashWorker/FlashWorker.hpp b/FprimeZephyrReference/Components/FlashWorker/FlashWorker.hpp index 2d182110..6bedd7bf 100644 --- a/FprimeZephyrReference/Components/FlashWorker/FlashWorker.hpp +++ b/FprimeZephyrReference/Components/FlashWorker/FlashWorker.hpp @@ -6,20 +6,15 @@ #ifndef Update_FlashWorker_HPP #define Update_FlashWorker_HPP -#include "Os/File.hpp" - #include "FprimeZephyrReference/Components/FlashWorker/FlashWorkerComponentAc.hpp" +#include "Os/File.hpp" #include namespace Components { class FlashWorker final : public FlashWorkerComponentBase { public: - constexpr static U8 REGION_NUMBER = 1; // slot1 - enum Step { - IDLE, - PREPARE, - UPDATE - }; + constexpr static U8 REGION_NUMBER = 1; // slot1 + enum Step { IDLE, PREPARE, UPDATE }; // ---------------------------------------------------------------------- // Component construction and destruction // ---------------------------------------------------------------------- @@ -30,6 +25,7 @@ class FlashWorker final : public FlashWorkerComponentBase { //! Destroy FlashWorker object ~FlashWorker(); + private: Update::UpdateStatus writeImage(const Fw::StringBase& file_name, Os::File& image_file); @@ -52,16 +48,16 @@ class FlashWorker final : public FlashWorkerComponentBase { //! Handler implementation for prepareImage void prepareImage_handler(FwIndexType portNum //!< The port number - ) override; + ) override; //! Handler implementation for updateImage void updateImage_handler(FwIndexType portNum, //!< The port number const Fw::StringBase& file) override; + private: - Step m_last_successful; - U8 m_data[CONFIG_IMG_BLOCK_BUF_SIZE]; - struct flash_img_context m_flash_context; - + Step m_last_successful; + U8 m_data[CONFIG_IMG_BLOCK_BUF_SIZE]; + struct flash_img_context m_flash_context; }; } // namespace Components diff --git a/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/CMakeLists.txt b/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/CMakeLists.txt index d88b3559..a42d8d56 100644 --- a/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/CMakeLists.txt +++ b/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/CMakeLists.txt @@ -1,4 +1,4 @@ register_fprime_library( AUTOCODER_INPUTS "${CMAKE_CURRENT_LIST_DIR}/UpdateStatus.fpp" -) \ No newline at end of file +) diff --git a/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/UpdateStatus.fpp b/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/UpdateStatus.fpp index 3c935d00..05e0b668 100644 --- a/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/UpdateStatus.fpp +++ b/FprimeZephyrReference/Components/FlashWorker/UpdateStatus/UpdateStatus.fpp @@ -4,7 +4,7 @@ # specifically for the FlashWorker implementation supplied by Proves. # # Copyright (c) 2025 Michael Starch -# +# # Licensed under the Apache License, Version 2.0. See LICENSE for details. # module Update { @@ -17,4 +17,4 @@ module Update { IMAGE_FILE_READ_ERROR, @< An error occurred reading the image file NEXT_BOOT_ERROR @< An error occurred setting the next boot image } -} \ No newline at end of file +} diff --git a/FprimeZephyrReference/Components/FlashWorker/docs/sdd.md b/FprimeZephyrReference/Components/FlashWorker/docs/sdd.md index 4c24e238..35f8f861 100644 --- a/FprimeZephyrReference/Components/FlashWorker/docs/sdd.md +++ b/FprimeZephyrReference/Components/FlashWorker/docs/sdd.md @@ -63,4 +63,4 @@ Add requirements in the chart below ## Change Log | Date | Description | |---|---| -|---| Initial Draft | \ No newline at end of file +|---| Initial Draft | diff --git a/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp b/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp index bb132e66..d03df6b9 100644 --- a/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp +++ b/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp @@ -138,7 +138,7 @@ module ReferenceDeployment { instance startupManager: Components.StartupManager base id 0x1003F000 - instance fileUplinkCollector: Utilities.BufferCollector base id 0x10040000 + instance fileUplinkCollector: Utilities.BufferCollector base id 0x10040000 } diff --git a/FprimeZephyrReference/project/config/UpdateConfig.fpp b/FprimeZephyrReference/project/config/UpdateConfig.fpp index 4c507f91..6422388d 100644 --- a/FprimeZephyrReference/project/config/UpdateConfig.fpp +++ b/FprimeZephyrReference/project/config/UpdateConfig.fpp @@ -3,18 +3,18 @@ # Update Subtopology configuration # # Copyright (c) 2025 Michael Starch -# +# # Licensed under the Apache License, Version 2.0. See LICENSE for details. # module Update { # Base ID for instance IDs in this subtopology constant BASE_ID = 0xA0000000 - + module QueueSizes { - constant updater = 5 # Updater should process quickly; small queue + constant updater = 5 # Updater should process quickly; small queue constant worker = 1 # Worker only handles one item at a time } - + module StackSizes { constant updater = 8 * 1024 # Minimal stack size, not much processing constant worker = 8 * 1024 # Minimal stack size, not much processing diff --git a/FprimeZephyrReference/project/config/UpdateStatus.fpp b/FprimeZephyrReference/project/config/UpdateStatus.fpp index fb81a25b..99fbcbd9 100644 --- a/FprimeZephyrReference/project/config/UpdateStatus.fpp +++ b/FprimeZephyrReference/project/config/UpdateStatus.fpp @@ -3,7 +3,7 @@ # UpdateStatus configuration # # Copyright (c) 2025 Michael Starch -# +# # Licensed under the Apache License, Version 2.0. See LICENSE for details. # module Update { From 7541d5c3c863eb05e71ce97d804db5f250c25e64 Mon Sep 17 00:00:00 2001 From: ineskhou Date: Thu, 4 Dec 2025 11:10:00 -0800 Subject: [PATCH 12/18] config for all comps, readmecorrections --- README.md | 12 +++++++++--- prj.conf | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 315e4fee..8092ef16 100644 --- a/README.md +++ b/README.md @@ -115,8 +115,11 @@ You can control the specific command lists of the satellite by writing a sequenc First, build the bootloader with west. This is easiest accomplished by building the `sysbuild` example "with_mcuboot" in zephyr. ``` -cd /samples/sysbuild/with_mcubuild + +in proves-core-reference +cd lib/zephyr-workspace/zephyr/samples/sysbuild/with_mcuboot /tools/bin/build-with-proves --sysbuild +(example /home/username/proves-core-reference/tools/bin/build-with-proves --sysbuild) ``` Once built, upload `build/mcuboot/zephyr/zephyr.uf2` like normally done. @@ -124,7 +127,10 @@ Once built, upload `build/mcuboot/zephyr/zephyr.uf2` like normally done. Then build Proves like normal. This will make a UF2, but not for the second flash region. To build a bootable image, use: ``` -/tools/bin/build-bootable-image ./build-artifacts/zephyr.signed.bin ./bootable.uf2 +/tools/bin/make-loadable-image ./build-artifacts/zephyr.signed.bin ./bootable.uf2 ``` -Now upload `bootable.uf2`. This should chain from MCUBoot to the bootable software image +Now upload `bootable.uf2`. This should chain from MCUBoot to the bootable software image, by changing the base address so it appears at slot0. Once you boot into it, you can use the FlashWorker component to write to slot 1 at runtime. + + +Now to fileuplink and update other parts. Upload Zephyr.signed.bin and set update.updater.update_image_from and set the next boot to book from _____ diff --git a/prj.conf b/prj.conf index 60179a2b..85eddcac 100644 --- a/prj.conf +++ b/prj.conf @@ -62,7 +62,7 @@ CONFIG_FS_FATFS_EXFAT=y CONFIG_FS_FATFS_MOUNT_MKFS=y CONFIG_FS_FATFS_FSTAB_AUTOMOUNT=y CONFIG_BOOTLOADER_MCUBOOT=y -CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="/home/starchmd/code/fprime-projects/proves-core-reference/lib/zephyr-workspace/bootloader/mcuboot/root-rsa-2048.pem" +CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="lib/zephyr-workspace/bootloader/mcuboot/root-rsa-2048.pem" CONFIG_FLASH=y CONFIG_FLASH_MAP=y CONFIG_STREAM_FLASH=y From 8c177aa43d32db3ad7fe8cb50fb2b56953ad0896 Mon Sep 17 00:00:00 2001 From: M Starch Date: Thu, 4 Dec 2025 21:12:31 -0800 Subject: [PATCH 13/18] Change updater priority from 90 to 5 --- FprimeZephyrReference/project/config/UpdateConfig.fpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FprimeZephyrReference/project/config/UpdateConfig.fpp b/FprimeZephyrReference/project/config/UpdateConfig.fpp index 6422388d..bffeb709 100644 --- a/FprimeZephyrReference/project/config/UpdateConfig.fpp +++ b/FprimeZephyrReference/project/config/UpdateConfig.fpp @@ -21,7 +21,7 @@ module Update { } module Priorities { - constant updater = 90 # Updater does real-time tasks; higher priority + constant updater = 5 # Updater does real-time tasks; higher priority constant worker = 15 # Worker does slow-running tasks; lower priority } From 77023cee25b10fc29dfb48ad002383c7870f605f Mon Sep 17 00:00:00 2001 From: ineskhou Date: Thu, 4 Dec 2025 21:20:46 -0800 Subject: [PATCH 14/18] updated buff collector id --- FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp b/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp index dbfeac55..a76c1a72 100644 --- a/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp +++ b/FprimeZephyrReference/ReferenceDeployment/Top/instances.fpp @@ -142,7 +142,7 @@ module ReferenceDeployment { instance startupManager: Components.StartupManager base id 0x1003F000 - instance fileUplinkCollector: Utilities.BufferCollector base id 0x10040000 + instance fileUplinkCollector: Utilities.BufferCollector base id 0x10041000 } From 042423444d986740d951e4c1c5ebefa175c8c4de Mon Sep 17 00:00:00 2001 From: ineskhou Date: Thu, 4 Dec 2025 21:30:27 -0800 Subject: [PATCH 15/18] added tca to board support packated --- .../proves_flight_control_board_v5c_rp2350a_m33_defconfig | 2 ++ .../proves_flight_control_board_v5d_rp2350a_m33_defconfig | 2 ++ 2 files changed, 4 insertions(+) diff --git a/boards/bronco_space/proves_flight_control_board_v5c/proves_flight_control_board_v5c_rp2350a_m33_defconfig b/boards/bronco_space/proves_flight_control_board_v5c/proves_flight_control_board_v5c_rp2350a_m33_defconfig index e4fe9675..278f926c 100644 --- a/boards/bronco_space/proves_flight_control_board_v5c/proves_flight_control_board_v5c_rp2350a_m33_defconfig +++ b/boards/bronco_space/proves_flight_control_board_v5c/proves_flight_control_board_v5c_rp2350a_m33_defconfig @@ -18,6 +18,8 @@ CONFIG_CDC_ACM_SERIAL_PID=0x000F CONFIG_CDC_ACM_SERIAL_VID=0x0028 CONFIG_CDC_ACM_SERIAL_PRODUCT_STRING="PROVES Flight Control Board v5c" CONFIG_I2C_TCA954X=y +CONFIG_I2C_TCA954X_ROOT_INIT_PRIO=70 +CONFIG_I2C_TCA954X_CHANNEL_INIT_PRIO=71 # Sensors CONFIG_LSM6DSO=y diff --git a/boards/bronco_space/proves_flight_control_board_v5d/proves_flight_control_board_v5d_rp2350a_m33_defconfig b/boards/bronco_space/proves_flight_control_board_v5d/proves_flight_control_board_v5d_rp2350a_m33_defconfig index daaf56bd..7144d9b6 100644 --- a/boards/bronco_space/proves_flight_control_board_v5d/proves_flight_control_board_v5d_rp2350a_m33_defconfig +++ b/boards/bronco_space/proves_flight_control_board_v5d/proves_flight_control_board_v5d_rp2350a_m33_defconfig @@ -19,6 +19,8 @@ CONFIG_CDC_ACM_SERIAL_VID=0x0028 CONFIG_CDC_ACM_SERIAL_PRODUCT_STRING="PROVES Flight Control Board v5d" CONFIG_I2C_TCA954X=y +CONFIG_I2C_TCA954X_ROOT_INIT_PRIO=70 +CONFIG_I2C_TCA954X_CHANNEL_INIT_PRIO=71 # Sensors CONFIG_LSM6DSO=y From 31aac67288588d3e8939bd856801ec157f69a448 Mon Sep 17 00:00:00 2001 From: hrfarmer Date: Thu, 4 Dec 2025 23:40:46 -0600 Subject: [PATCH 16/18] update UpdateConfig --- FprimeZephyrReference/project/config/UpdateConfig.fpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FprimeZephyrReference/project/config/UpdateConfig.fpp b/FprimeZephyrReference/project/config/UpdateConfig.fpp index bffeb709..7c8f924b 100644 --- a/FprimeZephyrReference/project/config/UpdateConfig.fpp +++ b/FprimeZephyrReference/project/config/UpdateConfig.fpp @@ -16,8 +16,8 @@ module Update { } module StackSizes { - constant updater = 8 * 1024 # Minimal stack size, not much processing - constant worker = 8 * 1024 # Minimal stack size, not much processing + constant updater = 4 * 1024 # Minimal stack size, not much processing + constant worker = 4 * 1024 # Minimal stack size, not much processing } module Priorities { From b71f8f43f095e874a16897c39b568f86984769cd Mon Sep 17 00:00:00 2001 From: hrfarmer Date: Thu, 4 Dec 2025 23:45:06 -0600 Subject: [PATCH 17/18] add make-loadable-image to makefile --- .gitignore | 1 + Makefile | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 2549b294..6b0bb4b5 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ lib/zephyr-workspace/* *.gcov build settings.ini +bootable.uf2 **/__pycache__/ **/*.egg-info/ diff --git a/Makefile b/Makefile index 1233ce2e..ddad9fb6 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,7 @@ generate-if-needed: .PHONY: build build: submodules zephyr fprime-venv generate-if-needed ## Build FPrime-Zephyr Proves Core Reference @$(UV_RUN) fprime-util build + ./tools/bin/make-loadable-image ./build-artifacts/zephyr.signed.bin bootable.uf2 .PHONY: test-integration test-integration: uv From 3fa6b7a6f03f572af522c3f74e13f948824f7d42 Mon Sep 17 00:00:00 2001 From: ineskhou Date: Thu, 4 Dec 2025 22:31:46 -0800 Subject: [PATCH 18/18] notes for debug --- README.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8092ef16..7d4af25e 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ cd lib/zephyr-workspace/zephyr/samples/sysbuild/with_mcuboot (example /home/username/proves-core-reference/tools/bin/build-with-proves --sysbuild) ``` -Once built, upload `build/mcuboot/zephyr/zephyr.uf2` like normally done. +Once built, cd upload `build/mcuboot/zephyr/zephyr.uf2` like normally done. Then build Proves like normal. This will make a UF2, but not for the second flash region. To build a bootable image, use: @@ -133,4 +133,22 @@ Then build Proves like normal. This will make a UF2, but not for the second flas Now upload `bootable.uf2`. This should chain from MCUBoot to the bootable software image, by changing the base address so it appears at slot0. Once you boot into it, you can use the FlashWorker component to write to slot 1 at runtime. -Now to fileuplink and update other parts. Upload Zephyr.signed.bin and set update.updater.update_image_from and set the next boot to book from _____ +Before, you currently need to run + +``` pip install git+http://github.com/LeStarch/fprime-gds.git@0e23d212 ``` (makes UART buffer not overrun but adding sleeps to file upload in gds) + +Now to fileuplink and update other parts. Upload Zephyr.signed.bin using the file uplink file + +set update.updater.update_image_from and set the next boot to book from _____ + +1. prepare image +2. update from (pass in the path) +3. configure_next_boot = test + +(either power cycle or run the reboot command, should reboot and come into that old version of software, check the version telemetry) + +Go to components/flashworker + +regionnumber = 1 try instead region number=2 + +(redo all the stuff)