Skip to content

[nrf fromlist] west: runners: Add ncs-provision to west flash command #2894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gchwier
Copy link
Contributor

@gchwier gchwier commented May 20, 2025

Added automatic KMU key provisioning for both NSIB and MCUboot.
A new --ncs-provision command line option added to nrfutil runner.
This enables automated key provisioning during the flashing process, to enable testing nRF54L aplications (with NSIB and/or MCUboot) using Twister.

  • required nrfutil device 2.10.2 or higher

For testing:
app with NSIB:
west build -p -b nrf54l15dk/nrf54l15/cpuapp $ZEPHYR_BASE/samples/hello_world -d build-54l-nsib -- -DSB_CONFIG_SECURE_BOOT_APPCORE=y
west flash --skip-rebuild -d build-54l-nsib --erase --ncs-provision

app with NSIB + MCUboot (with enabled KMU keys)
west build -p -b nrf54l15dk/nrf54l15/cpuapp $ZEPHYR_BASE/samples/hello_world -d build-54l-nsib_mcuboot_kmu -- -DSB_CONFIG_SECURE_BOOT_APPCORE=y -DSB_CONFIG_BOOTLOADER_MCUBOOT=y -DSB_CONFIG_MCUBOOT_SIGNATURE_USING_KMU=y
west flash --skip-rebuild -d build-54l-nsib_mcuboot_kmu --erase --ncs-provision

For testing with Twister, one can revert that commit:
nrfconnect/sdk-nrf@f4c0cc0
and run:
$ZEPHYR_BASE/scripts/twister -c -T tests/subsys/bootloader/boot_chains -p nrf54l15dk/nrf54l15/cpuapp --device-testing --device-serial /dev/ttyACM1 --west-flash="--recover,--ncs-provision" --enable-slow -vv -ll debug
(only boot_chains, bacause b0_lock causing rolling reboot)

@gchwier gchwier closed this May 20, 2025
@gchwier gchwier changed the title [nrf noup] west: runners: Add ncs-provision to west flash command POC [nrf noup] west: runners: Add ncs-provision to west flash command May 20, 2025
@gchwier gchwier reopened this May 20, 2025
@gchwier gchwier requested review from nvlsianpu, michalek-no and a team May 20, 2025 18:06
@gchwier gchwier added the DNM label May 20, 2025
Copy link
Contributor

@carlescufi carlescufi left a comment

Choose a reason for hiding this comment

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

I really do not want this amount of out-of-tree code in this file. It will be a nightmare to keep in sync.
Our options are:

  • Have everything, including provisioning, upstream (we could call it --provision instead). We already did something similar with the H20 SUIT support, where it was upstream although only needed for downstream
  • Use an extension command west ncs-provision
  • Change the bare minimum in this file, put the logic elsewhere

@gchwier
Copy link
Contributor Author

gchwier commented May 21, 2025

I really do not want this amount of out-of-tree code in this file. It will be a nightmare to keep in sync. Our options are:

  • Have everything, including provisioning, upstream
  • Use an extension command west ncs-provision
  • Change the bare minimum in this file, put the logic elsewhere

I fully agree, which is why I added the DNM label (unfortunately, I can't change the PR to draft status).

I created this as a POC to demonstrate how we can test a simple application without manual steps, eliminating the need for pytest harness in Twister.

Where is the issue with west ncs-provision?
west flash executes a reset after flashing, the application is then marked as "permanently invalidated". Calling west ncs-provision doesn't resolve the problem. Users need to flash with nrfutil (without reset), then call west ncs-provision, and finally reset the device.
This process will likely result in a poor user experience when trying to enable NSIB on the nRF54L.

FYI @nvlsianpu

@gchwier gchwier marked this pull request as draft May 21, 2025 11:51
@carlescufi
Copy link
Contributor

west flash executes a reset after flashing,

There is a --no-reset option to west flash. Why can't you have a west ncs-provision that invokes west flash --no-reset and then does whatever you need to do?

@gchwier
Copy link
Contributor Author

gchwier commented May 21, 2025

There is a --no-reset option to west flash. Why can't you have a west ncs-provision that invokes west flash --no-reset and then does whatever you need to do?

I forgot about --no-reset, it is an option for customer, then he can use:

  1. west flash --erase/--recover --no-reset
  2. west ncs-provision
  3. nrfutil device reset

or

  1. nrfutil device erase/recover
  2. west ncs-provision
  3. west flash

An option would be to extend west ncs-provision in sdk-nrf to call also west flash ... but it will not work with Twister .

@gchwier gchwier force-pushed the grch-west-flash-with-provision branch from 505a62b to 0d6a1a7 Compare May 26, 2025 13:24
@gchwier gchwier changed the title POC [nrf noup] west: runners: Add ncs-provision to west flash command [nrf fromlist] west: runners: Add ncs-provision to west flash command May 26, 2025
@gchwier gchwier force-pushed the grch-west-flash-with-provision branch 2 times, most recently from f391ea9 to cb24635 Compare May 29, 2025 15:03
Added automatic KMU key provisioning, when keyfile.json
file exists in the build directory.
This enables automated key provisioning during the
flashing process to enable testing nRF54L aplications using Twister.
Only applicable on nrfutil runner.

Upstream PR #: 90605

Signed-off-by: Grzegorz Chwierut <[email protected]>
@gchwier gchwier force-pushed the grch-west-flash-with-provision branch from cb24635 to 696147c Compare May 29, 2025 15:36
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants