xref: /openbmc/u-boot/scripts/build-whitelist.sh (revision a0e80c97)
1eed921d9SSimon Glass#!/bin/sh
2eed921d9SSimon Glass# Copyright (c) 2016 Google, Inc
3eed921d9SSimon Glass# Written by Simon Glass <sjg@chromium.org>
4eed921d9SSimon Glass#
5eed921d9SSimon Glass
6eed921d9SSimon Glass# This script creates the configuration whitelist file. This file contains
7eed921d9SSimon Glass# all the config options which are allowed to be used outside Kconfig.
8eed921d9SSimon Glass# Please do not add things to the whitelist. Instead, add your new option
9eed921d9SSimon Glass# to Kconfig.
10eed921d9SSimon Glass#
11eed921d9SSimon Glassexport LC_ALL=C LC_COLLATE=C
12eed921d9SSimon Glass
13eed921d9SSimon Glass# There are two independent greps. The first pulls out the component parts
14eed921d9SSimon Glass# of CONFIG_SYS_EXTRA_OPTIONS. An example is:
15eed921d9SSimon Glass#
16*6ff005cfSDave Prue#	SUN7I_GMAC,AHCI,SATAPWR=SUNXI_GPB(8)
17eed921d9SSimon Glass#
18eed921d9SSimon Glass# We want this to produce:
19*6ff005cfSDave Prue#	CONFIG_SUN7I_GMAC
20eed921d9SSimon Glass#	CONFIG_AHCI
21eed921d9SSimon Glass#	CONFIG_SATAPWR
22eed921d9SSimon Glass#
23eed921d9SSimon Glass# The second looks for the rest of the CONFIG options, but excludes those in
24eed921d9SSimon Glass# Kconfig and defconfig files.
25eed921d9SSimon Glass#
26eed921d9SSimon Glass(
27eed921d9SSimon Glassgit grep CONFIG_SYS_EXTRA_OPTIONS |sed -n \
28eed921d9SSimon Glass	's/.*CONFIG_SYS_EXTRA_OPTIONS="\(.*\)"/\1/ p' \
29eed921d9SSimon Glass	| tr , '\n' \
30eed921d9SSimon Glass	| sed 's/ *\([A-Za-z0-9_]*\).*/CONFIG_\1/'
31eed921d9SSimon Glass
32eed921d9SSimon Glassgit grep CONFIG_ | \
33eed921d9SSimon Glass	egrep -vi "(Kconfig:|defconfig:|README|\.py|\.pl:)" \
34eed921d9SSimon Glass	| tr ' \t' '\n\n' \
35eed921d9SSimon Glass	| sed -n 's/^\(CONFIG_[A-Za-z0-9_]*\).*/\1/p'
36eed921d9SSimon Glass) \
37eed921d9SSimon Glass	|sort |uniq >scripts/config_whitelist.txt.tmp1;
38eed921d9SSimon Glass
39eed921d9SSimon Glass# Finally, we need a list of the valid Kconfig options to exclude these from
40eed921d9SSimon Glass# the whitelist.
41eed921d9SSimon Glasscat `find . -name "Kconfig*"` |sed -n \
421f54a47cSBin Meng	-e 's/^\s*config *\([A-Za-z0-9_]*\).*$/CONFIG_\1/p' \
431f54a47cSBin Meng	-e 's/^\s*menuconfig *\([A-Za-z0-9_]*\).*$/CONFIG_\1/p' \
44eed921d9SSimon Glass	|sort |uniq >scripts/config_whitelist.txt.tmp2
45eed921d9SSimon Glass
46eed921d9SSimon Glass# Use only the options that are present in the first file but not the second.
47eed921d9SSimon Glasscomm -23 scripts/config_whitelist.txt.tmp1 scripts/config_whitelist.txt.tmp2 \
489608f43cSMasahiro Yamada	|sort |uniq >scripts/config_whitelist.txt.tmp3
499608f43cSMasahiro Yamada
509608f43cSMasahiro Yamada# If scripts/config_whitelist.txt already exists, take the intersection of the
519608f43cSMasahiro Yamada# current list and the new one.  We do not want to increase whitelist options.
529608f43cSMasahiro Yamadaif [ -r scripts/config_whitelist.txt ]; then
539608f43cSMasahiro Yamada	comm -12 scripts/config_whitelist.txt.tmp3 scripts/config_whitelist.txt \
549608f43cSMasahiro Yamada		> scripts/config_whitelist.txt.tmp4
559608f43cSMasahiro Yamada	mv scripts/config_whitelist.txt.tmp4 scripts/config_whitelist.txt
569608f43cSMasahiro Yamadaelse
579608f43cSMasahiro Yamada	mv scripts/config_whitelist.txt.tmp3 scripts/config_whitelist.txt
589608f43cSMasahiro Yamadafi
599608f43cSMasahiro Yamada
609608f43cSMasahiro Yamadarm scripts/config_whitelist.txt.tmp*
61eed921d9SSimon Glass
62eed921d9SSimon Glassunset LC_ALL LC_COLLATE
63