[U-Boot] [PATCH v5 06/15] kconfig: switch to Kconfig

Simon Glass sjg at chromium.org
Sat Jul 26 01:52:23 CEST 2014


Hi Masahiro,

On 24 July 2014 05:00, Masahiro Yamada <yamada.m at jp.panasonic.com> wrote:
> This commit enables Kconfig.
> Going forward, we use Kconfig for the board configuration.
> mkconfig will never be used. Nor will include/config.mk be generated.
>
> Kconfig must be adjusted for U-Boot because our situation is
> a little more complicated than Linux Kernel.
> We have to generate multiple boot images (Normal, SPL, TPL)
> from one source tree.
> Each image needs its own configuration input.
>
> Usage:
>
> Run "make <board>_defconfig" to do the board configuration.
>
> It will create .config file and additionally spl/.config, tpl/.config
> if SPL, TPL is enabled respectively.
>
> You can use "make config", "make menuconfig" etc. to create
> a new .config or modify the existing one.
>
> Use "make spl:config", "make spl:menuconfig" etc. for spl/.config
> and do likewise for tpl/.config file.
>
> The generic syntax of configuration targets for SPL, TPL is:
>
>   <target_image>:<config_command>
>
> When the configuration is done, run "make".
> (Or "make <board>_defconfig all" will do the configuration and build
> in one time.)
>
> For futher information of how Kconfig in U-Boot works,
> please read the comment block of scripts/multiconfig.py.
>
> By the way, there is another item worth remarking here:
> coexistence of Kconfig and board herder files.
>
> Prior to Kconfig, we used C headers to define a set of configs.
>
> We expect a very long term to migrate from C headers to Kconfig.
> Two different infractructure must coexist in the interim.
>
> In our former configuration scheme, include/autoconf.mk was generated
> for use in makefiles.
> It is still generated under include/, spl/include/, tpl/include/ directory
> for the Normal, SPL, TPL image, respectively.
>
> Signed-off-by: Masahiro Yamada <yamada.m at jp.panasonic.com>

Acked-by: Simon Glass <sjg at chromium.org>

I have a few comments below but if any of them are worth addressing
then I suggest a follow-up patch rather than changing what you have
here.

> ---
>
> Changes in v5:
>   - Rebase on commit fbe79a17fd
>
> Changes in v4:
>   - Have one defconfig file for each board by supporting conditional
>     definition in defconfig
>   - Put adjustment code into scripts/multiconfig.py
>
> Changes in v3:
>   - Invoke SPL/TPL configuration only for defconfig and silentoldconfig
>
> Changes in v2:
>   - Put dirty build rule into scripts/multiple_config.sh and
>     scripts/Makefile.autoconf
>   - Fix dependency tracking.
>     In v1, any change to Kconfig triggered re-complile of all objects.
>     In this version, re-compile is kept at a minimum.
>   - Fix a clean-source check
>     In v1, clean source tree check did not work correctly for
>     out-of-tree build.
>
>  .gitignore                        |   2 -
>  Makefile                          | 116 +++++------
>  arch/m68k/cpu/mcf52x2/config.mk   |  16 +-
>  arch/m68k/cpu/mcf532x/config.mk   |   6 +-
>  arch/m68k/cpu/mcf5445x/config.mk  |   4 +-
>  arch/powerpc/cpu/ppc4xx/config.mk |   4 +-
>  config.mk                         |  10 +
>  include/.gitignore                |   1 -
>  scripts/Makefile                  |   2 +-
>  scripts/Makefile.autoconf         | 100 ++++++++++
>  scripts/Makefile.build            |  31 ++-
>  scripts/Makefile.spl              |  31 +--
>  scripts/basic/fixdep.c            |   6 +-
>  scripts/kconfig/confdata.c        |   8 +
>  scripts/multiconfig.py            | 406 ++++++++++++++++++++++++++++++++++++++
>  tools/Makefile                    |   2 +-
>  tools/env/Makefile                |   2 +-
>  17 files changed, 615 insertions(+), 132 deletions(-)
>  create mode 100644 scripts/Makefile.autoconf
>  create mode 100755 scripts/multiconfig.py
>

