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 # loglevel changed with -l / --loglevel option
58 ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
60 -e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
61 -e "s/Power Macintosh/ppc/"`
67 printf "\n$0: execution interrupted manually.\n"
68 if [ "$mode" == "xml" ]; then
69 printf "$0: deleting incomplete xml output file.\n"
76 test "$verbose" == "true" && printf "$*\n"
81 test "$mode" == "xml" && printf "$*\n" >> $XMLFILE
86 test "$mode" == "xml" && {
97 # make this a function so we can easily select
98 # without breaking readability
99 ls -1 "$LBROOT/src/mainboard" | grep -v CVS
104 # make this a function so we can easily select
105 # without breaking readability
109 ls -1 $LBROOT/src/mainboard/$VENDOR | grep -v CVS
112 function architecture
116 ARCH=`cat $LBROOT/src/mainboard/$VENDOR/$MAINBOARD/Config.lb | \
117 grep ^arch | cut -f 2 -d\ `
118 echo $ARCH | sed s/ppc/powerpc/
121 function create_config
125 TARCH=$( architecture $VENDOR $MAINBOARD )
126 TARGCONFIG=$LBROOT/targets/$VENDOR/$MAINBOARD/Config-abuild.lb
128 # get a working payload for the board if we have one.
129 # the --payload option expects a directory containing
130 # a shell script payload.sh
131 # Usage: payload.sh [VENDOR] [DEVICE]
132 # the script returns an absolute path to the payload binary.
134 if [ -f $payloads/payload.sh ]; then
135 PAYLOAD=`sh $payloads/payload.sh $VENDOR $MAINBOARD`
136 printf "Using payload $PAYLOAD\n"
141 if [ -f $TARGCONFIG ]; then
142 cp $TARGCONFIG $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
143 printf "Using existing test target $TARGCONFIG"
144 xml " <config>$TARGCONFIG</config>"
147 printf " Creating config file..."
148 xml " <config>autogenerated</config>"
150 # This will make a target directory of ./VENDOR_MAINBOARD
152 target VENDOR_MAINBOARD
153 mainboard VENDOR/MAINBOARD
156 option CROSS_COMPILE="CROSS_PREFIX"
157 option HOSTCC="CROSS_HOSTCC"
163 if [ "$TARCH" == i386 ] ; then
166 option USE_FALLBACK_IMAGE=0
167 option ROM_IMAGE_SIZE=0x17000
168 option COREBOOT_EXTRA_VERSION=".0-normal"
173 option USE_FALLBACK_IMAGE=1
174 option ROM_IMAGE_SIZE=0x17000
175 option COREBOOT_EXTRA_VERSION=".0-fallback"
178 buildrom ./coreboot.rom ROM_SIZE "normal" "fallback"
183 option COREBOOT_EXTRA_VERSION=".0"
186 buildrom ./coreboot.rom ROM_SIZE "only"
189 ) > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
192 if [ "$loglevel" != "default" ]; then
193 LOGLEVEL1="option MAXIMUM_CONSOLE_LOGLEVEL=$loglevel"
194 LOGLEVEL2="option DEFAULT_CONSOLE_LOGLEVEL=$loglevel"
196 LOGLEVEL1="# no loglevel override"
200 if [ "`which lzma`" != "" -a "$PAYLOAD" != /dev/null ]; then
201 COMPRESSION="option CONFIG_COMPRESSED_PAYLOAD_LZMA=1"
203 COMPRESSION="# no compression"
206 cp $TARGET/Config-${VENDOR}_${MAINBOARD}.lb $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre
207 sed -e s:VENDOR:$VENDOR:g \
208 -e s:MAINBOARD:$MAINBOARD:g \
209 -e s:payload\ __PAYLOAD__:payload\ $PAYLOAD:g \
210 -e s:CROSSCC:"$CC":g \
211 -e s:CROSS_PREFIX:"$CROSS_COMPILE":g \
212 -e s:CROSS_HOSTCC:"$HOSTCC":g \
213 -e s:__COMPRESSION__:"$COMPRESSION":g \
214 -e s:__LOGLEVEL__:"$LOGLEVEL1"\
216 $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
220 function create_builddir
225 printf " Creating builddir..."
228 config_dir=$LBROOT/util/newconfig
229 yapps2_py=$config_dir/yapps2.py
230 config_g=$config_dir/config.g
231 config_lb=Config-${VENDOR}_${MAINBOARD}.lb
235 build_dir=${VENDOR}_${MAINBOARD}
236 config_py=$build_dir/config.py
238 if [ ! -d $build_dir ] ; then
241 if [ ! -f $config_py ]; then
242 $PYTHON $yapps2_py $config_g $config_py &> $build_dir/py.log
245 # make sure config.py is up-to-date
247 export PYTHONPATH=$config_dir
248 $PYTHON $config_py $config_lb $LBROOT &> $build_dir/config.log
249 if [ $? -eq 0 ]; then
251 xml " <builddir>ok</builddir>"
253 xmlfile $build_dir/config.log
258 printf "FAILED! Log excerpt:\n"
259 xml " <builddir>failed</builddir>"
261 xmlfile $build_dir/config.log
264 tail -n $CONTEXT $build_dir/config.log
269 function create_buildenv
273 create_config $VENDOR $MAINBOARD
274 create_builddir $VENDOR $MAINBOARD
277 function compile_target
282 printf " Compiling image "
283 test "$cpus" == "" && printf "in parallel .. "
284 test "$cpus" == "1" && printf "on 1 cpu .. "
285 test 0$cpus -gt 1 && printf "on %d cpus in parallel .. " $cpus
288 cd $TARGET/${VENDOR}_${MAINBOARD}
289 stime=`perl -e 'print time();'`
290 eval $MAKE $silent -j $cpus &> make.log
292 etime=`perl -e 'print time();'`
293 duration=$(( $etime - $stime ))
294 if [ $ret -eq 0 ]; then
295 xml " <compile>ok</compile>"
296 xml " <compiletime>${duration}s</compiletime>"
300 printf "ok\n" > compile.status
301 printf "ok. (took ${duration}s)\n"
305 xml " <compile>failed</compile>"
306 xml " <compiletime>${duration}s</compiletime>"
311 printf "FAILED after ${duration}s! Log excerpt:\n"
312 tail -n $CONTEXT make.log
318 function built_successfully
322 if [ -d "$TARGET/${VENDOR}_${MAINBOARD}" ]; then
323 cd $TARGET/${VENDOR}_${MAINBOARD}
324 if [ -r compile.status ] ; then
325 status=`cat compile.status`
329 [ "$buildall" != "true" -a "$status" == "ok" ]
332 function build_broken
336 [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
337 [ "$buildbroken" == "true" -o "$status" == "yes" ]
340 function build_target
344 TARCH=$( architecture $VENDOR $MAINBOARD )
346 # Allow architecture override in an abuild.info file.
347 # This is used for the Motorola Sandpoint, which is not a real target
348 # but a skeleton target for the Sandpoint X3.
349 [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
350 source $LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
354 CC="${CROSS_COMPILE}gcc"
356 found_crosscompiler=false
357 if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
358 # i386-elf target needs --divide, for i386-linux, that's the default
359 if [ "$TARCH" = "i386" ]; then
360 CC="$CC -Wa,--divide"
362 CROSS_COMPILE="$TARCH-elf-"
363 echo using $CROSS_COMPILE$CC
364 found_crosscompiler=true
369 printf "Processing mainboard/$VENDOR/$MAINBOARD"
373 xml " <vendor>$VENDOR</vendor>"
374 xml " <device>$MAINBOARD</device>"
376 xml " <architecture>$TARCH</architecture>"
379 if [ "$ARCH" = "$TARCH" -o $found_crosscompiler = true ]; then
380 printf " ($TARCH: ok)\n"
382 found_crosscompiler=false
383 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
385 found_crosscompiler=true
387 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
389 found_crosscompiler=true
391 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
392 for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
393 powerpc-7450-linux-gnu- powerpc-elf-; do
394 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
395 found_crosscompiler=true
396 CROSS_COMPILE=$prefix
402 # TBD: look for suitable cross compiler suite
403 # cross-$TARCH-gcc and cross-$TARCH-ld
406 if [ $found_crosscompiler == "false" ]; then
407 printf " ($TARCH: skipped, we're $ARCH)\n\n"
408 xml " <status>notbuilt</status>"
414 printf " ($TARCH: ok, we're $ARCH with a ${CROSS_COMPILE} cross compiler)\n"
416 xml " <path>`which ${CROSS_COMPILE}gcc`</path>"
417 xml " <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
423 CC=${CROSS_COMPILE}$CC
425 if [ "$stackprotect" = "true" ]; then
426 CC="$CC -fno-stack-protector"
429 if [ "$scanbuild" = "true" ]; then
431 mkdir -p $TARGET/${VENDOR}_${MAINBOARD}
432 mkdir -p $TARGET/scan-build-results-tmp
433 mv $ccwrap $TARGET/${VENDOR}_${MAINBOARD}
434 ccwrap=$TARGET/${VENDOR}_${MAINBOARD}/`basename $ccwrap`
435 echo '#!/bin/sh' > $ccwrap
436 echo $CC' "$@"' >> $ccwrap
439 MAKE="scan-build --use-cc=$ccwrap -o $TARGET/scan-build-results-tmp -analyze-headers $MAKE GCC=$ccwrap"
441 HOSTCC="CCC_CC=$HOSTCC \$(CC)"
444 built_successfully $VENDOR $MAINBOARD && \
446 printf " ( mainboard/$VENDOR/$MAINBOARD previously ok )\n\n"
447 xml " <status>previouslyok</status>"
453 build_broken $VENDOR $MAINBOARD || \
455 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
456 xml " <status>knownbroken</status>"
462 create_buildenv $VENDOR $MAINBOARD
463 if [ $? -eq 0 -a $configureonly -eq 0 ]; then
464 compile_target $VENDOR $MAINBOARD &&
465 xml " <status>ok</status>" ||
466 xml "<status>broken</status>"
467 if [ "$scanbuild" = "true" ]; then
468 mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
484 if [ "$hwtest" != "true" ]; then
488 # image does not exist. we silently skip the patch.
489 if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
493 which curl &> /dev/null
495 printf "curl is not installed but required for test submission. skipping test.\n\n"
500 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
501 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
504 # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
506 printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
508 curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
509 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
510 "http://qa.coreboot.org/deployment/send.php"
516 function remove_target
518 if [ "$remove" != "true" ]; then
525 # Save the generated coreboot.rom file of each board.
526 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
527 cp $TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom \
528 ${VENDOR}_${MAINBOARD}_coreboot.rom
531 printf "Removing build dir for board $VENDOR $MAINBOARD...\n"
532 rm -rf $TARGET/${VENDOR}_${MAINBOARD}
539 printf "Usage: $0 [-v] [-a] [-b] [-r] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
540 printf " $0 [-V|--version]\n"
541 printf " $0 [-h|--help]\n\n"
544 printf " [-v|--verbose] print more messages\n"
545 printf " [-a|--all] build previously succeeded ports as well\n"
546 printf " [-b|--broken] attempt to build ports that are known broken\n"
547 printf " [-r|--remove] remove output dir after build\n"
548 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
549 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
550 printf " [-V|--version] print version number and exit\n"
551 printf " [-h|--help] print this help and exit\n"
552 printf " [-x|--xml] write xml log file \n"
553 printf " (defaults to $XMLFILE)\n"
554 printf " [-T|--test] submit image(s) to automated test system\n"
555 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
556 printf " [-s|--silent] omit compiler calls in logs\n"
557 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
558 printf " [-sb|--scan-build] use clang's static analyzer\n"
559 printf " [-C|--config] configure-only mode\n"
560 printf " [lbroot] absolute path to coreboot sources\n"
561 printf " (defaults to $LBROOT)\n\n"
568 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
570 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
571 Copyright (C) 2006-2008 by coresystems GmbH <info@coresystems.de>
573 This program is free software; you may redistribute it under the terms
574 of the GNU General Public License. This program has absolutely no
583 LBROOT=$( cd ../..; pwd )
586 # parse parameters.. try to find out whether we're running GNU getopt
587 getoptbrand="`getopt -V`"
588 if [ "${getoptbrand:0:6}" == "getopt" ]; then
589 # Detected GNU getopt that supports long options.
590 args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config,loglevel Vvhat:bp:Tc:sxCl: -- "$@"`
593 # Detected non-GNU getopt
594 args=`getopt Vvhat:bp:Tc:sxCl: $*`
605 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
606 -t|--target) shift; target="$1"; shift;;
607 -a|--all) shift; buildall=true;;
608 -b|--broken) shift; buildbroken=true;;
609 -r|--remove) shift; remove=true; shift;;
610 -v|--verbose) shift; verbose=true;;
611 -V|--version) shift; myversion; exit 0;;
612 -h|--help) shift; myversion; myhelp; exit 0;;
613 -p|--payloads) shift; payloads="$1"; shift;;
614 -T|--test) shift; hwtest=true;;
615 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
616 -s|--silent) shift; silent="-s";;
617 -ns|--nostackprotect) shift; stackprotect=true;;
618 -sb|--scan-build) shift; scanbuild=true;;
619 -C|--config) shift; configureonly=1;;
620 -l|--loglevel) shift; loglevel="$1"; shift;;
622 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
627 # /path/to/freebios2/
628 test -z "$1" || LBROOT=$1
630 debug "LBROOT=$LBROOT"
632 xml '<?xml version="1.0" encoding="utf-8"?>'
635 if [ "$target" != "" ]; then
636 # build a single board
637 VENDOR=`printf $target|cut -f1 -d/`
638 MAINBOARD=`printf $target|cut -f2 -d/`
639 build_target $VENDOR $MAINBOARD
640 test_target $VENDOR $MAINBOARD
642 # build all boards per default
643 for VENDOR in $( vendors ); do
644 for MAINBOARD in $( mainboards $VENDOR ); do
645 build_target $VENDOR $MAINBOARD
646 test_target $VENDOR $MAINBOARD
647 remove_target $VENDOR $MAINBOARD