Simon Glass | 49e3aec | 2016-09-13 21:44:07 -0600 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Copyright (c) 2016 Google, Inc |
| 3 | # Written by Simon Glass <sjg@chromium.org> |
| 4 | # |
| 5 | # Check that the u-boot.cfg file provided does not introduce any new |
| 6 | # ad-hoc CONFIG options |
| 7 | # |
Masahiro Yamada | 54c4495 | 2016-09-26 13:04:58 +0900 | [diff] [blame] | 8 | # Use scripts/build-whitelist.sh to generate the list of current ad-hoc |
| 9 | # CONFIG options (those which are not in Kconfig). |
Simon Glass | 49e3aec | 2016-09-13 21:44:07 -0600 | [diff] [blame] | 10 | |
| 11 | # Usage |
| 12 | # check-config.sh <path to u-boot.cfg> <path to whitelist file> <source dir> |
| 13 | # |
| 14 | # For example: |
| 15 | # scripts/check-config.sh b/chromebook_link/u-boot.cfg kconfig_whitelist.txt . |
| 16 | |
Luca Ceresoli | 42b66b3 | 2018-03-15 11:08:56 +0100 | [diff] [blame] | 17 | set -e |
| 18 | set -u |
| 19 | |
Andy Shevchenko | 0393c2e | 2018-12-11 18:22:28 +0200 | [diff] [blame] | 20 | PROG_NAME="${0##*/}" |
| 21 | |
| 22 | usage() { |
| 23 | echo "$PROG_NAME <path to u-boot.cfg> <path to whitelist file> <source dir>" |
| 24 | exit 1 |
| 25 | } |
| 26 | |
| 27 | [ $# -ge 3 ] || usage |
| 28 | |
Simon Glass | 49e3aec | 2016-09-13 21:44:07 -0600 | [diff] [blame] | 29 | path="$1" |
| 30 | whitelist="$2" |
| 31 | srctree="$3" |
| 32 | |
| 33 | # Temporary files |
| 34 | configs="${path}.configs" |
| 35 | suspects="${path}.suspects" |
| 36 | ok="${path}.ok" |
| 37 | new_adhoc="${path}.adhoc" |
| 38 | |
| 39 | export LC_ALL=C |
| 40 | export LC_COLLATE=C |
| 41 | |
Roger Pau Monne | ccf1c7b | 2021-02-13 11:06:31 +0100 | [diff] [blame] | 42 | cat ${path} |sed -nr 's/^#define (CONFIG_[A-Za-z0-9_]*).*/\1/p' |sort |uniq \ |
Simon Glass | 49e3aec | 2016-09-13 21:44:07 -0600 | [diff] [blame] | 43 | >${configs} |
| 44 | |
| 45 | comm -23 ${configs} ${whitelist} > ${suspects} |
| 46 | |
Roger Pau Monne | ccf1c7b | 2021-02-13 11:06:31 +0100 | [diff] [blame] | 47 | cat `find ${srctree} -name "Kconfig*"` |sed -nr \ |
| 48 | -e 's/^[[:blank:]]*config *([A-Za-z0-9_]*).*$/CONFIG_\1/p' \ |
| 49 | -e 's/^[[:blank:]]*menuconfig ([A-Za-z0-9_]*).*$/CONFIG_\1/p' \ |
Bin Meng | 6a75b58 | 2017-06-29 11:36:25 +0800 | [diff] [blame] | 50 | |sort |uniq > ${ok} |
Simon Glass | 49e3aec | 2016-09-13 21:44:07 -0600 | [diff] [blame] | 51 | comm -23 ${suspects} ${ok} >${new_adhoc} |
| 52 | if [ -s ${new_adhoc} ]; then |
Masahiro Yamada | cf698a8 | 2017-01-31 20:11:33 +0900 | [diff] [blame] | 53 | echo >&2 "Error: You must add new CONFIG options using Kconfig" |
| 54 | echo >&2 "The following new ad-hoc CONFIG options were detected:" |
| 55 | cat >&2 ${new_adhoc} |
| 56 | echo >&2 |
| 57 | echo >&2 "Please add these via Kconfig instead. Find a suitable Kconfig" |
| 58 | echo >&2 "file and add a 'config' or 'menuconfig' option." |
Simon Glass | 49e3aec | 2016-09-13 21:44:07 -0600 | [diff] [blame] | 59 | # Don't delete the temporary files in case they are useful |
| 60 | exit 1 |
| 61 | else |
| 62 | rm ${suspects} ${ok} ${new_adhoc} |
| 63 | fi |