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" && {
116 # make this a function so we can easily select
117 # without breaking readability
118 ls -1 "$ROOT/src/mainboard" | grep -v Kconfig | grep -v Makefile
123 # make this a function so we can easily select
124 # without breaking readability
128 ls -1 $ROOT/src/mainboard/$VENDOR | grep -v Kconfig
131 function architecture
135 ARCH=`cat $ROOT/src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
136 grep "select ARCH_"|cut -f2- -d_`
137 echo $ARCH | sed s/X86/i386/
140 function create_config
146 build_dir=$TARGET/${VENDOR}_${MAINBOARD}
148 # get a working payload for the board if we have one.
149 # the --payload option expects a directory containing
150 # a shell script payload.sh
151 # Usage: payload.sh [VENDOR] [DEVICE]
152 # the script returns an absolute path to the payload binary.
154 if [ -f $payloads/payload.sh ]; then
155 PAYLOAD=`sh $payloads/payload.sh $VENDOR $MAINBOARD`
156 printf "Using payload $PAYLOAD\n"
159 [ "$update" = "true" ] && mv ${build_dir}/coreboot.rom coreboot.rom.tmp
160 mkdir -p ${build_dir}
161 mkdir -p $TARGET/sharedutils
162 [ "$update" = "true" ] && mv coreboot.rom.tmp ${build_dir}/coreboot.rom
164 if [ "$CONFIG" != "" ]; then
165 printf " Using existing configuration $CONFIG ... "
166 xml " <config>$CONFIG</config>"
167 cp src/mainboard/$VENDOR/$MAINBOARD/$CONFIG ${build_dir}/config.build
169 printf " Creating config file... "
170 xml " <config>autogenerated</config>"
171 grep "if[\t ]*VENDOR" src/mainboard/$VENDOR/$MAINBOARD/../Kconfig | \
172 sed "s,^.*\(VENDOR_.*\)[^A-Z0-9_]*,CONFIG_\1=y," > ${build_dir}/config.build
173 grep "if[\t ]*BOARD" src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
174 sed "s,^.*\(BOARD_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> ${build_dir}/config.build
175 grep "select[\t ]*ARCH" src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
176 sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> ${build_dir}/config.build
177 echo "CONFIG_MAINBOARD_DIR=\"$VENDOR/$MAINBOARD\"" >> ${build_dir}/config.build
178 echo "CONFIG_CBFS_PREFIX=\"$cbfs_prefix\"" >> ${build_dir}/config.build
179 if [ "$PAYLOAD" != "/dev/null" ]; then
180 echo "# CONFIG_PAYLOAD_NONE is not set" >> ${build_dir}/config.build
181 echo "# CONFIG_PAYLOAD_SEABIOS is not set" >> ${build_dir}/config.build
182 echo "CONFIG_PAYLOAD_ELF=y" >> ${build_dir}/config.build
183 echo "CONFIG_PAYLOAD_FILE=\"$PAYLOAD\"" >> ${build_dir}/config.build
186 if [ "$loglevel" != "default" ]; then
187 printf "(loglevel override) "
188 echo "CONFIG_MAXIMUM_CONSOLE_LOGLEVEL_$loglevel=y" >> ${build_dir}/config.build
189 echo "CONFIG_MAXIMUM_CONSOLE_LOGLEVEL=$loglevel" >> ${build_dir}/config.build
190 echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL_$loglevel=y" >> ${build_dir}/config.build
191 echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$loglevel" >> ${build_dir}/config.build
194 if [ "$update" != "false" ]; then
196 echo "CONFIG_UPDATE_IMAGE=y" >> ${build_dir}/config.build
199 if [ "$ccache" = "true" ]; then
200 printf "(ccache enabled) "
201 echo "CONFIG_CCACHE=y" >> ${build_dir}/config.build
204 if [ "$scanbuild" = "true" ]; then
205 printf "(scan-build enabled) "
206 echo "CONFIG_SCANBUILD_ENABLE=y" >> ${build_dir}/config.build
207 echo "CONFIG_SCANBUILD_REPORT_LOCATION=\"$TARGET/scan-build-results-tmp\"" >> ${build_dir}/config.build
211 #yes "" | $MAKE oldconfig -j $cpus obj=${build_dir} objutil=$TARGET/sharedutils &> ${build_dir}/config.log
212 yes "" | $MAKE oldconfig DOTCONFIG=${build_dir}/config.build obj=${build_dir} objutil=$TARGET/sharedutils &> ${build_dir}/config.log
214 if [ $ret -eq 0 ]; then
216 xml " <builddir>ok</builddir>"
218 xmlfile $build_dir/config.log
223 # Does this ever happen?
224 printf "FAILED!\nLog excerpt:\n"
225 xml " <builddir>failed</builddir>"
227 xmlfile $build_dir/config.log
230 tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log
235 function create_buildenv
241 create_config $VENDOR $MAINBOARD $CONFIG
244 # Allow simple "make" in the target directory
245 MAKEFILE=$TARGET/${VENDOR}_${MAINBOARD}/Makefile
246 echo "# autogenerated" > $MAKEFILE
247 echo "TOP=$ROOT" >> $MAKEFILE
248 echo "BUILD=$TARGET" >> $MAKEFILE
249 echo "OBJ=\$(BUILD)/${VENDOR}_${MAINBOARD}" >> $MAKEFILE
250 echo "OBJUTIL=\$(BUILD)/sharedutils" >> $MAKEFILE
251 echo "all:" >> $MAKEFILE
252 echo " @cp -a config.h config.h.bak" >> $MAKEFILE
253 echo " @cd \$(TOP); \$(MAKE) oldconfig DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> $MAKEFILE
254 echo " @tail -n+6 config.h > config.new; tail -n+6 config.h.bak > config.old" >> $MAKEFILE
255 echo " @cmp -s config.new config.old && cp -a config.h.bak config.h || echo \"Config file changed\"" >> $MAKEFILE
256 echo " @rm config.h.bak config.new config.old" >> $MAKEFILE
257 echo " @cd \$(TOP); \$(MAKE) DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> $MAKEFILE
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 #stime=`perl -e 'print time();' 2>/dev/null || date +%s`
274 build_dir=$TARGET/${VENDOR}_${MAINBOARD}
275 eval $MAKE $silent -j $cpus DOTCONFIG=${build_dir}/config.build obj=${build_dir} objutil=$TARGET/sharedutils \
276 &> ${build_dir}/make.log
278 mv .xcompile ${build_dir}/xcompile.build
279 cd $TARGET/${VENDOR}_${MAINBOARD}
281 etime=`perl -e 'print time();' 2>/dev/null || date +%s`
282 duration=$(( $etime - $stime ))
283 xml " <buildtime>${duration}s</buildtime>"
289 if [ $ret -eq 0 ]; then
290 xml " <compile>ok</compile>"
291 printf "ok\n" > compile.status
292 printf "ok. (took ${duration}s)\n"
296 xml " <compile>failed</compile>"
297 printf "FAILED after ${duration}s!\nLog excerpt:\n"
298 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
305 function build_broken
309 [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
310 [ "$buildbroken" == "true" -o "$status" == "yes" ]
313 function build_target
318 TARCH=$( architecture $VENDOR $MAINBOARD )
320 # Allow architecture override in an abuild.info file.
321 # This is used for the Motorola Sandpoint, which is not a real target
322 # but a skeleton target for the Sandpoint X3.
323 [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
324 source $ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
328 CC="${CROSS_COMPILE}gcc"
330 found_crosscompiler=false
331 if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
332 # i386-elf target needs --divide, for i386-linux, that's the default
333 if [ "$TARCH" = "i386" ]; then
334 CC="$CC -Wa,--divide"
336 CROSS_COMPILE="$TARCH-elf-"
338 CROSS_TEXT=", using $CROSS_COMPILE$CC"
339 found_crosscompiler=true
344 printf "Building $VENDOR/$MAINBOARD; "
348 xml " <vendor>$VENDOR</vendor>"
349 xml " <device>$MAINBOARD</device>"
351 xml " <architecture>$TARCH</architecture>"
354 if [ "$ARCH" = "$TARCH" -o $found_crosscompiler = true ]; then
355 printf "$TARCH: ok$CROSS_TEXT\n"
357 # FIXME this is basically the same as above.
358 found_crosscompiler=false
359 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
361 found_crosscompiler=true
363 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
365 found_crosscompiler=true
367 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
368 for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
369 powerpc-7450-linux-gnu- powerpc-elf-; do
370 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
371 found_crosscompiler=true
372 CROSS_COMPILE=$prefix
378 # TBD: look for suitable cross compiler suite
379 # cross-$TARCH-gcc and cross-$TARCH-ld
382 if [ $found_crosscompiler == "false" ]; then
383 printf "$TARCH: skipped, we're $ARCH\n\n"
384 xml " <status>notbuilt</status>"
390 printf "$TARCH: ok, $ARCH using ${CROSS_COMPILE}gcc\n"
392 xml " <path>`which ${CROSS_COMPILE}gcc`</path>"
393 xml " <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
399 CC=${CROSS_COMPILE}$CC
401 if [ "$stackprotect" = "true" ]; then
402 CC="$CC -fno-stack-protector"
405 build_broken $VENDOR $MAINBOARD || \
407 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
408 xml " <status>knownbroken</status>"
414 stime=`perl -e 'print time();' 2>/dev/null || date +%s`
415 create_buildenv $VENDOR $MAINBOARD $CONFIG
416 if [ $? -eq 0 -a $configureonly -eq 0 ]; then
417 if [ "$scanbuild" = "true" ]; then
418 rm -rf $TARGET/scan-build-results-tmp
420 compile_target $VENDOR $MAINBOARD &&
421 xml " <status>ok</status>" ||
422 xml "<status>broken</status>"
423 if [ "$scanbuild" = "true" ]; then
424 rm -rf $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
425 mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
428 # Not calculated here because we still print it in compile_target
429 #etime=`perl -e 'print time();' 2>/dev/null || date +%s`
430 #duration=$(( $etime - $stime ))
431 #xml " <buildtime>${duration}s</buildtime>"
444 if [ "$hwtest" != "true" ]; then
448 # image does not exist. we silently skip the patch.
449 if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
453 which curl &> /dev/null
455 printf "curl is not installed but required for test submission. skipping test.\n\n"
460 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
461 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
464 # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
466 printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
468 curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
469 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
470 "http://qa.coreboot.org/deployment/send.php"
476 function remove_target
478 if [ "$remove" != "true" ]; then
485 # Save the generated coreboot.rom file of each board.
486 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
487 cp $TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom \
488 ${VENDOR}_${MAINBOARD}_coreboot.rom
491 printf "Removing build dir for board $VENDOR $MAINBOARD...\n"
492 rm -rf $TARGET/${VENDOR}_${MAINBOARD}
499 printf "Usage: $0 [-v] [-a] [-b] [-r] [-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 " [-r|--remove] remove output dir after build\n"
508 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
509 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
510 printf " [-V|--version] print version number and exit\n"
511 printf " [-h|--help] print this help and exit\n"
512 printf " [-x|--xml] write xml log file \n"
513 printf " (defaults to $XMLFILE)\n"
514 printf " [-T|--test] submit image(s) to automated test system\n"
515 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
516 printf " [-s|--silent] omit compiler calls in logs\n"
517 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
518 printf " [-sb|--scan-build] use clang's static analyzer\n"
519 printf " [-y|--ccache] use ccache\n"
520 printf " [-C|--config] configure-only mode\n"
521 printf " [-l|--loglevel <num>] set loglevel\n"
522 printf " [-u|--update] update existing image\n"
523 printf " [-P|--prefix <name>] file name prefix in CBFS\n"
524 printf " [lbroot] absolute path to coreboot sources\n"
525 printf " (defaults to $ROOT)\n\n"
532 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
534 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
535 Copyright (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
537 This program is free software; you may redistribute it under the terms
538 of the GNU General Public License. This program has absolutely no
549 test -f util/sconfig/sconfig.l && ROOT=$( pwd )
550 test -f ../util/sconfig/sconfig.l && ROOT=$( cd ..; pwd )
551 test "$ROOT" = "" && ROOT=$( cd ../..; pwd )
553 # parse parameters.. try to find out whether we're running GNU getopt
554 getoptbrand="`getopt -V`"
555 if [ "${getoptbrand:0:6}" == "getopt" ]; then
556 # Detected GNU getopt that supports long options.
557 args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config,loglevel:,remove,prefix:,update,nostackprotect,scan-build,ccache -o Vvhat:bp:Tc:sxCl:rP:uy -- "$@"`
560 # Detected non-GNU getopt
561 args=`getopt Vvhat:bp:Tc:sxCl:rP:uy $*`
572 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
573 -t|--target) shift; target="$1"; shift;;
574 -a|--all) shift; buildall=true;;
575 -b|--broken) shift; buildbroken=true;;
576 -r|--remove) shift; remove=true;;
577 -v|--verbose) shift; verbose=true; silent='V=1';;
578 -V|--version) shift; myversion; exit 0;;
579 -h|--help) shift; myversion; myhelp; exit 0;;
580 -p|--payloads) shift; payloads="$1"; shift;;
581 -T|--test) shift; hwtest=true;;
582 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
583 -s|--silent) shift; silent="-s";;
584 -ns|--nostackprotect) shift; stackprotect=true;;
585 -sb|--scan-build) shift; scanbuild=true;;
586 -y|--ccache) shift; ccache=true;;
587 -C|--config) shift; configureonly=1;;
588 -l|--loglevel) shift; loglevel="$1"; shift;;
589 -u|--update) shift; update="true";;
590 -P|--prefix) shift; cbfs_prefix="$1"; shift;;
592 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
597 # /path/to/freebios2/
598 test -z "$1" || ROOT=$1
602 xml '<?xml version="1.0" encoding="utf-8"?>'
605 if [ "$target" != "" ]; then
606 # build a single board
607 VENDOR=`printf $target|cut -f1 -d/`
608 MAINBOARD=`printf $target|cut -f2 -d/`
609 CONFIG=`printf $target|cut -f3 -d/`
610 if [ ! -r $ROOT/src/mainboard/$target ]; then
611 printf "No such target: $target\n"
615 build_target $VENDOR $MAINBOARD $CONFIG
616 test_target $VENDOR $MAINBOARD
618 # build all boards per default
619 for VENDOR in $( vendors ); do
620 for MAINBOARD in $( mainboards $VENDOR ); do
621 build_target $VENDOR $MAINBOARD
622 test_target $VENDOR $MAINBOARD
623 remove_target $VENDOR $MAINBOARD