]> git.kernelconcepts.de Git - karo-tx-redboot.git/blobdiff - build.sh
imx53: fix broken calculation of PLL_FREQ_MIN
[karo-tx-redboot.git] / build.sh
index 8e6ebb2c49752e9cc55a0c7cbf6585502c533d01..eca1640393ba18c56fe33e9c06aaf3569834b148 100644 (file)
--- a/build.sh
+++ b/build.sh
@@ -1,30 +1,54 @@
-#!/bin/sh
-options="cnqrR"
+#!/bin/bash
+options="cnqrRp:"
 release=false
-tools_dir=${HOME}/projects/RedBoot/ecos/tools/bin/
-src_dir=$PWD/packages
+tools_dir="$PWD/tools/bin"
+ecosconfig="$tools_dir/tools/configtool/standalone/common/ecosconfig"
+src_dir="$PWD/packages"
 quiet=false
 clean=false
 rebuild=false
 doit=true
 make_opts=
+pattern="*"
 
 error() {
+    rc=$?
     if [ -n "${target}" ];then
        echo "${target} build aborted"
     fi
+    return $rc
 }
 
-if [ `uname -s` = Linux ];then
-    PATH=/usr/local/arm/cross-gcc-1.2.0/i686-pc-linux-gnu/bin:$PATH
-#    PATH=/usr/local/arm/cross-gcc-3.4.3-2.6.17/i686-pc-linux-gnu/bin:$PATH
-#    PATH=/usr/local/arm/cross-gcc/i686-pc-linux-gnu/bin:$PATH
-    PATH=$tools_dir:$PATH
-else
-    PATH=$PWD/host/tools/configtool:$PWD/build/tools/src/tools/configtool/standalone/common/:$PATH
-fi
+build_host_tools() {
+    echo "Building host tools in $tools_dir"
+    # Debian packages tcl-dev and tk-dev are required for this build
+    local wd="$PWD"
+    local tcldirs="/usr/lib/tcl /usr/local/lib/tcl"
+    local config_opts=""
+    for d in $tcldirs;do
+       if [ -d "$d" ];then
+           config_opts="$config_opts --with-tcl=${d%lib/tcl}"
+           break
+       fi
+    done
+    if [ -z "$config_opts" ];then
+       for d in /usr/lib/tcl*;do
+           [ -d "$d" ] || continue
+           config_opts="$config_opts --with-tcl-version=${d##*tcl}"
+       done
+    fi
+    if [ -z "$config_opts" ];then
+       echo "No Tcl installation found"
+       exit 1
+    fi
 
-ECOSCONFIG=$tools_dir/ecosconfig
+    export TCL_INC_DIR="$(. /usr/lib/tclConfig.sh; echo $TCL_INCLUDE_SPEC | sed 's/^-I//')"
+    mkdir -p "$tools_dir"
+    cd "$tools_dir"
+    sh ../src/configure $config_opts
+    make
+    cd "$wd"
+}
 
 while getopts "$options" opt;do
     case $opt in
@@ -35,6 +59,9 @@ while getopts "$options" opt;do
            doit=false
            make_opts="${make_opts} -n"
            ;;
+       p)
+           pattern="$OPTARG"
+           ;;
        q)
            quiet=true
            ;;
@@ -54,20 +81,21 @@ while getopts "$options" opt;do
 done
 shift $(($OPTIND - 1))
 
-cmd_prefix=${CROSS_COMPILE-arm-linux-}
-
 if [ $# -gt 0 ];then
     targets="$@"
 else
-    targets=$(cd config; ls *.ecc)
+    targets=$(cd config;ls $pattern.ecc)
 fi
 
 set -e
+trap error 0
 conf_dir="$PWD/config"
 [ -d build ] || mkdir -p build
 cd build
 wd=$PWD
-trap error 0
+if [ ! -x "${ecosconfig}" ];then
+    build_host_tools
+fi
 for target in ${targets};do
     target="${target%.ecc}"
     if [ ! -d "${target}" ];then
@@ -82,8 +110,19 @@ for target in ${targets};do
     inst_dir="$PWD/${target}_install"
 
     $quiet || echo "Checking configuration ${target}"
+    cp -p "${conf_dir}/${target}.ecc" "${conf_dir}/${target}.ecc.bak"
     echo ecosconfig --srcdir="$src_dir" --config="${conf_dir}/${target}.ecc" check
-    $doit && ${ECOSCONFIG} --srcdir="$src_dir" --config="${conf_dir}/${target}.ecc" check
+    if $doit;then
+       stty -isig # prevent CTRL-C from trashing the config file
+       set +e
+       "${ecosconfig}" --srcdir="$src_dir" --config="${conf_dir}/${target}.ecc" check
+       if [ $? != 0 ];then
+           mv "${conf_dir}/${target}.ecc.bak" "${conf_dir}/${target}.ecc"
+           exit 1
+       fi
+       set -e
+       stty isig
+    fi
 
     if $rebuild;then
        echo "Removing build dir ${build_dir} and ${inst_dir}"
@@ -94,28 +133,39 @@ for target in ${targets};do
        echo mkdir "${build_dir}"
        $doit && mkdir "${build_dir}"
     fi
-    echo ecosconfig --srcdir="$src_dir" --prefix="${inst_dir}" --config="${conf_dir}/${target}.ecc" tree
+    $doit && cd "${build_dir}"
+    echo ecosconfig --srcdir="$src_dir" --prefix="${inst_dir}" \
+       --config="${conf_dir}/${target}.ecc" tree
     if $doit;then
-       cd "${build_dir}"
-       ${ECOSCONFIG} --srcdir="$src_dir" --prefix="${inst_dir}" --config="${conf_dir}/${target}.ecc" tree
-       rm -f ${target} ../../current && ln -svf ${target} ../../current
-       rm -f ../install && ln -svf ${target}_install ../install
-       rm -f ../build && ln -svf ${target}_build ../build
+       stty -isig
+       "${ecosconfig}" --srcdir="$src_dir" --prefix="${inst_dir}" \
+           --config="${conf_dir}/${target}.ecc" tree
+       stty isig
+       rm -f "${target}" ../../current && ln -svf "${target}" ../../current
+       rm -f ../install && ln -svf "${target}_install" ../install
+       rm -f ../build && ln -svf "${target}_build" ../build
     fi
 
     if $clean;then
        $quiet || echo "Cleaning up build tree for ${target}"
-       make ${make_opts} COMMAND_PREFIX=${cmd_prefix} clean
+       make ${make_opts} clean
     fi
 
     $quiet || echo "Compiling ${target}"
-    [ -d "${build_dir}" ] && make -C "${build_dir}" COMMAND_PREFIX=${cmd_prefix} ${make_opts}
+    [ -d "${build_dir}" ]
+    make -C "${build_dir}" ${make_opts}
 
     cd $wd
     if $doit && [ -s "${inst_dir}/bin/redboot.elf" ];then
-       ${cmd_prefix}objdump -d "${inst_dir}/bin/redboot.elf" | grep '<Now_in_SDRAM>:' | grep -v 'a1f00[89a-f]'
+       bootstrap_addr="$(${cmd_prefix}nm "${inst_dir}/bin/redboot.elf" \
+           | sed '/Now_in_SDRAM/!d;s/ .*$//')"
+       if [ -n "$bootstrap_addr" ] && ! echo "$bootstrap_addr" | grep -i '^[0-9a-f]\{4\}0[0-7]';then
+           echo "ERROR: Bootstrap does not fit into first NAND page!"
+           echo $bootstrap_addr
+           exit 1
+       fi
     fi
     echo "${target} build finished"
-done
 
+done
 trap - 0