[U-Boot] [PATCH v3 06/11] kconfig: switch to Kconfig

Masahiro Yamada yamada.m at jp.panasonic.com
Tue Jun 24 05:53:09 CEST 2014


This commit enables Kconfig.
Going forward, we use Kconfig for 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 binary images (Normal, SPL, TPL)
from one source tree.
Each image needs its own configuration input.

In order to keep this scheme in Kconfig, some files must be modified.
But the modification should be minimum.

The location of Kconfig related files is as follows:

 [1] Normal U-Boot image
   - configs/<board>_defconfig        (default configuration)
   - .config                          (saved config list)
   - include/config/auto.conf         (for use in makefiles)
   - include/generated/autoconf.h     (for use in C sources)
   - include/config/*                 (for if_changed_dep)

 [2] SPL
   - configs/<board>_spl_defconfig    (default configuration)
   - spl/.config                      (saved config list)
   - spl/include/config/auto.conf     (for use in makefiles)
   - spl/include/generated/autoconf.h (for use in C sources)
   - spl/include/config/*             (for if_changed_dep)

 [3] TPL
   - configs/<board>_tpl_defconfig    (default configuration)
   - tpl/.config                      (saved config list)
   - tpl/include/config/auto.conf     (for use in makefiles)
   - tpl/include/generated/autoconf.h (for use in C sources)
   - tpl/include/config/*             (for if_changed_dep)

Usage:

Execute "make <board>_defconfig" to configure board and then run "make".
Or "make <board>_defconfig all" to configure and build in one time.

You can use "make config", "make menuconfig" etc. to create
a new .config or modify the existing one.

In Kconfig for U-boot, the configuration is done on three levels at most.

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>
---

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                          | 113 ++++++++++++++++++--------------------
 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         |  96 ++++++++++++++++++++++++++++++++
 scripts/Makefile.build            |  31 ++++-------
 scripts/Makefile.spl              |  31 +----------
 scripts/basic/fixdep.c            |   6 +-
 scripts/kconfig/Makefile          |   8 ++-
 scripts/kconfig/confdata.c        |   8 +++
 scripts/multiconfig.sh            | 102 ++++++++++++++++++++++++++++++++++
 tools/Makefile                    |   2 +-
 tools/env/Makefile                |   2 +-
 18 files changed, 311 insertions(+), 133 deletions(-)
 create mode 100644 scripts/Makefile.autoconf
 create mode 100644 scripts/multiconfig.sh

diff --git a/.gitignore b/.gitignore
index 2ddf57f..3b32485 100644
--- a/.gitignore
+++ b/.gitignore
@@ -57,8 +57,6 @@
 #
 /include/config/
 /include/generated/
-/include/spl-autoconf.mk
-/include/tpl-autoconf.mk
 
 # stgit generated dirs
 patches-*
diff --git a/Makefile b/Makefile
index e429212..7a953aa 100644
--- a/Makefile
+++ b/Makefile
@@ -166,9 +166,6 @@ VPATH		:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
 
 export srctree objtree VPATH
 
-MKCONFIG	:= $(srctree)/mkconfig
-export MKCONFIG
-
 # Make sure CDPATH settings don't interfere
 unexport CDPATH
 
@@ -189,9 +186,6 @@ HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
 
 export	HOSTARCH HOSTOS
 
-# Deal with colliding definitions from tcsh etc.
-VENDOR=
-
 #########################################################################
 
 # set default to nothing for native builds
@@ -199,6 +193,9 @@ ifeq ($(HOSTARCH),$(ARCH))
 CROSS_COMPILE ?=
 endif
 
+KCONFIG_CONFIG	?= .config
+export KCONFIG_CONFIG
+
 # SHELL used by kbuild
 CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
 	  else if [ -x /bin/bash ]; then echo /bin/bash; \
@@ -460,31 +457,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)$(MAKE) $(build)=scripts/kconfig $@
+
+%config: scripts_basic outputmakefile FORCE
+	+$(Q)$(CONFIG_SHELL) $(srctree)/scripts/multiconfig.sh $@
 
 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.
+autoconf_is_update := $(if $(wildcard $(KCONFIG_CONFIG)),$(shell find \
+		-path ./include/config/auto.conf -newer $(KCONFIG_CONFIG)))
+ifneq ($(autoconf_is_update),)
 include $(srctree)/config.mk
-
-ifeq ($(wildcard include/config.mk),)
-$(error "System not configured - see README")
 endif
 
 # If board code explicitly specified LDSCRIPT or CONFIG_SYS_LDSCRIPT, use
@@ -513,8 +528,8 @@ ifndef LDSCRIPT
 endif
 
 else
-
-
+# Dummy target needed, because used as prerequisite
+include/config/auto.conf: ;
 endif # $(dot-config)
 
 KBUILD_CFLAGS += -Os #-fomit-frame-pointer
@@ -563,7 +578,8 @@ KBUILD_CFLAGS += $(KCFLAGS)
 UBOOTINCLUDE    := \
 		-Iinclude \
 		$(if $(KBUILD_SRC), -I$(srctree)/include) \
-		-I$(srctree)/arch/$(ARCH)/include
+		-I$(srctree)/arch/$(ARCH)/include \
+		-include $(srctree)/include/linux/kconfig.h
 
 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
 CHECKFLAGS     += $(NOSTDINC_FLAGS)
@@ -1017,7 +1033,7 @@ define filechk_uboot.release
 endef
 
 # Store (new) UBOOTRELEASE string in include/config/uboot.release
-include/config/uboot.release: Makefile FORCE
+include/config/uboot.release: include/config/auto.conf FORCE
 	$(call filechk,uboot.release)
 
 
@@ -1035,8 +1051,8 @@ PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
 # 1) Check that make has not been executed in the kernel src $(srctree)
 prepare3: include/config/uboot.release
 ifneq ($(KBUILD_SRC),)
-	@$(kecho) '  Using $(srctree) as source for u-boot'
-	$(Q)if [ -f $(srctree)/include/config.mk ]; then \
+	@$(kecho) '  Using $(srctree) as source for U-Boot'
+	$(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then \
 		echo >&2 "  $(srctree) is not clean, please run 'make mrproper'"; \
 		echo >&2 "  in the '$(srctree)' directory.";\
 		/bin/false; \
@@ -1046,7 +1062,8 @@ endif
 # prepare2 creates a makefile if using a separate output directory
 prepare2: prepare3 outputmakefile
 
-prepare1: prepare2 $(version_h) $(timestamp_h)
+prepare1: prepare2 $(version_h) $(timestamp_h) \
+                   include/config/auto.conf
 ifeq ($(__HAVE_ARCH_GENERIC_BOARD),)
 ifeq ($(CONFIG_SYS_GENERIC_BOARD),y)
 	@echo >&2 "  Your architecture does not support generic board."
@@ -1088,29 +1105,6 @@ $(version_h): include/config/uboot.release FORCE
 $(timestamp_h): $(srctree)/Makefile FORCE
 	$(call filechk,timestamp.h)
 
-#
-# Auto-generate the autoconf.mk file (which is included by all makefiles)
-#
-# This target actually generates 2 files; autoconf.mk and autoconf.mk.dep.
-# the dep file is only include in this top level makefile to determine when
-# to regenerate the autoconf.mk file.
-
-quiet_cmd_autoconf_dep = GEN     $@
-      cmd_autoconf_dep = $(CC) -x c -DDO_DEPS_ONLY -M $(c_flags) \
-	-MQ include/autoconf.mk $(srctree)/include/common.h > $@ || rm $@
-
-include/autoconf.mk.dep: include/config.h include/common.h
-	$(call cmd,autoconf_dep)
-
-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 > $@; \
-	rm $@.tmp
-
-include/autoconf.mk: include/config.h
-	$(call cmd,autoconf)
-
 # ---------------------------------------------------------------------------
 
 PHONY += depend dep
@@ -1134,7 +1128,7 @@ spl/sunxi-spl.bin: spl/u-boot-spl
 	@:
 
 tpl/u-boot-tpl.bin: tools prepare
-	$(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all CONFIG_TPL_BUILD=y
+	$(Q)$(MAKE) obj=tpl -f $(srctree)/scripts/Makefile.spl all
 
 TAG_SUBDIRS := $(u-boot-dirs) include
 
@@ -1209,20 +1203,18 @@ include/license.h: tools/bin2header COPYING
 
 # Directories & files removed with 'make clean'
 CLEAN_DIRS  += $(MODVERDIR)
-CLEAN_FILES += u-boot.lds include/bmp_logo.h include/bmp_logo_data.h \
-	       include/autoconf.mk* include/spl-autoconf.mk \
-	       include/tpl-autoconf.mk
+CLEAN_FILES += u-boot.lds include/bmp_logo.h include/bmp_logo_data.h
 
 # Directories & files removed with 'make clobber'
-CLOBBER_DIRS  += spl tpl
+CLOBBER_DIRS  += $(foreach d, spl tpl, $(patsubst %,$d/%, \
+			$(filter-out include, $(shell ls -1 $d 2>/dev/null))))
 CLOBBER_FILES += u-boot* MLO* SPL System.map
 
 # Directories & files removed with 'make mrproper'
-MRPROPER_DIRS  += include/config include/generated          \
+MRPROPER_DIRS  += include/config include/generated spl tpl \
 		  .tmp_objdiff
-MRPROPER_FILES += .config .config.old \
-		  tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
-		  include/config.h include/config.mk
+MRPROPER_FILES += .config .config.old include/autoconf.mk* include/config.h \
+		  tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
 
 # clean - Delete most, but leave enough to build external modules
 #
@@ -1299,10 +1291,9 @@ help:
 	@echo  '  mrproper	  - Remove all generated files + config + various backup files'
 	@echo  '  distclean	  - mrproper + remove editor backup and patch files'
 	@echo  ''
-# uncomment after adding Kconfig feature
-#	@echo  'Configuration targets:'
-#	@$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
-#	@echo  ''
+	@echo  'Configuration targets:'
+	@$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
+	@echo  ''
 	@echo  'Other generic targets:'
 	@echo  '  all		  - Build all necessary images depending on configuration'
 	@echo  '  u-boot	  - Build the bare u-boot'
diff --git a/arch/m68k/cpu/mcf52x2/config.mk b/arch/m68k/cpu/mcf52x2/config.mk
index 34ad99e..f66000b 100644
--- a/arch/m68k/cpu/mcf52x2/config.mk
+++ b/arch/m68k/cpu/mcf52x2/config.mk
@@ -7,14 +7,14 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
-cfg=$(shell grep configs $(objtree)/include/config.h | sed 's/.*<\(configs.*\)>/\1/')
-is5208:=$(shell grep CONFIG_M5208 $(srctree)/include/$(cfg))
-is5249:=$(shell grep CONFIG_M5249 $(srctree)/include/$(cfg))
-is5253:=$(shell grep CONFIG_M5253 $(srctree)/include/$(cfg))
-is5271:=$(shell grep CONFIG_M5271 $(srctree)/include/$(cfg))
-is5272:=$(shell grep CONFIG_M5272 $(srctree)/include/$(cfg))
-is5275:=$(shell grep CONFIG_M5275 $(srctree)/include/$(cfg))
-is5282:=$(shell grep CONFIG_M5282 $(srctree)/include/$(cfg))
+cfg=$(srctree)/include/configs/$(CONFIG_SYS_CONFIG_NAME:"%"=%).h
+is5208:=$(shell grep CONFIG_M5208 $(cfg))
+is5249:=$(shell grep CONFIG_M5249 $(cfg))
+is5253:=$(shell grep CONFIG_M5253 $(cfg))
+is5271:=$(shell grep CONFIG_M5271 $(cfg))
+is5272:=$(shell grep CONFIG_M5272 $(cfg))
+is5275:=$(shell grep CONFIG_M5275 $(cfg))
+is5282:=$(shell grep CONFIG_M5282 $(cfg))
 
 ifneq (,$(findstring CONFIG_M5208,$(is5208)))
 PLATFORM_CPPFLAGS += -mcpu=5208
diff --git a/arch/m68k/cpu/mcf532x/config.mk b/arch/m68k/cpu/mcf532x/config.mk
index af94354..2efb60f 100644
--- a/arch/m68k/cpu/mcf532x/config.mk
+++ b/arch/m68k/cpu/mcf532x/config.mk
@@ -7,9 +7,9 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
-cfg=$(shell grep configs $(objtree)/include/config.h | sed 's/.*<\(configs.*\)>/\1/')
-is5301x:=$(shell grep CONFIG_MCF5301x $(srctree)/include/$(cfg))
-is532x:=$(shell grep CONFIG_MCF532x $(srctree)/include/$(cfg))
+cfg=$(srctree)/include/configs/$(CONFIG_SYS_CONFIG_NAME:"%"=%).h
+is5301x:=$(shell grep CONFIG_MCF5301x $(cfg))
+is532x:=$(shell grep CONFIG_MCF532x $(cfg))
 
 ifneq (,$(findstring CONFIG_MCF5301x,$(is5301x)))
 PLATFORM_CPPFLAGS += -mcpu=53015 -fPIC
diff --git a/arch/m68k/cpu/mcf5445x/config.mk b/arch/m68k/cpu/mcf5445x/config.mk
index 5fd0d4d..13f8a9f 100644
--- a/arch/m68k/cpu/mcf5445x/config.mk
+++ b/arch/m68k/cpu/mcf5445x/config.mk
@@ -9,8 +9,8 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
-cfg=$(shell grep configs $(objtree)/include/config.h | sed 's/.*<\(configs.*\)>/\1/')
-is5441x:=$(shell grep CONFIG_MCF5441x $(srctree)/include/$(cfg))
+cfg=$(srctree)/include/configs/$(CONFIG_SYS_CONFIG_NAME:"%"=%).h
+is5441x:=$(shell grep CONFIG_MCF5441x $(cfg))
 
 ifneq (,$(findstring CONFIG_MCF5441x,$(is5441x)))
 PLATFORM_CPPFLAGS += -mcpu=54418 -fPIC
diff --git a/arch/powerpc/cpu/ppc4xx/config.mk b/arch/powerpc/cpu/ppc4xx/config.mk
index 102f069..a7253b2 100644
--- a/arch/powerpc/cpu/ppc4xx/config.mk
+++ b/arch/powerpc/cpu/ppc4xx/config.mk
@@ -7,8 +7,8 @@
 
 PLATFORM_CPPFLAGS += -DCONFIG_4xx -mstring -msoft-float
 
-cfg=$(shell grep configs $(objtree)/include/config.h | sed 's/.*<\(configs.*\)>/\1/')
-is440:=$(shell grep CONFIG_440 $(srctree)/include/$(cfg))
+cfg=$(srctree)/include/configs/$(CONFIG_SYS_CONFIG_NAME:"%"=%).h
+is440:=$(shell grep CONFIG_440 $(cfg))
 
 ifneq (,$(findstring CONFIG_440,$(is440)))
 PLATFORM_CPPFLAGS += -Wa,-m440 -mcpu=440
diff --git a/config.mk b/config.mk
index 05864aa..3b74e99 100644
--- a/config.mk
+++ b/config.mk
@@ -20,6 +20,16 @@ LDFLAGS_FINAL :=
 OBJCOPYFLAGS :=
 #########################################################################
 
+ARCH := $(CONFIG_SYS_ARCH:"%"=%)
+CPU := $(CONFIG_SYS_CPU:"%"=%)
+BOARD := $(CONFIG_SYS_BOARD:"%"=%)
+ifneq ($(CONFIG_SYS_VENDOR),)
+VENDOR := $(CONFIG_SYS_VENDOR:"%"=%)
+endif
+ifneq ($(CONFIG_SYS_SOC),)
+SOC := $(CONFIG_SYS_SOC:"%"=%)
+endif
+
 # Some architecture config.mk files need to know what CPUDIR is set to,
 # so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
 # Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
diff --git a/include/.gitignore b/include/.gitignore
index bf142fc..8e41a95 100644
--- a/include/.gitignore
+++ b/include/.gitignore
@@ -2,4 +2,3 @@
 /bmp_logo.h
 /bmp_logo_data.h
 /config.h
-/config.mk
diff --git a/scripts/Makefile b/scripts/Makefile
index 68c998e..efe25bf 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -13,4 +13,4 @@ build_docproc: $(obj)/docproc
 	@:
 
 # Let clean descend into subdirs
-subdir-	+= basic
+subdir-	+= basic kconfig
diff --git a/scripts/Makefile.autoconf b/scripts/Makefile.autoconf
new file mode 100644
index 0000000..2a59517
--- /dev/null
+++ b/scripts/Makefile.autoconf
@@ -0,0 +1,96 @@
+# This helper makefile is used for creating
+#  - symbolic links (arch/$ARCH/include/asm/{arch,proc}
+#  - 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 because config.mk may not
+# be included from the top Makefile. 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 $@
+
+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 > $@;									\
+	rm $@.tmp
+
+$(obj)/autoconf.mk: FORCE
+	$(call cmd,autoconf)
+
+include/autoconf.mk include/autoconf.mk.dep: include/config.h
+
+# include/config.h
+# Prior to Kconfig, it was generated by mkconfig. Now it is created here.
+define filechk_config_h
+	(echo "/* Automatically generated - do not edit */";		\
+	for i in $$(echo $(CONFIG_SYS_EXTRA_OPTIONS) | sed 's/,/ /g'); do \
+		echo \#define CONFIG_$$i				\
+		| sed '/=/ {s/=/	/;q; } ; { s/$$/	1/; }'; \
+	done;								\
+	echo \#define CONFIG_BOARDDIR board/$(if $(VENDOR),$(VENDOR)/)$(BOARD);\
+	echo \#include \<config_cmd_defaults.h\>;			\
+	echo \#include \<config_defaults.h\>;				\
+	echo \#include \<configs/$(CONFIG_SYS_CONFIG_NAME).h\>;		\
+	echo \#include \<asm/config.h\>;				\
+	echo \#include \<config_fallbacks.h\>;				\
+	echo \#include \<config_uncmd_spl.h\>; )
+endef
+
+include/config.h: scripts/Makefile.autoconf create_symlink FORCE
+	$(call filechk,config_h)
+
+# symbolic links
+PHONY += create_symlink
+create_symlink:
+ifneq ($(KBUILD_SRC),)
+	$(Q)mkdir -p include/asm
+endif
+	$(Q)ln -fsn $(srctree)/arch/$(ARCH)/include/asm/arch-$(if $(SOC),$(SOC),$(CPU)) \
+		$(if $(KBUILD_SRC),,arch/$(ARCH)/)include/asm/arch
+
+PHONY += FORCE
+FORCE:
+
+.PHONY: $(PHONY)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 04c6f7d..baeaabe 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -3,14 +3,14 @@
 # ==========================================================================
 
 # Modified for U-Boot