> diff --git a/Makefile b/Makefile
> index ca212b5..c4d894f 100644
> --- a/Makefile
> +++ b/Makefile

> @@ -460,31 +458,49 @@ ifeq ($(config-targets),1)
>  # *config targets only - make sure prerequisites are updated, and descend
>  # in scripts/kconfig to make the *config target
>
> -# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
> -# KBUILD_DEFCONFIG may point out an alternative default configuration
> -# used for 'make defconfig'
> +KBUILD_DEFCONFIG := sandbox_defconfig
> +export KBUILD_DEFCONFIG KBUILD_KCONFIG
>
> -%_config:: outputmakefile
> -       @$(MKCONFIG) -A $(@:_config=)
> +config: scripts_basic outputmakefile FORCE
> +       +$(Q)$(PYTHON) $(srctree)/scripts/multiconfig.py $@
> +
> +%config: scripts_basic outputmakefile FORCE
> +       +$(Q)$(PYTHON) $(srctree)/scripts/multiconfig.py $@
>
>  else
>  # ===========================================================================
>  # Build targets only - this includes vmlinux, arch specific targets, clean
>  # targets and others. In general all targets except *config targets.
>
> -# load ARCH, BOARD, and CPU configuration
> --include include/config.mk
> -
>  ifeq ($(dot-config),1)
>  # Read in config
> +-include include/config/auto.conf
> +
> +# Read in dependencies to all Kconfig* files, make sure to run
> +# oldconfig if changes are detected.
> +-include include/config/auto.conf.cmd
> +
> +# To avoid any implicit rule to kick in, define an empty command
> +$(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
> +
> +# If .config is newer than include/config/auto.conf, someone tinkered
> +# with it and forgot to run make oldconfig.
> +# if auto.conf.cmd is missing then we are probably in a cleaned tree so
> +# we execute the config step to be sure to catch updated Kconfig files
> +include/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
> +       $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
> +
>  -include include/autoconf.mk
>  -include include/autoconf.mk.dep
>
> -# load other configuration
> +# We want to include arch/$(ARCH)/config.mk only when include/config/auto.conf
> +# is up-to-date. When we switch to a different board configuration, old CONFIG
> +# macros are still remaining in include/config/auto.conf. Without the following
> +# gimmick, wrong config.mk would be included leading nasty warnings/errors.

Add a few words:

> +# We want to include arch/$(ARCH)/config.mk only when include/config/auto.conf
> +# is up-to-date. When we switch to a different board configuration, the old CONFIG
> +# macros are still remaining in include/config/auto.conf. Without the following
> +# check, wrong config.mk would be included leading to nasty warnings/errors.

> +autoconf_is_update := $(if $(wildcard $(KCONFIG_CONFIG)),$(shell find \

autoconf_is_current?


> diff --git a/scripts/Makefile.autoconf b/scripts/Makefile.autoconf
> new file mode 100644
> index 0000000..44c3997
> --- /dev/null
> +++ b/scripts/Makefile.autoconf
> @@ -0,0 +1,100 @@
> +# This helper makefile is used for creating
> +#  - symbolic links (arch/$ARCH/include/asm/arch
> +#  - include/autoconf.mk, {spl,tpl}/include/autoconf.mk
> +#  - include/config.h
> +#
> +# When our migration to Kconfig is done
> +# (= When we move all CONFIGs from header files to Kconfig)
> +# this makefile can be deleted.
> +
> +# obj is "include" or "spl/include" or "tpl/include"
> +# for non-SPL, SPL, TPL, respectively
> +include $(obj)/config/auto.conf
> +
> +include scripts/Kbuild.include
> +
> +# Need to define CC and CPP again here in case the top Makefile did not
> +# include config.mk.  Some architectures expect CROSS_COMPILE to be defined
> +# in arch/$(ARCH)/config.mk
> +CC             = $(CROSS_COMPILE)gcc
> +CPP            = $(CC) -E
> +
> +include config.mk
> +
> +UBOOTINCLUDE    := \
> +               -I$(obj) \
> +               -Iinclude \
> +               $(if $(KBUILD_SRC), -I$(srctree)/include) \
> +               -I$(srctree)/arch/$(ARCH)/include \
> +               -include $(srctree)/include/linux/kconfig.h
> +
> +c_flags := $(KBUILD_CFLAGS) $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) \
> +                                       $(UBOOTINCLUDE) $(NOSTDINC_FLAGS)
> +
> +quiet_cmd_autoconf_dep = GEN     $@
> +      cmd_autoconf_dep = $(CC) -x c -DDO_DEPS_ONLY -M -MP $(c_flags) \
> +       -MQ include/config/auto.conf $(srctree)/include/common.h > $@ || {      \
> +               rm $@; false;                                                   \
> +       }
> +include/autoconf.mk.dep: FORCE
> +       $(call cmd,autoconf_dep)
> +
> +# We are migrating from board headers to Kconfig little by little.
> +# In the interim, we use both of
> +#  - include/config/auto.conf (generated by Kconfig)
> +#  - include/autoconf.mk      (used in the U-Boot conventional configuration)
> +# The following rule creates autoconf.mk
> +# include/config/auto.conf is grepped in order to avoid duplication of the
> +# same CONFIG macros
> +quiet_cmd_autoconf = GEN     $@
> +      cmd_autoconf = \
> +       $(CPP) $(c_flags) -DDO_DEPS_ONLY -dM $(srctree)/include/common.h > $@.tmp && {  \
> +               sed -n -f $(srctree)/tools/scripts/define2mk.sed $@.tmp |               \
> +               while read line; do                                                     \
> +                       if ! grep -q "$${line%=*}=" $(obj)/config/auto.conf; then       \
> +                               echo "$$line";                                          \
> +                       fi                                                              \
> +               done > $@;                                                              \

This seems quite inefficient. Would something using 'sort | uniq'
work? Or 'sort | comm -3' ?


> diff --git a/scripts/multiconfig.py b/scripts/multiconfig.py
> new file mode 100755
> index 0000000..544b44a
> --- /dev/null
> +++ b/scripts/multiconfig.py
> @@ -0,0 +1,406 @@
> +#!/usr/bin/env python
> +#
> +# Copyright (C) 2014, Masahiro Yamada <yamada.m at jp.panasonic.com>
> +#
> +# SPDX-License-Identifier:     GPL-2.0+
> +#
> +
> +'''
> +A wrapper script to adjust Kconfig for U-Boot
> +
> +The biggest difference between Linux Kernel and U-Boot in terms of the
> +board configuration is that U-Boot has to configure multiple boot images
> +per board: Normal, SPL, TPL.
> +We need to expand the functions of Kconfig to handle multiple boot images.
> +
> +Instead of touching various parts under scripts/kconfig/ directory,
> +pushing necessary adjustments into this single script would be better
> +for code maintainance. All the make targets related to the configuration
> +(make %config) should be invoked through this script.
> +
> +Let's see what is different from the original Kconfig.
> +
> +- config, menuconfig, etc.
> +
> +The commands "make config", "make menuconfig", etc. are used to create
> +or modify .config file, which stores configs for Normal boot image.

modify the .config file

> +
> +The location of that file for SPL, TPL image is spl/.config, tpl/.config,
> +respectively. Use "make spl:config", "make spl:menuconfig", etc. to create
> +or modify spl/.config file, which contains configs for SPL image.
> +Do likewise for tpl/.config file.
> +The generic syntax for SPL, TPL configuration is
> +"make <target_image>:<config_command>".
> +
> +- silentoldconfig
> +
> +The command "make silentoldconfig" updates .config, if necessary, and
> +additionally updates include/generated/autoconf.h and files under
> +include/configs/ directory. In U-Boot, it should do the same things for
> +SPL, TPL images for boards supporting them.
> +Depending on whether CONFIG_SPL, CONFIG_TPL is defined or not,
> +"make silentoldconfig" iterates three times at most changing the target
> +directory.
> +
> +To sum up, "make silentoldconfig" possibly updates
> +  - .config, include/generated/autoconf.h, include/config/*
> +  - spl/.config, spl/include/generated/autoconf.h, spl/include/config/*
> +    (in case CONFIG_SPL=y)
> +  - tpl/.config, tpl/include/generated/autoconf.h, tpl/include/config/*
> +    (in case CONFIG_TPL=y)
> +
> +- defconfig, <board>_defconfig
> +
> +The command "make <board>_defconfig" creates a new .config based on the
> +file configs/<board>_defconfig. The command "make defconfig" is the same
> +but the difference is it uses the file specified with KBUILD_DEFCONFIG
> +environment.
> +
> +We need to create .spl, spl/.config, tpl/.config for boards where SPL/TPL
> +is supported. One possible solution for that is to have multiple defconfig
> +files per board, but it would produce duplication among defconfigs.
> +The approach chosen here is to expand the feature and support conditional
> +definition in defconfig: The each line in defconfig has the form of:

s/The/Then/ ?

> +<condition>:<macro definition>
> +
> +The "<condition>:" prefix specifies which image the line is valid for.
> +The "<condition>:" is one of:
> +  None  - the line is valid only for Normal image
> +  S:    - the line is valid only for SPL image
> +  T:    - the line is valid only for TPL image
> +  ST:   - the line is valid for SPL and TPL images
> +  +S:   - the line is valid for Normal and SPL images
> +  +T:   - the line is valid for Normal and TPL images
> +  +ST:  - the line is valid for Normal, SPL and SPL images
> +
> +So, if neither CONFIG_SPL nor CONFIG_TPL is defined, the defconfig file
> +has no "<condition>:" part and has the same form of that of Linux Kernel.
> +
> +In U-Boot, for example, defconfig can be written like this:
> +
> +  CONFIG_FOO=100
> +  S:CONFIG_FOO=200
> +  T:CONFIG_FOO=300
> +  ST:CONFIG_BAR=y
> +  +S:CONFIG_BAZ=y
> +  +T:CONFIG_QUX=y
> +  +ST:CONFIG_QUUX=y
> +
> +The defconfig above is parsed by this script and internally divided into
> +three temporary defconfig files.
> +
> +  - Temporary defconfig for Normal image
> +     CONFIG_FOO=100
> +     CONFIG_BAZ=y
> +     CONFIG_QUX=y
> +     CONFIG_QUUX=y
> +
> +  - Temporary defconfig for SPL image
> +     CONFIG_FOO=200
> +     CONFIG_BAR=y
> +     CONFIG_BAZ=y
> +     CONFIG_QUUX=y
> +
> +  - Temporary defconfig for TPL image
> +     CONFIG_FOO=300
> +     CONFIG_BAR=y
> +     CONFIG_QUX=y
> +     CONFIG_QUUX=y
> +
> +They are passed to scripts/kconfig/conf, each is used for generating
> +.config, spl/.config, tpl/.config, respectively.
> +
> +- savedefconfig
> +
> +This is the reverse operation of "make defconfig".
> +If neither CONFIG_SPL nor CONFIG_TPL is defined in the .config file,
> +it works as "make savedefconfig" in Linux Kernel: create the minimal set
> +of config based on the .config and save it into "defconfig" file.
> +
> +If CONFIG_SPL or CONFIG_TPL is defined, the common lines among .config,
> +spl/.config, tpl/.config are coalesced together and output "defconfig"

Does this mean 'output to "defconfig"' ?

Regards,
Simon


More information about the U-Boot mailing list