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="January 29th, 2010"
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
37 # use old config method "newconfig"
40 # One might want to adjust these in case of cross compiling
41 for i in make gmake gnumake nonexistant_make; do
42 $i --version 2>/dev/null |grep "GNU Make" >/dev/null && break
44 if [ "$i" = "nonexistant_make" ]; then
45 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.
61 # stackprotect mode enabled by -ns option.
64 # loglevel changed with -l / --loglevel option
67 ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
69 -e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
70 -e "s/Power Macintosh/ppc/"`
76 printf "\n$0: execution interrupted manually.\n"
77 if [ "$mode" == "xml" ]; then
78 printf "$0: deleting incomplete xml output file.\n"
85 test "$verbose" == "true" && printf "$*\n"
90 test "$mode" == "xml" && printf "$*\n" >> $XMLFILE
95 test "$mode" == "xml" && {
106 # make this a function so we can easily select
107 # without breaking readability
108 ls -1 "$ROOT/src/mainboard" | grep -v Kconfig | grep -v Makefile
113 # make this a function so we can easily select
114 # without breaking readability
118 ls -1 $ROOT/src/mainboard/$VENDOR | grep -v Kconfig
121 function architecture
125 if [ $oldconfig -eq 1 ]; then
126 ARCH=`cat $ROOT/src/mainboard/$VENDOR/$MAINBOARD/Config.lb | \
127 grep ^arch | cut -f 2 -d\ `
128 echo $ARCH | sed s/ppc/powerpc/
130 ARCH=`cat $ROOT/src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
131 grep "select ARCH_"|cut -f2- -d_`
132 echo $ARCH | sed s/X86/i386/
136 function create_config_old
141 TARCH=$( architecture $VENDOR $MAINBOARD )
142 TARGCONFIG=$ROOT/targets/$VENDOR/$MAINBOARD/Config-abuild.lb
144 if [ "$CONFIG" != "" ]; then
145 TARGCONFIG=$ROOT/targets/$VENDOR/$MAINBOARD/$CONFIG
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"
161 if [ -f $TARGCONFIG ]; then
162 cp $TARGCONFIG $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
163 printf "Using existing test target $TARGCONFIG"
164 xml " <config>$TARGCONFIG</config>"
166 printf " Creating config file..."
167 xml " <config>autogenerated</config>"
169 # This will make a target directory of ./VENDOR_MAINBOARD
171 target VENDOR_MAINBOARD
172 mainboard VENDOR/MAINBOARD
175 option CONFIG_CROSS_COMPILE="CROSS_PREFIX"
176 option HOSTCC="CROSS_HOSTCC"
182 if [ "$TARCH" == i386 ] ; then
185 option CONFIG_USE_FALLBACK_IMAGE=0
186 option COREBOOT_EXTRA_VERSION=".0-normal"
191 option CONFIG_USE_FALLBACK_IMAGE=1
192 option COREBOOT_EXTRA_VERSION=".0-fallback"
195 buildrom ./coreboot.rom CONFIG_ROM_SIZE "normal" "fallback"
200 option COREBOOT_EXTRA_VERSION=".0"
203 buildrom ./coreboot.rom CONFIG_ROM_SIZE "only"
206 ) > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
209 if [ "$loglevel" != "default" ]; then
210 LOGLEVEL1="option CONFIG_MAXIMUM_CONSOLE_LOGLEVEL=$loglevel"
211 LOGLEVEL2="option CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$loglevel"
213 LOGLEVEL1="# no loglevel override"
217 COMPRESSION="# no compression"
218 if which lzma >/dev/null 2>/dev/null; then
219 if [ "$PAYLOAD" != /dev/null ]; then
220 COMPRESSION="option CONFIG_COMPRESSED_PAYLOAD_LZMA=1"
224 cp $TARGET/Config-${VENDOR}_${MAINBOARD}.lb $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre
225 sed -e s:VENDOR:$VENDOR:g \
226 -e s:MAINBOARD:$MAINBOARD:g \
227 -e s:payload\ __PAYLOAD__:payload\ $PAYLOAD:g \
228 -e s:CROSSCC:"$CC":g \
229 -e s:CROSS_PREFIX:"$CROSS_COMPILE":g \
230 -e s:CROSS_HOSTCC:"$HOSTCC":g \
231 -e s:__COMPRESSION__:"$COMPRESSION":g \
232 -e s:__LOGLEVEL__:"$LOGLEVEL1"\
234 $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
238 function create_config
244 build_dir=$TARGET/${VENDOR}_${MAINBOARD}
246 # get a working payload for the board if we have one.
247 # the --payload option expects a directory containing
248 # a shell script payload.sh
249 # Usage: payload.sh [VENDOR] [DEVICE]
250 # the script returns an absolute path to the payload binary.
252 if [ -f $payloads/payload.sh ]; then
253 PAYLOAD=`sh $payloads/payload.sh $VENDOR $MAINBOARD`
254 printf "Using payload $PAYLOAD\n"
257 $MAKE distclean obj=${build_dir}
258 mkdir -p ${build_dir}
260 if [ "$CONFIG" != "" ]; then
261 printf " Using existing configuration $CONFIG ... "
262 xml " <config>$CONFIG</config>"
265 printf " Creating config file... "
266 xml " <config>autogenerated</config>"
267 grep "depends[\t ]on[\t ]*VENDOR" src/mainboard/$VENDOR/$MAINBOARD/../Kconfig | \
268 sed "s,^.*\(VENDOR_.*\)[^A-Z0-9_]*,CONFIG_\1=y," > .config
269 grep "config[\t ]*BOARD" src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
270 sed "s,^.*\(BOARD_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> .config
271 grep "select[\t ]*ARCH" src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
272 sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> .config
273 echo "CONFIG_MAINBOARD_DIR=\"$VENDOR/$MAINBOARD\"" >> .config
274 if [ "$PAYLOAD" != "/dev/null" ]; then
275 echo "# CONFIG_PAYLOAD_NONE is not set" >> .config
276 echo "CONFIG_PAYLOAD_ELF=\"$PAYLOAD\"" >> .config
279 if [ "$loglevel" != "default" ]; then
280 printf "(loglevel override) "
281 echo "CONFIG_MAXIMUM_CONSOLE_LOGLEVEL_$loglevel=y"
282 echo "CONFIG_MAXIMUM_CONSOLE_LOGLEVEL=$loglevel"
283 echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL_$loglevel=y"
284 echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$loglevel"
288 yes "" | $MAKE oldconfig obj=${build_dir} > ${build_dir}/config.log
290 mv .config.old $TARGET/${VENDOR}_${MAINBOARD}/config.in
291 if [ $ret -eq 0 ]; then
293 xml " <builddir>ok</builddir>"
295 xmlfile $build_dir/config.log
300 printf "FAILED! Log excerpt:\n"
301 xml " <builddir>failed</builddir>"
303 xmlfile $build_dir/config.log
306 tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log
311 function create_builddir
316 printf " Creating builddir..."
319 config_dir=$ROOT/util/newconfig
320 yapps2_py=$config_dir/yapps2.py
321 config_g=$config_dir/config.g
322 config_lb=Config-${VENDOR}_${MAINBOARD}.lb
326 build_dir=${VENDOR}_${MAINBOARD}
327 config_py=$build_dir/config.py
329 if [ ! -d $build_dir ] ; then
332 if [ ! -f $config_py ]; then
333 $PYTHON $yapps2_py $config_g $config_py &> $build_dir/py.log
336 # make sure config.py is up-to-date
338 export PYTHONPATH=$config_dir
339 $PYTHON $config_py $config_lb $ROOT &> $build_dir/config.log
340 if [ $? -eq 0 ]; then
342 xml " <builddir>ok</builddir>"
344 xmlfile $build_dir/config.log
349 printf "FAILED! Log excerpt:\n"
350 xml " <builddir>failed</builddir>"
352 xmlfile $build_dir/config.log
355 tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log
360 function create_buildenv
365 if [ $oldconfig -eq 1 ]; then
366 create_config_old $VENDOR $MAINBOARD $CONFIG
367 create_builddir $VENDOR $MAINBOARD
369 create_config $VENDOR $MAINBOARD $CONFIG
370 cp .config $TARGET/${VENDOR}_${MAINBOARD}/coreboot.config
374 function compile_target
379 printf " Compiling image "
380 test "$cpus" == "" && printf "in parallel .. "
381 test "$cpus" == "1" && printf "on 1 cpu .. "
382 test 0$cpus -gt 1 && printf "on %d cpus in parallel .. " $cpus
385 stime=`perl -e 'print time();'`
386 if [ $oldconfig -eq 1 ]; then
387 cd $TARGET/${VENDOR}_${MAINBOARD}
388 eval $MAKE $silent -j $cpus &> make.log
391 build_dir=$TARGET/${VENDOR}_${MAINBOARD}
392 eval $MAKE $silent -j $cpus obj=${build_dir} \
393 &> ${build_dir}/make.log
395 mv .config ${build_dir}/config.build
396 mv .xcompile ${build_dir}/xcompile.build
397 mv ..config.tmp ${build_dir}/config.deps
398 cd $TARGET/${VENDOR}_${MAINBOARD}
400 etime=`perl -e 'print time();'`
401 duration=$(( $etime - $stime ))
402 if [ $ret -eq 0 ]; then
403 xml " <compile>ok</compile>"
404 xml " <compiletime>${duration}s</compiletime>"
408 printf "ok\n" > compile.status
409 printf "ok. (took ${duration}s)\n"
413 xml " <compile>failed</compile>"
414 xml " <compiletime>${duration}s</compiletime>"
419 printf "FAILED after ${duration}s! Log excerpt:\n"
420 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
426 function built_successfully
430 if [ -d "$TARGET/${VENDOR}_${MAINBOARD}" ]; then
431 cd $TARGET/${VENDOR}_${MAINBOARD}
432 if [ -r compile.status ] ; then
433 status=`cat compile.status`
437 [ "$buildall" != "true" -a "$status" == "ok" ]
440 function build_broken
444 [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
445 [ "$buildbroken" == "true" -o "$status" == "yes" ]
448 function build_target
453 TARCH=$( architecture $VENDOR $MAINBOARD )
455 # Allow architecture override in an abuild.info file.
456 # This is used for the Motorola Sandpoint, which is not a real target
457 # but a skeleton target for the Sandpoint X3.
458 [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
459 source $ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
463 CC="${CROSS_COMPILE}gcc"
465 found_crosscompiler=false
466 if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
467 # i386-elf target needs --divide, for i386-linux, that's the default
468 if [ "$TARCH" = "i386" ]; then
469 CC="$CC -Wa,--divide"
471 CROSS_COMPILE="$TARCH-elf-"
473 echo using $CROSS_COMPILE$CC
474 found_crosscompiler=true
479 printf "Processing mainboard/$VENDOR/$MAINBOARD"
483 xml " <vendor>$VENDOR</vendor>"
484 xml " <device>$MAINBOARD</device>"
486 xml " <architecture>$TARCH</architecture>"
489 if [ "$ARCH" = "$TARCH" -o $found_crosscompiler = true ]; then
490 printf " ($TARCH: ok)\n"
492 found_crosscompiler=false
493 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
495 found_crosscompiler=true
497 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
499 found_crosscompiler=true
501 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
502 for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
503 powerpc-7450-linux-gnu- powerpc-elf-; do
504 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
505 found_crosscompiler=true
506 CROSS_COMPILE=$prefix
512 # TBD: look for suitable cross compiler suite
513 # cross-$TARCH-gcc and cross-$TARCH-ld
516 if [ $found_crosscompiler == "false" ]; then
517 printf " ($TARCH: skipped, we're $ARCH)\n\n"
518 xml " <status>notbuilt</status>"
524 printf " ($TARCH: ok, we're $ARCH with a ${CROSS_COMPILE} cross compiler)\n"
526 xml " <path>`which ${CROSS_COMPILE}gcc`</path>"
527 xml " <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
533 CC=${CROSS_COMPILE}$CC
535 if [ "$stackprotect" = "true" ]; then
536 CC="$CC -fno-stack-protector"
539 if [ "$scanbuild" = "true" ]; then
541 mkdir -p $TARGET/${VENDOR}_${MAINBOARD}
542 mkdir -p $TARGET/scan-build-results-tmp
543 mv $ccwrap $TARGET/${VENDOR}_${MAINBOARD}
544 ccwrap=$TARGET/${VENDOR}_${MAINBOARD}/`basename $ccwrap`
545 echo '#!/bin/sh' > $ccwrap
546 echo $CC' "$@"' >> $ccwrap
549 MAKE="scan-build --use-cc=$ccwrap -o $TARGET/scan-build-results-tmp -analyze-headers $MAKE GCC=$ccwrap"
551 HOSTCC="CCC_CC=$HOSTCC \$(CC)"
554 built_successfully $VENDOR $MAINBOARD && \
556 printf " ( mainboard/$VENDOR/$MAINBOARD previously ok )\n\n"
557 xml " <status>previouslyok</status>"
563 build_broken $VENDOR $MAINBOARD || \
565 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
566 xml " <status>knownbroken</status>"
572 create_buildenv $VENDOR $MAINBOARD $CONFIG
573 if [ $? -eq 0 -a $configureonly -eq 0 ]; then
574 compile_target $VENDOR $MAINBOARD &&
575 xml " <status>ok</status>" ||
576 xml "<status>broken</status>"
577 if [ "$scanbuild" = "true" ]; then
578 mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
594 if [ "$hwtest" != "true" ]; then
598 # image does not exist. we silently skip the patch.
599 if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
603 which curl &> /dev/null
605 printf "curl is not installed but required for test submission. skipping test.\n\n"
610 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
611 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
614 # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
616 printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
618 curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
619 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
620 "http://qa.coreboot.org/deployment/send.php"
626 function remove_target
628 if [ "$remove" != "true" ]; then
635 # Save the generated coreboot.rom file of each board.
636 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
637 cp $TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom \
638 ${VENDOR}_${MAINBOARD}_coreboot.rom
641 printf "Removing build dir for board $VENDOR $MAINBOARD...\n"
642 rm -rf $TARGET/${VENDOR}_${MAINBOARD}
649 printf "Usage: $0 [-v] [-a] [-b] [-r] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
650 printf " $0 [-V|--version]\n"
651 printf " $0 [-h|--help]\n\n"
654 printf " [-v|--verbose] print more messages\n"
655 printf " [-a|--all] build previously succeeded ports as well\n"
656 printf " [-b|--broken] attempt to build ports that are known broken\n"
657 printf " [-r|--remove] remove output dir after build\n"
658 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
659 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
660 printf " [-V|--version] print version number and exit\n"
661 printf " [-h|--help] print this help and exit\n"
662 printf " [-x|--xml] write xml log file \n"
663 printf " (defaults to $XMLFILE)\n"
664 printf " [-T|--test] submit image(s) to automated test system\n"
665 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
666 printf " [-s|--silent] omit compiler calls in logs\n"
667 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
668 printf " [-sb|--scan-build] use clang's static analyzer\n"
669 printf " [-C|--config] configure-only mode\n"
670 printf " [-l|--loglevel <num>] set loglevel\n"
671 printf " [lbroot] absolute path to coreboot sources\n"
672 printf " (defaults to $ROOT)\n\n"
679 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
681 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
682 Copyright (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
684 This program is free software; you may redistribute it under the terms
685 of the GNU General Public License. This program has absolutely no
696 test -f util/newconfig/config.g && ROOT=$( pwd )
697 test -f ../util/newconfig/config.g && ROOT=$( cd ..; pwd )
698 test "$ROOT" = "" && ROOT=$( cd ../..; pwd )
700 # parse parameters.. try to find out whether we're running GNU getopt
701 getoptbrand="`getopt -V`"
702 if [ "${getoptbrand:0:6}" == "getopt" ]; then
703 # Detected GNU getopt that supports long options.
704 args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config,loglevel:,oldconfig Vvhat:bp:Tc:sxCl:o -- "$@"`
707 # Detected non-GNU getopt
708 args=`getopt Vvhat:bp:Tc:sxCl:o $*`
719 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
720 -t|--target) shift; target="$1"; shift;;
721 -a|--all) shift; buildall=true;;
722 -b|--broken) shift; buildbroken=true;;
723 -r|--remove) shift; remove=true; shift;;
724 -v|--verbose) shift; verbose=true;;
725 -V|--version) shift; myversion; exit 0;;
726 -h|--help) shift; myversion; myhelp; exit 0;;
727 -p|--payloads) shift; payloads="$1"; shift;;
728 -T|--test) shift; hwtest=true;;
729 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
730 -s|--silent) shift; silent="-s";;
731 -ns|--nostackprotect) shift; stackprotect=true;;
732 -sb|--scan-build) shift; scanbuild=true;;
733 -C|--config) shift; configureonly=1;;
734 -l|--loglevel) shift; loglevel="$1"; shift;;
735 -o|--oldconfig) shift; oldconfig=1;;
737 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
742 # /path/to/freebios2/
743 test -z "$1" || ROOT=$1
747 xml '<?xml version="1.0" encoding="utf-8"?>'
750 if [ "$target" != "" ]; then
751 # build a single board
752 VENDOR=`printf $target|cut -f1 -d/`
753 MAINBOARD=`printf $target|cut -f2 -d/`
754 CONFIG=`printf $target|cut -f3 -d/`
755 build_target $VENDOR $MAINBOARD $CONFIG
756 test_target $VENDOR $MAINBOARD
758 # build all boards per default
759 for VENDOR in $( vendors ); do
760 for MAINBOARD in $( mainboards $VENDOR ); do
761 build_target $VENDOR $MAINBOARD
762 test_target $VENDOR $MAINBOARD
763 remove_target $VENDOR $MAINBOARD