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"
20 # Where shall we place all the build trees?
21 TARGET=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 # Did any board fail to build?
41 # One might want to adjust these in case of cross compiling
42 for i in make gmake gnumake nonexistant_make; do
43 $i --version 2>/dev/null |grep "GNU Make" >/dev/null && break
45 if [ "$i" = "nonexistant_make" ]; then
46 echo No GNU Make found.
51 # this can be changed to xml by -x
54 # silent mode.. no compiler calls, only warnings in the log files.
55 # this is disabled per default but can be enabled with -s
58 # clang mode enabled by -sb option.
64 # stackprotect mode enabled by -ns option.
67 # loglevel changed with -l / --loglevel option
70 # update existing image
76 ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
78 -e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
79 -e "s/Power Macintosh/ppc/"`
85 printf "\n$0: execution interrupted manually.\n"
86 if [ "$mode" == "xml" ]; then
87 printf "$0: deleting incomplete xml output file.\n"
94 test "$verbose" == "true" && printf "$*\n"
99 test "$mode" == "xml" && printf "$*\n" >> $XMLFILE
105 test "$mode" == "xml" && {
114 test "$mode" == "junit" && printf "$*\n" >> $XMLFILE
120 test "$mode" == "junit" && {
130 # make this a function so we can easily select
131 # without breaking readability
132 ls -1 "$ROOT/src/mainboard" | grep -v Kconfig | grep -v Makefile
137 # make this a function so we can easily select
138 # without breaking readability
142 ls -1 $ROOT/src/mainboard/$VENDOR | grep -v Kconfig
145 function architecture
149 ARCH=`cat $ROOT/src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
150 grep "select ARCH_"|cut -f2- -d_`
151 echo $ARCH | sed s/X86/i386/
154 function create_config
160 build_dir=$TARGET/${VENDOR}_${MAINBOARD}
162 # get a working payload for the board if we have one.
163 # the --payload option expects a directory containing
164 # a shell script payload.sh
165 # Usage: payload.sh [VENDOR] [DEVICE]
166 # the script returns an absolute path to the payload binary.
168 if [ -f $payloads/payload.sh ]; then
169 PAYLOAD=`sh $payloads/payload.sh $VENDOR $MAINBOARD`
170 printf "Using payload $PAYLOAD\n"
173 [ "$update" = "true" ] && mv ${build_dir}/coreboot.rom coreboot.rom.tmp
174 mkdir -p ${build_dir}
175 mkdir -p $TARGET/sharedutils
176 [ "$update" = "true" ] && mv coreboot.rom.tmp ${build_dir}/coreboot.rom
178 if [ "$CONFIG" != "" ]; then
179 printf " Using existing configuration $CONFIG ... "
180 xml " <config>$CONFIG</config>"
181 cp src/mainboard/$VENDOR/$MAINBOARD/$CONFIG ${build_dir}/config.build
183 printf " Creating config file... "
184 xml " <config>autogenerated</config>"
185 grep "if[\t ]*VENDOR" src/mainboard/$VENDOR/$MAINBOARD/../Kconfig | \
186 sed "s,^.*\(VENDOR_.*\)[^A-Z0-9_]*,CONFIG_\1=y," > ${build_dir}/config.build
187 grep "if[\t ]*BOARD" src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
188 sed "s,^.*\(BOARD_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> ${build_dir}/config.build
189 grep "select[\t ]*ARCH" src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
190 sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> ${build_dir}/config.build
191 echo "CONFIG_MAINBOARD_DIR=\"$VENDOR/$MAINBOARD\"" >> ${build_dir}/config.build
192 echo "CONFIG_CBFS_PREFIX=\"$cbfs_prefix\"" >> ${build_dir}/config.build
193 if [ "$PAYLOAD" != "/dev/null" ]; then
194 echo "# CONFIG_PAYLOAD_NONE is not set" >> ${build_dir}/config.build
195 echo "# CONFIG_PAYLOAD_SEABIOS is not set" >> ${build_dir}/config.build
196 echo "CONFIG_PAYLOAD_ELF=y" >> ${build_dir}/config.build
197 echo "CONFIG_PAYLOAD_FILE=\"$PAYLOAD\"" >> ${build_dir}/config.build
200 if [ "$loglevel" != "default" ]; then
201 printf "(loglevel override) "
202 echo "CONFIG_MAXIMUM_CONSOLE_LOGLEVEL_$loglevel=y" >> ${build_dir}/config.build
203 echo "CONFIG_MAXIMUM_CONSOLE_LOGLEVEL=$loglevel" >> ${build_dir}/config.build
204 echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL_$loglevel=y" >> ${build_dir}/config.build
205 echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$loglevel" >> ${build_dir}/config.build
208 if [ "$update" != "false" ]; then
210 echo "CONFIG_UPDATE_IMAGE=y" >> ${build_dir}/config.build
213 if [ "$ccache" = "true" ]; then
214 printf "(ccache enabled) "
215 echo "CONFIG_CCACHE=y" >> ${build_dir}/config.build
218 if [ "$scanbuild" = "true" ]; then
219 printf "(scan-build enabled) "
220 echo "CONFIG_SCANBUILD_ENABLE=y" >> ${build_dir}/config.build
221 echo "CONFIG_SCANBUILD_REPORT_LOCATION=\"$TARGET/scan-build-results-tmp\"" >> ${build_dir}/config.build
225 #yes "" | $MAKE oldconfig -j $cpus obj=${build_dir} objutil=$TARGET/sharedutils &> ${build_dir}/config.log
226 yes "" | $MAKE oldconfig DOTCONFIG=${build_dir}/config.build obj=${build_dir} objutil=$TARGET/sharedutils &> ${build_dir}/config.log
228 if [ $ret -eq 0 ]; then
230 xml " <builddir>ok</builddir>"
232 xmlfile $build_dir/config.log
237 # Does this ever happen?
238 printf "FAILED!\nLog excerpt:\n"
239 xml " <builddir>failed</builddir>"
241 xmlfile $build_dir/config.log
244 tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log
249 function create_buildenv
255 create_config $VENDOR $MAINBOARD $CONFIG
258 # Allow simple "make" in the target directory
259 MAKEFILE=$TARGET/${VENDOR}_${MAINBOARD}/Makefile
260 echo "# autogenerated" > $MAKEFILE
261 echo "TOP=$ROOT" >> $MAKEFILE
262 echo "BUILD=$TARGET" >> $MAKEFILE
263 echo "OBJ=\$(BUILD)/${VENDOR}_${MAINBOARD}" >> $MAKEFILE
264 echo "OBJUTIL=\$(BUILD)/sharedutils" >> $MAKEFILE
265 echo "all:" >> $MAKEFILE
266 echo " @cp -a config.h config.h.bak" >> $MAKEFILE
267 echo " @cd \$(TOP); \$(MAKE) oldconfig DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> $MAKEFILE
268 echo " @tail -n+6 config.h > config.new; tail -n+6 config.h.bak > config.old" >> $MAKEFILE
269 echo " @cmp -s config.new config.old && cp -a config.h.bak config.h || echo \"Config file changed\"" >> $MAKEFILE
270 echo " @rm config.h.bak config.new config.old" >> $MAKEFILE
271 echo " @cd \$(TOP); \$(MAKE) DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> $MAKEFILE
276 function compile_target
281 printf " Compiling image "
282 test "$cpus" == "" && printf "in parallel .. "
283 test "$cpus" == "1" && printf "on 1 cpu .. "
284 test 0$cpus -gt 1 && printf "on %d cpus in parallel .. " $cpus
287 #stime=`perl -e 'print time();' 2>/dev/null || date +%s`
288 build_dir=$TARGET/${VENDOR}_${MAINBOARD}
289 eval $MAKE $silent -j $cpus DOTCONFIG=${build_dir}/config.build obj=${build_dir} objutil=$TARGET/sharedutils \
290 &> ${build_dir}/make.log
292 mv .xcompile ${build_dir}/xcompile.build
293 cd $TARGET/${VENDOR}_${MAINBOARD}
295 etime=`perl -e 'print time();' 2>/dev/null || date +%s`
296 duration=$(( $etime - $stime ))
297 xml " <buildtime>${duration}s</buildtime>"
298 junit " <testcase classname='board' name='$TARCH/$VENDOR/$MAINBOARD' time='$duration' >"
304 if [ $ret -eq 0 ]; then
305 xml " <compile>ok</compile>"
308 junit "</system-out>"
309 printf "ok\n" > compile.status
310 printf "ok. (took ${duration}s)\n"
314 xml " <compile>failed</compile>"
315 junit "<failure type='BuildFailed'>"
318 printf "FAILED after ${duration}s!\nLog excerpt:\n"
319 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
326 function build_broken
330 [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
331 [ "$buildbroken" == "true" -o "$status" == "yes" ]
334 function build_target
339 TARCH=$( architecture $VENDOR $MAINBOARD )
341 # Allow architecture override in an abuild.info file.
342 # This is used for the Motorola Sandpoint, which is not a real target
343 # but a skeleton target for the Sandpoint X3.
344 [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
345 source $ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
349 CC="${CROSS_COMPILE}gcc"
351 found_crosscompiler=false
352 if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
353 # i386-elf target needs --divide, for i386-linux, that's the default
354 if [ "$TARCH" = "i386" ]; then
355 CC="$CC -Wa,--divide"
357 CROSS_COMPILE="$TARCH-elf-"
359 CROSS_TEXT=", using $CROSS_COMPILE$CC"
360 found_crosscompiler=true
365 printf "Building $VENDOR/$MAINBOARD; "
369 xml " <vendor>$VENDOR</vendor>"
370 xml " <device>$MAINBOARD</device>"
372 xml " <architecture>$TARCH</architecture>"
375 if [ "$ARCH" = "$TARCH" -o $found_crosscompiler = true ]; then
376 printf "$TARCH: ok$CROSS_TEXT\n"
378 # FIXME this is basically the same as above.
379 found_crosscompiler=false
380 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
382 found_crosscompiler=true
384 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
386 found_crosscompiler=true
388 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
389 for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
390 powerpc-7450-linux-gnu- powerpc-elf-; do
391 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
392 found_crosscompiler=true
393 CROSS_COMPILE=$prefix
399 # TBD: look for suitable cross compiler suite
400 # cross-$TARCH-gcc and cross-$TARCH-ld
403 if [ $found_crosscompiler == "false" ]; then
404 printf "$TARCH: skipped, we're $ARCH\n\n"
405 xml " <status>notbuilt</status>"
409 junit " <testcase classname='board' name='$TARCH/$VENDOR/$MAINBOARD' >"
410 junit "<failure type='NoCrossCompiler'>No cross-compiler for $TARCH found</failure>"
414 printf "$TARCH: ok, $ARCH using ${CROSS_COMPILE}gcc\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 build_broken $VENDOR $MAINBOARD || \
431 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
432 xml " <status>knownbroken</status>"
435 junit " <testcase classname='board' name='$TARCH/$VENDOR/$MAINBOARD' >"
436 junit "<failure type='KnownBroken'>Board is marked as broken</failure>"
440 stime=`perl -e 'print time();' 2>/dev/null || date +%s`
441 create_buildenv $VENDOR $MAINBOARD $CONFIG
442 if [ $? -eq 0 -a $configureonly -eq 0 ]; then
443 if [ "$scanbuild" = "true" ]; then
444 rm -rf $TARGET/scan-build-results-tmp
446 compile_target $VENDOR $MAINBOARD &&
447 xml " <status>ok</status>" ||
448 xml "<status>broken</status>"
449 if [ "$scanbuild" = "true" ]; then
450 rm -rf $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
451 mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
454 # Not calculated here because we still print it in compile_target
455 #etime=`perl -e 'print time();' 2>/dev/null || date +%s`
456 #duration=$(( $etime - $stime ))
457 #xml " <buildtime>${duration}s</buildtime>"
471 if [ "$hwtest" != "true" ]; then
475 # image does not exist. we silently skip the patch.
476 if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
480 which curl &> /dev/null
482 printf "curl is not installed but required for test submission. skipping test.\n\n"
487 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
488 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
491 # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
493 printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
495 curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
496 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
497 "http://qa.coreboot.org/deployment/send.php"
503 function remove_target
505 if [ "$remove" != "true" ]; then
512 # Save the generated coreboot.rom file of each board.
513 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
514 cp $TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom \
515 ${VENDOR}_${MAINBOARD}_coreboot.rom
518 printf "Removing build dir for board $VENDOR $MAINBOARD...\n"
519 rm -rf $TARGET/${VENDOR}_${MAINBOARD}
526 printf "Usage: $0 [-v] [-a] [-b] [-r] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
527 printf " $0 [-V|--version]\n"
528 printf " $0 [-h|--help]\n\n"
531 printf " [-v|--verbose] print more messages\n"
532 printf " [-a|--all] build previously succeeded ports as well\n"
533 printf " [-b|--broken] attempt to build ports that are known broken\n"
534 printf " [-r|--remove] remove output dir after build\n"
535 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
536 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
537 printf " [-V|--version] print version number and exit\n"
538 printf " [-h|--help] print this help and exit\n"
539 printf " [-x|--xml] write xml log file \n"
540 printf " (defaults to $XMLFILE)\n"
541 printf " [-J|--junit] write JUnit formatted xml log file \n"
542 printf " (defaults to $XMLFILE)\n"
543 printf " [-T|--test] submit image(s) to automated test system\n"
544 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
545 printf " [-s|--silent] omit compiler calls in logs\n"
546 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
547 printf " [-sb|--scan-build] use clang's static analyzer\n"
548 printf " [-y|--ccache] use ccache\n"
549 printf " [-C|--config] configure-only mode\n"
550 printf " [-l|--loglevel <num>] set loglevel\n"
551 printf " [-u|--update] update existing image\n"
552 printf " [-P|--prefix <name>] file name prefix in CBFS\n"
553 printf " [lbroot] absolute path to coreboot sources\n"
554 printf " (defaults to $ROOT)\n\n"
561 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
563 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
564 Copyright (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
566 This program is free software; you may redistribute it under the terms
567 of the GNU General Public License. This program has absolutely no
578 test -f util/sconfig/sconfig.l && ROOT=$( pwd )
579 test -f ../util/sconfig/sconfig.l && ROOT=$( cd ..; pwd )
580 test "$ROOT" = "" && ROOT=$( cd ../..; pwd )
582 # parse parameters.. try to find out whether we're running GNU getopt
583 getoptbrand="`getopt -V`"
584 if [ "${getoptbrand:0:6}" == "getopt" ]; then
585 # Detected GNU getopt that supports long options.
586 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 -- "$@"`
589 # Detected non-GNU getopt
590 args=`getopt Vvhat:bp:Tc:sJxCl:rP:uy $*`
601 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
602 -J|--junit) shift; mode=junit; rm -f $XMLFILE ;;
603 -t|--target) shift; target="$1"; shift;;
604 -a|--all) shift; buildall=true;;
605 -b|--broken) shift; buildbroken=true;;
606 -r|--remove) shift; remove=true;;
607 -v|--verbose) shift; verbose=true; silent='V=1';;
608 -V|--version) shift; myversion; exit 0;;
609 -h|--help) shift; myversion; myhelp; exit 0;;
610 -p|--payloads) shift; payloads="$1"; shift;;
611 -T|--test) shift; hwtest=true;;
612 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
613 -s|--silent) shift; silent="-s";;
614 -ns|--nostackprotect) shift; stackprotect=true;;
615 -sb|--scan-build) shift; scanbuild=true;;
616 -y|--ccache) shift; ccache=true;;
617 -C|--config) shift; configureonly=1;;
618 -l|--loglevel) shift; loglevel="$1"; shift;;
619 -u|--update) shift; update="true";;
620 -P|--prefix) shift; cbfs_prefix="$1"; shift;;
622 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
627 # /path/to/freebios2/
628 test -z "$1" || ROOT=$1
632 xml '<?xml version="1.0" encoding="utf-8"?>'
635 junit '<?xml version="1.0" encoding="utf-8"?>'
638 if [ "$target" != "" ]; then
639 # build a single board
640 VENDOR=`printf $target|cut -f1 -d/`
641 MAINBOARD=`printf $target|cut -f2 -d/`
642 CONFIG=`printf $target|cut -f3 -d/`
643 if [ ! -r $ROOT/src/mainboard/$target ]; then
644 printf "No such target: $target\n"
649 build_target $VENDOR $MAINBOARD $CONFIG
650 test_target $VENDOR $MAINBOARD
652 # build all boards per default
653 for VENDOR in $( vendors ); do
654 for MAINBOARD in $( mainboards $VENDOR ); do
655 build_target $VENDOR $MAINBOARD
656 test_target $VENDOR $MAINBOARD
657 remove_target $VENDOR $MAINBOARD