Luis Machado | 7e48767 | 2019-07-23 13:58:12 -0300 | [diff] [blame] | 1 | #!/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 |
| 27 | OUTPUT="$(pwd)/output" |
| 28 | RESULT_FILE="${OUTPUT}/result.txt" |
| 29 | export RESULT_FILE |
| 30 | kernel_config="" |
| 31 | |
| 32 | # A list of space-separated config values to be checked. |
| 33 | # Example: CONFIG_VALUES="CONFIG_X CONFIG_Y CONFIG_Z" |
| 34 | CONFIG_VALUES='' |
| 35 | |
| 36 | usage() { |
| 37 | echo "Usage: $0 [-c config_values]" 1>&2 |
| 38 | exit 1 |
| 39 | } |
| 40 | |
| 41 | while getopts "c:h" o; do |
| 42 | case "$o" in |
| 43 | c) CONFIG_VALUES="${OPTARG}" ;; |
| 44 | h|*) usage ;; |
| 45 | esac |
| 46 | done |
| 47 | |
| 48 | # Find the location of the kernel's config file based on various standard |
| 49 | # locations. |
| 50 | find_config_file() { |
| 51 | if [ -e "/boot/config-$(uname -r)" ]; then |
Anders Roxell | 297c0fb | 2019-07-23 19:56:38 +0200 | [diff] [blame] | 52 | kernel_config="/boot/config-$(uname -r)" |
Luis Machado | 7e48767 | 2019-07-23 13:58:12 -0300 | [diff] [blame] | 53 | elif [ -e "/lib/modules/$(uname -r)/config" ]; then |
Anders Roxell | 297c0fb | 2019-07-23 19:56:38 +0200 | [diff] [blame] | 54 | kernel_config="/lib/modules/$(uname -r)/config" |
Luis Machado | 7e48767 | 2019-07-23 13:58:12 -0300 | [diff] [blame] | 55 | elif [ -e "/lib/kernel/config-$(uname -r)" ]; then |
Anders Roxell | 297c0fb | 2019-07-23 19:56:38 +0200 | [diff] [blame] | 56 | kernel_config="/lib/kernel/config-$(uname -r)" |
Anders Roxell | a082eca | 2019-07-23 20:01:01 +0200 | [diff] [blame] | 57 | elif [ -e "/proc/config.gz" ]; then |
| 58 | tmpfile=$(mktemp /tmp/config.XXXXX) |
| 59 | zcat /proc/config.gz > "${tmpfile}" |
| 60 | kernel_config=${tmpfile} |
Luis Machado | 7e48767 | 2019-07-23 13:58:12 -0300 | [diff] [blame] | 61 | fi |
| 62 | } |
| 63 | |
| 64 | check_config() { |
| 65 | |
| 66 | # Fetch the config file. |
| 67 | find_config_file |
| 68 | |
| 69 | if [ ! -f "${kernel_config}" ]; then |
Anders Roxell | 297c0fb | 2019-07-23 19:56:38 +0200 | [diff] [blame] | 70 | exit_on_fail "Kernel Config File ${kernel_config} does not exist..." |
Luis Machado | 7e48767 | 2019-07-23 13:58:12 -0300 | [diff] [blame] | 71 | fi |
| 72 | |
| 73 | info_msg "Found kernel config file in $kernel_config." |
| 74 | |
| 75 | # shellcheck disable=SC2068 |
| 76 | for c in ${@}; do |
Anders Roxell | 297c0fb | 2019-07-23 19:56:38 +0200 | [diff] [blame] | 77 | info_msg "Checking config option ${c}..." |
| 78 | cat < "${kernel_config}" | grep "${c}=[y|m]" > /dev/null |
Milosz Wasilewski | bd38e55 | 2021-03-02 11:20:21 +0000 | [diff] [blame] | 79 | check_return "config_value_${c}" |
Luis Machado | 7e48767 | 2019-07-23 13:58:12 -0300 | [diff] [blame] | 80 | done |
| 81 | } |
| 82 | |
| 83 | # Test run. |
| 84 | create_out_dir "${OUTPUT}" |
| 85 | |
| 86 | info_msg "About to run kernel config checker test..." |
| 87 | info_msg "Output directory: ${OUTPUT}" |
| 88 | |
| 89 | check_config "${CONFIG_VALUES}" |