[U-Boot] scripts to sanity-check the Kconfig files

while i'm in a chatty mood, a few years back, i wrote some simple shell scripts that scanned the linux kernel source tree for inconsistencies in the Kconfig files, and pointed out things like "config" entries that were never used or tested, "select" directives that referred to non-existent variables, and so on.
i just ran that first script on the current u-boot source, and there are quite a number of these. as just partial output, here are some Kconfig variables that are (apparently, as long as i didn't screw up anything in the script) defined but never used or tested anywhere:
... snip ...
CMD_MX_CYCLIC
cmd/Kconfig:338:config CMD_MX_CYCLIC
CPU_SPECIFIC_OPTIONS
arch/x86/cpu/ivybridge/Kconfig:23:config CPU_SPECIFIC_OPTIONS arch/x86/cpu/broadwell/Kconfig:21:config CPU_SPECIFIC_OPTIONS
DEBUG_EFI_CONSOLE
drivers/serial/Kconfig:115:config DEBUG_EFI_CONSOLE
DM_MOD_EXP
drivers/crypto/rsa_mod_exp/Kconfig:1:config DM_MOD_EXP ... snip ...
so as to that first example, that shows that the variable CMD_MX_CYCLIC is defined in cmd/Kconfig:
config CMD_MX_CYCLIC bool "mdc, mwc" help mdc - memory display cyclic mwc - memory write cyclic
but is never tested for anything, and a grep seems to show that:
$ grep -r CMD_MX_CYCLIC * cmd/Kconfig:config CMD_MX_CYCLIC configs/sandbox_noblk_defconfig:CONFIG_CMD_MX_CYCLIC=y configs/sandbox_spl_defconfig:CONFIG_CMD_MX_CYCLIC=y configs/sandbox_defconfig:CONFIG_CMD_MX_CYCLIC=y $
OTOH, if you search for just "MX_CYCLIC":
$ grep -r MX_CYCLIC *A cmd/Kconfig:config CMD_MX_CYCLIC cmd/mem.c:#ifdef CONFIG_MX_CYCLIC cmd/mem.c:#endif /* CONFIG_MX_CYCLIC */ cmd/mem.c:#ifdef CONFIG_MX_CYCLIC cmd/mem.c:#endif /* CONFIG_MX_CYCLIC */ configs/sandbox_noblk_defconfig:CONFIG_CMD_MX_CYCLIC=y configs/sandbox_spl_defconfig:CONFIG_CMD_MX_CYCLIC=y configs/sandbox_defconfig:CONFIG_CMD_MX_CYCLIC=y include/configs/ea20.h:#define CONFIG_MX_CYCLIC include/configs/lwmon5.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/M5249EVB.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/PMC405DE.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/x600.h:#define CONFIG_MX_CYCLIC /* enable mdc/mwc commands */ include/configs/ipam390.h:#define CONFIG_MX_CYCLIC include/configs/da850evm.h:#define CONFIG_MX_CYCLIC include/configs/bcm23550_w1d.h:#define CONFIG_MX_CYCLIC include/configs/bcm28155_ap.h:#define CONFIG_MX_CYCLIC include/configs/omapl138_lcdk.h:#define CONFIG_MX_CYCLIC include/configs/bcm_ep_board.h:#define CONFIG_MX_CYCLIC include/configs/amcore.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/digsy_mtc.h:#define CONFIG_MX_CYCLIC 1 include/configs/amcc-common.h:#define CONFIG_MX_CYCLIC /* enable mdc/mwc commands */ include/configs/xtfpga.h:#define CONFIG_MX_CYCLIC include/configs/xilinx-ppc.h:#define CONFIG_MX_CYCLIC /* enable mdc/mwc commands */ include/configs/ti_armv7_keystone2.h:#define CONFIG_MX_CYCLIC include/configs/PMC440.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/calimain.h:#define CONFIG_MX_CYCLIC include/configs/legoev3.h:#define CONFIG_MX_CYCLIC README:- CONFIG_MX_CYCLIC scripts/config_whitelist.txt:CONFIG_MX_CYCLIC $
so it would appear that the *correct* spelling is "CONFIG_MX_CYCLIC" as defined in the header file, which is what is being tested in the source file cmd/mem.c.
a more obvious example:
$ grep -r DM_MOD_EXP * drivers/crypto/rsa_mod_exp/Kconfig:config DM_MOD_EXP $
there is, however, "UCLASS_MOD_EXP"; perhaps that's what was meant:
$ grep -r UCLASS_MOD_EXP * board/freescale/common/fsl_validate.c: ret = uclass_get_device(UCLASS_MOD_EXP, 0, &mod_exp_dev); drivers/crypto/fsl/fsl_rsa.c: .id = UCLASS_MOD_EXP, drivers/crypto/rsa_mod_exp/mod_exp_sw.c: .id = UCLASS_MOD_EXP, drivers/crypto/rsa_mod_exp/mod_exp_uclass.c: .id = UCLASS_MOD_EXP, include/dm/uclass-id.h: UCLASS_MOD_EXP, /* RSA Mod Exp device */ lib/rsa/rsa-verify.c: ret = uclass_get_device(UCLASS_MOD_EXP, 0, &mod_exp_dev); $
there appears to be quite a lot of stuff like this.
rday

On 4.1.2017 15:38, Robert P. J. Day wrote:
while i'm in a chatty mood, a few years back, i wrote some simple shell scripts that scanned the linux kernel source tree for inconsistencies in the Kconfig files, and pointed out things like "config" entries that were never used or tested, "select" directives that referred to non-existent variables, and so on.
i just ran that first script on the current u-boot source, and there are quite a number of these. as just partial output, here are some Kconfig variables that are (apparently, as long as i didn't screw up anything in the script) defined but never used or tested anywhere:
... snip ...
CMD_MX_CYCLIC
cmd/Kconfig:338:config CMD_MX_CYCLIC
CPU_SPECIFIC_OPTIONS
arch/x86/cpu/ivybridge/Kconfig:23:config CPU_SPECIFIC_OPTIONS arch/x86/cpu/broadwell/Kconfig:21:config CPU_SPECIFIC_OPTIONS
DEBUG_EFI_CONSOLE
drivers/serial/Kconfig:115:config DEBUG_EFI_CONSOLE
DM_MOD_EXP
drivers/crypto/rsa_mod_exp/Kconfig:1:config DM_MOD_EXP ... snip ...
so as to that first example, that shows that the variable CMD_MX_CYCLIC is defined in cmd/Kconfig:
config CMD_MX_CYCLIC bool "mdc, mwc" help mdc - memory display cyclic mwc - memory write cyclic
but is never tested for anything, and a grep seems to show that:
$ grep -r CMD_MX_CYCLIC * cmd/Kconfig:config CMD_MX_CYCLIC configs/sandbox_noblk_defconfig:CONFIG_CMD_MX_CYCLIC=y configs/sandbox_spl_defconfig:CONFIG_CMD_MX_CYCLIC=y configs/sandbox_defconfig:CONFIG_CMD_MX_CYCLIC=y $
OTOH, if you search for just "MX_CYCLIC":
$ grep -r MX_CYCLIC *A cmd/Kconfig:config CMD_MX_CYCLIC cmd/mem.c:#ifdef CONFIG_MX_CYCLIC cmd/mem.c:#endif /* CONFIG_MX_CYCLIC */ cmd/mem.c:#ifdef CONFIG_MX_CYCLIC cmd/mem.c:#endif /* CONFIG_MX_CYCLIC */ configs/sandbox_noblk_defconfig:CONFIG_CMD_MX_CYCLIC=y configs/sandbox_spl_defconfig:CONFIG_CMD_MX_CYCLIC=y configs/sandbox_defconfig:CONFIG_CMD_MX_CYCLIC=y include/configs/ea20.h:#define CONFIG_MX_CYCLIC include/configs/lwmon5.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/M5249EVB.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/PMC405DE.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/x600.h:#define CONFIG_MX_CYCLIC /* enable mdc/mwc commands */ include/configs/ipam390.h:#define CONFIG_MX_CYCLIC include/configs/da850evm.h:#define CONFIG_MX_CYCLIC include/configs/bcm23550_w1d.h:#define CONFIG_MX_CYCLIC include/configs/bcm28155_ap.h:#define CONFIG_MX_CYCLIC include/configs/omapl138_lcdk.h:#define CONFIG_MX_CYCLIC include/configs/bcm_ep_board.h:#define CONFIG_MX_CYCLIC include/configs/amcore.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/digsy_mtc.h:#define CONFIG_MX_CYCLIC 1 include/configs/amcc-common.h:#define CONFIG_MX_CYCLIC /* enable mdc/mwc commands */ include/configs/xtfpga.h:#define CONFIG_MX_CYCLIC include/configs/xilinx-ppc.h:#define CONFIG_MX_CYCLIC /* enable mdc/mwc commands */ include/configs/ti_armv7_keystone2.h:#define CONFIG_MX_CYCLIC include/configs/PMC440.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/calimain.h:#define CONFIG_MX_CYCLIC include/configs/legoev3.h:#define CONFIG_MX_CYCLIC README:- CONFIG_MX_CYCLIC scripts/config_whitelist.txt:CONFIG_MX_CYCLIC $
so it would appear that the *correct* spelling is "CONFIG_MX_CYCLIC" as defined in the header file, which is what is being tested in the source file cmd/mem.c.
I looked at this. Correct name should be CONFIG_CMD_MX_CYCLIC and for the rest s/CONFIG_MX_CYCLIC/CONFIG_CMD_MX_CYCLIC/g with move to defconfig. + in Kconfig there should be dependecy on CMD_MEMORY.
Thanks, Michal

2017-01-05 0:22 GMT+09:00 Michal Simek monstr@monstr.eu:
On 4.1.2017 15:38, Robert P. J. Day wrote:
while i'm in a chatty mood, a few years back, i wrote some simple shell scripts that scanned the linux kernel source tree for inconsistencies in the Kconfig files, and pointed out things like "config" entries that were never used or tested, "select" directives that referred to non-existent variables, and so on.
i just ran that first script on the current u-boot source, and there are quite a number of these. as just partial output, here are some Kconfig variables that are (apparently, as long as i didn't screw up anything in the script) defined but never used or tested anywhere:
... snip ...
> CMD_MX_CYCLIC
cmd/Kconfig:338:config CMD_MX_CYCLIC
> CPU_SPECIFIC_OPTIONS
arch/x86/cpu/ivybridge/Kconfig:23:config CPU_SPECIFIC_OPTIONS arch/x86/cpu/broadwell/Kconfig:21:config CPU_SPECIFIC_OPTIONS
> DEBUG_EFI_CONSOLE
drivers/serial/Kconfig:115:config DEBUG_EFI_CONSOLE
> DM_MOD_EXP
drivers/crypto/rsa_mod_exp/Kconfig:1:config DM_MOD_EXP ... snip ...
so as to that first example, that shows that the variable CMD_MX_CYCLIC is defined in cmd/Kconfig:
config CMD_MX_CYCLIC bool "mdc, mwc" help mdc - memory display cyclic mwc - memory write cyclic
but is never tested for anything, and a grep seems to show that:
$ grep -r CMD_MX_CYCLIC * cmd/Kconfig:config CMD_MX_CYCLIC configs/sandbox_noblk_defconfig:CONFIG_CMD_MX_CYCLIC=y configs/sandbox_spl_defconfig:CONFIG_CMD_MX_CYCLIC=y configs/sandbox_defconfig:CONFIG_CMD_MX_CYCLIC=y $
OTOH, if you search for just "MX_CYCLIC":
$ grep -r MX_CYCLIC *A cmd/Kconfig:config CMD_MX_CYCLIC cmd/mem.c:#ifdef CONFIG_MX_CYCLIC cmd/mem.c:#endif /* CONFIG_MX_CYCLIC */ cmd/mem.c:#ifdef CONFIG_MX_CYCLIC cmd/mem.c:#endif /* CONFIG_MX_CYCLIC */ configs/sandbox_noblk_defconfig:CONFIG_CMD_MX_CYCLIC=y configs/sandbox_spl_defconfig:CONFIG_CMD_MX_CYCLIC=y configs/sandbox_defconfig:CONFIG_CMD_MX_CYCLIC=y include/configs/ea20.h:#define CONFIG_MX_CYCLIC include/configs/lwmon5.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/M5249EVB.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/PMC405DE.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/x600.h:#define CONFIG_MX_CYCLIC /* enable mdc/mwc commands */ include/configs/ipam390.h:#define CONFIG_MX_CYCLIC include/configs/da850evm.h:#define CONFIG_MX_CYCLIC include/configs/bcm23550_w1d.h:#define CONFIG_MX_CYCLIC include/configs/bcm28155_ap.h:#define CONFIG_MX_CYCLIC include/configs/omapl138_lcdk.h:#define CONFIG_MX_CYCLIC include/configs/bcm_ep_board.h:#define CONFIG_MX_CYCLIC include/configs/amcore.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/digsy_mtc.h:#define CONFIG_MX_CYCLIC 1 include/configs/amcc-common.h:#define CONFIG_MX_CYCLIC /* enable mdc/mwc commands */ include/configs/xtfpga.h:#define CONFIG_MX_CYCLIC include/configs/xilinx-ppc.h:#define CONFIG_MX_CYCLIC /* enable mdc/mwc commands */ include/configs/ti_armv7_keystone2.h:#define CONFIG_MX_CYCLIC include/configs/PMC440.h:#define CONFIG_MX_CYCLIC 1 /* enable mdc/mwc commands */ include/configs/calimain.h:#define CONFIG_MX_CYCLIC include/configs/legoev3.h:#define CONFIG_MX_CYCLIC README:- CONFIG_MX_CYCLIC scripts/config_whitelist.txt:CONFIG_MX_CYCLIC $
so it would appear that the *correct* spelling is "CONFIG_MX_CYCLIC" as defined in the header file, which is what is being tested in the source file cmd/mem.c.
I looked at this. Correct name should be CONFIG_CMD_MX_CYCLIC and for the rest s/CONFIG_MX_CYCLIC/CONFIG_CMD_MX_CYCLIC/g with move to defconfig.
- in Kconfig there should be dependecy on CMD_MEMORY.
For this one, it seems my mistake:
commit 60296a835cb176695a3ce3a50a843d2f03b77d32 Author: Masahiro Yamada yamada.m@jp.panasonic.com Date: Thu Nov 13 19:29:08 2014 +0900
commands: add more command entries in Kconfig
This commit adds some of command entries (CONFIG_CMD_*) to cover include/config_cmd_default.h and a little extra.
Because U-Boot supports lots of commands, they should be categorized according to their usage.
Signed-off-by: Masahiro Yamada yamada.m@jp.panasonic.com
I do not remember why.
As Michal suggested, renaming to CONFIG_CMD_MX_CYCLIC seems better...

On Wed, 4 Jan 2017, Michal Simek wrote:
I looked at this. Correct name should be CONFIG_CMD_MX_CYCLIC and for the rest s/CONFIG_MX_CYCLIC/CONFIG_CMD_MX_CYCLIC/g with move to defconfig.
- in Kconfig there should be dependecy on CMD_MEMORY.
for better or worse, i ran that cleanup script and posted the output here:
http://www.crashcourse.ca/wiki/index.php/U-Boot_Kconfig_cleanup
that list is *allegedly* variables that are defined in some Kconfig file, but are never tested anywhere in the code. the output isn't perfect, there are a bunch of false positives since what i consider a variable being "tested" is if, somewhere in the code base, there is a RE of the form:
"if.*<variable name>"
that script worked pretty well on kernel code, but doesn't take into account testing in the u-boot source involving "$(SPL_)" variants or testing with "CONFIG_IS_ENABLED", or config variables whose only purpose in life is to further "select" other variables.
in any case, the output isn't that lengthy, feel free to look through it to see if anything looks familiar. i've got a couple other scripts i'm going to run on the code base shortly.
rday
p.s. that output allegedly represents variables that are defined in a Kconfig file but are never tested, which is typically not considered that big a deal -- that normally happens when one removes a feature but forgets to remove the Kconfig variable corresponding to it.
i have a second script that identified the opposite -- Kconfig variables that *are* being tested but do not seem to be defined in any Kconfig file, normally a more serious issue.

On Wed, 4 Jan 2017, Michal Simek wrote:
... snip ...
so it would appear that the *correct* spelling is "CONFIG_MX_CYCLIC" as defined in the header file, which is what is being tested in the source file cmd/mem.c.
I looked at this. Correct name should be CONFIG_CMD_MX_CYCLIC and for the rest s/CONFIG_MX_CYCLIC/CONFIG_CMD_MX_CYCLIC/g with move to defconfig.
- in Kconfig there should be dependecy on CMD_MEMORY.
whoever is responsible for that code/feature/whatever is welcome to submit a patch for it; i wasn't offering to fix all this stuff. :-)
rday

Hi Michal,
2017-01-05 0:22 GMT+09:00 Michal Simek monstr@monstr.eu:
I looked at this. Correct name should be CONFIG_CMD_MX_CYCLIC and for the rest s/CONFIG_MX_CYCLIC/CONFIG_CMD_MX_CYCLIC/g with move to defconfig.
- in Kconfig there should be dependecy on CMD_MEMORY.
Could you fix this please?

On Fri, 13 Jan 2017, Masahiro Yamada wrote:
Hi Michal,
2017-01-05 0:22 GMT+09:00 Michal Simek monstr@monstr.eu:
I looked at this. Correct name should be CONFIG_CMD_MX_CYCLIC and for the rest s/CONFIG_MX_CYCLIC/CONFIG_CMD_MX_CYCLIC/g with move to defconfig.
- in Kconfig there should be dependecy on CMD_MEMORY.
Could you fix this please?
i wasn't sure if someone was expecting *me* to fix this simply because i pointed it out, but don't forget, there is a *ton* of Kbuild cleanup that could be done:
http://www.crashcourse.ca/wiki/index.php/U-Boot_Kconfig_cleanup
rday
participants (3)
-
Masahiro Yamada
-
Michal Simek
-
Robert P. J. Day