[U-Boot] [PATCH v3 02/11] Do not apply: tools: add genkconfig

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


 ========================================
 Do not apply this patch to the main line
 ========================================

 What is this tool?
 ------------------

This tool converts boards.cfg to defconfig and Kconfig files.

It automatically generates
 - arch/${ARCH}/Kconfig
 - board/${VENDOR}/${BOARD}/Kconfig
 - board/${BOARD}/Kconfig
 - configs/${TARGET_BOARD}_defconfig

 How to use?
 -----------

Open tools/print_allconfigs with an editor.

Adjust cross compilers part for your environment.

  # Specify your favoriate cross tools
  CROSS_COMPILE_ARC=arc-linux-
  CROSS_COMPILE_AARCH64=aarch64-linux-gnu-
  CROSS_COMPILE_ARM=arm-unknown-linux-gnueabi-
   [snip]
  CROSS_COMPILE_X86=i386-linux-

And then, run "tools/genkconfig".

 Why is this patch here?
 -----------------------

The file boards.cfg is touched very frequently.
All the time, new/old boards are being added/removed.

The next commit was generated based on the u-boot/master at the time
I posted it.
It will become out-dated soon.

You can update it with this tool.

Signed-off-by: Masahiro Yamada <yamada.m at jp.panasonic.com>
---

Changes in v3:
 - Create SPL defconfig into configs/<board>_spl_defconfig
   instead of conigs/spl/<board>_defconfig. Like the same for TPL.
   Because I want to handle Falcon boot more genericlly.
   If you build only configs/<board>_spl_defconfig, it is Falcon boot.
 - Create board select menu based on the 8th field of boards.cfg.
   It is common that many entries (= 7th field) share the same
   config header. So this change help to reduce the code redandancy.

Changes in v2:
 - Do not output CONFIG_BOARD_MAINTAINERS and CONFIG_BOARD_STATUS
 - Delete board/Kconfig and move "source board/*/*/Kconfig"
   statements to arch/*/Kconfig.

 tools/genkconfig       | 299 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/print_allconfigs |  77 +++++++++++++
 2 files changed, 376 insertions(+)
 create mode 100755 tools/genkconfig
 create mode 100755 tools/print_allconfigs

diff --git a/tools/genkconfig b/tools/genkconfig
new file mode 100755
index 0000000..3aaec2a
--- /dev/null
+++ b/tools/genkconfig
@@ -0,0 +1,299 @@
+#!/bin/bash
+
+set -e
+
+rm -rf configs
+mkdir configs
+find board -name Kconfig | xargs rm -f
+
+get_arch()
+{
+	case "$arch" in
+		powerpc) echo PPC;;
+		*)       echo ${1^^};;
+	esac
+}
+
+arch_list="arc arm avr32 blackfin m68k microblaze mips nds32 nios2 openrisc powerpc sandbox sh sparc x86"
+
+for arch in $arch_list
+do
+	ARCH=$(get_arch $arch)
+
+	case "$arch" in
+		blackfin) menu="Blackfin";;
+		m68k) menu="M68000";;
+		microblaze) menu="MicroBlaze";;
+		nios2) menu="Nios II";;
+		openrisc) menu="OpenRISC";;
+		powerpc) menu="PowerPC";;
+		sandbox) menu="Sandbox";;
+		sh) menu="SuperH";;
+		x86) menu="x86";;
+		*) menu=${arch^^};;
+	esac
+
+cat <<EOF > arch/$arch/Kconfig
+menu "$menu architecture"
+	depends on $ARCH
+
+config SYS_ARCH
+	string
+	default "$arch"
+
+EOF
+
+if [ "$arch" = "sandbox" ]; then
+cat <<EOF >> arch/$arch/Kconfig
+config SYS_CPU
+	string
+	default "$arch"
+
+config SYS_BOARD
+	string
+	default "$arch"
+
+config SYS_CONFIG_NAME
+	string
+	default "$arch"
+EOF
+else
+cat <<EOF >> arch/$arch/Kconfig
+choice
+	prompt "Target select"
+
+EOF
+fi
+
+done
+
+write_defconfig ()
+{
+	echo >> $defconfig "CONFIG_$ARCH=y"
+	if [ "$arch" != sandbox ]; then
+		echo >> $defconfig "CONFIG_$TARGET=y"
+	fi
+}
+
+write_main_defconfig()
+{
+	if [ "$tpl_enable" = "y" ]; then
+		echo >> $defconfig "CONFIG_SUBIMAGES=\"spl:${target}_spl_defconfig,tpl:${target}_tpl_defconfig\""
+	elif [ "$spl_enable" = "y" ]; then
+		echo >> $defconfig "CONFIG_SUBIMAGES=\"spl:${target}_spl_defconfig\""
+	fi
+
+	if [ "$spl_enable" = "y" ]; then
+		echo >> $defconfig "CONFIG_SPL=y"
+	fi
+
+	if [ "$tpl_enable" = "y" ]; then
+		echo >> $defconfig "CONFIG_TPL=y"
+	fi
+
+	write_defconfig
+
+	if [ "$extra_options" ]; then
+		# O2MNT_O2M110, O2MNT_O2M112, O2MNT_O2M113 boards include
+		# double-quotations in the extra option field.
+		# We must escape them.
+		echo >> $defconfig "CONFIG_SYS_EXTRA_OPTIONS=\"$(echo "$extra_options" | sed -e 's/"/\\"/g')\""
+	fi
+}
+
+write_spl_defconfig ()
+{
+	echo >> $defconfig "CONFIG_SPL=y"
+
+	if [ "$tpl_enable" = "y" ]; then
+		echo >> $defconfig "CONFIG_TPL=y"
+	fi
+
+	echo >> $defconfig "CONFIG_SPL_BUILD=y"
+
+	write_defconfig
+}
+
+write_tpl_defconfig ()
+{
+	echo >> $defconfig "CONFIG_SPL=y"
+	echo >> $defconfig "CONFIG_TPL=y"
+	echo >> $defconfig "CONFIG_SPL_BUILD=y"
+	echo >> $defconfig "CONFIG_TPL_BUILD=y"
+
+	write_defconfig
+}
+
+write_kconfig ()
+{
+	echo >> $kconfig
+	echo >> $kconfig "if $TARGET"
+	echo >> $kconfig
+
+	echo >> $kconfig "config SYS_CPU"
+	echo >> $kconfig "	string"
+	if [ "$spl_cpu" != "$cpu" ]; then
+		echo >> $kconfig "	default \"$spl_cpu\" if SPL_BUILD"
+		echo >> $kconfig "	default \"$cpu\" if !SPL_BUILD"
+	else
+		echo >> $kconfig "	default \"$cpu\""
+	fi
+	echo >> $kconfig
+
+	echo >> $kconfig "config SYS_BOARD"
+	echo >> $kconfig "	string"
+	echo >> $kconfig "	default \"$board\""
+	echo >> $kconfig
+
+	if [ "$vendor" != "-" ]; then
+		echo >> $kconfig "config SYS_VENDOR"
+		echo >> $kconfig "	string"
+		echo >> $kconfig "	default \"$vendor\""
+		echo >> $kconfig
+	fi
+
+	if [ "$soc" != "-" ]; then
+		echo >> $kconfig "config SYS_SOC"
+		echo >> $kconfig "	string"
+		echo >> $kconfig "	default \"$soc\""
+		echo >> $kconfig
+	fi
+
+	echo >> $kconfig "config SYS_CONFIG_NAME"
+	echo >> $kconfig "	string"
+	echo >> $kconfig "	default \"$config_name\""
+	echo >> $kconfig
+
+	echo >> $kconfig "endif"
+}
+
+sed -e 's/Orphan/Active/' -e 's/aarch64/arm/' -e '/#/d' -e '/^$/d' boards.cfg | \
+awk '$6 == "-" { $6 = $7 } $8 == "-" { $8 = $7 } { tmp = $7; $7 = $8; $8 = tmp; print }' | \
+sed -e 's/arm720t/arm0720t/' -e 's/arm920t/arm0920t/' \
+-e 's/arm926ejs/arm0926ejs/' -e 's/arm946t/arm0946t/' \
+-e 's/tegra20/tegra020/' -e 's/tegra30/tegra030/' | \
+tools/reformat.py -i -d '-' -s 8 | \
+sed -e 's/arm0720t/arm720t/' -e 's/arm0920t/arm920t/' \
+-e 's/arm0926ejs/arm926ejs/' -e 's/arm0946t/arm946t/' \
+-e 's/tegra020/tegra20/' -e 's/tegra030/tegra30/' |
+awk '{ tmp = $7; $7 = $8; $8 = tmp; print }' | \
+tee boards.cfg2 | \
+while read -r status arch cpu soc vendor board target options maintainers
+do
+
+	echo "processing $target"
+
+	# Tegra SoCs have different "cpu" and "spl_cpu"
+	spl_cpu=${cpu#*:}
+	cpu=${cpu%:*}
+
+	if [ "$board" = "<none>" ]; then
+		board=
+	fi
+
+	config_name=$target
+	extra_options=
+
+	[ "$options" != "-" ] && {
+		tmp="${options%:*}"
+		if [ "$tmp" ] ; then
+			config_name="$tmp"
+		fi
+
+		if [ "${tmp}" != "$options" ] ; then
+			extra_options=${options#*:}
+		fi
+	}
+
+	all_configs=$(tools/print_allconfigs $target)
+
+	if echo $all_configs | grep -q "CONFIG_SPL=y"; then
+		spl_enable=y
+	else
+		spl_enable=
+	fi
+
+	if echo $all_configs | grep -q "CONFIG_TPL=y"; then
+		tpl_enable=y
+	else
+		tpl_enable=
+	fi
+
+	if [ "$vendor" = "armltd" ]; then
+		prompt=$target
+	elif [ "$config_name" = "lacie_kw" -o "$config_name" = "spear3xx_evb" \
+		-o "$config_name" = "spear6xx_evb" ]; then
+		prompt=$board
+	else
+		if [ "${config_name^^}" = "${target^^}" ]; then
+			prompt=$target
+		else
+			prompt=$config_name
+		fi
+	fi
+
+	TARGET=$(echo TARGET_${prompt^^} | sed -e 's/-/_/g')
+
+	ARCH=$(get_arch $arch)
+
+	defconfig=configs/${target}_defconfig
+	write_main_defconfig
+
+	if [ "$spl_enable" = "y" ]; then
+		defconfig=configs/${target}_spl_defconfig
+		write_spl_defconfig
+	fi
+
+	if [ "$tpl_enable" = "y" ]; then
+		defconfig=configs/${target}_tpl_defconfig
+		write_tpl_defconfig
+	fi
+
+	if [ -z "$board" ]; then
+		kconfig=board/$vendor/Kconfig
+	elif [ "$vendor" != "-" ]; then
+		kconfig=board/$vendor/$board/Kconfig
+	else
+		kconfig=board/$board/Kconfig
+	fi
+
+	if [ "$target" != "sandbox" -a \( "$vendor" = "armltd" -o \
+		"$config_name" != "$config_name_prev" -o "$board" != "$board_prev" \) ]; then
+		write_kconfig
+		echo "source \"$kconfig\"" >> arch/$arch/Kconfig2
+		echo >> arch/$arch/Kconfig "config $TARGET"
+		echo >> arch/$arch/Kconfig "	bool \"Support $prompt\""
+		echo >> arch/$arch/Kconfig
+	fi
+
+	config_name_prev=$config_name
+	board_prev=$board
+done
+
+for arch in $arch_list
+do
+
+if [ "$arch" != sandbox ]; then
+cat<<EOF >> arch/$arch/Kconfig
+endchoice
+
+EOF
+
+sort arch/$arch/Kconfig2 | uniq >> arch/$arch/Kconfig
+rm arch/$arch/Kconfig2
+
+fi
+
+cat<<EOF >> arch/$arch/Kconfig
+
+endmenu
+EOF
+
+done
+
+for i in $(find board -path "board/*/Kconfig")
+do
+	# dropping the empty line at the beginning
+	sed -e "1d" $i > $i.tmp
+	mv $i.tmp $i
+done
diff --git a/tools/print_allconfigs b/tools/print_allconfigs
new file mode 100755
index 0000000..e00c333
--- /dev/null
+++ b/tools/print_allconfigs
@@ -0,0 +1,77 @@
+#!/bin/sh
+# Print all config macros for specified board
+#
+# Usage: tools/getconfigs <board>
+
+# Specify your favoriate cross tools
+CROSS_COMPILE_ARC=arc-linux-
+CROSS_COMPILE_AARCH64=aarch64-linux-gnu-
+CROSS_COMPILE_ARM=arm-unknown-linux-gnueabi-
+CROSS_COMPILE_AVR32=avr32-linux-
+CROSS_COMPILE_BLACKFIN=bfin-elf-
+CROSS_COMPILE_M68K=m68k-linux-
+CROSS_COMPILE_MICROBLAZE=microblaze-linux-
+CROSS_COMPILE_MIPS=mips-linux-
+CROSS_COMPILE_NDS32=nds32le-linux-
+CROSS_COMPILE_NIOS2=nios2-linux-
+CROSS_COMPILE_OPENRISC=or32-linux-
+CROSS_COMPILE_POWERPC=powerpc-linux-
+CROSS_COMPILE_SH=sh4-gentoo-linux-gnu-
+CROSS_COMPILE_SPARC=sparc-elf-
+CROSS_COMPILE_X86=i386-linux-
+
+if [ ! -r boards.cfg ]; then
+	echo >&2 "boards.cfg: not found"
+	echo >&2 "Run \"tools/print_allconfigs <target_board>\" at the top directory"
+	echo >&2 "Exit."
+	exit 1
+fi
+
+if [ $# != 1 ]; then
+	echo >&2 "Usage: tools/print_allconfigs <target_board>"
+	echo >&2 "Exit."
+	exit 2
+fi
+
+target=$1
+
+
+get_arch() {
+	local target=$1
+
+	awk '$7 == "'$target'" { print $2 }' boards.cfg
+}
+
+arch=$(get_arch $target)
+
+if [ -z "$arch" ]; then
+	echo >&2 "$target: target board not found in boards.cfg"
+	echo >&2 "Exit."
+	exit 3
+fi
+
+ARCH=$(echo $arch | tr '[:lower:]' '[:upper:]')
+
+eval CROSS_COMPILE=\$CROSS_COMPILE_$ARCH
+
+export CROSS_COMPILE
+
+rm -f include/autoconf.mk
+
+make ${target}_config include/autoconf.mk >/dev/null || { \
+	echo >&2 "make failed."
+	echo >&2 "Please check if CROSS_COMPILE_<ARCH> is correctly set."
+	echo >&2 "Exit."
+	exit 4
+}
+
+if [ ! -f include/autoconf.mk ]; then
+	echo >&2 "include/autoconf.mk: not found."
+	echo >&2 "Internal error."
+	echo >&2 "Exit."
+	exit 5
+fi
+
+cat include/autoconf.mk
+
+exit 0
-- 
1.9.1



More information about the U-Boot mailing list