Skip to content

Commit d3a8699

Browse files
michalek-norlubos
authored andcommitted
scripts: west_commands: 54l15 provisioning
Adds 'west provision' command, that allows to upload up to 3 ED25519 keys meant to be used for signature verification by the bootloader. Signed-off-by: Mateusz Michalek <[email protected]>
1 parent 8a409bb commit d3a8699

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@
594594
/scripts/west_commands/genboard/ @gmarull
595595
/scripts/west_commands/sbom/ @nrfconnect/ncs-si-muffin
596596
/scripts/west_commands/thingy91x_dfu.py @nrfconnect/ncs-cia
597+
/scripts/west_commands/ncs-provision.py @nrfconnect/ncs-pluto
597598
/scripts/bootloader/ @nrfconnect/ncs-pluto
598599
/scripts/ncs-docker-version.txt @nrfconnect/ncs-ci
599600
/scripts/print_docker_image.sh @nrfconnect/ncs-ci

scripts/west-commands.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ west-commands:
3434
- name: ncs-genboard
3535
class: NcsGenboard
3636
help: generate board skeleton files for any Nordic SoC
37+
- file: scripts/west_commands/ncs-provision.py
38+
commands:
39+
- name: ncs-provision
40+
class: NcsProvision
41+
help: Provision utility
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
6+
from pathlib import Path
7+
import re
8+
import sys
9+
import subprocess
10+
from cryptography.hazmat.primitives.serialization import load_pem_private_key
11+
from west.commands import WestCommand
12+
13+
nrf54l15_key_slots = [226, 228, 230]
14+
15+
16+
class NcsProvision(WestCommand):
17+
def __init__(self):
18+
super().__init__(
19+
"ncs-provision",
20+
"NCS provision",
21+
"NCS provision utility tool.",
22+
)
23+
24+
def do_add_parser(self, parser_adder):
25+
parser = parser_adder.add_parser(
26+
self.name, help=self.help, description=self.description
27+
)
28+
29+
subparsers = parser.add_subparsers(
30+
dest="command"
31+
)
32+
upload_parser = subparsers.add_parser("upload", help="Send to KMU")
33+
upload_parser.add_argument(
34+
"-k", "--key", type=Path, action='append', dest="keys",
35+
help="Input .pem file with ED25519 private key"
36+
)
37+
upload_parser.add_argument("-s", "--soc", type=str, help="SoC",
38+
choices=["nrf54l15"], required=True)
39+
40+
return parser
41+
42+
def do_run(self, args, unknown_args):
43+
if args.command == "upload":
44+
if args.soc == "nrf54l15":
45+
if len(args.keys) > len(nrf54l15_key_slots):
46+
sys.exit(
47+
"Error: requested upload of more keys than there are designated slots.")
48+
slot = 0
49+
for keyfile in args.keys:
50+
with open(keyfile, 'rb') as f:
51+
priv_key = load_pem_private_key(f.read(), password=None)
52+
pub_key = priv_key.public_key()
53+
nrfprovision = subprocess.run(
54+
["nrfprovision",
55+
"provision",
56+
"-r",
57+
"REVOKED",
58+
"-v",
59+
pub_key.public_bytes_raw().hex(),
60+
"-m",
61+
"0x10ba0030",
62+
"-i",
63+
str(nrf54l15_key_slots[slot]),
64+
"-a",
65+
"ED25519",
66+
"-d",
67+
"0x20000000",
68+
"--verify"],
69+
stderr=subprocess.PIPE,
70+
text=True)
71+
stderr = nrfprovision.stderr
72+
print(stderr, file=sys.stderr)
73+
if re.search('fail', stderr) or nrfprovision.returncode:
74+
sys.exit("Uploading failed!")
75+
slot += 1

0 commit comments

Comments
 (0)