|
|
6bca4c |
#!/bin/bash
|
|
|
6bca4c |
#
|
|
|
6bca4c |
# This script takes the merged config files and processes them through oldconfig
|
|
|
6bca4c |
# and listnewconfig
|
|
|
6bca4c |
#
|
|
|
6bca4c |
# Globally disable suggestion of appending '|| exit' or '|| return' to cd/pushd/popd commands
|
|
|
6bca4c |
# shellcheck disable=SC2164
|
|
|
6bca4c |
|
|
|
6bca4c |
usage()
|
|
|
6bca4c |
{
|
|
|
6bca4c |
# alphabetical order please
|
|
|
6bca4c |
echo "process_configs.sh [ options ] package_name kernel_version"
|
|
|
6bca4c |
echo " -a: report all errors, equivalent to [-c -n -w -i]"
|
|
|
6bca4c |
echo " -c: error on mismatched config options"
|
|
|
6bca4c |
echo " -i: continue on error"
|
|
|
6bca4c |
echo " -n: error on unset config options"
|
|
|
6bca4c |
echo " -t: test run, do not overwrite original config"
|
|
|
6bca4c |
echo " -w: error on misconfigured config options"
|
|
|
6bca4c |
echo " -z: commit new configs to pending directory"
|
|
|
6bca4c |
echo ""
|
|
|
6bca4c |
echo " A special CONFIG file tag, process_configs_known_broken can be added as a"
|
|
|
6bca4c |
echo " comment to any CONFIG file. This tag indicates that there is no way to "
|
|
|
6bca4c |
echo " fix a CONFIG's entry. This tag should only be used in extreme cases"
|
|
|
6bca4c |
echo " and is not to be used as a workaround to solve CONFIG problems."
|
|
|
6bca4c |
exit 1
|
|
|
6bca4c |
}
|
|
|
6bca4c |
|
|
|
6bca4c |
die()
|
|
|
6bca4c |
{
|
|
|
6bca4c |
echo "$1"
|
|
|
6bca4c |
exit 1
|
|
|
6bca4c |
}
|
|
|
6bca4c |
|
|
|
6bca4c |
get_cross_compile()
|
|
|
6bca4c |
{
|
|
|
6bca4c |
arch=$1
|
|
|
6bca4c |
if [[ "$CC_IS_CLANG" -eq 1 ]]; then
|
|
|
6bca4c |
echo "$arch"
|
|
|
6bca4c |
else
|
|
|
6bca4c |
echo "scripts/dummy-tools/"
|
|
|
6bca4c |
fi
|
|
|
6bca4c |
}
|
|
|
6bca4c |
|
|
|
6bca4c |
# stupid function to find top of tree to do kernel make configs
|
|
|
6bca4c |
switch_to_toplevel()
|
|
|
6bca4c |
{
|
|
|
6bca4c |
path="$(pwd)"
|
|
|
6bca4c |
while test -n "$path"
|
|
|
6bca4c |
do
|
|
|
6bca4c |
test -e "$path"/MAINTAINERS && \
|
|
|
6bca4c |
test -d "$path"/drivers && \
|
|
|
6bca4c |
break
|
|
|
6bca4c |
|
|
|
6bca4c |
path=$(dirname "$path")
|
|
|
6bca4c |
done
|
|
|
6bca4c |
|
|
|
6bca4c |
test -n "$path" || die "Can't find toplevel"
|
|
|
6bca4c |
echo "$path"
|
|
|
6bca4c |
}
|
|
|
6bca4c |
|
|
|
6bca4c |
checkoptions()
|
|
|
6bca4c |
{
|
|
|
6bca4c |
/usr/bin/awk '
|
|
|
6bca4c |
|
|
|
6bca4c |
/is not set/ {
|
|
|
6bca4c |
split ($0, a, "#");
|
|
|
6bca4c |
split(a[2], b);
|
|
|
6bca4c |
if (NR==FNR) {
|
|
|
6bca4c |
configs[b[1]]="is not set";
|
|
|
6bca4c |
} else {
|
|
|
6bca4c |
if (configs[b[1]] != "" && configs[b[1]] != "is not set")
|
|
|
6bca4c |
print "Found # "b[1] " is not set, after generation, had " b[1] " " configs[b[1]] " in Source tree";
|
|
|
6bca4c |
}
|
|
|
6bca4c |
}
|
|
|
6bca4c |
|
|
|
6bca4c |
/=/ {
|
|
|
6bca4c |
split ($0, a, "=");
|
|
|
6bca4c |
if (NR==FNR) {
|
|
|
6bca4c |
configs[a[1]]=a[2];
|
|
|
6bca4c |
} else {
|
|
|
6bca4c |
if (configs[a[1]] != "" && configs[a[1]] != a[2])
|
|
|
6bca4c |
print "Found "a[1]"="a[2]" after generation, had " a[1]"="configs[a[1]]" in Source tree";
|
|
|
6bca4c |
}
|
|
|
6bca4c |
}
|
|
|
6bca4c |
' "$1" "$2" > .mismatches
|
|
|
6bca4c |
|
|
|
6bca4c |
checkoptions_error=false
|
|
|
6bca4c |
if test -s .mismatches
|
|
|
6bca4c |
then
|
|
|
6bca4c |
while read -r LINE
|
|
|
6bca4c |
do
|
|
|
6bca4c |
if find ./ -name "$(echo "$LINE" | awk -F "=" ' { print $1 } ' | awk ' { print $2 }')" -print0 | xargs -0 grep ^ | grep -q "process_configs_known_broken"; then
|
|
|
6bca4c |
# This is a known broken config.
|
|
|
6bca4c |
# See script help warning.
|
|
|
6bca4c |
checkoptions_error=false
|
|
|
6bca4c |
else
|
|
|
6bca4c |
checkoptions_error=true
|
|
|
6bca4c |
break
|
|
|
6bca4c |
fi
|
|
|
6bca4c |
done < .mismatches
|
|
|
6bca4c |
|
|
|
6bca4c |
! $checkoptions_error && return
|
|
|
6bca4c |
|
|
|
6bca4c |
echo "Error: Mismatches found in configuration files"
|
|
|
6bca4c |
cat .mismatches
|
|
|
6bca4c |
RETURNCODE=1
|
|
|
6bca4c |
[ "$CONTINUEONERROR" ] || exit 1
|
|
|
6bca4c |
fi
|
|
|
6bca4c |
}
|
|
|
6bca4c |
|
|
|
6bca4c |
parsenewconfigs()
|
|
|
6bca4c |
{
|
|
|
6bca4c |
tmpdir=$(mktemp -d)
|
|
|
6bca4c |
|
|
|
6bca4c |
# This awk script reads the output of make listnewconfig
|
|
|
6bca4c |
# and puts it into CONFIG_FOO files. Using the output of
|
|
|
6bca4c |
# listnewconfig is much easier to ensure we get the default
|
|
|
6bca4c |
# output.
|
|
|
6bca4c |
/usr/bin/awk -v BASE="$tmpdir" '
|
|
|
6bca4c |
/is not set/ {
|
|
|
6bca4c |
split ($0, a, "#");
|
|
|
6bca4c |
split(a[2], b);
|
|
|
6bca4c |
OUT_FILE=BASE"/"b[1];
|
|
|
6bca4c |
print $0 >> OUT_FILE;
|
|
|
6bca4c |
}
|
|
|
6bca4c |
|
|
|
6bca4c |
/=/ {
|
|
|
6bca4c |
split ($0, a, "=");
|
|
|
6bca4c |
OUT_FILE=BASE"/"a[1];
|
|
|
6bca4c |
if (a[2] == "n")
|
|
|
6bca4c |
print "# " a[1] " is not set" >> OUT_FILE;
|
|
|
6bca4c |
else
|
|
|
6bca4c |
print $0 >> OUT_FILE;
|
|
|
6bca4c |
}
|
|
|
6bca4c |
|
|
|
6bca4c |
' .newoptions
|
|
|
6bca4c |
|
|
|
6bca4c |
# This awk script parses the output of helpnewconfig.
|
|
|
6bca4c |
# Each option is separated between ----- markers
|
|
|
6bca4c |
# The goal is to put all the help text as a comment in
|
|
|
6bca4c |
# each CONFIG_FOO file. Because of how awk works
|
|
|
6bca4c |
# there's a lot of moving files around and catting to
|
|
|
6bca4c |
# get what we need.
|
|
|
6bca4c |
/usr/bin/awk -v BASE="$tmpdir" '
|
|
|
6bca4c |
BEGIN { inpatch=0;
|
|
|
6bca4c |
outfile="none";
|
|
|
6bca4c |
symbol="none"; }
|
|
|
6bca4c |
/^Symbol: .*$/ {
|
|
|
6bca4c |
split($0, a, " ");
|
|
|
6bca4c |
symbol="CONFIG_"a[2];
|
|
|
6bca4c |
outfile=BASE "/fake_"symbol
|
|
|
6bca4c |
}
|
|
|
6bca4c |
/-----/ {
|
|
|
6bca4c |
if (inpatch == 0) {
|
|
|
6bca4c |
inpatch = 1;
|
|
|
6bca4c |
}
|
|
|
6bca4c |
else {
|
|
|
6bca4c |
if (symbol != "none") {
|
|
|
6bca4c |
system("cat " outfile " " BASE "/" symbol " > " BASE "/tmpf");
|
|
|
6bca4c |
system("mv " BASE "/tmpf " BASE "/" symbol);
|
|
|
6bca4c |
symbol="none"
|
|
|
6bca4c |
}
|
|
|
6bca4c |
outfile="none"
|
|
|
6bca4c |
inpatch = 0;
|
|
|
6bca4c |
}
|
|
|
6bca4c |
}
|
|
|
6bca4c |
!/-----/ {
|
|
|
6bca4c |
if (inpatch == 1 && outfile != "none") {
|
|
|
6bca4c |
print "# "$0 >> outfile;
|
|
|
6bca4c |
}
|
|
|
6bca4c |
}
|
|
|
6bca4c |
|
|
|
6bca4c |
|
|
|
6bca4c |
' .helpnewconfig
|
|
|
6bca4c |
|
|
|
6bca4c |
pushd "$tmpdir" &> /dev/null
|
|
|
6bca4c |
rm fake_*
|
|
|
6bca4c |
popd &> /dev/null
|
|
|
6bca4c |
for f in "$tmpdir"/*; do
|
|
|
6bca4c |
[[ -e "$f" ]] || break
|
|
|
6bca4c |
cp "$f" "$SCRIPT_DIR/pending$FLAVOR/generic/"
|
|
|
6bca4c |
done
|
|
|
6bca4c |
|
|
|
6bca4c |
rm -rf "$tmpdir"
|
|
|
6bca4c |
}
|
|
|
6bca4c |
|
|
|
6bca4c |
function commit_new_configs()
|
|
|
6bca4c |
{
|
|
|
6bca4c |
# assume we are in $source_tree/configs, need to get to top level
|
|
|
6bca4c |
pushd "$(switch_to_toplevel)" &>/dev/null
|
|
|
6bca4c |
|
|
|
6bca4c |
for cfg in "$SCRIPT_DIR/${PACKAGE_NAME}${KVERREL}${SUBARCH}"*.config
|
|
|
6bca4c |
do
|
|
|
6bca4c |
arch=$(head -1 "$cfg" | cut -b 3-)
|
|
|
6bca4c |
cfgtmp="${cfg}.tmp"
|
|
|
6bca4c |
cfgorig="${cfg}.orig"
|
|
|
6bca4c |
cat "$cfg" > "$cfgorig"
|
|
|
6bca4c |
|
|
|
6bca4c |
if [ "$arch" = "EMPTY" ]
|
|
|
6bca4c |
then
|
|
|
6bca4c |
# This arch is intentionally left blank
|
|
|
6bca4c |
continue
|
|
|
6bca4c |
fi
|
|
|
6bca4c |
echo -n "Checking for new configs in $cfg ... "
|
|
|
6bca4c |
|
|
|
6bca4c |
make ${MAKEOPTS} ARCH="$arch" CROSS_COMPILE=$(get_cross_compile $arch) KCONFIG_CONFIG="$cfgorig" listnewconfig >& .listnewconfig
|
|
|
6bca4c |
grep -E 'CONFIG_' .listnewconfig > .newoptions
|
|
|
6bca4c |
if test -s .newoptions
|
|
|
6bca4c |
then
|
|
|
6bca4c |
make ${MAKEOPTS} ARCH="$arch" CROSS_COMPILE=$(get_cross_compile $arch) KCONFIG_CONFIG="$cfgorig" helpnewconfig >& .helpnewconfig
|
|
|
6bca4c |
parsenewconfigs
|
|
|
6bca4c |
fi
|
|
|
6bca4c |
rm .newoptions
|
|
|
6bca4c |
echo "done"
|
|
|
6bca4c |
done
|
|
|
6bca4c |
|
|
|
6bca4c |
git add "$SCRIPT_DIR/pending$FLAVOR"
|
|
|
6bca4c |
git commit -m "[redhat] AUTOMATIC: New configs"
|
|
|
6bca4c |
}
|
|
|
6bca4c |
|
|
|
6bca4c |
function process_configs()
|
|
|
6bca4c |
{
|
|
|
6bca4c |
# assume we are in $source_tree/configs, need to get to top level
|
|
|
6bca4c |
pushd "$(switch_to_toplevel)" &>/dev/null
|
|
|
6bca4c |
|
|
|
6bca4c |
for cfg in "$SCRIPT_DIR/${PACKAGE_NAME}${KVERREL}${SUBARCH}"*.config
|
|
|
6bca4c |
do
|
|
|
6bca4c |
arch=$(head -1 "$cfg" | cut -b 3-)
|
|
|
6bca4c |
cfgtmp="${cfg}.tmp"
|
|
|
6bca4c |
cfgorig="${cfg}.orig"
|
|
|
6bca4c |
cat "$cfg" > "$cfgorig"
|
|
|
6bca4c |
|
|
|
6bca4c |
if [ "$arch" = "EMPTY" ]
|
|
|
6bca4c |
then
|
|
|
6bca4c |
# This arch is intentionally left blank
|
|
|
6bca4c |
continue
|
|
|
6bca4c |
fi
|
|
|
6bca4c |
echo -n "Processing $cfg ... "
|
|
|
6bca4c |
|
|
|
6bca4c |
make ${MAKEOPTS} ARCH="$arch" CROSS_COMPILE=$(get_cross_compile $arch) KCONFIG_CONFIG="$cfgorig" listnewconfig >& .listnewconfig
|
|
|
6bca4c |
grep -E 'CONFIG_' .listnewconfig > .newoptions
|
|
|
6bca4c |
if test -n "$NEWOPTIONS" && test -s .newoptions
|
|
|
6bca4c |
then
|
|
|
6bca4c |
echo "Found unset config items, please set them to an appropriate value"
|
|
|
6bca4c |
cat .newoptions
|
|
|
6bca4c |
rm .newoptions
|
|
|
6bca4c |
RETURNCODE=1
|
|
|
6bca4c |
[ "$CONTINUEONERROR" ] || exit 1
|
|
|
6bca4c |
fi
|
|
|
6bca4c |
rm .newoptions
|
|
|
6bca4c |
|
|
|
6bca4c |
grep -E 'config.*warning' .listnewconfig > .warnings
|
|
|
6bca4c |
if test -n "$CHECKWARNINGS" && test -s .warnings
|
|
|
6bca4c |
then
|
|
|
6bca4c |
echo "Found misconfigured config items, please set them to an appropriate value"
|
|
|
6bca4c |
cat .warnings
|
|
|
6bca4c |
rm .warnings
|
|
|
6bca4c |
RETURNCODE=1
|
|
|
6bca4c |
[ "$CONTINUEONERROR" ] || exit 1
|
|
|
6bca4c |
fi
|
|
|
6bca4c |
rm .warnings
|
|
|
6bca4c |
|
|
|
6bca4c |
rm .listnewconfig
|
|
|
6bca4c |
|
|
|
6bca4c |
make ${MAKEOPTS} ARCH="$arch" CROSS_COMPILE=$(get_cross_compile $arch) KCONFIG_CONFIG="$cfgorig" olddefconfig > /dev/null || exit 1
|
|
|
6bca4c |
echo "# $arch" > "$cfgtmp"
|
|
|
6bca4c |
cat "$cfgorig" >> "$cfgtmp"
|
|
|
6bca4c |
if test -n "$CHECKOPTIONS"
|
|
|
6bca4c |
then
|
|
|
6bca4c |
checkoptions "$cfg" "$cfgtmp"
|
|
|
6bca4c |
fi
|
|
|
6bca4c |
# if test run, don't overwrite original
|
|
|
6bca4c |
if test -n "$TESTRUN"
|
|
|
6bca4c |
then
|
|
|
6bca4c |
rm -f "$cfgtmp"
|
|
|
6bca4c |
else
|
|
|
6bca4c |
mv "$cfgtmp" "$cfg"
|
|
|
6bca4c |
fi
|
|
|
6bca4c |
rm -f "$cfgorig"
|
|
|
6bca4c |
echo "done"
|
|
|
6bca4c |
done
|
|
|
6bca4c |
rm "$SCRIPT_DIR"/*.config*.old
|
|
|
6bca4c |
popd > /dev/null
|
|
|
6bca4c |
|
|
|
6bca4c |
echo "Processed config files are in $SCRIPT_DIR"
|
|
|
6bca4c |
}
|
|
|
6bca4c |
|
|
|
6bca4c |
CHECKOPTIONS=""
|
|
|
6bca4c |
CONTINUEONERROR=""
|
|
|
6bca4c |
NEWOPTIONS=""
|
|
|
6bca4c |
TESTRUN=""
|
|
|
6bca4c |
CHECKWARNINGS=""
|
|
|
6bca4c |
MAKEOPTS=""
|
|
|
6bca4c |
CC_IS_CLANG=0
|
|
|
6bca4c |
|
|
|
6bca4c |
RETURNCODE=0
|
|
|
6bca4c |
|
|
|
6bca4c |
while [[ $# -gt 0 ]]
|
|
|
6bca4c |
do
|
|
|
6bca4c |
key="$1"
|
|
|
6bca4c |
case $key in
|
|
|
6bca4c |
-a)
|
|
|
6bca4c |
CHECKOPTIONS="x"
|
|
|
6bca4c |
CONTINUEONERROR="x"
|
|
|
6bca4c |
NEWOPTIONS="x"
|
|
|
6bca4c |
CHECKWARNINGS="x"
|
|
|
6bca4c |
;;
|
|
|
6bca4c |
-c)
|
|
|
6bca4c |
CHECKOPTIONS="x"
|
|
|
6bca4c |
;;
|
|
|
6bca4c |
-h)
|
|
|
6bca4c |
usage
|
|
|
6bca4c |
;;
|
|
|
6bca4c |
-i)
|
|
|
6bca4c |
CONTINUEONERROR="x"
|
|
|
6bca4c |
;;
|
|
|
6bca4c |
-n)
|
|
|
6bca4c |
NEWOPTIONS="x"
|
|
|
6bca4c |
;;
|
|
|
6bca4c |
-t)
|
|
|
6bca4c |
TESTRUN="x"
|
|
|
6bca4c |
;;
|
|
|
6bca4c |
-w)
|
|
|
6bca4c |
CHECKWARNINGS="x"
|
|
|
6bca4c |
;;
|
|
|
6bca4c |
-z)
|
|
|
6bca4c |
COMMITNEWCONFIGS="x"
|
|
|
6bca4c |
;;
|
|
|
6bca4c |
-m)
|
|
|
6bca4c |
shift
|
|
|
6bca4c |
if [ "$1" = "CC=clang" -o "$1" = "LLVM=1" ]; then
|
|
|
6bca4c |
CC_IS_CLANG=1
|
|
|
6bca4c |
fi
|
|
|
6bca4c |
MAKEOPTS="$MAKEOPTS $1"
|
|
|
6bca4c |
;;
|
|
|
6bca4c |
*)
|
|
|
6bca4c |
break;;
|
|
|
6bca4c |
esac
|
|
|
6bca4c |
shift
|
|
|
6bca4c |
done
|
|
|
6bca4c |
|
|
|
6bca4c |
PACKAGE_NAME="${1:-kernel-auto}" # defines the package name used
|
|
|
6bca4c |
KVERREL="$(test -n "$2" && echo "-$2" || echo "")"
|
|
|
6bca4c |
SUBARCH="$(test -n "$3" && echo "-$3" || echo "")"
|
|
|
6bca4c |
FLAVOR="$(test -n "$4" && echo "-$4" || echo "-common")"
|
|
|
6bca4c |
SCRIPT=$(readlink -f "$0")
|
|
|
6bca4c |
SCRIPT_DIR=$(dirname "$SCRIPT")
|
|
|
6bca4c |
|
|
|
6bca4c |
# Most RHEL options are options we want in Fedora so RHEL pending settings head
|
|
|
6bca4c |
# to common/
|
|
|
6bca4c |
if [ "$FLAVOR" = "-rhel" ]
|
|
|
6bca4c |
then
|
|
|
6bca4c |
FLAVOR="-common"
|
|
|
6bca4c |
fi
|
|
|
6bca4c |
|
|
|
6bca4c |
# to handle this script being a symlink
|
|
|
6bca4c |
cd "$SCRIPT_DIR"
|
|
|
6bca4c |
|
|
|
6bca4c |
if test -n "$COMMITNEWCONFIGS"; then
|
|
|
6bca4c |
commit_new_configs
|
|
|
6bca4c |
else
|
|
|
6bca4c |
process_configs
|
|
|
6bca4c |
fi
|
|
|
6bca4c |
|
|
|
6bca4c |
exit $RETURNCODE
|