RTOS & Firmware Stacks

# MCUboot A/B image swap and rollback testing in CI

Flash combined bootloader plus slot-0 and slot-1 images into a board twin and prove bad OTA updates revert cleanly.

OTA bootloaders fail in the field when power drops mid-swap or an unconfirmed image crashes before calling boot\_set\_confirmed(). Testing rollback manually requires repeated JTAG reflashing.

CircuitTwin models internal MCU Flash and external SPI NOR Flash (W25Q128JV) erase/program semantics, letting CI test corrupted trailers, bad ECDSA signatures and watchdog-triggered slot reverts automatically.

## MCUboot CI test cases

| Scenario           | Fault / Condition                  | Expected boot result                                  |
| ------------------ | ---------------------------------- | ----------------------------------------------------- |
| Valid test upgrade | Slot 1 signed image, not confirmed | Boots slot 1 once, then reverts to slot 0 after reset |
| Bad signature      | Flip 1 byte in slot 1 TLV payload  | MCUboot rejects slot 1 and boots slot 0               |
| Confirmed upgrade  | App calls boot\_set\_confirmed()   | Slot 1 stays permanent across power cycles            |

## Local CLI workflow

Shell - run MCUboot swap and rollback suite

```
ct test run --json --junit results/mcuboot.xml tests/mcuboot-rollback.suite.yaml
```

## Suite & fault configuration

tests/mcuboot-rollback.suite.yaml

```
version: 1
board: nucleo-f767zi
firmware: build/merged_mcuboot_ab.hex
tests:
  - name: unconfirmed-image-reverts-on-reset
    timeout_ms: 5000
    expect:
      console_contains: "REVERTED_TO_SLOT0"
      exit_code: 0
```

## CI pipeline integration

.github/workflows/mcuboot-ci.yml

```
name: MCUboot OTA Rollback CI
on: [push, pull_request]
jobs:
  mcuboot:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: ./scripts/build_mcuboot_ab.sh
      - uses: circuittwin/action@v1
        with:
          suite: tests/mcuboot-rollback.suite.yaml
```

## Troubleshooting checklist

| Symptom                                             | Fix                                                                                    |
| --------------------------------------------------- | -------------------------------------------------------------------------------------- |
| Bootloader jumps to wrong application reset address | Verify SCB->VTOR relocation and --header-size alignment match imgtool sign parameters. |
| External SPI flash swap fails on erase              | Confirm W25Q128JV 4 KB sector erase alignment matches BOOT\_MAX\_IMG\_SECTORS.         |

## Frequently asked questions

| Question                                                                           | Answer                                                                                                      |
| ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| Can CircuitTwin load merged Intel HEX images containing bootloader plus two slots? | Yes. Pass merged .hex or multi-image flash maps to ct run and verify the full reset-to-application handoff. |

## Related boards & component twins

[Board: nucleo-f767zi](https://circuittwin.ai/boards/nucleo-f767zi) [Board: nrf52840-dk](https://circuittwin.ai/boards/nrf52840-dk) [Board: b-u585i-iot02a](https://circuittwin.ai/boards/b-u585i-iot02a) [Twin: W25Q128JV](https://circuittwin.ai/twins/w25q128jv) [Twin: W25Q64JV](https://circuittwin.ai/twins/w25q64jv) [Twin: ATECC608A](https://circuittwin.ai/twins/atecc608a) [Supported binary & image formats](https://circuittwin.ai/docs/formats)

## More in RTOS & Firmware Stacks

[Zephyr RTOS CI without hardware benches](https://circuittwin.ai/guides/zephyr-rtos-ci-without-hardware) [FreeRTOS headless testing in CI](https://circuittwin.ai/guides/freertos-headless-testing) [ESP-IDF CI simulation for ESP32, S3 & C3](https://circuittwin.ai/guides/esp-idf-ci-simulation) [PX4 Pixhawk 6C simulation on real ARM ELF](https://circuittwin.ai/guides/px4-pixhawk-6c-simulation)

> ## Run this workflow on your own ELF
>
> Start free on CircuitTwin to run local board twins, fault matrices and CI checks with zero per-run credits.
>
> [Start now](https://app.circuittwin.ai/try) [Read the quickstart](https://circuittwin.ai/docs/quickstart) [Connect a coding agent](https://circuittwin.ai/docs/agents)
