[U-Boot] [RFCv2a PATCH 02/14] Do not apply: tools: add genkconfig

Masahiro Yamada yamada.m at jp.panasonic.com
Tue May 27 08:19:46 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/*_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>
---

 tools/genkconfig       | 244 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/print_allconfigs |  77 ++++++++++++++++
 2 files changed, 321 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..bed188d
--- /dev/null
+++ b/tools/genkconfig
@@ -0,0 +1,244 @@
+#!/bin/bash
+
+set -e
+
+rm -rf configs
+mkdir -p configs/spl configs/tpl
+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 ()
+{
+	if [ "$spl_enable" = "y" ]; then
+		echo >> $defconfig "CONFIG_SPL=y"
+	fi
+
+	if [ "$tpl_enable" = "y" ]; then
+		echo >> $defconfig "CONFIG_TPL=y"
+	fi
+
+	echo >> $defconfig "CONFIG_$ARCH=y"
+
+	if [ "$arch" != sandbox ]; then
+		echo >> $defconfig "CONFIG_$TARGET=y"
+	fi
+}
+
+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
+
+	if [ "$extra_options" ]; then
+		# O2MNT_O2M110, O2MNT_O2M112, O2MNT_O2M113 boards include
+		# double-quotations in the extra option field.
+		# We must escape them.
+		echo >> $kconfig "config SYS_EXTRA_OPTIONS"
+		echo >> $kconfig "	string"
+		echo >> $kconfig "	default \"$(echo "$extra_options" | sed -e 's/"/\\"/g')\""
+		echo >> $kconfig
+	fi
+
+	echo >> $kconfig "endif"
+}
+
+sed -e 's/Orphan/Active/' -e '/#/d' boards.cfg | \
+tools/reformat.py -i -d '-' -s 8 |
+while read -r status arch cpu soc vendor board target options maintainers
+do
+	case $status in
+	Active|Orphan) ;;
+	*)             continue ;;
+	esac
+
+	echo "processing $target"
+
+	if [ "$arch" = "aarch64" ]; then
+		arch=arm
+	fi
+
+	# Tegra SoCs have different "cpu" and "spl_cpu"
+	spl_cpu=${cpu#*:}
+	cpu=${cpu%:*}
+
+	if [ "$board" = "-" ]; then
+		board=$target
+	fi
+
+	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
+
+	TARGET=$(echo TARGET_${target^^} | sed -e 's/-/_/g')
+	ARCH=$(get_arch $arch)
+
+	defconfig=configs/${target}_defconfig
+	write_defconfig
+
+	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" ]; then
+		write_kconfig
+		echo "source \"$kconfig\"" >> arch/$arch/Kconfig2
+		echo >> arch/$arch/Kconfig "config $TARGET"
+		echo >> arch/$arch/Kconfig "	bool \"Support $target\""
+		echo >> arch/$arch/Kconfig
+	fi
+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