Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soc: kconfig: define Kconfig soc, series, and families from lists #6

Open
wants to merge 1 commit into
base: collab-hwm
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cmake/modules/hwm_v2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ if(NOT HWMv2)
return()
endif()

add_custom_target(hardware_model)

# Internal helper function for creation of Kconfig files.
function(kconfig_gen bin_dir file dirs)
file(MAKE_DIRECTORY "${bin_dir}")
Expand All @@ -44,7 +46,7 @@ list(TRANSFORM SOC_ROOT PREPEND "--soc-root=" OUTPUT_VARIABLE soc_root_args)
execute_process(COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/list_hardware.py
${arch_root_args} ${soc_root_args}
--archs --socs
--cmakeformat={TYPE}\;{NAME}\;{DIR}\;{HWM}
--cmakeformat={TYPE}\;{HWM}\;{NAME}\;{SERIES}\;{FAMILY}\;{DIR}
OUTPUT_VARIABLE ret_hw
ERROR_VARIABLE err_hw
RESULT_VARIABLE ret_val
Expand All @@ -70,14 +72,19 @@ 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;DIR;HWM;SERIES;FAMILY" "" ${line})

list(APPEND kconfig_soc_source_dir "${SOC_V2_DIR}")

if(HWM_TYPE STREQUAL "soc")
set(setting_name SOC_${SOC_V2_NAME}_DIR)
set_property(TARGET hardware_model APPEND PROPERTY SOCS ${SOC_V2_NAME})
set_property(TARGET hardware_model PROPERTY ${SOC_V2_NAME}_SERIES ${SOC_V2_SERIES})
set_property(TARGET hardware_model PROPERTY ${SOC_V2_NAME}_FAMILY ${SOC_V2_FAMILY})
else()
set(setting_name SOC_${HWM_TYPE}_${SOC_V2_NAME}_DIR)
string(TOUPPER ${HWM_TYPE} HWM_TYPE_UPPER)
set_property(TARGET hardware_model APPEND PROPERTY SOC_${HWM_TYPE_UPPER} ${SOC_V2_NAME})
endif()
# We support both SOC_foo_DIR and SOC_FOO_DIR.
set(${setting_name} ${SOC_V2_DIR})
Expand Down
18 changes: 18 additions & 0 deletions cmake/modules/kconfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ foreach(module_name ${ZEPHYR_MODULE_NAMES})
endif()
endforeach()

set(hardware_model_kconfig_env)
get_target_property(socs hardware_model SOCS)
get_target_property(families hardware_model SOC_FAMILY)
get_target_property(series hardware_model SOC_SERIES)
foreach(soc ${socs})
get_property(s_series TARGET hardware_model PROPERTY ${soc}_SERIES)
get_property(s_family TARGET hardware_model PROPERTY ${soc}_FAMILY)
list(APPEND hardware_model_kconfig_env "${soc}_SERIES=${s_series}")
list(APPEND hardware_model_kconfig_env "${soc}_FAMILY=${s_family}")
endforeach()
list(JOIN socs "," socs)
list(JOIN families "," families)
list(JOIN series "," series)
list(APPEND hardware_model_kconfig_env "SOCS=${socs}")
list(APPEND hardware_model_kconfig_env "SOC_SERIES=${series}")
list(APPEND hardware_model_kconfig_env "SOC_FAMILIES=${families}")

# A list of common environment settings used when invoking Kconfig during CMake
# configure time or menuconfig and related build target.
string(REPLACE ";" "\\\;" SHIELD_AS_LIST_ESCAPED "${SHIELD_AS_LIST}")
Expand Down Expand Up @@ -171,6 +188,7 @@ set(COMMON_KCONFIG_ENV_SETTINGS
EDT_PICKLE=${EDT_PICKLE}
# Export all Zephyr modules to Kconfig
${ZEPHYR_KCONFIG_MODULES_DIR}
${hardware_model_kconfig_env}
)

if(HWMv1)
Expand Down
9 changes: 9 additions & 0 deletions misc/Kconfig.empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Intentionally left empty.
#
# This file can be used when loading Kconfig files conditionally.
# Note, the snippet:
# if FOO
# source "bar/Kconfig"
# endif
# is not a conditional load in Kconfig, but simply applies `if FOO` on all
# entries in bar/Kconfig.
41 changes: 41 additions & 0 deletions scripts/kconfig/kconfigfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,43 @@ def sanitize_upper(kconf, _, string):
return re.sub(r'[^a-zA-Z0-9_]', '_', string).upper()


def defined(kconf, _, variable, true_value, false_value):
"""
Check if the variable is defined with a value.
If the variable defines a value, then <true_value> is returned
Else <false_value> is returned.
"""
if variable == "":
return false_value
return true_value


def get(kconf, _, list, index):
"""
Get the value from the list at <index>
This list is a comma separated string.
"""
local_list = list.split(',')
return local_list[int(index)]


def get_env_list(kconf, _, name):
"""
Return the environment list setting matching name.
"""
return os.environ.get(f"{name}")


def remove(kconf, _, inlist, element):
"""
Remove the element from the list.
This list is a comma separated string.
"""
local_list = inlist.split(',')
local_list.remove(element)
return ','.join(local_list)


def shields_list_contains(kconf, _, shield):
"""
Return "n" if cmake environment variable 'SHIELD_AS_LIST' doesn't exist.
Expand Down Expand Up @@ -921,4 +958,8 @@ def shields_list_contains(kconf, _, shield):
"dt_chosen_partition_addr_hex": (dt_chosen_partition_addr, 1, 3),
"sanitize_upper": (sanitize_upper, 1, 1),
"shields_list_contains": (shields_list_contains, 1, 1),
"defined": (defined, 3, 3),
"remove": (remove, 2, 2),
"get": (get, 2, 2),
"get_env_list": (get_env_list, 1, 1),
}
4 changes: 4 additions & 0 deletions scripts/list_hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,17 @@
info = args.cmakeformat.format(
TYPE='TYPE;' + type,
NAME='NAME;' + system.name,
SERIES='SERIES;' + str(system.series if type == 'soc' else ''),
FAMILY='FAMILY;' + str(system.family if type == 'soc' or type == 'series' else ''),

Check warning on line 252 in scripts/list_hardware.py

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

R1714

scripts/list_hardware.py:252 Consider merging these comparisons with 'in' by using 'type in ('soc', 'series')'. Use a set instead if elements are hashable. (consider-using-in)
DIR='DIR;' + Path(system.folder).as_posix(),
HWM='HWM;' + 'v2'
)
else:
info = args.format.format(
type=type,
name=system.name,
series=system.series if type == 'soc' else '',
family=system.family if type == 'soc' or type == 'series' else '',

Check warning on line 261 in scripts/list_hardware.py

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

R1714

scripts/list_hardware.py:261 Consider merging these comparisons with 'in' by using 'type in ('soc', 'series')'. Use a set instead if elements are hashable. (consider-using-in)
dir=system.folder,
hwm='v2'
)
Expand Down
20 changes: 20 additions & 0 deletions soc/Kconfig.soc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2024 Nordic Semiconductor ASA

# SPDX-License-Identifier: Apache-2.0

# Convert list of SoCs into Kconfig settings

SOC := $(get,$(SOCS),0)
SOC_UPPER := $(sanitize_upper,$(SOC))
SOCS := $(remove,$(SOCS),$(SOC))

config SOC_$(SOC_UPPER)
bool
select SOC_SERIES_$(defined,$($(SOC)_SERIES),$(sanitize_upper,$($(SOC)_SERIES)),NONE)
select SOC_FAMILY_$(defined,$($(SOC)_FAMILY),$(sanitize_upper,$($(SOC)_FAMILY)),NONE)

config SOC
default "$(SOC)" if SOC_$(SOC_UPPER)

RECURSIVE_SOURCE := ./$(RECURSIVE_SOURCE)
source "$(defined,$(SOCS),soc/$(RECURSIVE_SOURCE)Kconfig.soc,misc/Kconfig.empty)"
18 changes: 18 additions & 0 deletions soc/Kconfig.soc.family
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2024 Nordic Semiconductor ASA

# SPDX-License-Identifier: Apache-2.0

# Convert list of SoCs into Kconfig settings

FAMILY := $(get,$(SOC_FAMILIES),0)
FAMILY_UPPER := $(sanitize_upper,$(FAMILY))
SOC_FAMILIES := $(remove,$(SOC_FAMILIES),$(FAMILY))

config SOC_FAMILY_$(FAMILY_UPPER)
bool

config SOC_FAMILY
default "$(FAMILY)" if SOC_FAMILY_$(FAMILY_UPPER)

RECURSIVE_SOURCE := ./$(RECURSIVE_SOURCE)
source "$(defined,$(SOC_FAMILIES),soc/$(RECURSIVE_SOURCE)Kconfig.soc.family,misc/Kconfig.empty)"
5 changes: 5 additions & 0 deletions soc/Kconfig.soc.select
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

SERIES_UPPER := $(sanitize_upper,$($(SOC)_SERIES))

config SOC_$(SOC_UPPER)
select SOC_SERIES_$(SERIES_UPPER)
18 changes: 18 additions & 0 deletions soc/Kconfig.soc.series
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2024 Nordic Semiconductor ASA

# SPDX-License-Identifier: Apache-2.0

# Convert list of SoCs into Kconfig settings

SERIES := $(get,$(SOC_SERIES),0)
SERIES_UPPER := $(sanitize_upper,$(SERIES))
SOC_SERIES := $(remove,$(SOC_SERIES),$(SERIES))

config SOC_SERIES_$(SERIES_UPPER)
bool

config SOC_SERIES
default "$(SERIES)" if SOC_SERIES_$(SERIES_UPPER)

RECURSIVE_SOURCE := ./$(RECURSIVE_SOURCE)
source "$(defined,$(SOC_SERIES),soc/$(RECURSIVE_SOURCE)Kconfig.soc.series,misc/Kconfig.empty)"
23 changes: 23 additions & 0 deletions soc/Kconfig.v2
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,26 @@ config SOC_PART_NUMBER

# Source all Kconfig HWMv2 from SoC roots.
source "$(KCONFIG_BINARY_DIR)/soc/Kconfig.soc"

config SOC_SERIES_NONE
bool
help
Setting selected when the SoC is not part of a SoC series

config SOC_FAMILY_NONE
bool
help
Setting selected when the SoC is not part of a SoC family

SOCS := $(get_env_list,SOCS)
SOC_SERIES := $(get_env_list,SOC_SERIES)
SOC_FAMILIES := $(get_env_list,SOC_FAMILIES)

RECURSIVE_SOURCE :=
rsource "Kconfig.soc"

RECURSIVE_SOURCE :=
rsource "Kconfig.soc.series"

RECURSIVE_SOURCE :=
rsource "Kconfig.soc.family"
Loading