blob: 27f0ac9ee67b0b663cd921a3f5f4b2804c7f82a5 [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)"
Luis Machado7e487672019-07-23 13:58:12 -030057 fi
58}
59
60check_config() {
61
62 # Fetch the config file.
63 find_config_file
64
65 if [ ! -f "${kernel_config}" ]; then
Anders Roxell297c0fb2019-07-23 19:56:38 +020066 exit_on_fail "Kernel Config File ${kernel_config} does not exist..."
Luis Machado7e487672019-07-23 13:58:12 -030067 fi
68
69 info_msg "Found kernel config file in $kernel_config."
70
71 # shellcheck disable=SC2068
72 for c in ${@}; do
Anders Roxell297c0fb2019-07-23 19:56:38 +020073 info_msg "Checking config option ${c}..."
74 cat < "${kernel_config}" | grep "${c}=[y|m]" > /dev/null
75 check_return "config value: ${c}"
Luis Machado7e487672019-07-23 13:58:12 -030076 done
77}
78
79# Test run.
80create_out_dir "${OUTPUT}"
81
82info_msg "About to run kernel config checker test..."
83info_msg "Output directory: ${OUTPUT}"
84
85check_config "${CONFIG_VALUES}"