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

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

defconfig files for all target boards will be added in the next commit.

We already have more than 1000 boards.

Writing all defconfig files by hand is not realistic.

Instead, I wrote this ugly scripts to convert boards.cfg into defconfig.

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

Check out this commit as HEAD.

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/gendefconfigs".

  $ tools/gendefconfigs
  generating configs/vexpress_aemv8a_defconfig
  generating configs/axs101_defconfig
  generating configs/arcangel4_defconfig
  generating configs/arcangel4-be_defconfig
  generating configs/integratorcp_cm1136_defconfig
  generating configs/imx31_phycore_defconfig
  generating configs/qong_defconfig
  generating configs/mx31pdk_defconfig
    ...

Every defconfig files under configs/, spl/configs/, tpl/configs/
will be created/updated depending on boards.cfg.

 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 defconfig files by yourself with this tool.

And We must re-generate defconfig files from the latest boards.cfg
just before applying this series.

I expect Tom will run this tool to make sure up-to-date defconfigs
to be merged.

Signed-off-by: Masahiro Yamada <yamad...@jp.panasonic.com>
---

 tools/gendefconfigs    | 271 +++++++++++++++++++++++++++++++++++++++++++++++++
 tools/print_allconfigs |  77 ++++++++++++++
 2 files changed, 348 insertions(+)
 create mode 100755 tools/gendefconfigs
 create mode 100755 tools/print_allconfigs

