Skip to content

Commit

Permalink
[nrf fromlist] cmake: scripts: support SoC extension
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
tejlmand authored and 57300 committed Jun 12, 2024
1 parent ef0d90b commit e634791
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 21 deletions.
6 changes: 3 additions & 3 deletions cmake/modules/hwm_v2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ while(TRUE)
string(TOUPPER "${ARCH_V2_NAME}" ARCH_V2_NAME_UPPER)
set(ARCH_V2_${ARCH_V2_NAME_UPPER}_DIR ${ARCH_V2_DIR})
elseif(HWM_TYPE MATCHES "^soc|^series|^family")
cmake_parse_arguments(SOC_V2 "" "NAME;DIR;HWM" "" ${line})
cmake_parse_arguments(SOC_V2 "" "NAME;HWM" "DIR" ${line})

list(APPEND kconfig_soc_source_dir "${SOC_V2_DIR}")

Expand All @@ -83,9 +83,9 @@ while(TRUE)
set(setting_name SOC_${HWM_TYPE}_${SOC_V2_NAME}_DIR)
endif()
# We support both SOC_foo_DIR and SOC_FOO_DIR.
set(${setting_name} ${SOC_V2_DIR})
list(GET SOC_V2_DIR 0 ${setting_name})
string(TOUPPER ${setting_name} setting_name)
set(${setting_name} ${SOC_V2_DIR})
list(GET SOC_V2_DIR 0 ${setting_name})
endif()

if(idx EQUAL -1)
Expand Down
65 changes: 49 additions & 16 deletions scripts/list_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, folder='', soc_yaml=None):
self._socs = []
self._series = []
self._families = []
self._extended_socs = []

if soc_yaml is None:
return
Expand Down Expand Up @@ -76,17 +77,16 @@ def __init__(self, folder='', soc_yaml=None):
found_match = True
break


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

for f in data.get('family', []):
family = Family(f['name'], folder, [], [])
family = Family(f['name'], [folder], [], [])
for s in f.get('series', []):
series = Series(s['name'], folder, f['name'], [])
series = Series(s['name'], [folder], f['name'], [])
socs = [(Soc(soc['name'],
[c['name'] for c in soc.get('cpuclusters', [])],
folder, s['name'], f['name']))
[folder], s['name'], f['name']))
for soc in s.get('socs', [])]
series.socs.extend(socs)
self._series.append(series)
Expand All @@ -95,26 +95,36 @@ def __init__(self, folder='', soc_yaml=None):
family.socs.extend(socs)
socs = [(Soc(soc['name'],
[c['name'] for c in soc.get('cpuclusters', [])],
folder, None, f['name']))
[folder], None, f['name']))
for soc in f.get('socs', [])]
self._socs.extend(socs)
self._families.append(family)

for s in data.get('series', []):
series = Series(s['name'], folder, '', [])
series = Series(s['name'], [folder], '', [])
socs = [(Soc(soc['name'],
[c['name'] for c in soc.get('cpuclusters', [])],
folder, s['name'], ''))
[folder], s['name'], ''))
for soc in s.get('socs', [])]
series.socs.extend(socs)
self._series.append(series)
self._socs.extend(socs)

socs = [(Soc(soc['name'],
[c['name'] for c in soc.get('cpuclusters', [])],
folder, '', ''))
for soc in data.get('socs', [])]
self._socs.extend(socs)
for soc in data.get('socs', []):
mutual_exclusive = {'name', 'extend'}
if len(mutual_exclusive - soc.keys()) < 1:
sys.exit(f'ERROR: Malformed content in SoC file: {soc_yaml}\n'
f'{mutual_exclusive} are mutual exclusive at this level.')
if soc.get('name') is not None:
self._socs.append(Soc(soc['name'], [c['name'] for c in soc.get('cpuclusters', [])],
[folder], '', ''))
elif soc.get('extend') is not None:
self._extended_socs.append(Soc(soc['extend'],
[c['name'] for c in soc.get('cpuclusters', [])],
[folder], '', ''))
else:
sys.exit(f'ERROR: Malformed "socs" section in SoC file: {soc_yaml}\n'
f'Cannot find one of required keys {mutual_exclusive}.')

@staticmethod
def from_file(socs_file):
Expand All @@ -137,8 +147,23 @@ def from_yaml(socs_yaml):
def extend(self, systems):
self._families.extend(systems.get_families())
self._series.extend(systems.get_series())

for es in self._extended_socs[:]:
for s in systems.get_socs():
if s.name == es.name:
s.extend(es)
self._extended_socs.remove(es)
break
self._socs.extend(systems.get_socs())

for es in systems.get_extended_socs():
for s in self._socs:
if s.name == es.name:
s.extend(es)
break
else:
self._extended_socs.append(es)

def get_families(self):
return self._families

Expand All @@ -148,6 +173,9 @@ def get_series(self):
def get_socs(self):
return self._socs

def get_extended_socs(self):
return self._extended_socs

def get_soc(self, name):
try:
return next(s for s in self._socs if s.name == name)
Expand All @@ -160,23 +188,28 @@ def get_soc(self, name):
class Soc:
name: str
cpuclusters: List[str]
folder: str
folder: List[str]
series: str = ''
family: str = ''

def extend(self, soc):
if self.name == soc.name:
self.cpuclusters.extend(soc.cpuclusters)
self.folder.extend(soc.folder)


@dataclass
class Series:
name: str
folder: str
folder: List[str]
family: str
socs: List[Soc]


@dataclass
class Family:
name: str
folder: str
folder: List[str]
series: List[Series]
socs: List[Soc]

Expand Down Expand Up @@ -293,7 +326,7 @@ def dump_v2_system(args, type, system):
info = args.cmakeformat.format(
TYPE='TYPE;' + type,
NAME='NAME;' + system.name,
DIR='DIR;' + Path(system.folder).as_posix(),
DIR='DIR;' + ';'.join([Path(x).as_posix() for x in system.folder]),
HWM='HWM;' + 'v2'
)
else:
Expand Down
19 changes: 17 additions & 2 deletions scripts/schemas/soc-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,22 @@ schema;soc-schema:
- type: map
mapping:
name:
required: true
required: true # Note: either name or extend is required, but that is handled in python
type: str
cpuclusters:
include: cpucluster-schema

schema;soc-extend-schema:
required: false
type: seq
sequence:
- type: map
mapping:
name:
required: false # Note: either name or extend is required, but that is handled in python
type: str
extend:
required: false # Note: either name or extend is required, but that is handled in python
type: str
cpuclusters:
include: cpucluster-schema
Expand Down Expand Up @@ -60,7 +75,7 @@ mapping:
series:
include: series-schema
socs:
include: soc-schema
include: soc-extend-schema
vendor:
required: false
type: str
Expand Down

0 comments on commit e634791

Please sign in to comment.