Skip to content

Commit 2b1b447

Browse files
committed
scripts: snippets: Add support for board revisions
Allows snippets to specify additional files for specific revisions of boards Signed-off-by: Jamie McCrae <[email protected]>
1 parent 40d1438 commit 2b1b447

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

scripts/schemas/snippet-schema.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,36 @@ properties:
4646
qemu_cortex_m3:
4747
append:
4848
EXTRA_DTC_OVERLAY_FILE: m3.overlay
49+
50+
Board revisions can also be used which includes additional files:
51+
name: foo
52+
boards:
53+
nrf9160dk/nrf9160:
54+
append:
55+
# Base file will be applied first
56+
EXTRA_DTC_OVERLAY_FILE: first.overlay
57+
revisions:
58+
"0.7.0":
59+
append:
60+
# Will be applied on top of common board file
61+
EXTRA_DTC_OVERLAY_FILE: extra_0_7_0.overlay
4962
type: object
5063
patternProperties:
5164
"(.*)":
5265
type: object
5366
properties:
5467
append:
5568
include: append-schema
69+
revisions:
70+
type: object
71+
patternProperties:
72+
"(.*)":
73+
type: object
74+
properties:
75+
append:
76+
include: append-schema
77+
additionalProperties: false
78+
additionalProperties: false
5679
additionalProperties: false
5780
required:
5881
- name

scripts/snippets.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@
3131
# Marker type for an 'append:' configuration. Maps variables
3232
# to the list of values to append to them.
3333
Appends = Dict[str, List[str]]
34+
BoardRevisionAppends = Dict[str, Dict[str, List[str]]]
3435

3536
def _new_append():
3637
return defaultdict(list)
3738

3839
def _new_board2appends():
39-
return defaultdict(_new_append)
40+
return defaultdict(lambda: defaultdict(_new_append))
4041

4142
@dataclass
4243
class Snippet:
@@ -45,7 +46,7 @@ class Snippet:
4546

4647
name: str
4748
appends: Appends = field(default_factory=_new_append)
48-
board2appends: Dict[str, Appends] = field(default_factory=_new_board2appends)
49+
board2appends: Dict[str, BoardRevisionAppends] = field(default_factory=_new_board2appends)
4950

5051
def process_data(self, pathobj: Path, snippet_data: dict, sysbuild: bool):
5152
'''Process the data in a snippet.yml file, after it is loaded into a
@@ -68,10 +69,16 @@ def append_value(variable, value):
6869
if board.startswith('/') and not board.endswith('/'):
6970
_err(f"snippet file {pathobj}: board {board} starts with '/', so "
7071
"it must end with '/' to use a regular expression")
72+
for revision, appenddata in settings.get('revisions', {}).items():
73+
for variable, value in appenddata.get('append', {}).items():
74+
if (sysbuild is True and variable[0:3] == 'SB_') or \
75+
(sysbuild is False and variable[0:3] != 'SB_'):
76+
self.board2appends[board][revision][variable].append(
77+
append_value(variable, value))
7178
for variable, value in settings.get('append', {}).items():
7279
if (sysbuild is True and variable[0:3] == 'SB_') or \
7380
(sysbuild is False and variable[0:3] != 'SB_'):
74-
self.board2appends[board][variable].append(
81+
self.board2appends[board][""][variable].append(
7582
append_value(variable, value))
7683

7784
class Snippets(UserDict):
@@ -167,7 +174,18 @@ def print_appends_for_board(self, board: str, appends: Appends):
167174
self.print(f'''\
168175
# Appends for board '{board}'
169176
if("${{BOARD}}${{BOARD_QUALIFIERS}}" STREQUAL "{board}")''')
170-
self.print_appends(appends, 1)
177+
178+
# Output board variables first then board revision variables
179+
self.print_appends(appends[""], 1)
180+
181+
for revision in appends:
182+
if revision != "":
183+
self.print(f'''\
184+
# Appends for revision '{revision}'
185+
if("${{BOARD_REVISION}}" STREQUAL "{revision}")''')
186+
self.print_appends(appends[revision], 2)
187+
self.print(' endif()')
188+
171189
self.print('endif()')
172190

173191
def print_appends(self, appends: Appends, indent: int):

0 commit comments

Comments
 (0)