Skip to content

Conversation

@ahasztag
Copy link
Contributor

This PR enables the CONFIG_SB_CLEANUP_RAM option by default for nRF54L. To achieve that, it disables the conflicting EXT_API-s functionality for nRF54L, where it is not used and wasn't functional. Backwards compatibility for nRF52 and nRF53 is ensured.
Also, tests are added to verify the functionality works as expected.

@ahasztag ahasztag requested review from a team as code owners October 20, 2025 14:51
@NordicBuilder NordicBuilder added doc-required PR must not be merged without tech writer approval. changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. labels Oct 20, 2025
@NordicBuilder
Copy link
Contributor

NordicBuilder commented Oct 20, 2025

CI Information

To view the history of this post, click the 'edited' button above
Build number: 15

Inputs:

Sources:

sdk-nrf: PR head: d7a355a7aab148a8eb0025b8db176ef037324851

more details

sdk-nrf:

PR head: d7a355a7aab148a8eb0025b8db176ef037324851
merge base: e440814366666e0652cd80c8846016094c49e91f
target head (main): e440814366666e0652cd80c8846016094c49e91f
Diff

Github labels

Enabled Name Description
ci-disabled Disable the ci execution
ci-all-test Run all of ci, no test spec filtering will be done
ci-force-downstream Force execution of downstream even if twister fails
ci-run-twister Force run twister
ci-run-zephyr-twister Force run zephyr twister
List of changed files detected by CI (20)
doc
│  ├── nrf
│  │  ├── libraries
│  │  │  ├── security
│  │  │  │  ├── bootloader
│  │  │  │  │  │ fw_info.rst
samples
│  ├── bootloader
│  │  ├── prj.conf
│  │  │ prj_minimal.conf
subsys
│  ├── bootloader
│  │  ├── Kconfig
│  │  ├── bl_boot
│  │  │  │ bl_boot.c
│  ├── fw_info
│  │  ├── Kconfig
│  │  │ Kconfig.template.fw_info_ext_api
tests
│  ├── subsys
│  │  ├── bootloader
│  │  │  ├── b0_ram_cleanup
│  │  │  │  ├── CMakeLists.txt
│  │  │  │  ├── boards
│  │  │  │  │  │ nrf54l15dk_nrf54l15_cpuapp.overlay
│  │  │  │  ├── modules
│  │  │  │  │  ├── b0_cleanup_ram_test_prepare
│  │  │  │  │  │  ├── CMakeLists.txt
│  │  │  │  │  │  ├── src
│  │  │  │  │  │  │  │ b0_cleanup_ram_test_prepare.c
│  │  │  │  │  │  ├── zephyr
│  │  │  │  │  │  │  │ module.yml
│  │  │  │  ├── nrf54l15dk_nrf54l15_cpuapp_common.dtsi
│  │  │  │  ├── prj.conf
│  │  │  │  ├── src
│  │  │  │  │  │ main.c
│  │  │  │  ├── sysbuild.cmake
│  │  │  │  ├── sysbuild.conf
│  │  │  │  ├── sysbuild
│  │  │  │  │  ├── b0.conf
│  │  │  │  │  │ b0.overlay
│  │  │  │  │ testcase.yaml

Outputs:

Toolchain

Version: cfa6b06338
Build docker image: docker-dtr.nordicsemi.no/sw-production/ncs-build:cfa6b06338_bba2ea5f2e

Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped; ⚠️ Quarantine

  • ◻️ Toolchain - Skipped: existing toolchain is used
  • ✅ Build twister
    • sdk-nrf test count: 828
  • ✅ Integration tests
    • ✅ test-fw-nrfconnect-chip
    • ✅ test-fw-nrfconnect-nrf-iot_cloud
    • ✅ test-fw-nrfconnect-nrf-iot_zephyr_lwm2m
    • ✅ test-fw-nrfconnect-tfm
    • ✅ test-sdk-find-my
    • ✅ test-sdk-mcuboot
    • ✅ test-sdk-dfu
Disabled integration tests
    • test-fw-nrfconnect-nrf_lrcs_positioning
    • desktop52_verification
    • test-fw-nrfconnect-apps
    • test-fw-nrfconnect-ble_mesh
    • test-fw-nrfconnect-ble_samples
    • test-fw-nrfconnect-fem
    • test-fw-nrfconnect-nfc
    • test-fw-nrfconnect-nrf-iot_libmodem-nrf
    • test-fw-nrfconnect-nrf-iot_lwm2m
    • test-fw-nrfconnect-nrf-iot_samples
    • test-fw-nrfconnect-nrf-iot_serial_lte_modem
    • test-fw-nrfconnect-nrf-iot_thingy91
    • test-fw-nrfconnect-nrf_crypto
    • test-fw-nrfconnect-ps-main
    • test-fw-nrfconnect-rpc
    • test-fw-nrfconnect-rs
    • test-fw-nrfconnect-thread-main
    • test-low-level
    • test-sdk-audio
    • test-sdk-wifi
    • test-secdom-samples-public

