5 # This script builds coreboot images for all available targets.
7 # (C) 2004 by Stefan Reinauer <stepan@openbios.org>
8 # (C) 2006-2008 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="May 27th, 2008"
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 cat $LBROOT/src/mainboard/$VENDOR/$MAINBOARD/Config.lb | \
114 grep ^arch | cut -f 2 -d\
117 function create_config
121 TARCH=$( architecture $VENDOR $MAINBOARD )
122 TARGCONFIG=$LBROOT/targets/$VENDOR/$MAINBOARD/Config-abuild.lb
124 # get a working payload for the board if we have one.
125 # the --payload option expects a directory containing
126 # an executable shell script payload.sh
127 # Usage: payload.sh [VENDOR] [DEVICE]
128 # the script returns an absolute path to the payload binary.
130 if [ -x $payloads/payload.sh ]; then
131 PAYLOAD=`$payloads/payload.sh $VENDOR $MAINBOARD`
132 printf "Using payload $PAYLOAD\n"
137 if [ -f $TARGCONFIG ]; then
138 cp $TARGCONFIG $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
139 printf "Using existing test target $TARGCONFIG"
140 xml " <config>$TARGCONFIG</config>"
143 printf " Creating config file..."
144 xml " <config>autogenerated</config>"
146 # This will make a target directory of ./VENDOR_MAINBOARD
148 target VENDOR_MAINBOARD
149 mainboard VENDOR/MAINBOARD
152 option CROSS_COMPILE="CROSS_PREFIX"
153 option HOSTCC="CROSS_HOSTCC"
158 if [ "$TARCH" == i386 ] ; then
161 option USE_FALLBACK_IMAGE=0
162 option ROM_IMAGE_SIZE=0x17000
163 option COREBOOT_EXTRA_VERSION=".0-normal"
168 option USE_FALLBACK_IMAGE=1
169 option ROM_IMAGE_SIZE=0x17000
170 option COREBOOT_EXTRA_VERSION=".0-fallback"
173 buildrom ./coreboot.rom ROM_SIZE "normal" "fallback"
178 option COREBOOT_EXTRA_VERSION=".0"
181 buildrom ./coreboot.rom ROM_SIZE "only"
184 ) > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
187 if [ "`which lzma`" != "" -a "$PAYLOAD" != /dev/null ]; then
188 COMPRESSION="option CONFIG_COMPRESSED_PAYLOAD_LZMA=1"
190 COMPRESSION="# no compression"
193 cp $TARGET/Config-${VENDOR}_${MAINBOARD}.lb $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre
194 sed -e s:VENDOR:$VENDOR:g \
195 -e s:MAINBOARD:$MAINBOARD:g \
196 -e s:payload\ __PAYLOAD__:payload\ $PAYLOAD:g \
197 -e s:CROSSCC:"$CC":g \
198 -e s:CROSS_PREFIX:"$CROSS_COMPILE":g \
199 -e s:CROSS_HOSTCC:"$HOSTCC":g \
200 -e s:__COMPRESSION__:"$COMPRESSION":g \
201 $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
205 function create_builddir
210 printf " Creating builddir..."
213 config_dir=$LBROOT/util/newconfig
214 yapps2_py=$config_dir/yapps2.py
215 config_g=$config_dir/config.g
216 config_lb=Config-${VENDOR}_${MAINBOARD}.lb
220 build_dir=${VENDOR}_${MAINBOARD}
221 config_py=$build_dir/config.py
223 if [ ! -d $build_dir ] ; then
226 if [ ! -f $config_py ]; then
227 $PYTHON $yapps2_py $config_g $config_py &> $build_dir/py.log
230 # make sure config.py is up-to-date
232 export PYTHONPATH=$config_dir
233 $PYTHON $config_py $config_lb $LBROOT &> $build_dir/config.log
234 if [ $? -eq 0 ]; then
236 xml " <builddir>ok</builddir>"
238 xmlfile $build_dir/config.log
243 printf "FAILED! Log excerpt:\n"
244 xml " <builddir>failed</builddir>"
246 xmlfile $build_dir/config.log
249 tail -n $CONTEXT $build_dir/config.log
254 function create_buildenv
258 create_config $VENDOR $MAINBOARD
259 create_builddir $VENDOR $MAINBOARD
262 function compile_target
267 printf " Compiling image "
268 test "$cpus" == "" && printf "in parallel .. "
269 test "$cpus" == "1" && printf "on 1 cpu .. "
270 test 0$cpus -gt 1 && printf "on %d cpus in parallel .. " $cpus
273 cd $TARGET/${VENDOR}_${MAINBOARD}
274 stime=`perl -e 'print time();'`
275 eval $MAKE $silent -j $cpus &> make.log
277 etime=`perl -e 'print time();'`
278 duration=$(( $etime - $stime ))
279 if [ $ret -eq 0 ]; then
280 xml " <compile>ok</compile>"
281 xml " <compiletime>${duration}s</compiletime>"
285 printf "ok\n" > compile.status
286 printf "ok. (took ${duration}s)\n"
290 xml " <compile>failed</compile>"
291 xml " <compiletime>${duration}s</compiletime>"
296 printf "FAILED after ${duration}s! Log excerpt:\n"
297 tail -n $CONTEXT make.log
303 function built_successfully
307 if [ -d "$TARGET/${VENDOR}_${MAINBOARD}" ]; then
308 cd $TARGET/${VENDOR}_${MAINBOARD}
309 if [ -r compile.status ] ; then
310 status=`cat compile.status`
314 [ "$buildall" != "true" -a "$status" == "ok" ]
317 function build_broken
321 [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
322 [ "$buildbroken" == "true" -o "$status" == "yes" ]
325 function build_target
329 TARCH=$( architecture $VENDOR $MAINBOARD )
333 CC="${CROSS_COMPILE}gcc"
335 found_crosscompiler=false
336 if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
337 # i386-elf target needs --divide, for i386-linux, that's the default
339 if [ "$TARCH" = "i386" ]; then
340 CC="$CC -Wa,--divide"
343 CROSS_COMPILE="$TARCH-elf-"
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)\n"
399 xml " <path>`which ${CROSS_COMPILE}gcc`</path>"
400 xml " <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
406 if [ "$stackprotect" = "true" ]; then
407 CC="$CC -fno-stack-protector"
410 if [ "$scanbuild" = "true" ]; then
412 mkdir -p $TARGET/${VENDOR}_${MAINBOARD}
413 mkdir -p $TARGET/scan-build-results-tmp
414 mv $ccwrap $TARGET/${VENDOR}_${MAINBOARD}
415 ccwrap=$TARGET/${VENDOR}_${MAINBOARD}/`basename $ccwrap`
416 echo '#!/bin/sh' > $ccwrap
417 echo $CC' "$@"' >> $ccwrap
420 MAKE="scan-build --use-cc=$ccwrap -o $TARGET/scan-build-results-tmp -analyze-headers $MAKE GCC=$ccwrap"
422 HOSTCC="CCC_CC=$HOSTCC \$(CC)"
425 built_successfully $VENDOR $MAINBOARD && \
427 printf " ( mainboard/$VENDOR/$MAINBOARD previously ok )\n\n"
428 xml " <status>previouslyok</status>"
434 build_broken $VENDOR $MAINBOARD || \
436 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
437 xml " <status>knownbroken</status>"
443 create_buildenv $VENDOR $MAINBOARD
444 if [ $? -eq 0 -a $configureonly -eq 0 ]; then
445 compile_target $VENDOR $MAINBOARD &&
446 xml " <status>ok</status>" ||
447 xml "<status>broken</status>"
448 if [ "$scanbuild" = "true" ]; then
449 mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
465 if [ "$hwtest" != "true" ]; then
469 # image does not exist. we silently skip the patch.
470 if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
474 which curl &> /dev/null
476 printf "curl is not installed but required for test submission. skipping test.\n\n"
481 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
482 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
485 # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
487 printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
489 curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
490 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
491 "http://qa.coreboot.org/deployment/send.php"
499 printf "Usage: $0 [-v] [-a] [-b] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
500 printf " $0 [-V|--version]\n"
501 printf " $0 [-h|--help]\n\n"
504 printf " [-v|--verbose] print more messages\n"
505 printf " [-a|--all] build previously succeeded ports as well\n"
506 printf " [-b|--broken] attempt to build ports that are known broken\n"
507 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
508 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
509 printf " [-V|--version] print version number and exit\n"
510 printf " [-h|--help] print this help and exit\n"
511 printf " [-x|--xml] write xml log file \n"
512 printf " (defaults to $XMLFILE)\n"
513 printf " [-T|--test] submit image(s) to automated test system\n"
514 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
515 printf " [-s|--silent] omit compiler calls in logs\n"
516 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
517 printf " [-sb|--scan-build] use clang's static analyzer\n"
518 printf " [-C|--config] configure-only mode\n"
519 printf " [lbroot] absolute path to coreboot sources\n"
520 printf " (defaults to $LBROOT)\n\n"
527 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
529 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
530 Copyright (C) 2006-2008 by coresystems GmbH <info@coresystems.de>
532 This program is free software; you may redistribute it under the terms
533 of the GNU General Public License. This program has absolutely no
542 LBROOT=$( cd ../..; pwd )
545 # parse parameters.. try to find out whether we're running GNU getopt
546 getoptbrand="`getopt -V`"
547 if [ "${getoptbrand:0:6}" == "getopt" ]; then
548 # Detected GNU getopt that supports long options.
549 args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config Vvhat:bp:Tc:sxC -- "$@"`
552 # Detected non-GNU getopt
553 args=`getopt Vvhat:bp:Tc:sxC $*`
564 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
565 -t|--target) shift; target="$1"; shift;;
566 -a|--all) shift; buildall=true;;
567 -b|--broken) shift; buildbroken=true;;
568 -v|--verbose) shift; verbose=true;;
569 -V|--version) shift; myversion; exit 0;;
570 -h|--help) shift; myversion; myhelp; exit 0;;
571 -p|--payloads) shift; payloads="$1"; shift;;
572 -T|--test) shift; hwtest=true;;
573 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
574 -s|--silent) shift; silent="-s";;
575 -ns|--nostackprotect) shift; stackprotect=true;;
576 -sb|--scan-build) shift; scanbuild=true;;
577 -C|--config) shift; configureonly=1;;
579 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
584 # /path/to/freebios2/
585 test -z "$1" || LBROOT=$1
587 debug "LBROOT=$LBROOT"
589 xml '<?xml version="1.0" encoding="utf-8"?>'
592 if [ "$target" != "" ]; then
593 # build a single board
594 VENDOR=`printf $target|cut -f1 -d/`
595 MAINBOARD=`printf $target|cut -f2 -d/`
596 build_target $VENDOR $MAINBOARD
597 test_target $VENDOR $MAINBOARD
599 # build all boards per default
600 for VENDOR in $( vendors ); do
601 for MAINBOARD in $( mainboards $VENDOR ); do
602 build_target $VENDOR $MAINBOARD
603 test_target $VENDOR $MAINBOARD