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"
502 function remove_target
504 if [ "$remove" != "true" ]; then
511 # Save the generated coreboot.rom file of each board.
512 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
513 cp $TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom \
514 ${VENDOR}_${MAINBOARD}_coreboot.rom
517 printf "Removing build dir for board $VENDOR $MAINBOARD...\n"
518 rm -rf $TARGET/${VENDOR}_${MAINBOARD}
525 printf "Usage: $0 [-v] [-a] [-b] [-r] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
526 printf " $0 [-V|--version]\n"
527 printf " $0 [-h|--help]\n\n"
530 printf " [-v|--verbose] print more messages\n"
531 printf " [-a|--all] build previously succeeded ports as well\n"
532 printf " [-b|--broken] attempt to build ports that are known broken\n"
533 printf " [-r|--remove] remove output dir after build\n"
534 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
535 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
536 printf " [-V|--version] print version number and exit\n"
537 printf " [-h|--help] print this help and exit\n"
538 printf " [-x|--xml] write xml log file \n"
539 printf " (defaults to $XMLFILE)\n"
540 printf " [-T|--test] submit image(s) to automated test system\n"
541 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
542 printf " [-s|--silent] omit compiler calls in logs\n"
543 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
544 printf " [-sb|--scan-build] use clang's static analyzer\n"
545 printf " [-C|--config] configure-only mode\n"
546 printf " [lbroot] absolute path to coreboot sources\n"
547 printf " (defaults to $LBROOT)\n\n"
554 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
556 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
557 Copyright (C) 2006-2008 by coresystems GmbH <info@coresystems.de>
559 This program is free software; you may redistribute it under the terms
560 of the GNU General Public License. This program has absolutely no
569 LBROOT=$( cd ../..; pwd )
572 # parse parameters.. try to find out whether we're running GNU getopt
573 getoptbrand="`getopt -V`"
574 if [ "${getoptbrand:0:6}" == "getopt" ]; then
575 # Detected GNU getopt that supports long options.
576 args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config Vvhat:bp:Tc:sxC -- "$@"`
579 # Detected non-GNU getopt
580 args=`getopt Vvhat:bp:Tc:sxC $*`
591 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
592 -t|--target) shift; target="$1"; shift;;
593 -a|--all) shift; buildall=true;;
594 -b|--broken) shift; buildbroken=true;;
595 -r|--remove) shift; remove=true; shift;;
596 -v|--verbose) shift; verbose=true;;
597 -V|--version) shift; myversion; exit 0;;
598 -h|--help) shift; myversion; myhelp; exit 0;;
599 -p|--payloads) shift; payloads="$1"; shift;;
600 -T|--test) shift; hwtest=true;;
601 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
602 -s|--silent) shift; silent="-s";;
603 -ns|--nostackprotect) shift; stackprotect=true;;
604 -sb|--scan-build) shift; scanbuild=true;;
605 -C|--config) shift; configureonly=1;;
607 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
612 # /path/to/freebios2/
613 test -z "$1" || LBROOT=$1
615 debug "LBROOT=$LBROOT"
617 xml '<?xml version="1.0" encoding="utf-8"?>'
620 if [ "$target" != "" ]; then
621 # build a single board
622 VENDOR=`printf $target|cut -f1 -d/`
623 MAINBOARD=`printf $target|cut -f2 -d/`
624 build_target $VENDOR $MAINBOARD
625 test_target $VENDOR $MAINBOARD
627 # build all boards per default
628 for VENDOR in $( vendors ); do
629 for MAINBOARD in $( mainboards $VENDOR ); do
630 build_target $VENDOR $MAINBOARD
631 test_target $VENDOR $MAINBOARD
632 remove_target $VENDOR $MAINBOARD