Skip to content

Commit b6211b8

Browse files
committed
scripts: west_commands: introduce ncs-board-actions
Add a new command that allows to obtain a list of available board actions given a board directory. For now, only nRF54H boards have an action. Script may be improved in the future if list of commands grows. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent f0ba5f5 commit b6211b8

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,7 @@
658658
/scripts/requirements-*.txt @nrfconnect/ncs-co-build-system @nrfconnect/ncs-ci
659659
/scripts/west_commands/create_board/ @gmarull
660660
/scripts/west_commands/ncs-bicr.py @gmarull
661+
/scripts/west_commands/ncs-board-actions.py @gmarull
661662
/scripts/west_commands/sbom/ @nrfconnect/ncs-si-muffin
662663
/scripts/west_commands/thingy91x_dfu.py @nrfconnect/ncs-cia
663664
/scripts/west_commands/ncs-provision.py @nrfconnect/ncs-pluto

scripts/west-commands.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ west-commands:
4444
- name: ncs-bicr
4545
class: NcsBICR
4646
help: Assist with board BICR creation for any applicable Nordic SoC
47+
- file: scripts/west_commands/ncs-board-actions.py
48+
commands:
49+
- name: ncs-board-actions
50+
class: NcsBoardActions
51+
help: Obtain available actions for any board
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright (c) 2024 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
3+
4+
import json
5+
import os
6+
import re
7+
from pathlib import Path
8+
9+
from west.commands import WestCommand
10+
11+
12+
def soc_series_detect(board_dir):
13+
found_defconfig = None
14+
for defconfig in board_dir.glob("Kconfig.*"):
15+
if defconfig.name == "Kconfig.defconfig":
16+
continue
17+
18+
found_defconfig = defconfig
19+
break
20+
21+
if not found_defconfig:
22+
raise FileNotFoundError("Board defconfig file not found")
23+
24+
with open(found_defconfig, "r") as f:
25+
for line in f.readlines():
26+
m = re.match(".*select SOC_(NRF[0-9]{2}[A-Z]{,1}).*", line)
27+
if not m:
28+
continue
29+
30+
return m.group(1).lower()
31+
32+
raise ValueError("Unsupported board")
33+
34+
35+
class NcsBoardActions(WestCommand):
36+
def __init__(self):
37+
super().__init__(
38+
"ncs-board-actions", "Obtain available actions for any board", ""
39+
)
40+
41+
def do_add_parser(self, parser_adder):
42+
parser = parser_adder.add_parser(
43+
self.name, help=self.help, description=self.description
44+
)
45+
46+
parser.add_argument(
47+
"-d", "--board-dir", type=Path, help="Target board directory"
48+
)
49+
50+
return parser
51+
52+
def do_run(self, args, unknown_args):
53+
board_dir = args.board_dir
54+
if not board_dir:
55+
board_dir = Path(os.getcwd())
56+
57+
board_spec = board_dir / "board.yml"
58+
if not board_spec.exists():
59+
raise FileNotFoundError("Invalid board directory")
60+
61+
series = soc_series_detect(board_dir)
62+
commands = []
63+
64+
if series == "nrf54h":
65+
commands.extend(
66+
[
67+
{
68+
"name": "Create/Edit BICR",
69+
"command": "west",
70+
"args": ["ncs-bicr", "--board-dir", str(board_dir.resolve())],
71+
"properties": {
72+
"providesJsonSchema": True,
73+
}
74+
}
75+
]
76+
)
77+
78+
print(json.dumps({"commands": commands}))

0 commit comments

Comments
 (0)