diff --git a/tools/gendefconfigs b/tools/gendefconfigs
new file mode 100755
index 0000000..757ff92
--- /dev/null
+++ b/tools/gendefconfigs
@@ -0,0 +1,271 @@
+#!/bin/sh
+# Generate configs/*_defconfig from boards.cfg
+# Usage: run "tools/genconfigs at the top directory
+
+set -e
+
+rm -rf configs spl/configs tpl/configs
+mkdir -p configs spl/configs tpl/configs
+
+if [ ! -r boards.cfg ]; then
+       echo >&2 "boards.cfg: not found"
+       echo >&2 "Run \"tools/genconfigs\" at the top directory"
+       echo >&2 "Exit."
+       exit 1
+fi
+
+get_config_arch () {
+       case $1 in
+               arc)        echo ARC;;
+               aarch64)    echo ARM;;
+               arm)        echo ARM;;
+               avr32)      echo AVR32;;
+               blackfin)   echo BLACKFIN;;
+               m68k)       echo M68K;;
+               microblaze) echo MICROBLAZE;;
+               mips)       echo MIPS;;
+               nds32)      echo NDS32;;
+               nios2)      echo NIOS2;;
+               openrisc)   echo OPENRISC;;
+               powerpc)    echo PPC;;
+               sandbox)    echo ;; # sandbox is default so return nothing
+               sh)         echo SH;;
+               sparc)      echo SPARC;;
+               x86)        echo X86;;
+               *)          echo >&2 "Unknow arch $1. Exit."; exit 1;;
+       esac
+}
+
+get_config_cpu () {
+       case $1 in
+               mcf5227x)  echo ;; # MCF5227x is default for M68K
+               mcf523x)   echo MCF523x;;
+               mcf52x2)
+                       if echo $all_configs | grep -q "CONFIG_MCF52x2=y"; then
+                               echo MCF52x2;
+                       elif echo $all_configs | grep -q "CONFIG_MCF520x=y"; 
then
+                               echo MCF520x;
+                       else
+                               echo >%2 "Unknown cpu $1. Exit." exit 1;
+                       fi
+                       ;;
+               mcf532x)
+                       if echo $all_configs | grep -q "CONFIG_MCF532x=y"; then
+                               echo MCF532x;
+                       elif echo $all_configs | grep -q "CONFIG_MCF5301x=y"; 
then
+                               echo MCF5301x;
+                       else
+                               echo >%2 "Unknown cpu $1. Exit." exit 1;
+                       fi
+                       ;;
+               mcf5445x)
+                       if echo $all_configs | grep -q "CONFIG_MCF5445x=y"; then
+                               echo MCF5445x;
+                       elif echo $all_configs | grep -q "CONFIG_MCF5441x=y"; 
then
+                               echo MCF5441x;
+                       else
+                               echo >%2 "Unknown cpu $1. Exit." exit 1;
+                       fi
+                       ;;
+               mcf547x_8x) echo MCF547x_8x;;
+               mips32)    echo ;; # MIPS32 is default for MIPS
+               mips64)    echo MIPS64;;
+               ppc4xx)    echo 4xx;;
+               74xx_7xx)  echo 74xx_7xx;;
+               mpc512x)   echo MPC512X;;
+               mpc5xx)    echo 5xx;;
+               mpc5xxx)   echo MPC5xxx;;
+               mpc824x)   echo MPC824X;;
+               mpc8260)   echo MPC8260;;
+               mpc83xx)   echo MPC83xx;;
+               mpc85xx)   echo MPC85xx;;
+               mpc86xx)   echo MPC86xx;;
+               mpc8xx)    echo ;; # 8xx is default for PPC
+               ppc4xx)    echo 4xx;;
+               sh2)       echo ;; # SH2 is default for SH
+               sh3)       echo SH3;;
+               sh4)       echo SH4;;
+               leon2)     echo ;; # LEN2 is default for Sparc
+               leon3)     echo LEON3;;
+               *) ;;
+       esac
+}
+
+create_main_defconfig () {
+       outfile=configs/${target}_defconfig
+
+       echo "generating $outfile"
+
+       if [ "$spl_enable" = "y" ]; then
+               echo "CONFIG_SPL=y" >> $outfile
+       fi
+
+       if [ "$tpl_enable" = "y" ]; then
+               echo "CONFIG_TPL=y" >> $outfile
+       fi
+
+       ARCH=$(get_config_arch $arch)
+
+       if [ -n "$ARCH" ]; then
+               echo "CONFIG_$ARCH=y" >> $outfile
+       fi
+
+       CPU=$(get_config_cpu $cpu)
+
+       if [ -n "$CPU" ]; then
+               echo "CONFIG_$CPU=y" >> $outfile
+       fi
+
+       if [ "$ARCH" = "ARM" ]; then
+               echo "CONFIG_SYS_CPU=\"$cpu\"" >> $outfile
+       fi
+
+       if [ "$soc" != "-" ]; then
+               echo "CONFIG_SOC_DIR=y" >> $outfile
+               echo "CONFIG_SYS_SOC=\"$soc\"" >> $outfile
+       fi
+
+       if [ "$board" != "<none>" ]; then
+               echo "CONFIG_SYS_BOARD=\"$board\"" >> $outfile
+       fi
+
+       if [ "$vendor" != "-" ]; then
+               echo "CONFIG_VENDOR_DIR=y" >> $outfile
+               echo "CONFIG_SYS_VENDOR=\"$vendor\"" >> $outfile
+       fi
+
+       echo "CONFIG_SYS_CONFIG_NAME=\"$config_name\"" >> $outfile
+
+       if [ -n "$extra_options" ]; then
+               # O2MNT_O2M110, O2MNT_O2M112, O2MNT_O2M113 boards include
+               # double-quotations in the extra option field.
+               # We must escape them.
+               echo "CONFIG_SYS_EXTRA_OPTIONS=\"$(echo "$extra_options" | sed 
-e 's/"/\\"/g')\"" >> $outfile
+       fi
+
+       if [ "$maintainer" != "-" ]; then
+               echo "CONFIG_BOARD_MAINTAINER=\"$maintainer\"" >> $outfile
+       fi
+
+       if [ "$status" = "Orphan" ]; then
+               echo "CONFIG_ORPHAN_BOARD=y" >> $outfile
+       fi
+}
+
+create_spl_tpl_defconfig () {
+       echo "generating $outfile"
+
+       ARCH=$(get_config_arch $arch)
+
+       if [ -n "$ARCH" ]; then
+               echo "CONFIG_$ARCH=y" >> $outfile
+       fi
+
+       CPU=$(get_config_cpu $spl_cpu)
+
+       if [ -n "$CPU" ]; then
+               echo "CONFIG_$CPU=y" >> $outfile
+       fi
+
+       if [ "$ARCH" = "ARM" ]; then
+               echo "CONFIG_SYS_CPU=\"$spl_cpu\"" >> $outfile
+       fi
+
+       if [ "$soc" != "-" ]; then
+               echo "CONFIG_SOC_DIR=y" >> $outfile
+               echo "CONFIG_SYS_SOC=\"$soc\"" >> $outfile
+       fi
+
+       if [ "$board" != "<none>" ]; then
+               echo "CONFIG_SYS_BOARD=\"$board\"" >> $outfile
+       fi
+
+       if [ "$vendor" != "-" ]; then
+               echo "CONFIG_VENDOR_DIR=y" >> $outfile
+               echo "CONFIG_SYS_VENDOR=\"$vendor\"" >> $outfile
+       fi
+
+       echo "CONFIG_SYS_CONFIG_NAME=\"$config_name\"" >> $outfile
+}
+
+create_spl_defconfig () {
+       outfile=spl/configs/${target}_defconfig
+       create_spl_tpl_defconfig
+}
+
+create_tpl_defconfig () {
+       outfile=tpl/configs/${target}_defconfig
+       create_spl_tpl_defconfig
+}
+
+while read line
+do
+       # skip comments
+       if echo $line | grep -q '^#'; then
+               continue
+       fi
+
+       # skip empty lines
+       if [ -z "$line" ]; then
+               continue
+       fi
+
+       set $line
+
+       status=$1
+
+       arch=$2
+       # Tegra SoCs have different "cpu" and "spl_cpu"
+       cpu=${3%:*}
+       spl_cpu=${3#*:}
+
+       soc=$4
+       vendor=$5
+       if [ "$6" = "-" ]; then
+               board=$7
+       else
+               board=$6
+       fi
+       target=$7
+       config_name=$7
+       extra_options=
+       defconfig_file="${target}_defconfig"
+       [ $# -gt 7 ] && [ "$8" != "-" ] && {
+               tmp="${8%:*}"
+               if [ "$tmp" ] ; then
+                       config_name="$tmp"
+               fi
+
+               if [ "${tmp}" != "$8" ] ; then
+                       extra_options=${8#*:}
+               fi
+       }
+
+       shift; shift; shift; shift; shift; shift; shift; shift;
+       maintainer="$@"
+
+       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
+
+       create_main_defconfig
+
+       if [ "$spl_enable" = "y" ]; then
+               create_spl_defconfig
+       fi
+
+       if [ "$tpl_enable" = "y" ]; then
+               create_tpl_defconfig
+       fi
+
+done < boards.cfg
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.8.3.2

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to