Note: This message is automatically posted and updated by the CI

@github-actions
Copy link

You can find the documentation preview for this PR here.

Preview links for modified nRF Connect SDK documents:

https://ncsdoc.z6.web.core.windows.net/PR-25136/nrf/libraries/security/bootloader/fw_info.html

@ahasztag ahasztag marked this pull request as draft October 21, 2025 06:10
@ahasztag

This comment was marked as outdated.

@ahasztag ahasztag changed the title NSIB: Cleanup RAM fixes and tests - nRF54L [Do not review yet] NSIB: Cleanup RAM fixes and tests - nRF54L Oct 21, 2025
@ahasztag ahasztag force-pushed the NCSDK-34936_enable_SB_CLEANUP_RAM branch from acda681 to 96aa097 Compare October 21, 2025 06:55
@ahasztag ahasztag marked this pull request as ready for review October 21, 2025 06:56
@ahasztag ahasztag changed the title [Do not review yet] NSIB: Cleanup RAM fixes and tests - nRF54L NSIB: Cleanup RAM fixes and tests - nRF54L Oct 21, 2025
@ahasztag ahasztag force-pushed the NCSDK-34936_enable_SB_CLEANUP_RAM branch from 96aa097 to 27b6e00 Compare October 21, 2025 06:59
@ahasztag ahasztag changed the title NSIB: Cleanup RAM fixes and tests - nRF54L [Do not review yet] NSIB: Cleanup RAM fixes and tests - nRF54L Oct 21, 2025
@ahasztag ahasztag marked this pull request as draft October 21, 2025 07:00
@ahasztag ahasztag force-pushed the NCSDK-34936_enable_SB_CLEANUP_RAM branch from 27b6e00 to 388413f Compare October 21, 2025 07:09
@ahasztag ahasztag changed the title [Do not review yet] NSIB: Cleanup RAM fixes and tests - nRF54L NSIB: Cleanup RAM fixes and tests - nRF54L Oct 21, 2025
@ahasztag ahasztag marked this pull request as ready for review October 21, 2025 07:09
@NordicBuilder NordicBuilder requested review from a team October 21, 2025 12:07
Comment on lines 102 to 103
bool "Perform RAM cleanup"
default y
depends on !FW_INFO_PROVIDE_ENABLE
Copy link
Contributor

Choose a reason for hiding this comment

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

Has the exact same issue as mcu-tools/mcuboot#2451 has including destroying any data sharing capabilities because it doesn't even clear the correct RAM range

Copy link
Contributor Author

@ahasztag ahasztag Oct 21, 2025

Choose a reason for hiding this comment

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

It doesn't, as it has the dependency on FW_INFO_PROVIDE which is automatically selected by EXT_API-s. Perhaps instead FW_INFO_PROVIDE_ENABLE we should rather use a more generic Kconfig, like DATA_SHARING_ENABLED, but I do not see a point of adding it until other means of data sharing apart from EXT_API-s are added.

Note that for nRF52/nRF53 platforms this will be 'n' due to FW_INFO_PROVIDE

Copy link
Contributor

Choose a reason for hiding this comment

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

EXT_API is not panned to be used on nRF54l devices.

Copy link
Contributor

Choose a reason for hiding this comment

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

By data sharing, I mean data sharing in general, unrelated to ext APIs. E.g. a user can no longer have any memory retained between boots, nor can they share any information from application to bootloader or vice versa - and this is a feature customers and even FAEs are using

Copy link
Contributor

Choose a reason for hiding this comment

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

FAO @vidarbe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is also the retention subsystem, but the current code won't erase the retention memory - I've added a build assert to ensure that: https://github.com/nrfconnect/sdk-nrf/pull/25136/files#diff-a58c0467d91771dc35ca94bb2297b3de0cd6f6330192c6924ca6f56ed973a4f3R26-R44

Also, I've added a test in this PR to verify that indeed the retention memory is not erased.

By the way, considering the boot loops in MCUBOOT, please see: mcu-tools/mcuboot#2451 (comment) - this issue is not present in NSIB, as we have CONFIG_MPU_STACK_GUARD=n - for now, I added a "depends on" so that we do not run into the issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

PM does not support retention, it would be non-init RAM using a PM static file, e.g. https://github.com/CanvasDM/bt610_firmware/blob/main/pm_static.sb.bt610.yml#L114

Copy link
Contributor Author

@ahasztag ahasztag Oct 24, 2025

Choose a reason for hiding this comment

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

I see, I will in fact remove the default y.
I just keep it for the time being to see which tests fail

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. Removed the default y - it causes to much issues at the moment.

