blob: bf3b2dda23b9516c7cff7641671c00ae77e7746f [file] [log] [blame]
Luis Machado7e487672019-07-23 13:58:12 -03001#!/bin/sh
2#
3# Kernel config checker
4#
5# Checks if a set of CONFIG_* values are defined in the config file for a
6# particular version of the Linux kernel.
7#
8# Copyright (C) 2019, Linaro Limited.
9#
10# This program is free software; you can redistribute it and/or
11# modify it under the terms of the GNU General Public License
12# as published by the Free Software Foundation; either version 2
13# of the License, or (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23#
24
25# shellcheck disable=SC1091
26. ../../lib/sh-test-lib
27OUTPUT="$(pwd)/output"
28RESULT_FILE="${OUTPUT}/result.txt"
29export RESULT_FILE
30kernel_config=""
31
32# A list of space-separated config values to be checked.
33# Example: CONFIG_VALUES="CONFIG_X CONFIG_Y CONFIG_Z"
34CONFIG_VALUES=''
35
36usage() {
37 echo "Usage: $0 [-c config_values]" 1>&2
38 exit 1
39}
40
41while getopts "c:h" o; do
42 case "$o" in
43 c) CONFIG_VALUES="${OPTARG}" ;;
44 h|*) usage ;;
45 esac
46done
47
48# Find the location of the kernel's config file based on various standard
49# locations.
50find_config_file() {
51 if [ -e "/boot/config-$(uname -r)" ]; then
Anders Roxell297c0fb2019-07-23 19:56:38 +020052 kernel_config="/boot/config-$(uname -r)"
Luis Machado7e487672019-07-23 13:58:12 -030053 elif [ -e "/lib/modules/$(uname -r)/config" ]; then
Anders Roxell297c0fb2019-07-23 19:56:38 +020054 kernel_config="/lib/modules/$(uname -r)/config"
Luis Machado7e487672019-07-23 13:58:12 -030055 elif [ -e "/lib/kernel/config-$(uname -r)" ]; then
Anders Roxell297c0fb2019-07-23 19:56:38 +020056 kernel_config="/lib/kernel/config-$(uname -r)"
Anders Roxella082eca2019-07-23 20:01:01 +020057 elif [ -e "/proc/config.gz" ]; then
58 tmpfile=$(mktemp /tmp/config.XXXXX)
59 zcat /proc/config.gz > "${tmpfile}"
60 kernel_config=${tmpfile}
Luis Machado7e487672019-07-23 13:58:12 -030061 fi
62}
63
64check_config() {
65
66 # Fetch the config file.
67 find_config_file
68
69 if [ ! -f "${kernel_config}" ]; then
Anders Roxell297c0fb2019-07-23 19:56:38 +020070 exit_on_fail "Kernel Config File ${kernel_config} does not exist..."
Luis Machado7e487672019-07-23 13:58:12 -030071 fi
72
73 info_msg "Found kernel config file in $kernel_config."
74
75 # shellcheck disable=SC2068
76 for c in ${@}; do
Anders Roxell297c0fb2019-07-23 19:56:38 +020077 info_msg "Checking config option ${c}..."
78 cat < "${kernel_config}" | grep "${c}=[y|m]" > /dev/null
Milosz Wasilewskibd38e552021-03-02 11:20:21 +000079 check_return "config_value_${c}"
Luis Machado7e487672019-07-23 13:58:12 -030080 done
81}
82
83# Test run.
84create_out_dir "${OUTPUT}"
85
86info_msg "About to run kernel config checker test..."
87info_msg "Output directory: ${OUTPUT}"
88
89check_config "${CONFIG_VALUES}"