xref: /openbmc/linux/Documentation/features/scripts/features-refresh.sh (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1be99f610SAndrea Parri#
2be99f610SAndrea Parri# Small script that refreshes the kernel feature support status in place.
3be99f610SAndrea Parri#
4be99f610SAndrea Parri
5be99f610SAndrea Parrifor F_FILE in Documentation/features/*/*/arch-support.txt; do
6be99f610SAndrea Parri	F=$(grep "^#         Kconfig:" "$F_FILE" | cut -c26-)
7be99f610SAndrea Parri
8be99f610SAndrea Parri	#
9be99f610SAndrea Parri	# Each feature F is identified by a pair (O, K), where 'O' can
10be99f610SAndrea Parri	# be either the empty string (for 'nop') or "not" (the logical
11be99f610SAndrea Parri	# negation operator '!'); other operators are not supported.
12be99f610SAndrea Parri	#
13be99f610SAndrea Parri	O=""
14be99f610SAndrea Parri	K=$F
15be99f610SAndrea Parri	if [[ "$F" == !* ]]; then
16be99f610SAndrea Parri		O="not"
17be99f610SAndrea Parri		K=$(echo $F | sed -e 's/^!//g')
18be99f610SAndrea Parri	fi
19be99f610SAndrea Parri
20be99f610SAndrea Parri	#
21be99f610SAndrea Parri	# F := (O, K) is 'valid' iff there is a Kconfig file (for some
22be99f610SAndrea Parri	# arch) which contains K.
23be99f610SAndrea Parri	#
24be99f610SAndrea Parri	# Notice that this definition entails an 'asymmetry' between
25be99f610SAndrea Parri	# the case 'O = ""' and the case 'O = "not"'. E.g., F may be
26be99f610SAndrea Parri	# _invalid_ if:
27be99f610SAndrea Parri	#
28be99f610SAndrea Parri	# [case 'O = ""']
29be99f610SAndrea Parri	#   1) no arch provides support for F,
30be99f610SAndrea Parri	#   2) K does not exist (e.g., it was renamed/mis-typed);
31be99f610SAndrea Parri	#
32be99f610SAndrea Parri	# [case 'O = "not"']
33be99f610SAndrea Parri	#   3) all archs provide support for F,
34be99f610SAndrea Parri	#   4) as in (2).
35be99f610SAndrea Parri	#
36be99f610SAndrea Parri	# The rationale for adopting this definition (and, thus, for
37be99f610SAndrea Parri	# keeping the asymmetry) is:
38be99f610SAndrea Parri	#
39be99f610SAndrea Parri	#       We want to be able to 'detect' (2) (or (4)).
40be99f610SAndrea Parri	#
41be99f610SAndrea Parri	# (1) and (3) may further warn the developers about the fact
42be99f610SAndrea Parri	# that K can be removed.
43be99f610SAndrea Parri	#
44be99f610SAndrea Parri	F_VALID="false"
45be99f610SAndrea Parri	for ARCH_DIR in arch/*/; do
46be99f610SAndrea Parri		K_FILES=$(find $ARCH_DIR -name "Kconfig*")
47be99f610SAndrea Parri		K_GREP=$(grep "$K" $K_FILES)
48be99f610SAndrea Parri		if [ ! -z "$K_GREP" ]; then
49be99f610SAndrea Parri			F_VALID="true"
50be99f610SAndrea Parri			break
51be99f610SAndrea Parri		fi
52be99f610SAndrea Parri	done
53be99f610SAndrea Parri	if [ "$F_VALID" = "false" ]; then
54be99f610SAndrea Parri		printf "WARNING: '%s' is not a valid Kconfig\n" "$F"
55be99f610SAndrea Parri	fi
56be99f610SAndrea Parri
57be99f610SAndrea Parri	T_FILE="$F_FILE.tmp"
58be99f610SAndrea Parri	grep "^#" $F_FILE > $T_FILE
59be99f610SAndrea Parri	echo "    -----------------------" >> $T_FILE
60be99f610SAndrea Parri	echo "    |         arch |status|" >> $T_FILE
61be99f610SAndrea Parri	echo "    -----------------------" >> $T_FILE
62be99f610SAndrea Parri	for ARCH_DIR in arch/*/; do
63*7b5a5242STiezhu Yang		ARCH=$(echo $ARCH_DIR | sed -e 's/^arch//g' | sed -e 's/\///g')
64be99f610SAndrea Parri		K_FILES=$(find $ARCH_DIR -name "Kconfig*")
65be99f610SAndrea Parri		K_GREP=$(grep "$K" $K_FILES)
66be99f610SAndrea Parri		#
67be99f610SAndrea Parri		# Arch support status values for (O, K) are updated according
68be99f610SAndrea Parri		# to the following rules.
69be99f610SAndrea Parri		#
70be99f610SAndrea Parri		#   - ("", K) is 'supported by a given arch', if there is a
71be99f610SAndrea Parri		#     Kconfig file for that arch which contains K;
72be99f610SAndrea Parri		#
73be99f610SAndrea Parri		#   - ("not", K) is 'supported by a given arch', if there is
74be99f610SAndrea Parri		#     no Kconfig file for that arch which contains K;
75be99f610SAndrea Parri		#
76be99f610SAndrea Parri		#   - otherwise: preserve the previous status value (if any),
77be99f610SAndrea Parri		#                default to 'not yet supported'.
78be99f610SAndrea Parri		#
79be99f610SAndrea Parri		# Notice that, according these rules, invalid features may be
80be99f610SAndrea Parri		# updated/modified.
81be99f610SAndrea Parri		#
82be99f610SAndrea Parri		if [ "$O" = "" ] && [ ! -z "$K_GREP" ]; then
83be99f610SAndrea Parri			printf "    |%12s: |  ok  |\n" "$ARCH" >> $T_FILE
84be99f610SAndrea Parri		elif [ "$O" = "not" ] && [ -z "$K_GREP" ]; then
85be99f610SAndrea Parri			printf "    |%12s: |  ok  |\n" "$ARCH" >> $T_FILE
86be99f610SAndrea Parri		else
87be99f610SAndrea Parri			S=$(grep -v "^#" "$F_FILE" | grep " $ARCH:")
88be99f610SAndrea Parri			if [ ! -z "$S" ]; then
89be99f610SAndrea Parri				echo "$S" >> $T_FILE
90be99f610SAndrea Parri			else
91be99f610SAndrea Parri				printf "    |%12s: | TODO |\n" "$ARCH" \
92be99f610SAndrea Parri					>> $T_FILE
93be99f610SAndrea Parri			fi
94be99f610SAndrea Parri		fi
95be99f610SAndrea Parri	done
96be99f610SAndrea Parri	echo "    -----------------------" >> $T_FILE
97be99f610SAndrea Parri	mv $T_FILE $F_FILE
98be99f610SAndrea Parridone
99