multiconfig.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #!/bin/sh
  2. #
  3. # A wrapper script to adjust Kconfig for U-Boot
  4. #
  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.
  10. #
  11. # Copyright (C) 2014, Masahiro Yamada <yamada.m@jp.panasonic.com>
  12. #
  13. # SPDX-License-Identifier: GPL-2.0+
  14. #
  15. set -e
  16. # Set "DEBUG" enavironment variable to show debug messages
  17. debug () {
  18. if [ $DEBUG ]; then
  19. echo "$@"
  20. fi
  21. }
  22. # Useful shorthands
  23. build () {
  24. debug $progname: $MAKE -f $srctree/scripts/Makefile.build obj="$@"
  25. $MAKE -f $srctree/scripts/Makefile.build obj="$@"
  26. }
  27. autoconf () {
  28. debug $progname: $MAKE -f $srctree/scripts/Makefile.autoconf obj="$@"
  29. $MAKE -f $srctree/scripts/Makefile.autoconf obj="$@"
  30. }
  31. # Make a configuration target
  32. # Usage:
  33. # run_make_config <target> <objdir>
  34. # <target>: Make target such as "config", "menuconfig", "defconfig", etc.
  35. # <objdir>: Target directory where the make command is run.
  36. # Typically "", "spl", "tpl" for Normal, SPL, TPL, respectively.
  37. run_make_config () {
  38. target=$1
  39. objdir=$2
  40. # Linux expects defconfig files in arch/$(SRCARCH)/configs/ directory,
  41. # but U-Boot has them in configs/ directory.
  42. # Give SRCARCH=.. to fake scripts/kconfig/Makefile.
  43. options="SRCARCH=.. KCONFIG_OBJDIR=$objdir"
  44. if [ "$objdir" ]; then
  45. options="$options KCONFIG_CONFIG=$objdir/$KCONFIG_CONFIG"
  46. mkdir -p $objdir
  47. fi
  48. build scripts/kconfig $options $target
  49. }
  50. # Parse .config file to detect if CONFIG_SPL, CONFIG_TPL is enabled
  51. # and returns:
  52. # "" if neither CONFIG_SPL nor CONFIG_TPL is defined
  53. # "spl" if CONFIG_SPL is defined but CONFIG_TPL is not
  54. # "spl tpl" if both CONFIG_SPL and CONFIG_TPL are defined
  55. get_enabled_subimages() {
  56. if [ ! -r "$KCONFIG_CONFIG" ]; then
  57. # This should never happen
  58. echo "$progname: $KCONFIG_CONFIG not found" >&2
  59. exit 1
  60. fi
  61. # CONFIG_SPL=y -> spl
  62. # CONFIG_TPL=y -> tpl
  63. sed -n -e 's/^CONFIG_\(SPL\|TPL\)=y$/\1/p' $KCONFIG_CONFIG | \
  64. tr '[A-Z]' '[a-z]'
  65. }
  66. do_silentoldconfig () {
  67. run_make_config silentoldconfig
  68. subimages=$(get_enabled_subimages)
  69. for obj in $subimages
  70. do
  71. mkdir -p $obj/include/config $obj/include/generated
  72. run_make_config silentoldconfig $obj
  73. done
  74. # If the following part fails, include/config/auto.conf should be
  75. # deleted so "make silentoldconfig" will be re-run on the next build.
  76. autoconf include include/autoconf.mk include/autoconf.mk.dep || {
  77. rm -f include/config/auto.conf
  78. exit 1
  79. }
  80. # include/config.h has been updated after "make silentoldconfig".
  81. # We need to touch include/config/auto.conf so it gets newer
  82. # than include/config.h.
  83. # Otherwise, 'make silentoldconfig' would be invoked twice.
  84. touch include/config/auto.conf
  85. for obj in $subimages
  86. do
  87. autoconf $obj/include $obj/include/autoconf.mk || {
  88. rm -f include/config/auto.conf
  89. exit 1
  90. }
  91. done
  92. }
  93. cleanup_after_defconfig () {
  94. rm -f configs/.tmp_defconfig
  95. # ignore 'Directory not empty' error
  96. # without using non-POSIX option '--ignore-fail-on-non-empty'
  97. rmdir arch configs 2>/dev/null || true
  98. }
  99. # Usage:
  100. # do_board_defconfig <board>_defconfig
  101. do_board_defconfig () {
  102. defconfig_path=$srctree/configs/$1
  103. tmp_defconfig_path=configs/.tmp_defconfig
  104. mkdir -p arch configs
  105. # defconfig for Normal:
  106. # pick lines without prefixes and lines starting '+' prefix
  107. # and rip the prefixes off.
  108. sed -n -e '/^[+A-Z]*:/!p' -e 's/^+[A-Z]*://p' $defconfig_path \
  109. > configs/.tmp_defconfig
  110. run_make_config .tmp_defconfig || {
  111. cleanup_after_defconfig
  112. exit 1
  113. }
  114. for img in $(get_enabled_subimages)
  115. do
  116. symbol=$(echo $img | cut -c 1 | tr '[a-z]' '[A-Z]')
  117. # defconfig for SPL, TPL:
  118. # pick lines with 'S', 'T' prefix and rip the prefixes off
  119. sed -n -e 's/^[+A-Z]*'$symbol'[A-Z]*://p' $defconfig_path \
  120. > configs/.tmp_defconfig
  121. run_make_config .tmp_defconfig $img || {
  122. cleanup_after_defconfig
  123. exit 1
  124. }
  125. done
  126. cleanup_after_defconfig
  127. }
  128. do_defconfig () {
  129. if [ "$KBUILD_DEFCONFIG" ]; then
  130. do_board_defconfig $KBUILD_DEFCONFIG
  131. echo "*** Default configuration is based on '$KBUILD_DEFCONFIG'"
  132. else
  133. run_make_config defconfig
  134. fi
  135. }
  136. do_savedefconfig () {
  137. if [ -r "$KCONFIG_CONFIG" ]; then
  138. subimages=$(get_enabled_subimages)
  139. else
  140. subimages=
  141. fi
  142. run_make_config savedefconfig
  143. output_lines=
  144. # -r option is necessay because some string-type configs may include
  145. # backslashes as an escape character
  146. while read -r line
  147. do
  148. output_lines="$output_lines $line"
  149. done < defconfig
  150. for img in $subimages
  151. do
  152. run_make_config savedefconfig $img
  153. symbol=$(echo $img | cut -c 1 | tr '[a-z]' '[A-Z]')
  154. unmatched=
  155. while read -r line
  156. do
  157. tmp=
  158. match=
  159. # coalesce common lines together
  160. for i in $output_lines
  161. do
  162. case "$i" in
  163. "[+A-Z]*:$line")
  164. tmp="$tmp $unmatched"
  165. i=$(echo "$i" | \
  166. sed -e "s/^\([^:]\)*/\1$symbol/")
  167. tmp="$tmp $i"
  168. match=1
  169. ;;
  170. "$line")
  171. tmp="$tmp $unmatched"
  172. tmp="$tmp +$symbol:$i"
  173. match=1
  174. ;;
  175. *)
  176. tmp="$tmp $i"
  177. ;;
  178. esac
  179. done
  180. if [ "$match" ]; then
  181. output_lines="$tmp"
  182. unmatched=
  183. else
  184. unmatched="$unmatched $symbol:$line"
  185. fi
  186. done < defconfig
  187. done
  188. rm -f defconfig
  189. for line in $output_lines
  190. do
  191. echo $line >> defconfig
  192. done
  193. }
  194. # Usage:
  195. # do_others <objdir>/<target>
  196. # The field "<objdir>/" is typically empy, "spl/", "tpl/" for Normal, SPL, TPL,
  197. # respectively.
  198. # The field "<target>" is a configuration target such as "config",
  199. # "menuconfig", etc.
  200. do_others () {
  201. target=${1##*/}
  202. if [ "$target" = "$1" ]; then
  203. objdir=
  204. else
  205. objdir=${1%/*}
  206. fi
  207. run_make_config $target $objdir
  208. }
  209. progname=$(basename $0)
  210. target=$1
  211. case $target in
  212. *_defconfig)
  213. do_board_defconfig $target;;
  214. *_config)
  215. # backward compatibility
  216. do_board_defconfig ${target%_config}_defconfig;;
  217. silentoldconfig)
  218. do_silentoldconfig;;
  219. defconfig)
  220. do_defconfig;;
  221. savedefconfig)
  222. do_savedefconfig;;
  223. *)
  224. do_others $target;;
  225. esac