Skip to content

fix(dfu): let a BLE DFU start over after the central disconnects - #85

Merged
jamesarich merged 2 commits into
masterfrom
fix/ble-dfu-retry-after-disconnect
Oct 26, 2026
Merged

jamesarich merged 2 commits into
masterfrom
fix/ble-dfu-retry-after-disconnect

Conversation

@jamesarich

@jamesarich jamesarich commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Checklist

  • PR title specifically describes the change
  • tools/build_all.py (or CI's board matrix) passes

Description of Change

A BLE central that disconnects mid-transfer left the DFU state machine where it stopped, so the reconnecting central's START_DFU was answered with status 2 (INVALID_STATE) until the board was reset. A phone could not retry a dropped update. The bootloader now returns the session to idle when the central disconnects (not on the activate teardown): it clears the session and transport state and drops stores still waiting on a lazy erase, and the next START erases and starts over.

Tested with gcc 12.3 images on the RAK4631 (S140 6.1.1) and the Wio Tracker L1 (S140 7.3.0), 244 B packets with PRN 10 and the 20 B legacy client: a drop at about 30 s followed by a retry completes and boots the new app 28 of 28, 25 of them with the retry started 12 to 15 ms after the drop. Master refuses the same retry with status 2. A normal BLE OTA, a UF2 install and a serial DFU are unaffected.

Summary by CodeRabbit

  • New Features

    • BLE firmware updates can now be restarted after a central device disconnects mid-transfer, without resetting the board.
    • An unfinished update session can be abandoned so a new transfer can begin.
  • Bug Fixes

    • Restarting a transfer after disconnection now clears the previous transfer’s state, helping the new update proceed cleanly.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6868c436-e0d2-43bc-96cc-fde2c519639c
Commits

Reviewing files that changed from the base of the PR and between 497bc17 and 2a3e696.

Files selected for processing: 6
  • changelog.md
  • lib/sdk11/components/drivers_nrf/pstorage/pstorage.h
  • lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c
  • lib/sdk11/components/libraries/bootloader_dfu/dfu.h
  • lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c
  • lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The change adds APIs to discard pending persistent-storage operations and reset an unfinished DFU session. When a central disconnects externally, the BLE transport clears session state and restarts advertising.

Changes: BLE DFU session reset

Layer / File(s) Summary
Storage and DFU reset APIs
lib/sdk11/components/drivers_nrf/pstorage/pstorage.h, lib/sdk11/components/drivers_nrf/pstorage/pstorage_raw.c, lib/sdk11/components/libraries/bootloader_dfu/dfu.h, lib/sdk11/components/libraries/bootloader_dfu/dfu_single_bank.c
The pstorage interface adds pstorage_discard_pending(), which removes buffered entries while preserving an in-flight entry when applicable. The DFU API adds dfu_reset_session(), which discards pending operations, clears transfer state, and returns eligible sessions to IDLE.
BLE disconnect reset
lib/sdk11/components/libraries/bootloader_dfu/dfu_transport_ble.c, changelog.md
After an external disconnect, the BLE transport resets the DFU and BLE transfer state before restarting advertising. The changelog records the behavior.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant BLEEventHandler
  participant session_reset
  participant dfu_reset_session
  participant pstorage_discard_pending
  participant Advertising
  BLEEventHandler->>session_reset: external disconnect
  session_reset->>dfu_reset_session: reset DFU session
  dfu_reset_session->>pstorage_discard_pending: discard pending operations
  session_reset->>BLEEventHandler: clear BLE transfer state
  BLEEventHandler->>Advertising: restart advertising
Loading

Suggested reviewers: oltaco

Merge Risk: Minimal · up to 2a3e6

The reviewed disconnect path supports starting a fresh BLE DFU transfer, with no identified issue requiring a fix before merge.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 5 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: allowing a BLE DFU session to restart after the central disconnects.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 5 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit saw the link go down,
Then watched the transfer start anew.
The buffers cleared, the state reset,
The beacon called the board back through.
One hop, one fresh beginning.

Comment @coderabbitai help to get the list of available commands.

@jamesarich
jamesarich added this pull request to the merge queue Oct 26, 2026
Merged via the queue into master with commit 32c3cc8 Oct 26, 2026
23 checks passed
@jamesarich
jamesarich deleted the fix/ble-dfu-retry-after-disconnect branch October 26, 2026 11:26
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.

1 participant