Skip to content

Commit c563b26

Browse files
tejlmand57300
authored andcommitted
[nrf fromtree] cmake: scripts: support SoC extension
Fixes: #72374 Support extending an existing SoC with new CPU clusters. This commit introduces the following changes to allow an SoC to be extended out-of-tree. The SoC yaml schema is extended to support an extend field which will be used to identify the SoC to be extended with extra CPU clusters. A SoC 'a_soc' can be extended like this: > socs: > extend: a_soc > cpuclusters: > - name: extra_core Signed-off-by: Torsten Rasmussen <[email protected]> (cherry picked from commit 98b186c)
1 parent 289aa39 commit c563b26

File tree

4 files changed

+84
-26
lines changed

4 files changed

+84
-26
lines changed

cmake/modules/hwm_v2.cmake

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,23 @@ while(TRUE)
7373
string(TOUPPER "${ARCH_V2_NAME}" ARCH_V2_NAME_UPPER)
7474
set(ARCH_V2_${ARCH_V2_NAME_UPPER}_DIR ${ARCH_V2_DIR})
7575
elseif(HWM_TYPE MATCHES "^soc|^series|^family")
76-
cmake_parse_arguments(SOC_V2 "" "NAME;DIR;HWM" "" ${line})
76+
cmake_parse_arguments(SOC_V2 "" "NAME;HWM" "DIR" ${line})
7777

7878
list(APPEND kconfig_soc_source_dir "${SOC_V2_DIR}")
79+
string(TOUPPER "${SOC_V2_NAME}" SOC_V2_NAME_UPPER)
80+
string(TOUPPER "${HWM_TYPE}" HWM_TYPE_UPPER)
7981

8082
if(HWM_TYPE STREQUAL "soc")
81-
set(setting_name SOC_${SOC_V2_NAME}_DIR)
83+
# We support both SOC_foo_DIR and SOC_FOO_DIR.
84+
set(SOC_${SOC_V2_NAME}_DIRECTORIES ${SOC_V2_DIR})
85+
set(SOC_${SOC_V2_NAME_UPPER}_DIRECTORIES ${SOC_V2_DIR})
86+
list(GET SOC_V2_DIR 0 SOC_${SOC_V2_NAME}_DIR)
87+
list(GET SOC_V2_DIR 0 SOC_${SOC_V2_NAME_UPPER}_DIR)
8288
else()
83-
set(setting_name SOC_${HWM_TYPE}_${SOC_V2_NAME}_DIR)
89+
# We support both SOC_series_foo_DIR and SOC_SERIES_FOO_DIR (and family / FAMILY).
90+
set(SOC_${HWM_TYPE}_${SOC_V2_NAME}_DIR ${SOC_V2_DIR})
91+
set(SOC_${HWM_TYPE_UPPER}_${SOC_V2_NAME_UPPER}_DIR ${SOC_V2_DIR})
8492
endif()
85-
# We support both SOC_foo_DIR and SOC_FOO_DIR.
86-
set(${setting_name} ${SOC_V2_DIR})
87-
string(TOUPPER ${setting_name} setting_name)
88-
set(${setting_name} ${SOC_V2_DIR})
8993
endif()
9094

9195
if(idx EQUAL -1)

cmake/modules/soc_v2.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@ if(HWMv2)
2828
set(SOC_FAMILY ${CONFIG_SOC_FAMILY})
2929
set(SOC_V2_DIR ${SOC_${SOC_NAME}_DIR})
3030
set(SOC_FULL_DIR ${SOC_V2_DIR} CACHE PATH "Path to the SoC directory." FORCE)
31-
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${SOC_V2_DIR}/soc.yml)
31+
set(SOC_DIRECTORIES ${SOC_${SOC_NAME}_DIRECTORIES} CACHE INTERNAL
32+
"List of SoC directories for SoC (${SOC_NAME})" FORCE
33+
)
34+
foreach(dir ${SOC_DIRECTORIES})
35+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${dir}/soc.yml)
36+
endforeach()
3237
endif()

scripts/list_hardware.py

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self, folder='', soc_yaml=None):
3535
self._socs = []
3636
self._series = []
3737
self._families = []
38+
self._extended_socs = []
3839

3940
if soc_yaml is None:
4041
return
@@ -47,12 +48,12 @@ def __init__(self, folder='', soc_yaml=None):
4748
sys.exit(f'ERROR: Malformed yaml {soc_yaml.as_posix()}', e)
4849

4950
for f in data.get('family', []):
50-
family = Family(f['name'], folder, [], [])
51+
family = Family(f['name'], [folder], [], [])
5152
for s in f.get('series', []):
52-
series = Series(s['name'], folder, f['name'], [])
53+
series = Series(s['name'], [folder], f['name'], [])
5354
socs = [(Soc(soc['name'],
5455
[c['name'] for c in soc.get('cpuclusters', [])],
55-
folder, s['name'], f['name']))
56+
[folder], s['name'], f['name']))
5657
for soc in s.get('socs', [])]
5758
series.socs.extend(socs)
5859
self._series.append(series)
@@ -61,26 +62,36 @@ def __init__(self, folder='', soc_yaml=None):
6162
family.socs.extend(socs)
6263
socs = [(Soc(soc['name'],
6364
[c['name'] for c in soc.get('cpuclusters', [])],
64-
folder, None, f['name']))
65+
[folder], None, f['name']))
6566
for soc in f.get('socs', [])]
6667
self._socs.extend(socs)
6768
self._families.append(family)
6869