@ahasztag ahasztag force-pushed the NCSDK-34936_enable_SB_CLEANUP_RAM branch from ae55a0c to 119cc0d Compare October 21, 2025 12:10
@NordicBuilder NordicBuilder requested a review from a team October 21, 2025 12:10
@ahasztag ahasztag force-pushed the NCSDK-34936_enable_SB_CLEANUP_RAM branch from c390b34 to d97a84c Compare October 21, 2025 12:42
@NordicBuilder NordicBuilder requested a review from a team October 21, 2025 12:42
@ahasztag ahasztag requested a review from de-nordic October 22, 2025 09:04
@ahasztag ahasztag force-pushed the NCSDK-34936_enable_SB_CLEANUP_RAM branch from d97a84c to 3c4fa42 Compare October 23, 2025 13:36
@NordicBuilder NordicBuilder requested review from a team October 23, 2025 13:36
@ahasztag ahasztag force-pushed the NCSDK-34936_enable_SB_CLEANUP_RAM branch from 3c4fa42 to f94d72b Compare October 23, 2025 14:33
@NordicBuilder NordicBuilder requested a review from a team October 23, 2025 14:33
@ahasztag ahasztag force-pushed the NCSDK-34936_enable_SB_CLEANUP_RAM branch from f94d72b to 495650b Compare October 24, 2025 08:54
@NordicBuilder NordicBuilder requested a review from a team October 24, 2025 08:54
@ahasztag ahasztag force-pushed the NCSDK-34936_enable_SB_CLEANUP_RAM branch from 495650b to f8c4da6 Compare October 24, 2025 10:21
Comment on lines 27 to 42
#define REGIONS_OVERLAP(addr1, size1, addr2, size2) \
((addr1) < ((addr2) + (size2)) && (addr2) < ((addr1) + (size1)))

#define RETAINED_RAM_ADDR(ret_ram_node) DT_REG_ADDR(DT_PARENT(ret_ram_node))
#define RETAINED_RAM_SIZE(ret_ram_node) DT_REG_SIZE(DT_PARENT(ret_ram_node))


#define CHECK_RETAINED_RAM_NO_SRAM_OVERLAP(ret_ram_node) \
BUILD_ASSERT(!REGIONS_OVERLAP(CONFIG_SRAM_BASE_ADDRESS, CONFIG_SRAM_SIZE * 1024, \
RETAINED_RAM_ADDR(ret_ram_node), RETAINED_RAM_SIZE(ret_ram_node)), \
"Retained RAM region overlaps with defined SRAM, cannot cleanup RAM")

/* Ensure that the retained RAM region does not overlap with the defined SRAM region.
* Otherwise, the RAM cleanup would overwrite the retained RAM region.
*/
DT_FOREACH_STATUS_OKAY(zephyr_retained_ram, CHECK_RETAINED_RAM_NO_SRAM_OVERLAP);
Copy link
Contributor

Choose a reason for hiding this comment

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

note that this check is not really worth keeping since anyone that modifies the driver and changes the name will now get a false negative on this, likewise if they only define it in their application app.overlay file, let's not try to guess how things will work that fail basic sniff tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, removed

@@ -0,0 +1,10 @@
#
# Copyright (c) 2025 Nordic Semiconductor
#
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this in a zephyr sub folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By mistake, moved

@ahasztag ahasztag force-pushed the NCSDK-34936_enable_SB_CLEANUP_RAM branch from f8c4da6 to 99d39d1 Compare October 24, 2025 11:42
@NordicBuilder NordicBuilder requested a review from a team October 24, 2025 11:43
@ahasztag ahasztag force-pushed the NCSDK-34936_enable_SB_CLEANUP_RAM branch from 99d39d1 to fa79724 Compare October 24, 2025 11:50
@ahasztag ahasztag requested a review from nordicjm October 24, 2025 11:53
cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(NONE)
Copy link
Contributor

Choose a reason for hiding this comment

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

project name is missing i.e. b0_ram_cleanup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, seems to be a general issue in test/subsys/bootloader - that is why it was also here, I copied the test.
I will create a task to fix that throughout the whole directory

The SB_CLEANUP_RAM was being blocked by the EXT_APIs,
which were enabled in the NSIB-s prj.conf

There are currently no use cases for EXT_APIs for nRF54L
and cleanup up RAM after NSIB finishes its work is an important
feature, so the part enabling the EXT_APIs needed to be removed
from the NSIB-s prj.conf

However, backwards compatibility with applications working
on nRF52 and nRF53 needed to be mantained, so the EXT_APIs
are now enabled by default in KConfings for the NSIB image
for these platforms. Note this change aligns with the EXT_APIs
documentation - in the documentation it is not described
how to enable the EXT_APIs in NSIB when adding a new custom
EXT_API. Now, the template will ensure it is enabled in
NSIB.

Signed-off-by: Artur Hadasz <[email protected]>
This commit adds tests to verify if the NSIB
RAM cleanup functionality works as expected.

Signed-off-by: Artur Hadasz <[email protected]>
@ahasztag ahasztag force-pushed the NCSDK-34936_enable_SB_CLEANUP_RAM branch from fa79724 to d7a355a Compare October 28, 2025 08:11
@NordicBuilder NordicBuilder requested a review from a team October 28, 2025 08:12
@tomchy tomchy merged commit 1b963fc into nrfconnect:main Oct 28, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. doc-required PR must not be merged without tech writer approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants