unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / build.sh
index 8e6ebb2..e258acc 100644 (file)
--- a/build.sh
+++ b/build.sh
@@ -1,31 +1,56 @@
 #!/bin/sh
 options="cnqrR"
 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=
 
+cmd_prefix=${CROSS_COMPILE-arm-926ejs-linux-gnu-}
+
 error() {
     if [ -n "${target}" ];then
        echo "${target} build aborted"
     fi
 }
 
+build_host_tools() {
+    echo "Building host tools in $tools_dir"
+
+    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
+           config_opts="$config_opts --with-tcl-version=${d##*tcl}"
+       done
+    fi
+    if [ -z "$config_opts" ];then
+       echo "No Tcl installation found"
+       exit 1
+    fi
+
+    mkdir -p "$tools_dir"
+    cd "$tools_dir"
+    sh ../src/configure $config_opts
+    make
+    cd "$wd"
+}
+
 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
+    PATH="/usr/local/arm/cross-gcc-4.2.0/i686-pc-linux-gnu/bin:$PATH"
 fi
 
-ECOSCONFIG=$tools_dir/ecosconfig
-
 while getopts "$options" opt;do
     case $opt in
        c)
@@ -54,8 +79,6 @@ while getopts "$options" opt;do
 done
 shift $(($OPTIND - 1))
 
-cmd_prefix=${CROSS_COMPILE-arm-linux-}
-
 if [ $# -gt 0 ];then
     targets="$@"
 else
@@ -63,11 +86,14 @@ else
 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 +108,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,13 +131,17 @@ 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
@@ -109,13 +150,22 @@ for target in ${targets};do
     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}" COMMAND_PREFIX=${cmd_prefix} ${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 ! echo "$bootstrap_addr" | grep -i '^[0-9a-f]\{4\}0[0-7]';then
+#      if ! ${cmd_prefix}nm "${inst_dir}/bin/redboot.elf" \
+#          | grep 'Now_in_SDRAM' | 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