6970
for s in data.get('series', []):
70-
series = Series(s['name'], folder, '', [])
71+
series = Series(s['name'], [folder], '', [])
7172
socs = [(Soc(soc['name'],
7273
[c['name'] for c in soc.get('cpuclusters', [])],
73-
folder, s['name'], ''))
74+
[folder], s['name'], ''))
7475
for soc in s.get('socs', [])]
7576
series.socs.extend(socs)
7677
self._series.append(series)
7778
self._socs.extend(socs)
7879

79-
socs = [(Soc(soc['name'],
80-
[c['name'] for c in soc.get('cpuclusters', [])],
81-
folder, '', ''))
82-
for soc in data.get('socs', [])]
83-
self._socs.extend(socs)
80+
for soc in data.get('socs', []):
81+
mutual_exclusive = {'name', 'extend'}
82+
if len(mutual_exclusive - soc.keys()) < 1:
83+
sys.exit(f'ERROR: Malformed content in SoC file: {soc_yaml}\n'
84+
f'{mutual_exclusive} are mutual exclusive at this level.')
85+
if soc.get('name') is not None:
86+
self._socs.append(Soc(soc['name'], [c['name'] for c in soc.get('cpuclusters', [])],
87+
[folder], '', ''))
88+
elif soc.get('extend') is not None:
89+
self._extended_socs.append(Soc(soc['extend'],
90+
[c['name'] for c in soc.get('cpuclusters', [])],
91+
[folder], '', ''))
92+
else:
93+
sys.exit(f'ERROR: Malformed "socs" section in SoC file: {soc_yaml}\n'
94+
f'Cannot find one of required keys {mutual_exclusive}.')
8495

8596
# Ensure that any runner configuration matches socs and cpuclusters declared in the same
8697
# soc.yml file
@@ -97,7 +108,7 @@ def __init__(self, folder='', soc_yaml=None):
97108
if components and components[-1] == 'ns':
98109
components.pop()
99110

100-
for soc in self._socs:
111+
for soc in self._socs + self._extended_socs:
101112
if re.match(fr'^{soc_name}$', soc.name) is not None:
102113
if soc.cpuclusters and components:
103114
check_string = '/'.join(components)
@@ -133,8 +144,23 @@ def from_yaml(socs_yaml):
133144
def extend(self, systems):
134145
self._families.extend(systems.get_families())
135146
self._series.extend(systems.get_series())
147+
148+
for es in self._extended_socs[:]:
149+
for s in systems.get_socs():
150+
if s.name == es.name:
151+
s.extend(es)
152+
self._extended_socs.remove(es)
153+
break
136154
self._socs.extend(systems.get_socs())
137155

156+
for es in systems.get_extended_socs():
157+
for s in self._socs:
158+
if s.name == es.name:
159+
s.extend(es)
160+
break
161+
else:
162+
self._extended_socs.append(es)
163+
138164
def get_families(self):
139165
return self._families
140166

@@ -144,6 +170,9 @@ def get_series(self):
144170
def get_socs(self):
145171
return self._socs
146172

173+
def get_extended_socs(self):
174+
return self._extended_socs
175+
147176
def get_soc(self, name):
148177
try:
149178
return next(s for s in self._socs if s.name == name)
@@ -156,23 +185,28 @@ def get_soc(self, name):
156185
class Soc:
157186
name: str
158187
cpuclusters: List[str]
159-
folder: str
188+
folder: List[str]
160189
series: str = ''
161190
family: str = ''
162191

192+
def extend(self, soc):
193+
if self.name == soc.name:
194+
self.cpuclusters.extend(soc.cpuclusters)
195+
self.folder.extend(soc.folder)
196+
163197

164198
@dataclass
165199
class Series:
166200
name: str
167-
folder: str
201+
folder: List[str]
168202
family: str
169203
socs: List[Soc]
170204

171205

172206
@dataclass
173207
class Family:
174208
name: str
175-
folder: str
209+
folder: List[str]
176210
series: List[Series]
177211
socs: List[Soc]
178212

@@ -289,7 +323,7 @@ def dump_v2_system(args, type, system):
289323
info = args.cmakeformat.format(
290324
TYPE='TYPE;' + type,
291325
NAME='NAME;' + system.name,
292-
DIR='DIR;' + Path(system.folder).as_posix(),
326+
DIR='DIR;' + ';'.join([Path(x).as_posix() for x in system.folder]),
293327
HWM='HWM;' + 'v2'
294328
)
295329
else:

scripts/schemas/soc-schema.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,22 @@ schema;soc-schema:
2424
- type: map
2525
mapping:
2626
name:
27-
required: true
27+
required: true # Note: either name or extend is required, but that is handled in python
28+
type: str
29+
cpuclusters:
30+
include: cpucluster-schema
31+
32+
schema;soc-extend-schema:
33+
required: false
34+
type: seq
35+
sequence:
36+
- type: map
37+
mapping:
38+
name:
39+
required: false # Note: either name or extend is required, but that is handled in python
40+
type: str
41+
extend:
42+
required: false # Note: either name or extend is required, but that is handled in python
2843
type: str
2944
cpuclusters:
3045
include: cpucluster-schema
@@ -60,7 +75,7 @@ mapping:
6075
series:
6176
include: series-schema
6277
socs:
63-
include: soc-schema
78+
include: soc-extend-schema
6479
vendor:
6580
required: false
6681
type: str

0 commit comments

Comments
 (0)