-ifeq ($(CONFIG_TPL_BUILD),y)
-  src := $(patsubst tpl/%,%,$(obj))
-else
-  ifeq ($(CONFIG_SPL_BUILD),y)
-    src := $(patsubst spl/%,%,$(obj))
-  else
-    src := $(obj)
-  endif
+prefix := tpl
+src := $(patsubst $(prefix)/%,%,$(obj))
+ifeq ($(obj),$(src))
+prefix := spl
+src := $(patsubst $(prefix)/%,%,$(obj))
+ifeq ($(obj),$(src))
+prefix := .
+endif
 endif
 
 PHONY := __build
@@ -40,18 +40,9 @@ subdir-asflags-y :=
 subdir-ccflags-y :=
 
 # Read auto.conf if it exists, otherwise ignore
--include include/config/auto.conf
-
-# Added for U-Boot: Load U-Boot configuration
-ifeq ($(CONFIG_TPL_BUILD),y)
-  -include include/tpl-autoconf.mk
-else
-  ifeq ($(CONFIG_SPL_BUILD),y)
-    -include include/spl-autoconf.mk
-  else
-    -include include/autoconf.mk
-  endif
-endif
+# Modified for U-Boot
+-include $(prefix)/include/config/auto.conf
+-include $(prefix)/include/autoconf.mk
 
 include scripts/Kbuild.include
 
diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl
index bf677aa..88c01d1 100644
--- a/scripts/Makefile.spl
+++ b/scripts/Makefile.spl
@@ -21,13 +21,10 @@ _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
 
 include $(srctree)/scripts/Kbuild.include
 
-CONFIG_SPL_BUILD := y
-export CONFIG_SPL_BUILD
+UBOOTINCLUDE := -I$(obj)/include $(UBOOTINCLUDE)
 
-KBUILD_CPPFLAGS += -DCONFIG_SPL_BUILD
-ifeq ($(CONFIG_TPL_BUILD),y)
-KBUILD_CPPFLAGS += -DCONFIG_TPL_BUILD
-endif
+-include $(obj)/include/config/auto.conf
+-include $(obj)/include/autoconf.mk
 
 ifeq ($(CONFIG_TPL_BUILD),y)
 export CONFIG_TPL_BUILD
@@ -36,14 +33,6 @@ else
 SPL_BIN := u-boot-spl
 endif
 
-include include/config.mk
-
-ifeq ($(CONFIG_TPL_BUILD),y)
-  -include include/tpl-autoconf.mk
-else
-  -include include/spl-autoconf.mk
-endif
-
 include $(srctree)/config.mk
 
 # Enable garbage collection of un-used sections for SPL
@@ -53,20 +42,6 @@ LDFLAGS_FINAL += --gc-sections
 # FIX ME
 cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \
 							$(NOSTDINC_FLAGS)
