5 # This script builds coreboot images for all available targets.
7 # (C) 2004 by Stefan Reinauer <stepan@openbios.org>
8 # (C) 2006-2010 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="December 10th, 2010"
18 ABUILD_VERSION="0.9.1"
22 # Where shall we place all the build trees?
23 TARGET=coreboot-builds
24 XMLFILE=$TOP/abuild.xml
27 # path to payload. Should be more generic
30 # Lines of error context to be printed in FAILURE case
33 TESTSUBMISSION="http://qa.coreboot.org/deployment/send.php"
35 # Number of CPUs to compile on per default
41 # Did any board fail to build?
44 # One might want to adjust these in case of cross compiling
45 for i in make gmake gnumake nonexistant_make; do
46 $i --version 2>/dev/null |grep "GNU Make" >/dev/null && break
48 if [ "$i" = "nonexistant_make" ]; then
49 echo No GNU Make found.
54 # this can be changed to xml by -x
57 # silent mode.. no compiler calls, only warnings in the log files.
58 # this is disabled per default but can be enabled with -s
61 # clang mode enabled by -sb option.
67 # stackprotect mode enabled by -ns option.
70 # loglevel changed with -l / --loglevel option
73 # update existing image
79 ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
81 -e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
82 -e "s/Power Macintosh/ppc/"`
88 printf "\n$0: execution interrupted manually.\n"
89 if [ "$mode" == "xml" ]; then
90 printf "$0: deleting incomplete xml output file.\n"
97 test "$verbose" == "true" && printf "$*\n"
102 test "$mode" == "xml" && printf "$*\n" >> $XMLFILE
108 test "$mode" == "xml" && {
117 test "$mode" == "junit" && printf "$*\n" >> $XMLFILE
123 test "$mode" == "junit" && {
133 # make this a function so we can easily select
134 # without breaking readability
135 ls -1 "$ROOT/src/mainboard" | grep -v Kconfig | grep -v Makefile
140 # make this a function so we can easily select
141 # without breaking readability
145 ls -1 $ROOT/src/mainboard/$VENDOR | grep -v Kconfig
148 function architecture
152 ARCH=`cat $ROOT/src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
153 grep "select ARCH_"|cut -f2- -d_`
154 echo $ARCH | sed s/X86/i386/
157 function create_config
163 build_dir=$TARGET/${VENDOR}_${MAINBOARD}
165 # get a working payload for the board if we have one.
166 # the --payload option expects a directory containing
167 # a shell script payload.sh
168 # Usage: payload.sh [VENDOR] [DEVICE]
169 # the script returns an absolute path to the payload binary.
171 if [ -f $payloads/payload.sh ]; then
172 PAYLOAD=`sh $payloads/payload.sh $VENDOR $MAINBOARD`
173 printf "Using payload $PAYLOAD\n"
176 [ "$update" = "true" ] && mv ${build_dir}/coreboot.rom coreboot.rom.tmp
177 mkdir -p ${build_dir}
178 mkdir -p $TARGET/sharedutils
179 [ "$update" = "true" ] && mv coreboot.rom.tmp ${build_dir}/coreboot.rom
181 if [ "$CONFIG" != "" ]; then
182 printf " Using existing configuration $CONFIG ... "
183 xml " <config>$CONFIG</config>"
184 cp src/mainboard/$VENDOR/$MAINBOARD/$CONFIG ${build_dir}/config.build
186 printf " Creating config file... "
187 xml " <config>autogenerated</config>"
188 grep "if[\t ]*VENDOR" src/mainboard/$VENDOR/$MAINBOARD/../Kconfig | \
189 sed "s,^.*\(VENDOR_.*\)[^A-Z0-9_]*,CONFIG_\1=y," > ${build_dir}/config.build
190 grep "if[\t ]*BOARD" src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
191 sed "s,^.*\(BOARD_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> ${build_dir}/config.build
192 grep "select[\t ]*ARCH" src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
193 sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> ${build_dir}/config.build
194 echo "CONFIG_MAINBOARD_DIR=\"$VENDOR/$MAINBOARD\"" >> ${build_dir}/config.build
195 echo "CONFIG_CBFS_PREFIX=\"$cbfs_prefix\"" >> ${build_dir}/config.build
196 if [ "$PAYLOAD" != "/dev/null" ]; then
197 echo "# CONFIG_PAYLOAD_NONE is not set" >> ${build_dir}/config.build
198 echo "# CONFIG_PAYLOAD_SEABIOS is not set" >> ${build_dir}/config.build
199 echo "CONFIG_PAYLOAD_ELF=y" >> ${build_dir}/config.build
200 echo "CONFIG_PAYLOAD_FILE=\"$PAYLOAD\"" >> ${build_dir}/config.build
203 if [ "$loglevel" != "default" ]; then
204 printf "(loglevel override) "
205 echo "CONFIG_MAXIMUM_CONSOLE_LOGLEVEL_$loglevel=y" >> ${build_dir}/config.build
206 echo "CONFIG_MAXIMUM_CONSOLE_LOGLEVEL=$loglevel" >> ${build_dir}/config.build
207 echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL_$loglevel=y" >> ${build_dir}/config.build
208 echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$loglevel" >> ${build_dir}/config.build
211 if [ "$update" != "false" ]; then
213 echo "CONFIG_UPDATE_IMAGE=y" >> ${build_dir}/config.build
216 if [ "$ccache" = "true" ]; then
217 printf "(ccache enabled) "
218 echo "CONFIG_CCACHE=y" >> ${build_dir}/config.build
221 if [ "$scanbuild" = "true" ]; then
222 printf "(scan-build enabled) "
223 echo "CONFIG_SCANBUILD_ENABLE=y" >> ${build_dir}/config.build
224 echo "CONFIG_SCANBUILD_REPORT_LOCATION=\"$TARGET/scan-build-results-tmp\"" >> ${build_dir}/config.build
228 #yes "" | $MAKE oldconfig obj=${build_dir} objutil=$TARGET/sharedutils &> ${build_dir}/config.log
229 yes "" | $MAKE oldconfig DOTCONFIG=${build_dir}/config.build obj=${build_dir} objutil=$TARGET/sharedutils &> ${build_dir}/config.log
231 if [ $ret -eq 0 ]; then
233 xml " <builddir>ok</builddir>"
235 xmlfile $build_dir/config.log
240 # Does this ever happen?
241 printf "FAILED!\nLog excerpt:\n"
242 xml " <builddir>failed</builddir>"
244 xmlfile $build_dir/config.log
247 tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log
252 function create_buildenv
258 create_config $VENDOR $MAINBOARD $CONFIG
261 # Allow simple "make" in the target directory
262 MAKEFILE=$TARGET/${VENDOR}_${MAINBOARD}/Makefile
263 echo "# autogenerated" > $MAKEFILE
264 echo "TOP=$ROOT" >> $MAKEFILE
265 echo "BUILD=$TARGET" >> $MAKEFILE
266 echo "OBJ=\$(BUILD)/${VENDOR}_${MAINBOARD}" >> $MAKEFILE
267 echo "OBJUTIL=\$(BUILD)/sharedutils" >> $MAKEFILE
268 echo "all:" >> $MAKEFILE
269 echo " @cp -a config.h config.h.bak" >> $MAKEFILE
270 echo " @cd \$(TOP); \$(MAKE) oldconfig DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> $MAKEFILE
271 echo " @tail -n+6 config.h > config.new; tail -n+6 config.h.bak > config.old" >> $MAKEFILE
272 echo " @cmp -s config.new config.old && cp -a config.h.bak config.h || echo \"Config file changed\"" >> $MAKEFILE
273 echo " @rm config.h.bak config.new config.old" >> $MAKEFILE
274 echo " @cd \$(TOP); \$(MAKE) DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> $MAKEFILE
279 function compile_target
284 printf " Compiling image "
285 test "$cpus" == "" && printf "in parallel .. "
286 test "$cpus" == "1" && printf "on 1 cpu .. "
287 test 0$cpus -gt 1 && printf "on %d cpus in parallel .. " $cpus
290 #stime=`perl -e 'print time();' 2>/dev/null || date +%s`
291 build_dir=$TARGET/${VENDOR}_${MAINBOARD}
292 eval $MAKE $silent DOTCONFIG=${build_dir}/config.build obj=${build_dir} objutil=$TARGET/sharedutils \
293 &> ${build_dir}/make.log
295 cp .xcompile ${build_dir}/xcompile.build
296 cd $TARGET/${VENDOR}_${MAINBOARD}
298 etime=`perl -e 'print time();' 2>/dev/null || date +%s`
299 duration=$(( $etime - $stime ))
300 xml " <buildtime>${duration}s</buildtime>"
301 junit " <testcase classname='board' name='$TARCH/$VENDOR/$MAINBOARD' time='$duration' >"
307 if [ $ret -eq 0 ]; then
308 xml " <compile>ok</compile>"
311 junit "</system-out>"
312 printf "ok\n" > compile.status
313 printf "ok. (took ${duration}s)\n"
317 xml " <compile>failed</compile>"
318 junit "<failure type='BuildFailed'>"
321 printf "FAILED after ${duration}s!\nLog excerpt:\n"
322 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
329 function build_broken
333 [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
334 [ "$buildbroken" == "true" -o "$status" == "yes" ]
337 function build_target
342 TARCH=$( architecture $VENDOR $MAINBOARD )
344 # Allow architecture override in an abuild.info file.
345 # This is used for the Motorola Sandpoint, which is not a real target
346 # but a skeleton target for the Sandpoint X3.
347 [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
348 source $ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
352 CC="${CROSS_COMPILE}gcc"
354 found_crosscompiler=false
355 if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
356 # i386-elf target needs --divide, for i386-linux, that's the default
357 if [ "$TARCH" = "i386" ]; then
358 CC="$CC -Wa,--divide"
360 CROSS_COMPILE="$TARCH-elf-"
362 CROSS_TEXT=", using $CROSS_COMPILE$CC"
363 found_crosscompiler=true
368 printf "Building $VENDOR/$MAINBOARD; "
369 XMLFILE=$TOP/$TARGET/${VENDOR}_${MAINBOARD}/abuild.xml
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$CROSS_TEXT\n"
382 # FIXME this is basically the same as above.
383 found_crosscompiler=false
384 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
386 found_crosscompiler=true
388 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
390 found_crosscompiler=true
392 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
393 for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
394 powerpc-7450-linux-gnu- powerpc-elf-; do
395 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
396 found_crosscompiler=true
397 CROSS_COMPILE=$prefix
403 # TBD: look for suitable cross compiler suite
404 # cross-$TARCH-gcc and cross-$TARCH-ld
407 if [ $found_crosscompiler == "false" ]; then
408 printf "$TARCH: skipped, we're $ARCH\n\n"
409 xml " <status>notbuilt</status>"
413 junit " <testcase classname='board' name='$TARCH/$VENDOR/$MAINBOARD' >"
414 junit "<failure type='NoCrossCompiler'>No cross-compiler for $TARCH found</failure>"
418 printf "$TARCH: ok, $ARCH using ${CROSS_COMPILE}gcc\n"
420 xml " <path>`which ${CROSS_COMPILE}gcc`</path>"
421 xml " <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
427 CC=${CROSS_COMPILE}$CC
429 if [ "$stackprotect" = "true" ]; then
430 CC="$CC -fno-stack-protector"
433 build_broken $VENDOR $MAINBOARD || \
435 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
436 xml " <status>knownbroken</status>"
439 junit " <testcase classname='board' name='$TARCH/$VENDOR/$MAINBOARD' >"
440 junit "<failure type='KnownBroken'>Board is marked as broken</failure>"
444 stime=`perl -e 'print time();' 2>/dev/null || date +%s`
445 create_buildenv $VENDOR $MAINBOARD $CONFIG
446 if [ $? -eq 0 -a $configureonly -eq 0 ]; then
447 if [ "$scanbuild" = "true" ]; then
448 rm -rf $TARGET/scan-build-results-tmp
450 compile_target $VENDOR $MAINBOARD &&
451 xml " <status>ok</status>" ||
452 xml "<status>broken</status>"
453 if [ "$scanbuild" = "true" ]; then
454 rm -rf $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
455 mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
458 # Not calculated here because we still print it in compile_target
459 #etime=`perl -e 'print time();' 2>/dev/null || date +%s`
460 #duration=$(( $etime - $stime ))
461 #xml " <buildtime>${duration}s</buildtime>"
475 if [ "$hwtest" != "true" ]; then
479 # image does not exist. we silently skip the patch.
480 if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
484 which curl &> /dev/null
486 printf "curl is not installed but required for test submission. skipping test.\n\n"
491 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
492 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
495 # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
497 printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
499 curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
500 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
501 "http://qa.coreboot.org/deployment/send.php"
507 function remove_target
509 if [ "$remove" != "true" ]; then
516 # Save the generated coreboot.rom file of each board.
517 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
518 cp $TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom \
519 ${VENDOR}_${MAINBOARD}_coreboot.rom
522 printf "Removing build dir for board $VENDOR $MAINBOARD...\n"
523 rm -rf $TARGET/${VENDOR}_${MAINBOARD}
530 printf "Usage: $0 [-v] [-a] [-b] [-r] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
531 printf " $0 [-V|--version]\n"
532 printf " $0 [-h|--help]\n\n"
535 printf " [-v|--verbose] print more messages\n"
536 printf " [-a|--all] build previously succeeded ports as well\n"
537 printf " [-b|--broken] attempt to build ports that are known broken\n"
538 printf " [-r|--remove] remove output dir after build\n"
539 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
540 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
541 printf " [-V|--version] print version number and exit\n"
542 printf " [-h|--help] print this help and exit\n"
543 printf " [-x|--xml] write xml log file \n"
544 printf " (defaults to $XMLFILE)\n"
545 printf " [-J|--junit] write JUnit formatted xml log file \n"
546 printf " (defaults to $XMLFILE)\n"
547 printf " [-T|--test] submit image(s) to automated test system\n"
548 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
549 printf " [-s|--silent] omit compiler calls in logs\n"
550 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
551 printf " [-sb|--scan-build] use clang's static analyzer\n"
552 printf " [-y|--ccache] use ccache\n"
553 printf " [-C|--config] configure-only mode\n"
554 printf " [-l|--loglevel <num>] set loglevel\n"
555 printf " [-u|--update] update existing image\n"
556 printf " [-P|--prefix <name>] file name prefix in CBFS\n"
557 printf " [lbroot] absolute path to coreboot sources\n"
558 printf " (defaults to $ROOT)\n\n"
565 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
567 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
568 Copyright (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
570 This program is free software; you may redistribute it under the terms
571 of the GNU General Public License. This program has absolutely no
582 test -f util/sconfig/sconfig.l && ROOT=$( pwd )
583 test -f ../util/sconfig/sconfig.l && ROOT=$( cd ..; pwd )
584 test "$ROOT" = "" && ROOT=$( 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,junit,xml,config,loglevel:,remove,prefix:,update,nostackprotect,scan-build,ccache -o Vvhat:bp:Tc:sJxCl:rP:uy -- "$@"`
593 # Detected non-GNU getopt
594 args=`getopt Vvhat:bp:Tc:sJxCl:rP:uy $*`
605 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
606 -J|--junit) shift; mode=junit; rm -f $XMLFILE ;;
607 -t|--target) shift; target="$1"; shift;;
608 -a|--all) shift; buildall=true;;
609 -b|--broken) shift; buildbroken=true;;
610 -r|--remove) shift; remove=true;;
611 -v|--verbose) shift; verbose=true; silent='V=1';;
612 -V|--version) shift; myversion; exit 0;;
613 -h|--help) shift; myversion; myhelp; exit 0;;
614 -p|--payloads) shift; payloads="$1"; shift;;
615 -T|--test) shift; hwtest=true;;
616 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
617 -s|--silent) shift; silent="-s";;
618 -ns|--nostackprotect) shift; stackprotect=true;;
619 -sb|--scan-build) shift; scanbuild=true;;
620 -y|--ccache) shift; ccache=true;;
621 -C|--config) shift; configureonly=1;;
622 -l|--loglevel) shift; loglevel="$1"; shift;;
623 -u|--update) shift; update="true";;
624 -P|--prefix) shift; cbfs_prefix="$1"; shift;;
626 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
631 if [ "$cpus" != "1" ]; then
632 export MAKEFLAGS="-j $cpus"
635 # /path/to/freebios2/
636 test -z "$1" || ROOT=$1
640 xml '<?xml version="1.0" encoding="utf-8"?>'
643 junit '<?xml version="1.0" encoding="utf-8"?>'
646 if [ "$target" != "" ]; then
647 # build a single board
648 VENDOR=`printf $target|cut -f1 -d/`
649 MAINBOARD=`printf $target|cut -f2 -d/`
650 CONFIG=`printf $target|cut -f3 -d/`
651 if [ ! -r $ROOT/src/mainboard/$target ]; then
652 printf "No such target: $target\n"
657 build_target $VENDOR $MAINBOARD $CONFIG
658 test_target $VENDOR $MAINBOARD
659 test "$mode" != "text" && cat $TARGET/${VENDOR}_${MAINBOARD}/abuild.xml >> $REAL_XMLFILE
660 XMLFILE=$REAL_XMLFILE
662 # build all boards per default
663 for VENDOR in $( vendors ); do
664 for MAINBOARD in $( mainboards $VENDOR ); do
665 build_target $VENDOR $MAINBOARD
666 test_target $VENDOR $MAINBOARD
667 remove_target $VENDOR $MAINBOARD
670 if [ "$mode" != "text" ]; then
671 for xmlfile in $TARGET/*_*/abuild.xml; do
672 cat $xmlfile >> $REAL_XMLFILE
675 XMLFILE=$REAL_XMLFILE