xref: /openbmc/u-boot/scripts/check-config.sh (revision 1f54a47c)
1371244cbSSimon Glass#!/bin/sh
2371244cbSSimon Glass# Copyright (c) 2016 Google, Inc
3371244cbSSimon Glass# Written by Simon Glass <sjg@chromium.org>
4371244cbSSimon Glass#
5371244cbSSimon Glass# Check that the u-boot.cfg file provided does not introduce any new
6371244cbSSimon Glass# ad-hoc CONFIG options
7371244cbSSimon Glass#
87b76daabSMasahiro Yamada# Use scripts/build-whitelist.sh to generate the list of current ad-hoc
97b76daabSMasahiro Yamada# CONFIG options (those which are not in Kconfig).
10371244cbSSimon Glass
11371244cbSSimon Glass# Usage
12371244cbSSimon Glass#    check-config.sh <path to u-boot.cfg> <path to whitelist file> <source dir>
13371244cbSSimon Glass#
14371244cbSSimon Glass# For example:
15371244cbSSimon Glass#   scripts/check-config.sh b/chromebook_link/u-boot.cfg kconfig_whitelist.txt .
16371244cbSSimon Glass
17371244cbSSimon Glasspath="$1"
18371244cbSSimon Glasswhitelist="$2"
19371244cbSSimon Glasssrctree="$3"
20371244cbSSimon Glass
21371244cbSSimon Glass# Temporary files
22371244cbSSimon Glassconfigs="${path}.configs"
23371244cbSSimon Glasssuspects="${path}.suspects"
24371244cbSSimon Glassok="${path}.ok"
25371244cbSSimon Glassnew_adhoc="${path}.adhoc"
26371244cbSSimon Glass
27371244cbSSimon Glassexport LC_ALL=C
28371244cbSSimon Glassexport LC_COLLATE=C
29371244cbSSimon Glass
30371244cbSSimon Glasscat ${path} |sed -n 's/^#define \(CONFIG_[A-Za-z0-9_]*\).*/\1/p' |sort |uniq \
31371244cbSSimon Glass	>${configs}
32371244cbSSimon Glass
33371244cbSSimon Glasscomm -23 ${configs} ${whitelist} > ${suspects}
34371244cbSSimon Glass
35371244cbSSimon Glasscat `find ${srctree} -name "Kconfig*"` |sed -n \
36*1f54a47cSBin Meng	-e 's/^\s*config *\([A-Za-z0-9_]*\).*$/CONFIG_\1/p' \
37*1f54a47cSBin Meng	-e 's/^\s*menuconfig \([A-Za-z0-9_]*\).*$/CONFIG_\1/p' \
38*1f54a47cSBin Meng	|sort |uniq > ${ok}
39371244cbSSimon Glasscomm -23 ${suspects} ${ok} >${new_adhoc}
40371244cbSSimon Glassif [ -s ${new_adhoc} ]; then
411bdd942bSMasahiro Yamada	echo >&2 "Error: You must add new CONFIG options using Kconfig"
421bdd942bSMasahiro Yamada	echo >&2 "The following new ad-hoc CONFIG options were detected:"
431bdd942bSMasahiro Yamada	cat >&2 ${new_adhoc}
441bdd942bSMasahiro Yamada	echo >&2
451bdd942bSMasahiro Yamada	echo >&2 "Please add these via Kconfig instead. Find a suitable Kconfig"
461bdd942bSMasahiro Yamada	echo >&2 "file and add a 'config' or 'menuconfig' option."
47371244cbSSimon Glass	# Don't delete the temporary files in case they are useful
48371244cbSSimon Glass	exit 1
49371244cbSSimon Glasselse
50371244cbSSimon Glass	rm ${suspects} ${ok} ${new_adhoc}
51371244cbSSimon Glassfi
52