-c_flags := $(KBUILD_CFLAGS) $(cpp_flags)
-
-# Auto-generate the spl-autoconf.mk file (which is included by all makefiles for SPL)
-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 > $@; \
-	rm $@.tmp
-
-include/tpl-autoconf.mk: include/config.h
-	$(call cmd,autoconf)
-
-include/spl-autoconf.mk: include/config.h
-	$(call cmd,autoconf)
 
 HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n)
 
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
index b304068..1a41723 100644
--- a/scripts/basic/fixdep.c
+++ b/scripts/basic/fixdep.c
@@ -221,7 +221,11 @@ static void use_config(const char *m, int slen)
 
 	define_config(m, slen, hash);
 
-	printf("    $(wildcard include/config/");
+	/* printf("    $(wildcard include/config/"); */
+	/* modified for U-Boot */
+	printf("    $(wildcard %sinclude/config/",
+	       strncmp(depfile, "spl/", 4) ?
+	       (strncmp(depfile, "tpl/", 4) ? "" : "tpl/") : "spl/");
 	for (i = 0; i < slen; i++) {
 		c = m[i];
 		if (c == '_')
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index 9c4d241..5748055 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -98,11 +98,15 @@ ifeq ($(KBUILD_DEFCONFIG),)
 	$< --defconfig $(Kconfig)
 else
 	@echo "*** Default configuration is based on '$(KBUILD_DEFCONFIG)'"
-	$(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
+	@: Modified for U-Boot
+	@: $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$(KBUILD_DEFCONFIG) $(Kconfig)
+	$(Q)$< --defconfig=configs/$(KBUILD_DEFCONFIG) $(Kconfig)
 endif
 
 %_defconfig: $(obj)/conf
-	$(Q)$< --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)
+	@: Modified for U-Boot
+	@: $(Q)$< --defconfig=arch/$(SRCARCH)/configs/$@ $(Kconfig)
+	$(Q)$< --defconfig=configs/$@ $(Kconfig)
 
 # Help text used by make help
 help:
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index f88d90f..d2655e7 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -951,6 +951,14 @@ int conf_write_autoconf(void)
 	FILE *out, *tristate, *out_h;
 	int i;
 
+	/*
+	 * Added for U-Boot SPL/TPL
+	 */
+	name = getenv("KBUILD_SUBDIR");
+	if (name && name[0])
+		if (chdir(name))
+			return 1;
+
 	sym_clear_all_valid();
 
 	file_write_dep("include/config/auto.conf.cmd");
diff --git a/scripts/multiconfig.sh b/scripts/multiconfig.sh
new file mode 100644
index 0000000..d82f635
--- /dev/null
+++ b/scripts/multiconfig.sh
@@ -0,0 +1,102 @@
+#!/bin/sh -e
+
+get_command () {
+	echo ${1#*:}
+}
+
+get_outdir () {
+	tmp=${1%:*}
+	if [ "$tmp" = "$1" ]; then
+		tmp=
+	fi
+
+	echo $tmp
+}
+
+# create or update
+#  - symbolic link (arch/$ARCH/include/asm/arch)
+#  - include/autoconf.mk, {spl,tpl}/include/autoconf.mk
+#  - include/config.h
+# We are still relying U-Boot conventional configuration,
+# which is based on header files (include/configs/<board_name>.h)
+# We can delete the following lines after moving all CONFIG
+# from header files to Kconfig.
+make_autoconf () {
+	outdir=$1
+
+	if [ -z "$outdir" ]; then
+		$MAKE -f $srctree/scripts/Makefile.autoconf obj=include \
+			include/autoconf.mk include/autoconf.mk.dep
+
+		# include/config.h is updated after "make silentoldconfig".
+		# We need to touch include/config/auto.conf so it gets newer
+		# than include/config.h.
+		# Otherwise, "make silentoldconfig" is run twice.
+		touch include/config/auto.conf
+	else
+		$MAKE -f $srctree/scripts/Makefile.autoconf \
+			obj=$outdir/include $outdir/include/autoconf.mk
+	fi
+}
+
+do_defconfig_for_subimages () {
+	subimages=$(sed -n -e 's/,/ /g' -e 's/CONFIG_SUBIMAGES="\(.*\)"/\1/p' \
+							$KCONFIG_CONFIG)
+
+	for image in $subimages
+	do
+		do_config $image
+	done
+}
+
+do_silentoldconfig_for_subimages () {
+	subimages=$(sed -n -e 's/,/ /g' -e 's/CONFIG_SUBIMAGES="\(.*\)"/\1/p' \
+							$KCONFIG_CONFIG)
+
+	for image in $subimages
+	do
+		__do_config silentoldconfig $(get_outdir $image)
+	done
+}
+
+__do_config () {
+	command=$1
+	outdir=$2
+
+	if [ "$outdir" ]; then
+		mkdir -p $outdir
+
+		if [ "$command" = "silentoldconfig" ]; then
+			mkdir -p $outdir/include/config \
+						$outdir/include/generated
+		fi
+
+		options="KBUILD_SUBDIR=$outdir \
+					KCONFIG_CONFIG=$outdir/$KCONFIG_CONFIG"
+	else
+		options=
+	fi
+
+	$MAKE -f $srctree/scripts/Makefile.build obj=scripts/kconfig \
+							$options $command
+
+	if [ "$command" = silentoldconfig ]; then
+		make_autoconf $outdir
+	fi
+
+	if [ "$outdir" ]; then
+		return
+	fi
+
+	case "$command" in
+	defconfig|*_defconfig)	do_defconfig_for_subimages;;
+	silentoldconfig)	do_silentoldconfig_for_subimages;;
+	*)			;;
+	esac
+}
+
+do_config () {
+	__do_config $(get_command $1) $(get_outdir $1)
+}
+
+do_config $1
diff --git a/tools/Makefile b/tools/Makefile
index 3a1180f..63b6e90 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -192,7 +192,7 @@ endif # !LOGO_BMP
 # Define _GNU_SOURCE to obtain the getline prototype from stdio.h
 #
 HOST_EXTRACFLAGS += -include $(srctree)/include/libfdt_env.h \
-		$(patsubst -I%,-idirafter%, $(UBOOTINCLUDE)) \
+		$(patsubst -I%,-idirafter%, $(filter -I%, $(UBOOTINCLUDE))) \
 		-I$(srctree)/lib/libfdt \
 		-I$(srctree)/tools \
 		-DCONFIG_SYS_TEXT_BASE=$(CONFIG_SYS_TEXT_BASE) \
diff --git a/tools/env/Makefile b/tools/env/Makefile
index f5368bc..4927489 100644
--- a/tools/env/Makefile
+++ b/tools/env/Makefile
@@ -11,7 +11,7 @@
 HOSTCC = $(CC)
 
 # Compile for a hosted environment on the target
-HOST_EXTRACFLAGS  = $(patsubst -I%,-idirafter%, $(UBOOTINCLUDE)) \
+HOST_EXTRACFLAGS  = $(patsubst -I%,-idirafter%, $(filter -I%, $(UBOOTINCLUDE))) \
 		-idirafter $(srctree)/tools/env \
 		-DUSE_HOSTCC \
 		-DTEXT_BASE=$(TEXT_BASE)
-- 
1.9.1



More information about the U-Boot mailing list