Skip to content

subsys: allow to resume FOTA process#104

Merged
edmont merged 5 commits into
nrfconnect:mainfrom
edmont:pr/resume-fota
May 13, 2026
Merged

subsys: allow to resume FOTA process#104
edmont merged 5 commits into
nrfconnect:mainfrom
edmont:pr/resume-fota

Conversation

@edmont
Copy link
Copy Markdown
Collaborator

@edmont edmont commented Apr 30, 2026

Persist minimal OTA session metadata and reuse DFU progress state
so interrupted Zigbee FOTA downloads can resume after reboot.

KRKNWK-21784

@edmont edmont requested a review from Copilot April 30, 2026 13:41
@edmont edmont requested a review from a team as a code owner April 30, 2026 13:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for resuming interrupted Zigbee OTA (FOTA) downloads after reboot by persisting minimal OTA session metadata in Zephyr settings and restoring DFU multi-image progress so downloads can continue from the previous offset.

Changes:

  • Add persisted “resume state” (settings) and restore logic to restart an in-progress Zigbee OTA download after reboot/rejoin.
  • Extend DFU multi-target writer integration to expose offset/reset hooks needed for progress restore.
  • Adjust Kconfig to introduce a resume option and default-enable a settings backend (NVS/ZMS) based on flash type.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
subsys/lib/zigbee_scenes/Kconfig Removes direct imply NVS from scenes (backend now handled centrally).
subsys/lib/zigbee_fota/src/zigbee_fota.c Implements settings-backed resume state save/restore and integrates it into OTA/DFU flow.
subsys/lib/zigbee_fota/src/dfu_multi_target.c Adds DFU writer offset/reset hooks (behind save-progress config).
subsys/lib/zigbee_fota/Kconfig Introduces ZIGBEE_FOTA_DOWNLOAD_RESUME option and selects required dependencies.
subsys/Kconfig Adds default backend selection (NVS vs ZMS) when Zigbee scenes/resume are enabled.
Comments suppressed due to low confidence (1)

subsys/lib/zigbee_fota/src/zigbee_fota.c:604

  • The new gap check only rejects file_offset > current_offset, which allows file_offset < current_offset (duplicate/rewound fragments). With the current offset-to-DFU calculation, this can underflow (unsigned wrap) and/or re-write already-flashed data, corrupting the DFU stream. Either restore the strict file_offset != current_offset rejection, or explicitly handle file_offset < current_offset by skipping already-processed bytes before calling dfu_multi_image_write().
	if (ota->upgrade.receive.file_offset > current_offset) {
		LOG_WRN("OTA transfer gap. Expected: %d, received: %d",
			current_offset,
			ota->upgrade.receive.file_offset);
		return ZB_ZCL_OTA_UPGRADE_STATUS_ERROR;
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread subsys/lib/zigbee_fota/src/zigbee_fota.c
Comment thread subsys/lib/zigbee_fota/Kconfig Outdated
Comment thread subsys/lib/zigbee_fota/Kconfig
Comment thread subsys/Kconfig
Comment thread subsys/lib/zigbee_fota/src/zigbee_fota.c Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 30, 2026

Documentation Preview

The documentation has been built successfully. You can view the preview here: preview

Generated at: 2026-05-13 09:18:01 UTC with commit 84baa93.

Expand to view changed pages
File Preview
docs/lib/zigbee_fota.rst View

Note: The preview will be available after GitHub Pages deployment completes (usually 1-2 minutes). Ensure that generated at timestamp is up to date. If the Pull Request is stale for more than 30 days, the preview may be deleted. In this case, please update the Pull Request, or re-run the Build Documentation workflow to generate a new preview.

@edmont edmont force-pushed the pr/resume-fota branch 2 times, most recently from 6b20db7 to a41800e Compare May 4, 2026 10:22
edmont added 2 commits May 5, 2026 09:21
Persist minimal OTA session metadata and reuse DFU progress state
so interrupted Zigbee FOTA downloads can resume after reboot.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Enable NVS or ZMS if Zigbe Scenes or FOTA download resume features
are enabled.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
@edmont edmont force-pushed the pr/resume-fota branch from a41800e to 7404b73 Compare May 5, 2026 07:21
@edmont edmont requested a review from annwoj May 8, 2026 11:49
Comment thread subsys/lib/zigbee_fota/src/zigbee_fota.c Outdated
@edmont edmont requested a review from kkasperczyk-no May 12, 2026 07:11
Copy link
Copy Markdown
Contributor

@kkasperczyk-no kkasperczyk-no left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one more thing that came to my mind. If someone have used scenes before and will perform the DFU, the settings key name is going to change and data will be lost.

If you think it's a real threat we could do:

  1. Inform in migration guide that someone needs to set back define to use old key name (easier option)
  2. Implement auto-migration code that will copy existing entries and assign it with new key names (cool, but more complex and harder to maintain)

Comment thread docs/lib/zigbee_fota.rst Outdated
Comment thread docs/lib/zigbee_fota.rst Outdated
edmont added 3 commits May 13, 2026 11:16
Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Buffer trailing bytes from Zigbee OTA blocks when synchronous DFU stream
writes are enabled. This lets the OTA client consume every received byte
while only passing aligned intermediate writes to dfu_multi_image, avoiding
early aborts when OTA block boundaries do not match the flash write
alignment.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
Shorten settings keys names used in the add-on and define all of
them in a single header for ease of handling them.

Signed-off-by: Eduardo Montoya <eduardo.montoya@nordicsemi.no>
@edmont edmont merged commit 988b930 into nrfconnect:main May 13, 2026
4 checks passed
@edmont edmont deleted the pr/resume-fota branch May 13, 2026 10: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.

4 participants