From patchwork Tue May 27 06:27:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 352711 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 0E75514008A for ; Tue, 27 May 2014 16:28:50 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3775D4B7C4; Tue, 27 May 2014 08:28:47 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UOfXhd55syre; Tue, 27 May 2014 08:28:45 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E4BF34B7B9; Tue, 27 May 2014 08:28:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CEE96A73DC for ; Tue, 27 May 2014 08:28:06 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zYESL1qqUDWP for ; Tue, 27 May 2014 08:28:03 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from smtp.mei.co.jp (smtp.mei.co.jp [133.183.100.20]) by theia.denx.de (Postfix) with ESMTP id 4ED3F4B7A9 for ; Tue, 27 May 2014 08:27:56 +0200 (CEST) Received: from mail-gw.jp.panasonic.com ([157.8.1.157]) by smtp.mei.co.jp (8.12.11.20060614/3.7W/kc-maile11) with ESMTP id s4R6Rkdx029475; Tue, 27 May 2014 15:27:46 +0900 (JST) Received: from epochmail.jp.panasonic.com ([157.8.1.130]) by mail.jp.panasonic.com (8.11.6p2/3.7W/kc-maili16) with ESMTP id s4R6RkM17660; Tue, 27 May 2014 15:27:46 +0900 Received: by epochmail.jp.panasonic.com (8.12.11.20060308/3.7W/lomi14) id s4R6RkIr025525; Tue, 27 May 2014 15:27:46 +0900 Received: from poodle by lomi14.jp.panasonic.com (8.12.11.20060308/3.7W) with ESMTP id s4R6Rkas025507; Tue, 27 May 2014 15:27:46 +0900 Received: from beagle.diag.org (beagle.diag.org [10.184.179.16]) by poodle (Postfix) with ESMTP id 41B702740043; Tue, 27 May 2014 15:27:46 +0900 (JST) From: Masahiro Yamada To: u-boot@lists.denx.de Date: Tue, 27 May 2014 15:27:31 +0900 Message-Id: <1401172063-17281-3-git-send-email-yamada.m@jp.panasonic.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1401172063-17281-1-git-send-email-yamada.m@jp.panasonic.com> References: <1401172063-17281-1-git-send-email-yamada.m@jp.panasonic.com> Cc: Tom Rini Subject: [U-Boot] [RFCv2b PATCH 02/14] Do not apply: tools: add genkconfig X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de ======================================== 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 - arch/${ARCH}/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 --- tools/genkconfig | 239 +++++++++++++++++++++++++++++++++++++++++++++++++ tools/print_allconfigs | 77 ++++++++++++++++ 2 files changed, 316 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..14126ab --- /dev/null +++ b/tools/genkconfig @@ -0,0 +1,239 @@ +#!/bin/bash + +set -e + +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 + rm -rf arch/$arch/configs + mkdir arch/$arch/configs + + 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 < arch/$arch/Kconfig +config $ARCH + bool + default y + +config SYS_ARCH + string + default "$arch" + +EOF + +if [ "$arch" = "sandbox" ]; then +cat <> 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 <> 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 + + 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" = "" ]; 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=arch/$arch/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<> arch/$arch/Kconfig +endchoice + +EOF + +sort arch/$arch/Kconfig2 | uniq >> arch/$arch/Kconfig +rm arch/$arch/Kconfig2 + +fi + +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 + +# 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 \" at the top directory" + echo >&2 "Exit." + exit 1 +fi + +if [ $# != 1 ]; then + echo >&2 "Usage: tools/print_allconfigs " + 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_ 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