Skip to content

Commit dcd260f

Browse files
committed
west: runners: Add ncs-provision to west flash command
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. Signed-off-by: Grzegorz Chwierut <[email protected]>
1 parent f6821fb commit dcd260f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

scripts/west_commands/runners/nrf_common.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def __init__(self, cfg, family, softreset, pinreset, dev_id, erase=False,
9797

9898
# Only applicable for nrfutil
9999
self.suit_starter = False
100+
self.ncs_provision = False
100101

101102
self.tool_opt = []
102103
if tool_opt is not None:
@@ -468,6 +469,13 @@ def program_hex(self):
468469
if self.build_conf.get('CONFIG_SOC_NRF54H20_IRON') and core == "Network":
469470
core = "Application"
470471

472+
if self.erase or self.recover:
473+
# provision keys if keyfile.json exists in the build directory
474+
keyfile = Path(self.cfg.build_dir).parent / 'keyfile.json'
475+
if keyfile.exists():
476+
self.logger.info(f'Provisioning key file: {keyfile}')
477+
self.exec_op('x-provision-keys', keyfile=str(keyfile), defer=True)
478+
471479
self.op_program(self.hex_, erase_arg, ext_mem_erase_opt, defer=True, core=core)
472480
self.flush(force=False)
473481

@@ -542,6 +550,9 @@ def do_exec_op(self, op, force=False):
542550
Throws subprocess.CalledProcessError with the appropriate
543551
returncode if a failure arises.'''
544552

553+
def do_ncs_provision(self):
554+
''' Provision default keys. Only applicable for nrfutil '''
555+
545556
def flush_ops(self, force=True):
546557
''' Execute any remaining ops in the self.ops array.
547558
Throws subprocess.CalledProcessError with the appropriate
@@ -589,6 +600,8 @@ def do_run(self, command, **kwargs):
589600
if self.recover:
590601
self.recover_target()
591602
self.program_hex()
603+
if self.ncs_provision:
604+
self.do_ncs_provision()
592605
if self.reset:
593606
self.reset_target()
594607
# All done, now flush any outstanding ops

scripts/west_commands/runners/nrfutil.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ def _append_batch(self, op, json_file):
147147
cmd += ['--reset-kind', _op['kind']]
148148
elif op_type == 'erase':
149149
cmd.append(f'--{_op["kind"]}')
150+
elif op_type == 'x-provision-keys':
151+
cmd += ['--key-file', _op['keyfile']]
150152

151153
cmd += ['--core', op['core']] if op.get('core') else []
152154
cmd += ['--x-family', f'{self.family}']

0 commit comments

Comments
 (0)