Skip to content

Commit c400511

Browse files
committed
kconfig: dump API/feature info based on devicetree & Kconfig symbols
Walk devicetree compatibles that are enabled and dump out API and feature info based on the Kconfig symbols we have enabled. Signed-off-by: Kumar Gala <[email protected]>
1 parent 0fe53eb commit c400511

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

scripts/kconfig/kconfig.py

+58-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# Zephyr doesn't use tristate symbols. They're supported here just to make the
2525
# script a bit more generic.
2626
from kconfiglib import Kconfig, split_expr, expr_value, expr_str, BOOL, \
27-
TRISTATE, TRI_TO_STR, AND, OR
27+
TRISTATE, TRI_TO_STR, AND, OR, STRING, TYPE_TO_STR, Symbol
2828

2929

3030
def main():
@@ -112,6 +112,63 @@ def main():
112112
else:
113113
edt = None
114114

115+
SYM_TO_TYPE = {
116+
"FLASH_HAS_DRIVER_ENABLED": "api",
117+
"SERIAL_HAS_DRIVER": "api",
118+
"ENTROPY_HAS_DRIVER": "api",
119+
"SERIAL_SUPPORT_INTERRUPT": "feature",
120+
"SERIAL_SUPPORT_ASYNC": "feature",
121+
}
122+
123+
if edt:
124+
for compat in edt.compat2okay.keys():
125+
device_sym = compat2symbol(kconf, compat)
126+
127+
if device_sym:
128+
# print("C: %s" % compat)
129+
# print("N: %s" % device_sym.name)
130+
# print(device_sym)
131+
# for r in device_sym.referenced:
132+
# if isinstance(r, Symbol) and r != kconf.y:
133+
# print("R: %s" % r.name)
134+
for (sym, cond) in device_sym.selects:
135+
# print("S: %s" % sym.name)
136+
if sym.name in SYM_TO_TYPE:
137+
print('dts compatible: "%s" Kconfig Symbol: %s' % (compat, device_sym.name))
138+
print("%s - %s" % (SYM_TO_TYPE[sym.name], sym.name))
139+
print("")
140+
141+
def compat2symbol(kconf, compat):
142+
dt_sym = None
143+
for sym in kconf.syms.values():
144+
if sym.type == STRING and sym.str_value == compat:
145+
dt_sym = sym
146+
147+
if dt_sym == None:
148+
# print("error found no symbol matching %s" % compat)
149+
return None
150+
151+
dt_has_sym = None
152+
for r in dt_sym.referenced:
153+
if isinstance(r, Symbol):
154+
if "DT_HAS_" in r.name:
155+
dt_has_sym = r
156+
157+
if dt_has_sym == None:
158+
print("error found no symbol matching %s" % compat)
159+
160+
device_sym = None
161+
for sym in kconf.syms.values():
162+
if sym == dt_sym:
163+
continue
164+
for r in sym.referenced:
165+
if isinstance(r, Symbol) and r == dt_has_sym:
166+
if device_sym:
167+
print("ERROR - only expect one device symbol to match")
168+
device_sym = sym
169+
170+
return device_sym
171+
115172

116173
def check_no_promptless_assign(kconf):
117174
# Checks that no promptless symbols are assigned

0 commit comments

Comments
 (0)