5 # This script builds coreboot images for all available targets.
7 # (C) 2004 by Stefan Reinauer <stepan@openbios.org>
8 # (C) 2006-2009 by coresystems GmbH <info@coresystems.de>
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.
15 #set -x # Turn echo on....
17 ABUILD_DATE="April 10th, 2009"
18 ABUILD_VERSION="0.8.1"
20 # Where shall we place all the build trees?
21 TARGET=$( pwd )/coreboot-builds
22 XMLFILE=$( pwd )/abuild.xml
24 # path to payload. Should be more generic
27 # Lines of error context to be printed in FAILURE case
30 TESTSUBMISSION="http://qa.coreboot.org/deployment/send.php"
32 # Number of CPUs to compile on per default
38 # One might want to adjust these in case of cross compiling
42 # this can be changed to xml by -x
45 # silent mode.. no compiler calls, only warnings in the log files.
46 # this is disabled per default but can be enabled with -s
49 # clang mode enabled by -sb option.
52 # stackprotect mode enabled by -ns option.
55 ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
57 -e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
58 -e "s/Power Macintosh/ppc/"`
64 printf "\n$0: execution interrupted manually.\n"
65 if [ "$mode" == "xml" ]; then
66 printf "$0: deleting incomplete xml output file.\n"
73 test "$verbose" == "true" && printf "$*\n"
78 test "$mode" == "xml" && printf "$*\n" >> $XMLFILE
83 test "$mode" == "xml" && {
94 # make this a function so we can easily select
95 # without breaking readability
96 ls -1 "$LBROOT/src/mainboard" | grep -v CVS
101 # make this a function so we can easily select
102 # without breaking readability
106 ls -1 $LBROOT/src/mainboard/$VENDOR | grep -v CVS
109 function architecture
113 ARCH=`cat $LBROOT/src/mainboard/$VENDOR/$MAINBOARD/Config.lb | \
114 grep ^arch | cut -f 2 -d\ `
115 echo $ARCH | sed s/ppc/powerpc/
118 function create_config
122 TARCH=$( architecture $VENDOR $MAINBOARD )
123 TARGCONFIG=$LBROOT/targets/$VENDOR/$MAINBOARD/Config-abuild.lb
125 # get a working payload for the board if we have one.
126 # the --payload option expects a directory containing
127 # an executable shell script payload.sh
128 # Usage: payload.sh [VENDOR] [DEVICE]
129 # the script returns an absolute path to the payload binary.
131 if [ -x $payloads/payload.sh ]; then
132 PAYLOAD=`$payloads/payload.sh $VENDOR $MAINBOARD`
133 printf "Using payload $PAYLOAD\n"
138 if [ -f $TARGCONFIG ]; then
139 cp $TARGCONFIG $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
140 printf "Using existing test target $TARGCONFIG"
141 xml " <config>$TARGCONFIG</config>"
144 printf " Creating config file..."
145 xml " <config>autogenerated</config>"
147 # This will make a target directory of ./VENDOR_MAINBOARD
149 target VENDOR_MAINBOARD
150 mainboard VENDOR/MAINBOARD
153 option CROSS_COMPILE="CROSS_PREFIX"
154 option HOSTCC="CROSS_HOSTCC"
159 if [ "$TARCH" == i386 ] ; then
162 option USE_FALLBACK_IMAGE=0
163 option ROM_IMAGE_SIZE=0x17000
164 option COREBOOT_EXTRA_VERSION=".0-normal"
169 option USE_FALLBACK_IMAGE=1
170 option ROM_IMAGE_SIZE=0x17000
171 option COREBOOT_EXTRA_VERSION=".0-fallback"
174 buildrom ./coreboot.rom ROM_SIZE "normal" "fallback"
179 option COREBOOT_EXTRA_VERSION=".0"
182 buildrom ./coreboot.rom ROM_SIZE "only"
185 ) > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
188 if [ "`which lzma`" != "" -a "$PAYLOAD" != /dev/null ]; then
189 COMPRESSION="option CONFIG_COMPRESSED_PAYLOAD_LZMA=1"
191 COMPRESSION="# no compression"
194 cp $TARGET/Config-${VENDOR}_${MAINBOARD}.lb $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre
195 sed -e s:VENDOR:$VENDOR:g \
196 -e s:MAINBOARD:$MAINBOARD:g \
197 -e s:payload\ __PAYLOAD__:payload\ $PAYLOAD:g \
198 -e s:CROSSCC:"$CC":g \
199 -e s:CROSS_PREFIX:"$CROSS_COMPILE":g \
200 -e s:CROSS_HOSTCC:"$HOSTCC":g \
201 -e s:__COMPRESSION__:"$COMPRESSION":g \
202 $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
206 function create_builddir
211 printf " Creating builddir..."
214 config_dir=$LBROOT/util/newconfig
215 yapps2_py=$config_dir/yapps2.py
216 config_g=$config_dir/config.g
217 config_lb=Config-${VENDOR}_${MAINBOARD}.lb
221 build_dir=${VENDOR}_${MAINBOARD}
222 config_py=$build_dir/config.py
224 if [ ! -d $build_dir ] ; then
227 if [ ! -f $config_py ]; then
228 $PYTHON $yapps2_py $config_g $config_py &> $build_dir/py.log
231 # make sure config.py is up-to-date
233 export PYTHONPATH=$config_dir
234 $PYTHON $config_py $config_lb $LBROOT &> $build_dir/config.log
235 if [ $? -eq 0 ]; then
237 xml " <builddir>ok</builddir>"
239 xmlfile $build_dir/config.log
244 printf "FAILED! Log excerpt:\n"
245 xml " <builddir>failed</builddir>"
247 xmlfile $build_dir/config.log
250 tail -n $CONTEXT $build_dir/config.log
255 function create_buildenv
259 create_config $VENDOR $MAINBOARD
260 create_builddir $VENDOR $MAINBOARD
263 function compile_target
268 printf " Compiling image "
269 test "$cpus" == "" && printf "in parallel .. "
270 test "$cpus" == "1" && printf "on 1 cpu .. "
271 test 0$cpus -gt 1 && printf "on %d cpus in parallel .. " $cpus
274 cd $TARGET/${VENDOR}_${MAINBOARD}
275 stime=`perl -e 'print time();'`
276 eval $MAKE $silent -j $cpus &> make.log
278 etime=`perl -e 'print time();'`
279 duration=$(( $etime - $stime ))
280 if [ $ret -eq 0 ]; then
281 xml " <compile>ok</compile>"
282 xml " <compiletime>${duration}s</compiletime>"
286 printf "ok\n" > compile.status
287 printf "ok. (took ${duration}s)\n"
291 xml " <compile>failed</compile>"
292 xml " <compiletime>${duration}s</compiletime>"
297 printf "FAILED after ${duration}s! Log excerpt:\n"
298 tail -n $CONTEXT make.log
304 function built_successfully
308 if [ -d "$TARGET/${VENDOR}_${MAINBOARD}" ]; then
309 cd $TARGET/${VENDOR}_${MAINBOARD}
310 if [ -r compile.status ] ; then
311 status=`cat compile.status`
315 [ "$buildall" != "true" -a "$status" == "ok" ]
318 function build_broken
322 [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
323 [ "$buildbroken" == "true" -o "$status" == "yes" ]
326 function build_target
330 TARCH=$( architecture $VENDOR $MAINBOARD )
332 # Allow architecture override in an abuild.info file.
333 # This is used for the Motorola Sandpoint, which is not a real target
334 # but a skeleton target for the Sandpoint X3.
335 [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
336 source $LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
340 CC="${CROSS_COMPILE}gcc"
342 found_crosscompiler=false
343 if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
344 # i386-elf target needs --divide, for i386-linux, that's the default
345 if [ "$TARCH" = "i386" ]; then
346 CC="$CC -Wa,--divide"
348 CROSS_COMPILE="$TARCH-elf-"
349 echo using $CROSS_COMPILE$CC
350 found_crosscompiler=true
355 printf "Processing mainboard/$VENDOR/$MAINBOARD"
359 xml " <vendor>$VENDOR</vendor>"
360 xml " <device>$MAINBOARD</device>"
362 xml " <architecture>$TARCH</architecture>"
365 if [ "$ARCH" = "$TARCH" -o $found_crosscompiler = true ]; then
366 printf " ($TARCH: ok)\n"
368 found_crosscompiler=false
369 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
371 found_crosscompiler=true
373 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
375 found_crosscompiler=true
377 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
378 for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
379 powerpc-7450-linux-gnu- powerpc-elf-; do
380 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
381 found_crosscompiler=true
382 CROSS_COMPILE=$prefix
388 # TBD: look for suitable cross compiler suite
389 # cross-$TARCH-gcc and cross-$TARCH-ld
392 if [ $found_crosscompiler == "false" ]; then
393 printf " ($TARCH: skipped, we're $ARCH)\n\n"
394 xml " <status>notbuilt</status>"
400 printf " ($TARCH: ok, we're $ARCH with a ${CROSS_COMPILE} cross compiler)\n"
402 xml " <path>`which ${CROSS_COMPILE}gcc`</path>"
403 xml " <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
409 CC=${CROSS_COMPILE}$CC
411 if [ "$stackprotect" = "true" ]; then
412 CC="$CC -fno-stack-protector"
415 if [ "$scanbuild" = "true" ]; then
417 mkdir -p $TARGET/${VENDOR}_${MAINBOARD}
418 mkdir -p $TARGET/scan-build-results-tmp
419 mv $ccwrap $TARGET/${VENDOR}_${MAINBOARD}
420 ccwrap=$TARGET/${VENDOR}_${MAINBOARD}/`basename $ccwrap`
421 echo '#!/bin/sh' > $ccwrap
422 echo $CC' "$@"' >> $ccwrap
425 MAKE="scan-build --use-cc=$ccwrap -o $TARGET/scan-build-results-tmp -analyze-headers $MAKE GCC=$ccwrap"
427 HOSTCC="CCC_CC=$HOSTCC \$(CC)"
430 built_successfully $VENDOR $MAINBOARD && \
432 printf " ( mainboard/$VENDOR/$MAINBOARD previously ok )\n\n"
433 xml " <status>previouslyok</status>"
439 build_broken $VENDOR $MAINBOARD || \
441 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
442 xml " <status>knownbroken</status>"
448 create_buildenv $VENDOR $MAINBOARD
449 if [ $? -eq 0 -a $configureonly -eq 0 ]; then
450 compile_target $VENDOR $MAINBOARD &&
451 xml " <status>ok</status>" ||
452 xml "<status>broken</status>"
453 if [ "$scanbuild" = "true" ]; then
454 mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
470 if [ "$hwtest" != "true" ]; then
474 # image does not exist. we silently skip the patch.
475 if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
479 which curl &> /dev/null
481 printf "curl is not installed but required for test submission. skipping test.\n\n"
486 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
487 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
490 # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
492 printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
494 curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
495 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
496 "http://qa.coreboot.org/deployment/send.php"
504 printf "Usage: $0 [-v] [-a] [-b] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
505 printf " $0 [-V|--version]\n"
506 printf " $0 [-h|--help]\n\n"
509 printf " [-v|--verbose] print more messages\n"
510 printf " [-a|--all] build previously succeeded ports as well\n"
511 printf " [-b|--broken] attempt to build ports that are known broken\n"
512 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
513 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
514 printf " [-V|--version] print version number and exit\n"
515 printf " [-h|--help] print this help and exit\n"
516 printf " [-x|--xml] write xml log file \n"
517 printf " (defaults to $XMLFILE)\n"
518 printf " [-T|--test] submit image(s) to automated test system\n"
519 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
520 printf " [-s|--silent] omit compiler calls in logs\n"
521 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
522 printf " [-sb|--scan-build] use clang's static analyzer\n"
523 printf " [-C|--config] configure-only mode\n"
524 printf " [lbroot] absolute path to coreboot sources\n"
525 printf " (defaults to $LBROOT)\n\n"
532 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
534 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
535 Copyright (C) 2006-2008 by coresystems GmbH <info@coresystems.de>
537 This program is free software; you may redistribute it under the terms
538 of the GNU General Public License. This program has absolutely no
547 LBROOT=$( cd ../..; pwd )
550 # parse parameters.. try to find out whether we're running GNU getopt
551 getoptbrand="`getopt -V`"
552 if [ "${getoptbrand:0:6}" == "getopt" ]; then
553 # Detected GNU getopt that supports long options.
554 args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config Vvhat:bp:Tc:sxC -- "$@"`
557 # Detected non-GNU getopt
558 args=`getopt Vvhat:bp:Tc:sxC $*`
569 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
570 -t|--target) shift; target="$1"; shift;;
571 -a|--all) shift; buildall=true;;
572 -b|--broken) shift; buildbroken=true;;
573 -v|--verbose) shift; verbose=true;;
574 -V|--version) shift; myversion; exit 0;;
575 -h|--help) shift; myversion; myhelp; exit 0;;
576 -p|--payloads) shift; payloads="$1"; shift;;
577 -T|--test) shift; hwtest=true;;
578 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
579 -s|--silent) shift; silent="-s";;
580 -ns|--nostackprotect) shift; stackprotect=true;;
581 -sb|--scan-build) shift; scanbuild=true;;
582 -C|--config) shift; configureonly=1;;
584 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
589 # /path/to/freebios2/
590 test -z "$1" || LBROOT=$1
592 debug "LBROOT=$LBROOT"
594 xml '<?xml version="1.0" encoding="utf-8"?>'
597 if [ "$target" != "" ]; then
598 # build a single board
599 VENDOR=`printf $target|cut -f1 -d/`
600 MAINBOARD=`printf $target|cut -f2 -d/`
601 build_target $VENDOR $MAINBOARD
602 test_target $VENDOR $MAINBOARD
604 # build all boards per default
605 for VENDOR in $( vendors ); do
606 for MAINBOARD in $( mainboards $VENDOR ); do
607 build_target $VENDOR $MAINBOARD
608 test_target $VENDOR $MAINBOARD