-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure-vmlinux.sh
executable file
·104 lines (85 loc) · 2.06 KB
/
configure-vmlinux.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# configure-vmlinux.sh
set -eu
set -o pipefail
dir="$(dirname "$(realpath "$0")")"
source "$dir/env.sh"
# read_config array file
# read a file in Kconfig format into an associative array.
#
# Valid values are "y", "n", "m". Unset options are turned into "n".
read_config() {
local -n arr=$1
local file=$2
while IFS='=' read -r cfg value
do
if [[ -v arr[$cfg] ]]; then
echo "Error: $cfg is redefined by $file."
exit 1
fi
arr[$cfg]=$value
done < <(sed -E 's/^# (CONFIG_.+) is not set$/\1=n/; /^\#/d; /^$/d' "$file")
}
# Figure out all valid options
# allconfig doesn't contain all config, since Kconfig seems to omit
# some implicit options like CONFIG_DEBUG_INFO. This is the best I can come
# up with.
declare -A allconfig
make allyesconfig > /dev/null
read_config allconfig .config
# Use defconfig as the base
declare -A config
make defconfig
read_config config .config
# Remove all modules
for cfg in "${!config[@]}"; do
if [[ "${config[$cfg]}" == "m" ]]; then
unset config[$cfg]
fi
done
# Merge configuration snippets
declare -A overrides
for file in "$dir/config" "$dir/config-$ARCH"; do
echo "Merging $file"
read_config overrides "$file"
done
for cfg in "${!overrides[@]}"; do
echo "$cfg=${overrides[$cfg]}"
config[$cfg]="${overrides[$cfg]}"
done
rm .config
for cfg in "${!config[@]}"; do
echo "$cfg=${config[$cfg]}" >> .config
done
# Add missing configuration options.
make olddefconfig
# Validate that all the options have the value we want.
declare -A effective
read_config effective .config
status=0
for cfg in "${!overrides[@]}"; do
if [[ ! -v effective[$cfg] ]]; then
if [[ ! -v allconfig[$cfg] ]]; then
echo "Ignoring unrecognised option $cfg"
continue
fi
echo "Option $cfg: not present in config"
status=1
continue
fi
want="${overrides[$cfg]}"
have="${effective[$cfg]}"
case "$want" in
y|n|m)
if [[ "$have" != "$want" ]]; then
echo "Option $cfg: expected '$want', found '$have'"
status=1
fi
;;
*)
echo "Option $cfg: don't know how to handle '$want'"
status=1
;;
esac
done
exit $status