multiconfig.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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=y$/spl/p' -e 's/^CONFIG_TPL=y$/tpl/p' \
  64. $KCONFIG_CONFIG
  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. if [ ! -r $defconfig_path ]; then
  105. echo >&2 "***"
  106. echo >&2 "*** Can't find default configuration \"configs/$1\"!"
  107. echo >&2 "***"
  108. exit 1
  109. fi
  110. mkdir -p arch configs
  111. # defconfig for Normal:
  112. # pick lines without prefixes and lines starting '+' prefix
  113. # and rip the prefixes off.
  114. sed -n -e '/^[+A-Z]*:/!p' -e 's/^+[A-Z]*://p' $defconfig_path \
  115. > configs/.tmp_defconfig
  116. run_make_config .tmp_defconfig || {
  117. cleanup_after_defconfig
  118. exit 1
  119. }
  120. for img in $(get_enabled_subimages)
  121. do
  122. symbol=$(echo $img | cut -c 1 | tr '[a-z]' '[A-Z]')
  123. # defconfig for SPL, TPL:
  124. # pick lines with 'S', 'T' prefix and rip the prefixes off
  125. sed -n -e 's/^[+A-Z]*'$symbol'[A-Z]*://p' $defconfig_path \
  126. > configs/.tmp_defconfig
  127. run_make_config .tmp_defconfig $img || {
  128. cleanup_after_defconfig
  129. exit 1
  130. }
  131. done
  132. cleanup_after_defconfig
  133. }
  134. do_defconfig () {
  135. if [ "$KBUILD_DEFCONFIG" ]; then
  136. do_board_defconfig $KBUILD_DEFCONFIG
  137. echo "*** Default configuration is based on '$KBUILD_DEFCONFIG'"
  138. else
  139. run_make_config defconfig
  140. fi
  141. }
  142. do_board_felconfig () {
  143. do_board_defconfig ${1%%_felconfig}_defconfig
  144. if ! grep -q CONFIG_ARCH_SUNXI=y .config || ! grep -q CONFIG_SPL=y .config ; then
  145. echo "$progname: Cannot felconfig a non-sunxi or non-SPL platform" >&2
  146. exit 1
  147. fi
  148. sed -i -e 's/\# CONFIG_SPL_FEL is not set/CONFIG_SPL_FEL=y/g' \
  149. .config spl/.config
  150. }
  151. do_savedefconfig () {
  152. if [ -r "$KCONFIG_CONFIG" ]; then
  153. subimages=$(get_enabled_subimages)
  154. else
  155. subimages=
  156. fi
  157. run_make_config savedefconfig
  158. output_lines=
  159. # -r option is necessay because some string-type configs may include
  160. # backslashes as an escape character
  161. while read -r line
  162. do
  163. output_lines="$output_lines%$line"
  164. done < defconfig
  165. for img in $subimages
  166. do
  167. run_make_config savedefconfig $img
  168. symbol=$(echo $img | cut -c 1 | tr '[a-z]' '[A-Z]')
  169. unmatched=
  170. while read -r line
  171. do
  172. tmp=
  173. match=
  174. # "# CONFIG_FOO is not set" should not be divided.
  175. # Use "%" as a separator, instead of a whitespace.
  176. # "%" is unlikely to appear in defconfig context.
  177. save_IFS=$IFS
  178. IFS=%
  179. # coalesce common lines together
  180. for i in $output_lines
  181. do
  182. case "$i" in
  183. [+A-Z]*:$line)
  184. tmp="$tmp%$unmatched"
  185. i=$(echo "$i" | \
  186. sed -e "s/^\([^:]*\)/\1$symbol/")
  187. tmp="$tmp%$i"
  188. match=1
  189. ;;
  190. $line)
  191. tmp="$tmp%$unmatched"
  192. tmp="$tmp%+$symbol:$i"
  193. match=1
  194. ;;
  195. *)
  196. tmp="$tmp%$i"
  197. ;;
  198. esac
  199. done
  200. # Restore the default separator for the outer for loop.
  201. IFS=$save_IFS
  202. if [ "$match" ]; then
  203. output_lines="$tmp"
  204. unmatched=
  205. else
  206. unmatched="$unmatched%$symbol:$line"
  207. fi
  208. done < defconfig
  209. output_lines="$output_lines%$unmatched"
  210. done
  211. rm -f defconfig
  212. touch defconfig
  213. save_IFS=$IFS
  214. IFS=%
  215. for line in $output_lines
  216. do
  217. case "$line" in
  218. "")
  219. # do not output blank lines
  220. ;;
  221. *)
  222. echo $line >> defconfig
  223. ;;
  224. esac
  225. done
  226. IFS=$save_IFS
  227. }
  228. # Some sanity checks before running "make <objdir>/<target>",
  229. # where <objdir> should be either "spl" or "tpl".
  230. # Doing "make spl/menuconfig" etc. on a non-SPL board makes no sense.
  231. # It should be allowed only when ".config" exists and "CONFIG_SPL" is enabled.
  232. #
  233. # Usage:
  234. # check_enabled_sumbimage <objdir>/<target> <objdir>
  235. check_enabled_subimage () {
  236. case $2 in
  237. spl|tpl) ;;
  238. *)
  239. echo >&2 "***"
  240. echo >&2 "*** \"make $1\" is not supported."
  241. echo >&2 "***"
  242. exit 1
  243. ;;
  244. esac
  245. test -r "$KCONFIG_CONFIG" && get_enabled_subimages | grep -q $2 || {
  246. config=CONFIG_$(echo $2 | tr '[a-z]' '[A-Z]')
  247. echo >&2 "***"
  248. echo >&2 "*** Create \"$KCONFIG_CONFIG\" with \"$config\" enabled"
  249. echo >&2 "*** before \"make $1\"."
  250. echo >&2 "***"
  251. exit 1
  252. }
  253. }
  254. # Usage:
  255. # do_others <objdir>/<target>
  256. # The field "<objdir>/" is typically empy, "spl/", "tpl/" for Normal, SPL, TPL,
  257. # respectively.
  258. # The field "<target>" is a configuration target such as "config",
  259. # "menuconfig", etc.
  260. do_others () {
  261. target=${1##*/}
  262. if [ "$target" = "$1" ]; then
  263. objdir=
  264. else
  265. objdir=${1%/*}
  266. check_enabled_subimage $1 $objdir
  267. if [ -f "$objdir/$KCONFIG_CONFIG" ]; then
  268. timestamp_before=$(stat --printf="%Y" \
  269. $objdir/$KCONFIG_CONFIG)
  270. fi
  271. fi
  272. run_make_config $target $objdir
  273. if [ "$timestamp_before" -a -f "$objdir/$KCONFIG_CONFIG" ]; then
  274. timestamp_after=$(stat --printf="%Y" $objdir/$KCONFIG_CONFIG)
  275. if [ "$timestamp_after" -gt "$timestamp_before" ]; then
  276. # $objdir/.config has been updated.
  277. # touch .config to invoke "make silentoldconfig"
  278. touch $KCONFIG_CONFIG
  279. fi
  280. fi
  281. }
  282. progname=$(basename $0)
  283. target=$1
  284. case $target in
  285. *_defconfig)
  286. do_board_defconfig $target;;
  287. *_felconfig)
  288. do_board_felconfig $target;;
  289. *_config)
  290. # backward compatibility
  291. do_board_defconfig ${target%_config}_defconfig;;
  292. silentoldconfig)
  293. do_silentoldconfig;;
  294. defconfig)
  295. do_defconfig;;
  296. savedefconfig)
  297. do_savedefconfig;;
  298. *)
  299. do_others $target;;
  300. esac