Skip to content

Commit e634791

Browse files
tejlmand57300
authored andcommitted
[nrf fromlist] cmake: scripts: support SoC extension
Upstream PR: zephyrproject-rtos/zephyr#72857 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 board 'cos' can be extended like this: > socs: > extend: cos > cpuclusters: > - name: extra_core Signed-off-by: Torsten Rasmussen <[email protected]> (cherry picked from commit 0c73756be4f885b7be4bebc233c4746de03e1b52)
1 parent ef0d90b commit e634791

File tree

3 files changed

+69
-21
lines changed

3 files changed

+69
-21
lines changed

cmake/modules/hwm_v2.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ 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}")
7979

@@ -83,9 +83,9 @@ while(TRUE)
8383
set(setting_name SOC_${HWM_TYPE}_${SOC_V2_NAME}_DIR)
8484
endif()
8585
# We support both SOC_foo_DIR and SOC_FOO_DIR.
86-
set(${setting_name} ${SOC_V2_DIR})
86+
list(GET SOC_V2_DIR 0 ${setting_name})
8787
string(TOUPPER ${setting_name} setting_name)
88-
set(${setting_name} ${SOC_V2_DIR})
88+
list(GET SOC_V2_DIR 0 ${setting_name})
8989
endif()
9090

9191
if(idx EQUAL -1)

scripts/list_hardware.py

Lines changed: 49 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
@@ -76,17 +77,16 @@ def __init__(self, folder='', soc_yaml=None):
7677
found_match = True
7778
break
7879

79-
8080
if found_match is False:
8181
sys.exit(f'ERROR: SoC qualifier match unresolved: {qualifiers}')
8282

8383
for f in data.get('family', []):
84-
family = Family(f['name'], folder, [], [])
84+
family = Family(f['name'], [folder], [], [])
8585
for s in f.get('series', []):
86-
series = Series(s['name'], folder, f['name'], [])
86+
series = Series(s['name'], [folder], f['name'], [])
8787
socs = [(Soc(soc['name'],
8888
[c['name'] for c in soc.get('cpuclusters', [])],
89-
folder, s['name'], f['name']))
89+
[folder], s['name'], f['name']))
9090
for soc in s.get('socs', [])]
9191
series.socs.extend(socs)
9292
self._series.append(series)
@@ -95,26 +95,36 @@ def __init__(self, folder='', soc_yaml=None):
9595
family.socs.extend(socs)
9696
socs = [(Soc(soc['name'],
9797
[c['name'] for c in soc.get('cpuclusters', [])],
98-
folder, None, f['name']))
98+
[folder], None, f['name']))
9999
for soc in f.get('socs', [])]
100100
self._socs.extend(socs)
101101
self._families.append(family)
102102

103103
for s in data.get('series', []):
104-
series = Series(s['name'], folder, '', [])
104+
series = Series(s['name'], [folder], '', [])
105105
socs = [(Soc(soc['name'],
106106
[c['name'] for c in soc.get('cpuclusters', [])],
107-
folder, s['name'], ''))
107+
[folder], s['name'], ''))
108108
for soc in s.get('socs', [])]
109109
series.socs.extend(socs)
110110
self._series.append(series)
111111
self._socs.extend(socs)
112112

113-
socs = [(Soc(soc['name'],
114-
[c['name'] for c in soc.get('cpuclusters', [])],
115-
folder, '', ''))
116-
for soc in data.get('socs', [])]
117-
self._socs.extend(socs)
113+
for soc in data.get('socs', []):
114+
mutual_exclusive = {'name', 'extend'}
115+
if len(mutual_exclusive - soc.keys()) < 1:
116+
sys.exit(f'ERROR: Malformed content in SoC file: {soc_yaml}\n'
117+
f'{mutual_exclusive} are mutual exclusive at this level.')
118+
if soc.get('name') is not None:
119+
self._socs.append(Soc(soc['name'], [c['name'] for c in soc.get('cpuclusters', [])],
120+
[folder], '', ''))
121+
elif soc.get('extend') is not None:
122+
self._extended_socs.append(Soc(soc['extend'],
123+
[c['name'] for c in soc.get('cpuclusters', [])],
124+
[folder], '', ''))
125+
else:
126+
sys.exit(f'ERROR: Malformed "socs" section in SoC file: {soc_yaml}\n'
127+
f'Cannot find one of required keys {mutual_exclusive}.')
118128

119129
@staticmethod
120130
def from_file(socs_file):
@@ -137,8 +147,23 @@ def from_yaml(socs_yaml):
137147
def extend(self, systems):
138148
self._families.extend(systems.get_families())
139149
self._series.extend(systems.get_series())
150+
151+
for es in self._extended_socs[:]:
152+
for s in systems.get_socs():
153+
if s.name == es.name:
154+
s.extend(es)
155+
self._extended_socs.remove(es)
156+
break
140157
self._socs.extend(systems.get_socs())
141158

159+
for es in systems.get_extended_socs():
160+
for s in self._socs:
161+
if s.name == es.name:
162+
s.extend(es)
163+
break
164+
else:
165+
self._extended_socs.append(es)
166+
142167
def get_families(self):
143168
return self._families
144169

@@ -148,6 +173,9 @@ def get_series(self):
148173
def get_socs(self):
149174
return self._socs
150175

176+
def get_extended_socs(self):
177+
return self._extended_socs
178+
151179
def get_soc(self, name):
152180
try:
153181
return next(s for s in self._socs if s.name == name)
@@ -160,23 +188,28 @@ def get_soc(self, name):
160188
class Soc:
161189
name: str
162190
cpuclusters: List[str]
163-
folder: str
191+
folder: List[str]
164192
series: str = ''
165193
family: str = ''
166194

195+
def extend(self, soc):
196+
if self.name == soc.name:
197+
self.cpuclusters.extend(soc.cpuclusters)
198+
self.folder.extend(soc.folder)
199+
167200

168201
@dataclass
169202
class Series:
170203
name: str
171-
folder: str
204+
folder: List[str]
172205
family: str
173206
socs: List[Soc]
174207

175208

176209
@dataclass
177210
class Family:
178211
name: str
179-
folder: str
212+
folder: List[str]
180213
series: List[Series]
181214
socs: List[Soc]
182215

@@ -293,7 +326,7 @@ def dump_v2_system(args, type, system):
293326
info = args.cmakeformat.format(
294327
TYPE='TYPE;' + type,
295328
NAME='NAME;' + system.name,
296-
DIR='DIR;' + Path(system.folder).as_posix(),
329+
DIR='DIR;' + ';'.join([Path(x).as_posix() for x in system.folder]),
297330
HWM='HWM;' + 'v2'
298331
)
299332
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)