Skip to content

Add MCUboot bootloader and firmware update support#2

Open
spoorcc wants to merge 1 commit intomainfrom
claude/add-mcuboot-bootloader-XwPYC
Open

Add MCUboot bootloader and firmware update support#2
spoorcc wants to merge 1 commit intomainfrom
claude/add-mcuboot-bootloader-XwPYC

Conversation

@spoorcc
Copy link
Contributor

@spoorcc spoorcc commented Mar 9, 2026

Summary

This PR integrates MCUboot secure bootloader and firmware update capabilities into the custom_plank board. It enables over-the-air (OTA) firmware updates via MCUmgr/SMP protocol over UART, with proper flash partitioning and bootloader configuration.

Key Changes

  • Flash partitioning (custom_plank.dts):

    • Added zephyr,code-partition reference to slot0_partition
    • Defined complete flash layout with 5 partitions: MCUboot (48 KB), Slot 0 (448 KB), Slot 1 (448 KB), Scratch (16 KB), and Storage (64 KB)
    • Total 1 MB flash allocation with detailed comments documenting the layout
  • Application configuration (custom_plank.conf):

    • Enabled MCUboot integration (CONFIG_BOOTLOADER_MCUBOOT=y)
    • Configured flash access and management (FLASH, FLASH_MAP, STREAM_FLASH)
    • Enabled image manager with progressive erase (IMG_MANAGER, IMG_ERASE_PROGRESSIVELY)
    • Added MCUmgr subsystem with UART transport for remote firmware management
    • Enabled image and OS management command groups
  • MCUboot bootloader configuration (mcuboot.conf):

    • Configured SWAP_USING_MOVE strategy to avoid dedicated scratch sector overhead
    • Set flash sector budget to 256 (safe for 112-sector slots)
    • Enabled RSA-2048 image signing for secure boot
    • Configured upgrade-only mode with logging
  • Dependency management:

    • Added MCUboot to west.yml manifest (zephyrproject-rtos, main branch)
    • Added MCUboot to dfetch.yaml for alternative dependency resolution

Implementation Details

The flash layout supports dual-slot firmware updates with MCUboot as the secure bootloader. The configuration uses SWAP_USING_MOVE for efficient sector management without requiring a dedicated scratch partition. Image signing with RSA-2048 ensures firmware authenticity. MCUmgr over UART enables remote image upload, confirmation, and device reset for seamless OTA updates.

https://claude.ai/code/session_01MXGFeBsm7tePm9ggz6fc8w

Adds secure bootloader support via MCUboot and an over-the-air (OTA)
firmware update path using MCUmgr/SMP over UART for the custom_plank
(nrf52840) board.

Changes
-------
dfetch.yaml
  - Add MCUboot (zephyrproject-rtos/mcuboot, main) fetched to
    bootloader/mcuboot/.  The dfetch CMake module auto-discovers it as
    a Zephyr module via its zephyr/module.yml.

application/west.yml
  - Register the bootloader/mcuboot project so that west sysbuild can
    locate and build MCUboot as a child image alongside the application.

application/boards/vendor/custom_plank/custom_plank.dts
  - Add fixed-partitions map for the 1 MB nrf52840 flash:
      0x000000  48 KB   boot_partition   (MCUboot, read-only)
      0x00C000  448 KB  slot0_partition  (active image)
      0x07C000  448 KB  slot1_partition  (update candidate)
      0x0EC000  16 KB   scratch_partition(swap workspace)
      0x0F0000  64 KB   storage_partition(NVS/settings)
  - Set zephyr,code-partition = &slot0_partition in /chosen so the
    linker places the application inside the correct slot.

application/app/boards/custom_plank.conf  (new)
  - Board-specific Kconfig fragment that:
    * CONFIG_BOOTLOADER_MCUBOOT=y  – links image for slot0 + trailer
    * Flash / stream-flash / img-manager for update state tracking
    * MCUmgr over UART (SMP) with IMG and OS command groups for
      host-side image upload via `mcumgr` or `nrfutil device`

application/app/sysbuild/mcuboot.conf  (new)
  - MCUboot Kconfig overrides applied by sysbuild:
    * SWAP_USING_MOVE (no dedicated scratch erase needed)
    * RSA-2048 image signing (replace root-rsa-2048.pem for production)
    * BOOT_MAX_IMG_SECTORS=256 (covers 448 KB / 4 KB sectors)

Build instructions
------------------
  # Fetch MCUboot source
  dfetch update

  # Build bootloader + application together (recommended)
  west build --sysbuild -b custom_plank application/app

  # Flash
  west flash

  # Upload a new image over UART with mcumgr CLI
  mcumgr --conntype serial --connstring /dev/ttyUSB0,baud=115200 \
    image upload build/app/zephyr/zephyr.signed.bin

https://claude.ai/code/session_01MXGFeBsm7tePm9ggz6fc8w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants