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 3rd, 2009"
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 )
334 CC="${CROSS_COMPILE}gcc"
336 found_crosscompiler=false
337 if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
338 # i386-elf target needs --divide, for i386-linux, that's the default
339 if [ "$TARCH" = "i386" ]; then
340 CC="$CC -Wa,--divide"
342 CROSS_COMPILE="$TARCH-elf-"
343 echo using $CROSS_COMPILE$CC
344 found_crosscompiler=true
349 printf "Processing mainboard/$VENDOR/$MAINBOARD"
353 xml " <vendor>$VENDOR</vendor>"
354 xml " <device>$MAINBOARD</device>"
356 xml " <architecture>$TARCH</architecture>"
359 [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
360 source $LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
362 if [ "$ARCH" = "$TARCH" -o $found_crosscompiler = true ]; then
363 printf " ($TARCH: ok)\n"
365 found_crosscompiler=false
366 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
368 found_crosscompiler=true
370 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
372 found_crosscompiler=true
374 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
375 for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
376 powerpc-7450-linux-gnu- powerpc-elf-; do
377 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
378 found_crosscompiler=true
379 CROSS_COMPILE=$prefix
385 # TBD: look for suitable cross compiler suite
386 # cross-$TARCH-gcc and cross-$TARCH-ld
389 if [ $found_crosscompiler == "false" ]; then
390 printf " ($TARCH: skipped, we're $ARCH)\n\n"
391 xml " <status>notbuilt</status>"
397 printf " ($TARCH: ok, we're $ARCH with a ${CROSS_COMPILE} cross compiler)\n"
399 xml " <path>`which ${CROSS_COMPILE}gcc`</path>"
400 xml " <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
406 CC=${CROSS_COMPILE}$CC
408 if [ "$stackprotect" = "true" ]; then
409 CC="$CC -fno-stack-protector"
412 if [ "$scanbuild" = "true" ]; then
414 mkdir -p $TARGET/${VENDOR}_${MAINBOARD}
415 mkdir -p $TARGET/scan-build-results-tmp
416 mv $ccwrap $TARGET/${VENDOR}_${MAINBOARD}
417 ccwrap=$TARGET/${VENDOR}_${MAINBOARD}/`basename $ccwrap`
418 echo '#!/bin/sh' > $ccwrap
419 echo $CC' "$@"' >> $ccwrap
422 MAKE="scan-build --use-cc=$ccwrap -o $TARGET/scan-build-results-tmp -analyze-headers $MAKE GCC=$ccwrap"
424 HOSTCC="CCC_CC=$HOSTCC \$(CC)"
427 built_successfully $VENDOR $MAINBOARD && \
429 printf " ( mainboard/$VENDOR/$MAINBOARD previously ok )\n\n"
430 xml " <status>previouslyok</status>"
436 build_broken $VENDOR $MAINBOARD || \
438 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
439 xml " <status>knownbroken</status>"
445 create_buildenv $VENDOR $MAINBOARD
446 if [ $? -eq 0 -a $configureonly -eq 0 ]; then
447 compile_target $VENDOR $MAINBOARD &&
448 xml " <status>ok</status>" ||
449 xml "<status>broken</status>"
450 if [ "$scanbuild" = "true" ]; then
451 mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
467 if [ "$hwtest" != "true" ]; then
471 # image does not exist. we silently skip the patch.
472 if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
476 which curl &> /dev/null
478 printf "curl is not installed but required for test submission. skipping test.\n\n"
483 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
484 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
487 # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
489 printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
491 curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
492 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
493 "http://qa.coreboot.org/deployment/send.php"
501 printf "Usage: $0 [-v] [-a] [-b] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
502 printf " $0 [-V|--version]\n"
503 printf " $0 [-h|--help]\n\n"
506 printf " [-v|--verbose] print more messages\n"
507 printf " [-a|--all] build previously succeeded ports as well\n"
508 printf " [-b|--broken] attempt to build ports that are known broken\n"
509 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
510 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
511 printf " [-V|--version] print version number and exit\n"
512 printf " [-h|--help] print this help and exit\n"
513 printf " [-x|--xml] write xml log file \n"
514 printf " (defaults to $XMLFILE)\n"
515 printf " [-T|--test] submit image(s) to automated test system\n"
516 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
517 printf " [-s|--silent] omit compiler calls in logs\n"
518 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
519 printf " [-sb|--scan-build] use clang's static analyzer\n"
520 printf " [-C|--config] configure-only mode\n"
521 printf " [lbroot] absolute path to coreboot sources\n"
522 printf " (defaults to $LBROOT)\n\n"
529 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
531 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
532 Copyright (C) 2006-2008 by coresystems GmbH <info@coresystems.de>
534 This program is free software; you may redistribute it under the terms
535 of the GNU General Public License. This program has absolutely no
544 LBROOT=$( cd ../..; pwd )
547 # parse parameters.. try to find out whether we're running GNU getopt
548 getoptbrand="`getopt -V`"
549 if [ "${getoptbrand:0:6}" == "getopt" ]; then
550 # Detected GNU getopt that supports long options.
551 args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config Vvhat:bp:Tc:sxC -- "$@"`
554 # Detected non-GNU getopt
555 args=`getopt Vvhat:bp:Tc:sxC $*`
566 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
567 -t|--target) shift; target="$1"; shift;;
568 -a|--all) shift; buildall=true;;
569 -b|--broken) shift; buildbroken=true;;
570 -v|--verbose) shift; verbose=true;;
571 -V|--version) shift; myversion; exit 0;;
572 -h|--help) shift; myversion; myhelp; exit 0;;
573 -p|--payloads) shift; payloads="$1"; shift;;
574 -T|--test) shift; hwtest=true;;
575 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
576 -s|--silent) shift; silent="-s";;
577 -ns|--nostackprotect) shift; stackprotect=true;;
578 -sb|--scan-build) shift; scanbuild=true;;
579 -C|--config) shift; configureonly=1;;
581 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
586 # /path/to/freebios2/
587 test -z "$1" || LBROOT=$1
589 debug "LBROOT=$LBROOT"
591 xml '<?xml version="1.0" encoding="utf-8"?>'
594 if [ "$target" != "" ]; then
595 # build a single board
596 VENDOR=`printf $target|cut -f1 -d/`
597 MAINBOARD=`printf $target|cut -f2 -d/`
598 build_target $VENDOR $MAINBOARD
599 test_target $VENDOR $MAINBOARD
601 # build all boards per default
602 for VENDOR in $( vendors ); do
603 for MAINBOARD in $( mainboards $VENDOR ); do
604 build_target $VENDOR $MAINBOARD
605 test_target $VENDOR $MAINBOARD