User Tools

Site Tools


u-boot_unused_configs

This is an old revision of the document!


Overview

Script that scans a Kbuild-based code base to identify CONFIG_ options that are defined in Kconfig files but that appear to be unused/untested in the code base.

Please do not make fun of the coding style of the script; I wrote it many, many years ago, and it would probably be far better written in Python.

The script

The script takes, as an optional argument, the specific directory you want to examine, and you're encouraged to be specific as the full output will be immense.

#!/bin/sh

# Uncomment whatever debugging you want to see.

SCAN_DIR=${1-*}

#  Collect config variables from Kconfig* files of interest.

SELECTED_KCONFIG_FILES=$(find ${SCAN_DIR} -name "Kconfig*")

if [ "${SELECTED_KCONFIG_FILES}" = "" ] ; then
        echo "No kconfig files, exiting."
        exit 1
fi

ALL_KCONFIG_FILES=$(find * -name "Kconfig*")

# echo SELECTED_KCONFIG_FILES = "${SELECTED_KCONFIG_FILES}"
# echo ALL_KCONFIG_FILES = "${ALL_KCONFIG_FILES}"

KCONFIG_VARS1=$(grep ^config ${SELECTED_KCONFIG_FILES} | awk '{print $2}' | sort -u)
KCONFIG_VARS2=$(grep ^menuconfig ${SELECTED_KCONFIG_FILES} | awk '{print $2}' | sort -u)

# echo KCONFIG_VARS1 = "${KCONFIG_VARS1}"
# echo KCONFIG_VARS2 = "${KCONFIG_VARS2}"

for kv in ${KCONFIG_VARS1} ${KCONFIG_VARS2} ; do
        # echo "Checking ${kv} ..."
        grep -q "depends on.*${kv}" ${ALL_KCONFIG_FILES} ||
        grep -q "if.*${kv}" ${ALL_KCONFIG_FILES} ||
        grep -q "default.*${kv}" ${ALL_KCONFIG_FILES} ||
        grep -r -w -q --exclude="*defconfig" "CONFIG_${kv}" * ||  {
                echo ">>>>> ${kv}"
                grep -rwn ${kv} * | grep -v defconfig
        }

done

False positives

This script will almost certainly generate false positives as the test is whether there is a Kbuild directive of the form “config X” with no subsequent reference anywhere to “CONFIG_X”; I failed to take into account the possible test of the form:

#if CONFIG_IS_ENABLED(X)

so I can clearly improve the script.

Example

Here's a single example of running the script on the directory drivers/mmc, which generates some of the very false positives I just warned about, but also displays actual unused configs.

>>>>> MMC_HS200_SUPPORT
drivers/mmc/Kconfig:116:        select MMC_HS200_SUPPORT
drivers/mmc/Kconfig:127:config MMC_HS200_SUPPORT
drivers/mmc/renesas-sdhi.c:21:    CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
drivers/mmc/renesas-sdhi.c:372:    CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
drivers/mmc/renesas-sdhi.c:413:    CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
drivers/mmc/renesas-sdhi.c:528:    CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
drivers/mmc/mmc-uclass.c:372:    CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
drivers/mmc/mmc-uclass.c:399:    CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
drivers/mmc/mmc.c:782:#if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT)
drivers/mmc/mmc.c:804:#if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
drivers/mmc/mmc.c:856:#if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT)
drivers/mmc/mmc.c:908:#if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT)
drivers/mmc/mmc.c:1830:#if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT)
drivers/mmc/mmc.c:1949:#if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
drivers/mmc/mmc.c:2784:    CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
include/mmc.h:17:#if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT)
include/mmc.h:694:    CONFIG_IS_ENABLED(MMC_HS200_SUPPORT) || \
>>>>> MMC_HS400_SUPPORT
drivers/mmc/Kconfig:114:config MMC_HS400_SUPPORT
drivers/mmc/renesas-sdhi.c:22:    CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
drivers/mmc/renesas-sdhi.c:373:    CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
drivers/mmc/renesas-sdhi.c:414:    CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
drivers/mmc/renesas-sdhi.c:529:    CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
drivers/mmc/mmc-uclass.c:373:    CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
drivers/mmc/mmc-uclass.c:400:    CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
drivers/mmc/mmc.c:787:#if CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
drivers/mmc/mmc.c:805:    CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
drivers/mmc/mmc.c:862:#if CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
drivers/mmc/mmc.c:1823:#if CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
drivers/mmc/mmc.c:1873:#if CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
drivers/mmc/mmc.c:1950:    CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
drivers/mmc/mmc.c:2785:    CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
include/mmc.h:543:#if CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
include/mmc.h:695:    CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)
>>>>> MMC_UHS_SUPPORT
drivers/mmc/omap_hsmmc.c:433:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/omap_hsmmc.c:1526:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/Kconfig:98:config MMC_UHS_SUPPORT
drivers/mmc/renesas-sdhi.c:20:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
drivers/mmc/renesas-sdhi.c:371:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
drivers/mmc/renesas-sdhi.c:386:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/renesas-sdhi.c:412:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
drivers/mmc/renesas-sdhi.c:417:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/renesas-sdhi.c:527:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
drivers/mmc/mmc-uclass.c:63:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/mmc-uclass.c:371:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
drivers/mmc/mmc-uclass.c:398:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
drivers/mmc/mmc.c:32:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/mmc.c:475:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/mmc.c:602:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/mmc.c:1207:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/mmc.c:1291:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/mmc.c:1330:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/mmc.c:1615:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/mmc.c:1640:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/mmc.c:1663:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
drivers/mmc/mmc.c:2783:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
include/mmc.h:20:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
include/mmc.h:452:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
include/mmc.h:539:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
include/mmc.h:557:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
include/mmc.h:693:#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || \
>>>>> SPL_MMC_HS200_SUPPORT
drivers/mmc/Kconfig:134:config SPL_MMC_HS200_SUPPORT
>>>>> SPL_MMC_HS400_SUPPORT
drivers/mmc/Kconfig:121:config SPL_MMC_HS400_SUPPORT
>>>>> SPL_MMC_TINY
drivers/mmc/Kconfig:155:config SPL_MMC_TINY
>>>>> SPL_MMC_UHS_SUPPORT
drivers/mmc/Kconfig:106:config SPL_MMC_UHS_SUPPORT

As you can see, most of that represent false positives, but the last few lines do in fact show Kbuild options that are unreferenced anywhere in the code base.

u-boot_unused_configs.1555153906.txt.gz · Last modified: 2019/04/13 11:11 by rpjday