huangcm
2025-09-01 53d8e046ac1bf2ebe94f671983e3d3be059df91a
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
 
RETVAL=0
ARCHES="arm64 arm x86"
if [ -z "$ANDROID_BUILD_TOP" ]; then
   echo "ANDROID_BUILD_TOP not set, exiting"
   exit 1
fi
AFRAGS="$ANDROID_BUILD_TOP/kernel/configs"
KERNEL_VERSIONS=`ls -d $AFRAGS/android-* | xargs -n 1 basename`
 
check_fragment()
{
   ERRORS=0
 
   while read line; do
       grep -q "$line" .config
       if [ $? -ne 0 ]
       then
           echo "Error, $line not found in merged config."
           ERRORS=1
       fi
   done < <(grep -v -E "^#  " $1)
 
   if [ $ERRORS -ne 0 ]
   then
       echo "Errors encountered while checking $1"
       RETVAL=1
   else
       echo "Fragment $1 is okay"
   fi
   echo ""
}
 
check_arches()
{
   for arch in $ARCHES; do
       rm .config
       make ARCH=$arch allnoconfig
       FRAGMENTS="$AFRAGS/$version/android-base.config \
              $AFRAGS/$version/android-recommended.config"
       if [ -f $AFRAGS/$version/android-base-$arch.config ]; then
           FRAGMENTS="$FRAGMENTS $AFRAGS/$version/android-base-$arch.config"
       fi
       if [ -f $AFRAGS/$version/android-recommended-$arch.config ]; then
           FRAGMENTS="$FRAGMENTS $AFRAGS/$version/android-recommended-$arch.config"
       fi
       ARCH=$arch scripts/kconfig/merge_config.sh .config $FRAGMENTS &> /dev/null
       for f in $FRAGMENTS; do
           check_fragment $f
       done
   done
}
 
check_configs()
{
   for version in $KERNEL_VERSIONS; do
       echo "Changing to $KERNEL_PATH"
       cd $KERNEL_PATH
       git checkout $version
       check_arches
   done
}
 
show_help()
{
   cat << EOF
Usage: ${0##*/} [-h] [-a arches] [-v versions] -k path-to-kernel
Check that the kernel config fragments are consistent with the Kconfig files
in the given kernel versions. This requires an android common kernel repo to
be checked out and made available to this script via the -k option or the
KERNEL_PATH environment variable. Note this script does not verify the
configs in the conditional XML fragments.
 
   -h        display this help and exit
   -a arches    quote-enclosed whitespace separated list of
                        architectures to check, valid architectures are
           arm64, arm, and x86
   -k kernel    path to android common kernel repo
   -v versions    quote-enclosed whitespace separated list of
           kernel versions to check (android-x.y)
EOF
}
 
OPTIND=1
while getopts "h?a:v:k:" opt; do
   case "$opt" in
       h|\?)
           show_help
           exit 0
           ;;
       a)
           ARCHES="$OPTARG"
           ;;
       v)
           KERNEL_VERSIONS="$OPTARG"
           ;;
       k)
           KERNEL_PATH="${OPTARG/#\~/$HOME}"
           ;;
   esac
done
 
check_configs