diff --git a/scripts/dts/gen_driver_kconfig_dts.py b/scripts/dts/gen_driver_kconfig_dts.py index dafe7fcf9df3..1eecb1ba437c 100755 --- a/scripts/dts/gen_driver_kconfig_dts.py +++ b/scripts/dts/gen_driver_kconfig_dts.py @@ -61,6 +61,12 @@ def compat2kconfig(compat): printfile(f'') printfile(f'config DT_HAS_{compat_ident}_ENABLED') printfile(f'\tdef_bool $(dt_compat_enabled,$(DT_COMPAT_{compat_ident}))') + printfile(f'') + printfile(f'if DT_HAS_{compat_ident}_ENABLED') + printfile(f'config DT_{compat_ident}') + printfile(f'\tstring') + printfile(f'\tdefault "{compat}"') + printfile(f'endif') def main(): global kconfig_file diff --git a/scripts/kconfig/kconfig.py b/scripts/kconfig/kconfig.py index b9a139d4bb40..e0bfee3563e6 100755 --- a/scripts/kconfig/kconfig.py +++ b/scripts/kconfig/kconfig.py @@ -13,11 +13,18 @@ import os import sys import textwrap +import pickle +from pathlib import Path +ZEPHYR_BASE = str(Path(__file__).resolve().parents[2]) +sys.path.insert(0, os.path.join(ZEPHYR_BASE, "scripts", "dts", + "python-devicetree", "src")) + +from devicetree import edtlib # Zephyr doesn't use tristate symbols. They're supported here just to make the # script a bit more generic. from kconfiglib import Kconfig, split_expr, expr_value, expr_str, BOOL, \ - TRISTATE, TRI_TO_STR, AND, OR + TRISTATE, TRI_TO_STR, AND, OR, STRING, TYPE_TO_STR, Symbol def main(): @@ -96,6 +103,72 @@ def main(): # Write the list of parsed Kconfig files to a file write_kconfig_filenames(kconf, args.kconfig_list_out) + EDT_PICKLE = os.environ.get("EDT_PICKLE") + + # The "if" handles a missing dts. + if EDT_PICKLE is not None and os.path.isfile(EDT_PICKLE): + with open(EDT_PICKLE, 'rb') as f: + edt = pickle.load(f) + else: + edt = None + + SYM_TO_TYPE = { + "FLASH_HAS_DRIVER_ENABLED": "api", + "SERIAL_HAS_DRIVER": "api", + "ENTROPY_HAS_DRIVER": "api", + "SERIAL_SUPPORT_INTERRUPT": "feature", + "SERIAL_SUPPORT_ASYNC": "feature", + } + + if edt: + for compat in edt.compat2okay.keys(): + device_sym = compat2symbol(kconf, compat) + + if device_sym: +# print("C: %s" % compat) +# print("N: %s" % device_sym.name) +# print(device_sym) +# for r in device_sym.referenced: +# if isinstance(r, Symbol) and r != kconf.y: +# print("R: %s" % r.name) + for (sym, cond) in device_sym.selects: +# print("S: %s" % sym.name) + if sym.name in SYM_TO_TYPE: + print('dts compatible: "%s" Kconfig Symbol: %s' % (compat, device_sym.name)) + print("%s - %s" % (SYM_TO_TYPE[sym.name], sym.name)) + print("") + +def compat2symbol(kconf, compat): + dt_sym = None + for sym in kconf.syms.values(): + if sym.type == STRING and sym.str_value == compat: + dt_sym = sym + + if dt_sym == None: +# print("error found no symbol matching %s" % compat) + return None + + dt_has_sym = None + for r in dt_sym.referenced: + if isinstance(r, Symbol): + if "DT_HAS_" in r.name: + dt_has_sym = r + + if dt_has_sym == None: + print("error found no symbol matching %s" % compat) + + device_sym = None + for sym in kconf.syms.values(): + if sym == dt_sym: + continue + for r in sym.referenced: + if isinstance(r, Symbol) and r == dt_has_sym: + if device_sym: + print("ERROR - only expect one device symbol to match") + device_sym = sym + + return device_sym + def check_no_promptless_assign(kconf): # Checks that no promptless symbols are assigned