3 # A wrapper script to adjust Kconfig for U-Boot
5 # Instead of touching various parts under the scripts/kconfig/ directory,
6 # pushing necessary adjustments into this single script would be better
7 # for code maintainance. All the make targets related to the configuration
8 # (make %config) should be invoked via this script.
9 # See doc/README.kconfig for further information of Kconfig.
11 # Copyright (C) 2014, Masahiro Yamada <yamada.m@jp.panasonic.com>
13 # SPDX-License-Identifier: GPL-2.0+
18 # Set "DEBUG" enavironment variable to show debug messages
27 debug $progname: $MAKE -f $srctree/scripts/Makefile.build obj="$@"
28 $MAKE -f $srctree/scripts/Makefile.build obj="$@"
32 debug $progname: $MAKE -f $srctree/scripts/Makefile.autoconf obj="$@"
33 $MAKE -f $srctree/scripts/Makefile.autoconf obj="$@"
36 # Make a configuration target
38 # run_make_config <target> <objdir>
39 # <target>: Make target such as "config", "menuconfig", "defconfig", etc.
40 # <objdir>: Target directory where the make command is run.
41 # Typically "", "spl", "tpl" for Normal, SPL, TPL, respectively.
46 # Linux expects defconfig files in arch/$(SRCARCH)/configs/ directory,
47 # but U-Boot has them in configs/ directory.
48 # Give SRCARCH=.. to fake scripts/kconfig/Makefile.
49 options="SRCARCH=.. KCONFIG_OBJDIR=$objdir"
50 if [ "$objdir" ]; then
51 options="$options KCONFIG_CONFIG=$objdir/$KCONFIG_CONFIG"
55 build scripts/kconfig $options $target
58 # Parse .config file to detect if CONFIG_SPL, CONFIG_TPL is enabled
60 # "" if neither CONFIG_SPL nor CONFIG_TPL is defined
61 # "spl" if CONFIG_SPL is defined but CONFIG_TPL is not
62 # "spl tpl" if both CONFIG_SPL and CONFIG_TPL are defined
63 get_enabled_subimages() {
64 if [ ! -r "$KCONFIG_CONFIG" ]; then
65 # This should never happen
66 echo "$progname: $KCONFIG_CONFIG not found" >&2
72 sed -n -e 's/^CONFIG_\(SPL\|TPL\)=y$/\1/p' $KCONFIG_CONFIG | \
76 do_silentoldconfig () {
77 run_make_config silentoldconfig
78 subimages=$(get_enabled_subimages)
82 mkdir -p $obj/include/config $obj/include/generated
83 run_make_config silentoldconfig $obj
86 # If the following part fails, include/config/auto.conf should be
87 # deleted so "make silentoldconfig" will be re-run on the next build.
88 autoconf include include/autoconf.mk include/autoconf.mk.dep || {
89 rm -f include/config/auto.conf
93 # include/config.h has been updated after "make silentoldconfig".
94 # We need to touch include/config/auto.conf so it gets newer
95 # than include/config.h.
96 # Otherwise, 'make silentoldconfig' would be invoked twice.
97 touch include/config/auto.conf
101 autoconf $obj/include $obj/include/autoconf.mk || {
102 rm -f include/config/auto.conf
108 cleanup_after_defconfig () {
109 rm -f configs/.tmp_defconfig
110 # ignore 'Directory not empty' error
111 # without using non-POSIX option '--ignore-fail-on-non-empty'
112 rmdir arch configs 2>/dev/null || true
116 # do_board_defconfig <board>_defconfig
117 do_board_defconfig () {
118 defconfig_path=$srctree/configs/$1
119 tmp_defconfig_path=configs/.tmp_defconfig
121 mkdir -p arch configs
122 # defconfig for Normal:
123 # pick lines without prefixes and lines starting '+' prefix
124 # and rip the prefixes off.
125 sed -n -e '/^[+A-Z]*:/!p' -e 's/^+[A-Z]*://p' $defconfig_path \
126 > configs/.tmp_defconfig
128 run_make_config .tmp_defconfig || {
129 cleanup_after_defconfig
133 for img in $(get_enabled_subimages)
135 symbol=$(echo $img | cut -c 1 | tr '[a-z]' '[A-Z]')
136 # defconfig for SPL, TPL:
137 # pick lines with 'S', 'T' prefix and rip the prefixes off
138 sed -n -e 's/^[+A-Z]*'$symbol'[A-Z]*://p' $defconfig_path \
139 > configs/.tmp_defconfig
140 run_make_config .tmp_defconfig $img || {
141 cleanup_after_defconfig
146 cleanup_after_defconfig
150 if [ "$KBUILD_DEFCONFIG" ]; then
151 do_board_defconfig $KBUILD_DEFCONFIG
152 echo "*** Default configuration is based on '$KBUILD_DEFCONFIG'"
154 run_make_config defconfig
158 do_savedefconfig () {
159 if [ -r "$KCONFIG_CONFIG" ]; then
160 subimages=$(get_enabled_subimages)
165 run_make_config savedefconfig
169 # -r option is necessay because some string-type configs may include
170 # backslashes as an escape character
173 output_lines="$output_lines $line"
176 for img in $subimages
178 run_make_config savedefconfig $img
180 symbol=$(echo $img | cut -c 1 | tr '[a-z]' '[A-Z]')
188 # coalesce common lines together
189 for i in $output_lines
193 tmp="$tmp $unmatched"
195 sed -e "s/^\([^:]\)*/\1$symbol/")
200 tmp="$tmp $unmatched"
201 tmp="$tmp +$symbol:$i"
210 if [ "$match" ]; then
214 unmatched="$unmatched $symbol:$line"
220 for line in $output_lines
222 echo $line >> defconfig
227 # do_others <objdir>/<target>
228 # The field "<objdir>/" is typically empy, "spl/", "tpl/" for Normal, SPL, TPL,
230 # The field "<target>" is a configuration target such as "config",
235 if [ "$target" = "$1" ]; then
241 run_make_config $target $objdir
244 progname=$(basename $0)
249 do_board_defconfig $target;;
251 # backward compatibility
252 do_board_defconfig ${target%_config}_defconfig;;