root/trunk/coreboot-v2/util/abuild/abuild

Revision 3623, 13.3 kB (checked in by mjones, 6 days ago)

Add an abuild command line option for -fno-stack-protect for toolchains that might require it.

Signed-off-by: Marc Jones <marc.jones@…>
Acked-by: Stefan Reinauer <stepan@…>

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/bin/bash
2#
3#  coreboot autobuild
4#
5#  This script builds coreboot images for all available targets.
6#
7#  (C) 2004 by Stefan Reinauer <stepan@openbios.org>
8#  (C) 2006-2008 by coresystems GmbH <info@coresystems.de>
9#
10#  This file is subject to the terms and conditions of the GNU General
11#  Public License. See the file COPYING in the main directory of this
12#  archive for more details.
13#     
14
15#set -x # Turn echo on....
16
17ABUILD_DATE="May 27th, 2008"
18ABUILD_VERSION="0.7"
19
20# Where shall we place all the build trees?
21TARGET=$( pwd )/coreboot-builds
22XMLFILE=$( pwd )/abuild.xml
23
24# path to payload. Should be more generic
25PAYLOAD=/dev/null
26
27# Lines of error context to be printed in FAILURE case
28CONTEXT=5
29
30TESTSUBMISSION="http://qa.coreboot.org/deployment/send.php"
31
32# Number of CPUs to compile on per default
33cpus=1
34
35# One might want to adjust these in case of cross compiling
36MAKE="make"
37PYTHON=python
38
39# this can be changed to xml by -x
40mode=text
41
42# silent mode.. no compiler calls, only warnings in the log files.
43# this is disabled per default but can be enabled with -s
44silent=
45
46# stackprotect mode enabled by -ns option.
47stackprotect=false
48
49ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
50        -e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
51        -e "s/Power Macintosh/ppc/"`
52
53trap interrupt INT
54
55function interrupt
56{
57        printf "\n$0: execution interrupted manually.\n"
58        if [ "$mode" == "xml" ]; then
59                printf "$0: deleting incomplete xml output file.\n"
60        fi
61        exit 1
62}
63
64function debug
65{
66        test "$verbose" == "true" && printf "$*\n"
67}
68
69function xml
70{
71        test "$mode" == "xml" && printf "$*\n" >> $XMLFILE
72}
73
74function xmlfile
75{
76        test "$mode" == "xml" && {
77                printf '<![CDATA[\n'
78                cat $1
79                printf ']]>\n'
80        } >> $XMLFILE
81}
82
83
84
85function vendors
86{
87        # make this a function so we can easily select
88        # without breaking readability
89        ls -1 "$LBROOT/src/mainboard" | grep -v CVS
90}
91
92function mainboards
93{
94        # make this a function so we can easily select
95        # without breaking readability
96       
97        VENDOR=$1
98       
99        ls -1 $LBROOT/src/mainboard/$VENDOR | grep -v CVS
100}
101
102function architecture
103{
104        VENDOR=$1
105        MAINBOARD=$2
106        cat $LBROOT/src/mainboard/$VENDOR/$MAINBOARD/Config.lb | \
107                grep ^arch | cut -f 2 -d\
108}
109
110function create_config
111{
112        VENDOR=$1
113        MAINBOARD=$2
114        TARCH=$( architecture $VENDOR $MAINBOARD )
115        TARGCONFIG=$LBROOT/targets/$VENDOR/$MAINBOARD/Config-abuild.lb
116
117        # get a working payload for the board if we have one.
118        # the --payload option expects a directory containing
119        # an executable shell script payload.sh
120        #   Usage: payload.sh [VENDOR] [DEVICE]
121        # the script returns an absolute path to the payload binary.
122
123        if [ -x $payloads/payload.sh ]; then
124                PAYLOAD=`$payloads/payload.sh $VENDOR $MAINBOARD`
125                printf "Using payload $PAYLOAD\n"
126        fi
127       
128        mkdir -p $TARGET
129
130        if [ -f $TARGCONFIG ]; then
131                cp $TARGCONFIG $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
132                printf "Using existing test target $TARGCONFIG"
133                xml "  <config>$TARGCONFIG</config>"
134        else
135
136                printf "  Creating config file..."
137                xml "  <config>autogenerated</config>"
138                ( cat << EOF
139# This will make a target directory of ./VENDOR_MAINBOARD
140
141target VENDOR_MAINBOARD
142mainboard VENDOR/MAINBOARD
143
144option CC="CROSSCC"
145option CROSS_COMPILE="CROSS_PREFIX"
146option HOSTCC="CROSS_HOSTCC"
147
148__COMPRESSION__
149
150EOF
151                if [ "$TARCH" == i386 ] ; then
152                        cat <<EOF
153romimage "normal"
154        option USE_FALLBACK_IMAGE=0
155        option ROM_IMAGE_SIZE=0x17000
156        option COREBOOT_EXTRA_VERSION=".0-normal"
157        payload __PAYLOAD__
158end
159
160romimage "fallback"
161        option USE_FALLBACK_IMAGE=1
162        option ROM_IMAGE_SIZE=0x17000
163        option COREBOOT_EXTRA_VERSION=".0-fallback"
164        payload __PAYLOAD__
165end
166buildrom ./coreboot.rom ROM_SIZE "normal" "fallback"
167EOF
168                else
169                        cat <<EOF
170romimage "only"
171        option COREBOOT_EXTRA_VERSION=".0"
172        payload __PAYLOAD__
173end
174buildrom ./coreboot.rom ROM_SIZE "only"
175EOF
176                fi
177                ) > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
178        fi
179
180        if [ "`which lzma`" != "" -a "$PAYLOAD" != /dev/null ]; then
181                COMPRESSION="option CONFIG_COMPRESSED_PAYLOAD_LZMA=1"
182        else
183                COMPRESSION="# no compression"
184        fi
185
186        sed -i.pre -e s:VENDOR:$VENDOR:g \
187                -e s:MAINBOARD:$MAINBOARD:g \
188                -e s:payload\ __PAYLOAD__:payload\ $PAYLOAD:g \
189                -e s:CROSSCC:"$CC":g \
190                -e s:CROSS_PREFIX:"$CROSS_COMPILE":g \
191                -e s:CROSS_HOSTCC:"$HOSTCC":g \
192                -e s:__COMPRESSION__:"$COMPRESSION":g \
193                $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
194        printf " ok\n"
195}
196
197function create_builddir
198{       
199        VENDOR=$1
200        MAINBOARD=$2
201       
202        printf "  Creating builddir..."
203
204        target_dir=$TARGET
205        config_dir=$LBROOT/util/newconfig
206        yapps2_py=$config_dir/yapps2.py
207        config_g=$config_dir/config.g
208        config_lb=Config-${VENDOR}_${MAINBOARD}.lb
209
210        cd $target_dir
211
212        build_dir=${VENDOR}_${MAINBOARD}
213        config_py=$build_dir/config.py
214
215        if [ ! -d $build_dir ] ; then
216                mkdir -p $build_dir
217        fi
218        if [ ! -f $config_py ]; then
219                $PYTHON $yapps2_py $config_g $config_py &> $build_dir/py.log
220        fi
221
222        # make sure config.py is up-to-date
223
224        export PYTHONPATH=$config_dir
225        $PYTHON $config_py $config_lb $LBROOT &> $build_dir/config.log
226        if [ $? -eq 0 ]; then
227                printf "ok\n"
228                xml "  <builddir>ok</builddir>"
229                xml ""
230                return 0
231        else
232                printf "FAILED! Log excerpt:\n"
233                xml "  <builddir>failed</builddir>"
234                xml "  <log>"
235                xmlfile $build_dir/config.log
236                xml "  </log>"
237                xml ""
238                tail -n $CONTEXT $build_dir/config.log
239                return 1
240        fi
241}
242
243function create_buildenv
244{
245        VENDOR=$1
246        MAINBOARD=$2
247        create_config $VENDOR $MAINBOARD
248        create_builddir $VENDOR $MAINBOARD
249}
250
251function compile_target
252{       
253        VENDOR=$1
254        MAINBOARD=$2
255
256        printf "  Compiling image "
257        test "$cpus" == "" && printf "in parallel .. "
258        test "$cpus" == "1" && printf "on 1 cpu .. "
259        test 0$cpus -gt 1 && printf "on %d cpus in parallel .. " $cpus
260
261        CURR=$( pwd )
262        cd $TARGET/${VENDOR}_${MAINBOARD}
263        stime=`date +%s`
264        eval $MAKE $silent -j $cpus &> make.log
265        ret=$?
266        etime=`date +%s`
267        duration=$(( $etime - $stime ))
268        if [ $ret -eq 0 ]; then
269                xml "  <compile>ok</compile>"
270                xml "  <compiletime>${duration}s</compiletime>"
271                printf "ok\n" > compile.status
272                printf "ok. (took ${duration}s)\n"
273                cd $CURR
274                return 0
275        else
276                xml "  <compile>failed</compile>"
277                xml "  <compiletime>${duration}s</compiletime>"
278                xml "  <log>"
279                xmlfile make.log
280                xml "  </log>"
281
282                printf "FAILED after ${duration}s! Log excerpt:\n"
283                tail -n $CONTEXT make.log
284                cd $CURR
285                return 1
286        fi
287}
288
289function built_successfully
290{
291        CURR=`pwd`
292        status="fail"
293        if [ -d "$TARGET/${VENDOR}_${MAINBOARD}" ]; then
294                cd $TARGET/${VENDOR}_${MAINBOARD}
295                if [ -r compile.status ] ; then
296                        status=`cat compile.status`
297                fi
298                cd $CURR
299        fi
300        [ "$buildall" != "true" -a "$status" == "ok" ]
301}
302
303function build_broken
304{
305        CURR=`pwd`
306        status="yes"
307        [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
308        [ "$buildbroken" == "true" -o "$status" == "yes" ]
309}
310
311function build_target
312{
313        VENDOR=$1
314        MAINBOARD=$2
315        TARCH=$( architecture $VENDOR $MAINBOARD )
316
317        # default setting
318
319        if [ "`uname -s`" == Darwin ]; then
320                # Darwin requires i386-elf-[binuitils|gcc] from MacPorts
321                # and a link from i386-elf-gcc-<version> to i386-elf-gcc
322                CC="$TARCH-elf-gcc -Wa,--divide"
323                CROSS_COMPILE="$TARCH-elf-"
324        else
325                CC='$(CROSS_COMPILE)gcc'
326                CROSS_COMPILE=''
327        fi
328       
329        if  [ "$stackprotect" = "true" ]; then
330                CC="$CC -fno-stack-protector"
331        fi
332
333        HOSTCC='gcc'
334       
335        printf "Processing mainboard/$VENDOR/$MAINBOARD"
336
337        xml "<mainboard>"
338        xml ""
339        xml "  <vendor>$VENDOR</vendor>"
340        xml "  <device>$MAINBOARD</device>"
341        xml ""
342        xml "  <architecture>$TARCH</architecture>"
343        xml ""
344       
345        [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
346                source $LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
347       
348        if [ "$ARCH" == "$TARCH" ]; then
349                printf " ($TARCH: ok)\n"
350        else
351                found_crosscompiler=false
352                if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
353                        CC="gcc -m32"
354                        found_crosscompiler=true
355                fi
356                if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
357                        CC="gcc -m32"
358                        found_crosscompiler=true
359                fi
360                if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
361                        for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
362                            powerpc-7450-linux-gnu-; do
363                                if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
364                                        found_crosscompiler=true
365                                        CROSS_COMPILE=$prefix
366                                fi
367                        done
368                fi
369
370       
371                # TBD: look for suitable cross compiler suite
372                # cross-$TARCH-gcc and cross-$TARCH-ld
373               
374                # Check result:
375                if [ $found_crosscompiler == "false" ]; then
376                        printf " ($TARCH: skipped, we're $ARCH)\n\n"
377                        xml "  <status>notbuilt</status>"
378                        xml ""
379                        xml "</mainboard>"
380               
381                        return 0
382                else
383                        printf " ($TARCH: ok, we're $ARCH)\n"
384                        xml "  <compiler>"
385                        xml "    <path>`which ${CROSS_COMPILE}gcc`</path>"
386                        xml "    <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
387                        xml "  </compiler>"
388                        xml ""
389                fi
390        fi
391
392        built_successfully $VENDOR $MAINBOARD && \
393        {
394                printf " ( mainboard/$VENDOR/$MAINBOARD previously ok )\n\n"
395                xml "  <status>previouslyok</status>"
396                xml ""
397                xml "</mainboard>"
398                return 0
399        }
400
401        build_broken $VENDOR $MAINBOARD || \
402        {
403                printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
404                xml "  <status>knownbroken</status>"
405                xml ""
406                xml "</mainboard>"
407                return 0
408        }
409       
410        create_buildenv $VENDOR $MAINBOARD
411        if [ $? -eq 0 ]; then
412                compile_target $VENDOR $MAINBOARD &&
413                        xml "  <status>ok</status>" ||
414                        xml "<status>broken</status>"
415        fi
416
417        xml ""
418        xml "</mainboard>"
419
420        printf "\n"
421}
422
423function test_target
424{
425        VENDOR=$1
426        MAINBOARD=$2
427
428        if [ "$hwtest" != "true" ]; then
429                return 0
430        fi
431
432        # image does not exist. we silently skip the patch.
433        if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
434                return 0
435        fi
436
437        which curl &> /dev/null
438        if [ $? != 0 ]; then
439                printf "curl is not installed but required for test submission.  skipping test.\n\n"
440                return 0
441        fi
442
443        CURR=`pwd`
444        if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
445                printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
446                return 0
447        fi
448        # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
449
450        printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
451
452        curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
453                -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
454                "http://qa.coreboot.org/deployment/send.php"
455
456        printf "\n"
457        return 0
458}
459
460function myhelp
461{
462        printf "Usage: $0 [-v] [-a] [-b] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
463        printf "       $0 [-V|--version]\n"
464        printf "       $0 [-h|--help]\n\n"
465
466        printf "Options:\n"
467        printf "    [-v|--verbose]                print more messages\n"
468        printf "    [-a|--all]                    build previously succeeded ports as well\n"
469        printf "    [-b|--broken]                 attempt to build ports that are known broken\n"
470        printf "    [-t|--target <vendor/board>]  attempt to build target vendor/board only\n"
471        printf "    [-p|--payloads <dir>]         use payloads in <dir> to build images\n"
472        printf "    [-V|--version]                print version number and exit\n"
473        printf "    [-h|--help]                   print this help and exit\n"
474        printf "    [-x|--xml]                    write xml log file \n"
475        printf "                                  (defaults to $XMLFILE)\n"
476        printf "    [-T|--test]                   submit image(s) to automated test system\n"
477        printf "    [-c|--cpus <numcpus>]         build on <numcpus> at the same time\n"
478        printf "    [-s|--silent]                 omit compiler calls in logs\n"
479        printf "    [-ns|--nostackprotect]        use gcc -fno-stack-protector option\n"
480        printf "    [lbroot]                      absolute path to coreboot sources\n"
481        printf "                                  (defaults to $LBROOT)\n\n"
482}
483
484function myversion
485{
486        cat << EOF
487
488coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
489
490Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
491Copyright (C) 2006-2008 by coresystems GmbH <info@coresystems.de>
492
493This program is free software; you may redistribute it under the terms
494of the GNU General Public License. This program has absolutely no
495warranty.
496
497EOF
498}
499
500# default options
501target=""
502buildall=false
503LBROOT=$( cd ../..; pwd )
504verbose=false
505
506# parse parameters.. try to find out whether we're running GNU getopt
507getoptbrand="`getopt -V`"
508if [ "${getoptbrand:0:6}" == "getopt" ]; then
509        # Detected GNU getopt that supports long options.
510        args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml Vvhat:bp:Tc:sx -- "$@"`
511        eval set "$args"
512else
513        # Detected non-GNU getopt
514        args=`getopt Vvhat:bp:Tc:sx $*`
515        set -- $args
516fi
517
518if [ $? != 0 ]; then
519        myhelp
520        exit 1
521fi
522
523while true ; do
524        case "$1" in
525                -x|--xml)       shift; mode=xml; rm -f $XMLFILE ;;
526                -t|--target)    shift; target="$1"; shift;;
527                -a|--all)       shift; buildall=true;;
528                -b|--broken)    shift; buildbroken=true;;
529                -v|--verbose)   shift; verbose=true;;
530                -V|--version)   shift; myversion; exit 0;;
531                -h|--help)      shift; myversion; myhelp; exit 0;;
532                -p|--payloads)  shift; payloads="$1"; shift;;
533                -T|--test)      shift; hwtest=true;;
534                -c|--cpus)      shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
535                -s|--silent)    shift; silent="-s";;
536                -ns|--nostackprotect) shift; stackprotect=true;;
537                --)             shift; break;;
538                -*)             printf "Invalid option\n\n"; myhelp; exit 1;;
539                *)              break;;
540        esac
541done
542
543# /path/to/freebios2/
544test -z "$1" || LBROOT=$1
545
546debug "LBROOT=$LBROOT"
547
548xml '<?xml version="1.0" encoding="utf-8"?>'
549xml '<abuild>'
550
551if [ "$target" != "" ]; then
552        # build a single board
553        VENDOR=`printf $target|cut -f1 -d/`
554        MAINBOARD=`printf $target|cut -f2 -d/`
555        build_target $VENDOR $MAINBOARD
556        test_target $VENDOR $MAINBOARD
557else
558        # build all boards per default
559        for VENDOR in $( vendors ); do
560                for MAINBOARD in $( mainboards $VENDOR ); do
561                        build_target $VENDOR $MAINBOARD
562                        test_target $VENDOR $MAINBOARD
563                done
564        done
565fi
566xml '</abuild>'
Note: See TracBrowser for help on using the browser.