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
39 for i in make gmake gnumake nonexistant_make; do
40 $i --version 2>/dev/null |grep "GNU Make" >/dev/null && break
42 if [ "$i" = "nonexistant_make" ]; then
43 echo No GNU Make found.
49 # this can be changed to xml by -x
52 # silent mode.. no compiler calls, only warnings in the log files.
53 # this is disabled per default but can be enabled with -s
56 # clang mode enabled by -sb option.
59 # stackprotect mode enabled by -ns option.
62 # loglevel changed with -l / --loglevel option
65 ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
67 -e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
68 -e "s/Power Macintosh/ppc/"`
74 printf "\n$0: execution interrupted manually.\n"
75 if [ "$mode" == "xml" ]; then
76 printf "$0: deleting incomplete xml output file.\n"
83 test "$verbose" == "true" && printf "$*\n"
88 test "$mode" == "xml" && printf "$*\n" >> $XMLFILE
93 test "$mode" == "xml" && {
104 # make this a function so we can easily select
105 # without breaking readability
106 ls -1 "$LBROOT/src/mainboard" | grep -v Kconfig | grep -v Makefile
111 # make this a function so we can easily select
112 # without breaking readability
116 ls -1 $LBROOT/src/mainboard/$VENDOR | grep -v Kconfig
119 function architecture
123 ARCH=`cat $LBROOT/src/mainboard/$VENDOR/$MAINBOARD/Config.lb | \
124 grep ^arch | cut -f 2 -d\ `
125 echo $ARCH | sed s/ppc/powerpc/
128 function create_config
133 TARCH=$( architecture $VENDOR $MAINBOARD )
134 TARGCONFIG=$LBROOT/targets/$VENDOR/$MAINBOARD/Config-abuild.lb
136 if [ "$CONFIG" != "" ]; then
137 TARGCONFIG=$LBROOT/targets/$VENDOR/$MAINBOARD/$CONFIG
140 # get a working payload for the board if we have one.
141 # the --payload option expects a directory containing
142 # a shell script payload.sh
143 # Usage: payload.sh [VENDOR] [DEVICE]
144 # the script returns an absolute path to the payload binary.
146 if [ -f $payloads/payload.sh ]; then
147 PAYLOAD=`sh $payloads/payload.sh $VENDOR $MAINBOARD`
148 printf "Using payload $PAYLOAD\n"
153 if [ -f $TARGCONFIG ]; then
154 cp $TARGCONFIG $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
155 printf "Using existing test target $TARGCONFIG"
156 xml " <config>$TARGCONFIG</config>"
159 printf " Creating config file..."
160 xml " <config>autogenerated</config>"
162 # This will make a target directory of ./VENDOR_MAINBOARD
164 target VENDOR_MAINBOARD
165 mainboard VENDOR/MAINBOARD
168 option CONFIG_CROSS_COMPILE="CROSS_PREFIX"
169 option HOSTCC="CROSS_HOSTCC"
175 if [ "$TARCH" == i386 ] ; then
178 option CONFIG_USE_FALLBACK_IMAGE=0
179 option COREBOOT_EXTRA_VERSION=".0-normal"
184 option CONFIG_USE_FALLBACK_IMAGE=1
185 option COREBOOT_EXTRA_VERSION=".0-fallback"
188 buildrom ./coreboot.rom CONFIG_ROM_SIZE "normal" "fallback"
193 option COREBOOT_EXTRA_VERSION=".0"
196 buildrom ./coreboot.rom CONFIG_ROM_SIZE "only"
199 ) > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
202 if [ "$loglevel" != "default" ]; then
203 LOGLEVEL1="option CONFIG_MAXIMUM_CONSOLE_LOGLEVEL=$loglevel"
204 LOGLEVEL2="option CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$loglevel"
206 LOGLEVEL1="# no loglevel override"
210 COMPRESSION="# no compression"
211 if which lzma >/dev/null 2>/dev/null; then
212 if [ "$PAYLOAD" != /dev/null ]; then
213 COMPRESSION="option CONFIG_COMPRESSED_PAYLOAD_LZMA=1"
217 cp $TARGET/Config-${VENDOR}_${MAINBOARD}.lb $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre
218 sed -e s:VENDOR:$VENDOR:g \
219 -e s:MAINBOARD:$MAINBOARD:g \
220 -e s:payload\ __PAYLOAD__:payload\ $PAYLOAD:g \
221 -e s:CROSSCC:"$CC":g \
222 -e s:CROSS_PREFIX:"$CROSS_COMPILE":g \
223 -e s:CROSS_HOSTCC:"$HOSTCC":g \
224 -e s:__COMPRESSION__:"$COMPRESSION":g \
225 -e s:__LOGLEVEL__:"$LOGLEVEL1"\
227 $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
231 function create_builddir
236 printf " Creating builddir..."
239 config_dir=$LBROOT/util/newconfig
240 yapps2_py=$config_dir/yapps2.py
241 config_g=$config_dir/config.g
242 config_lb=Config-${VENDOR}_${MAINBOARD}.lb
246 build_dir=${VENDOR}_${MAINBOARD}
247 config_py=$build_dir/config.py
249 if [ ! -d $build_dir ] ; then
252 if [ ! -f $config_py ]; then
253 $PYTHON $yapps2_py $config_g $config_py &> $build_dir/py.log
256 # make sure config.py is up-to-date
258 export PYTHONPATH=$config_dir
259 $PYTHON $config_py $config_lb $LBROOT &> $build_dir/config.log
260 if [ $? -eq 0 ]; then
262 xml " <builddir>ok</builddir>"
264 xmlfile $build_dir/config.log
269 printf "FAILED! Log excerpt:\n"
270 xml " <builddir>failed</builddir>"
272 xmlfile $build_dir/config.log
275 tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log
280 function create_buildenv
285 create_config $VENDOR $MAINBOARD $CONFIG
286 create_builddir $VENDOR $MAINBOARD
289 function compile_target
294 printf " Compiling image "
295 test "$cpus" == "" && printf "in parallel .. "
296 test "$cpus" == "1" && printf "on 1 cpu .. "
297 test 0$cpus -gt 1 && printf "on %d cpus in parallel .. " $cpus
300 cd $TARGET/${VENDOR}_${MAINBOARD}
301 stime=`perl -e 'print time();'`
302 eval $MAKE $silent -j $cpus &> make.log
304 etime=`perl -e 'print time();'`
305 duration=$(( $etime - $stime ))
306 if [ $ret -eq 0 ]; then
307 xml " <compile>ok</compile>"
308 xml " <compiletime>${duration}s</compiletime>"
312 printf "ok\n" > compile.status
313 printf "ok. (took ${duration}s)\n"
317 xml " <compile>failed</compile>"
318 xml " <compiletime>${duration}s</compiletime>"
323 printf "FAILED after ${duration}s! Log excerpt:\n"
324 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
330 function built_successfully
334 if [ -d "$TARGET/${VENDOR}_${MAINBOARD}" ]; then
335 cd $TARGET/${VENDOR}_${MAINBOARD}
336 if [ -r compile.status ] ; then
337 status=`cat compile.status`
341 [ "$buildall" != "true" -a "$status" == "ok" ]
344 function build_broken
348 [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
349 [ "$buildbroken" == "true" -o "$status" == "yes" ]
352 function build_target
357 TARCH=$( architecture $VENDOR $MAINBOARD )
359 # Allow architecture override in an abuild.info file.
360 # This is used for the Motorola Sandpoint, which is not a real target
361 # but a skeleton target for the Sandpoint X3.
362 [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
363 source $LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
367 CC="${CROSS_COMPILE}gcc"
369 found_crosscompiler=false
370 if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
371 # i386-elf target needs --divide, for i386-linux, that's the default
372 if [ "$TARCH" = "i386" ]; then
373 CC="$CC -Wa,--divide"
375 CROSS_COMPILE="$TARCH-elf-"
377 echo using $CROSS_COMPILE$CC
378 found_crosscompiler=true
383 printf "Processing mainboard/$VENDOR/$MAINBOARD"
387 xml " <vendor>$VENDOR</vendor>"
388 xml " <device>$MAINBOARD</device>"
390 xml " <architecture>$TARCH</architecture>"
393 if [ "$ARCH" = "$TARCH" -o $found_crosscompiler = true ]; then
394 printf " ($TARCH: ok)\n"
396 found_crosscompiler=false
397 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
399 found_crosscompiler=true
401 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
403 found_crosscompiler=true
405 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
406 for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
407 powerpc-7450-linux-gnu- powerpc-elf-; do
408 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
409 found_crosscompiler=true
410 CROSS_COMPILE=$prefix
416 # TBD: look for suitable cross compiler suite
417 # cross-$TARCH-gcc and cross-$TARCH-ld
420 if [ $found_crosscompiler == "false" ]; then
421 printf " ($TARCH: skipped, we're $ARCH)\n\n"
422 xml " <status>notbuilt</status>"
428 printf " ($TARCH: ok, we're $ARCH with a ${CROSS_COMPILE} cross compiler)\n"
430 xml " <path>`which ${CROSS_COMPILE}gcc`</path>"
431 xml " <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
437 CC=${CROSS_COMPILE}$CC
439 if [ "$stackprotect" = "true" ]; then
440 CC="$CC -fno-stack-protector"
443 if [ "$scanbuild" = "true" ]; then
445 mkdir -p $TARGET/${VENDOR}_${MAINBOARD}
446 mkdir -p $TARGET/scan-build-results-tmp
447 mv $ccwrap $TARGET/${VENDOR}_${MAINBOARD}
448 ccwrap=$TARGET/${VENDOR}_${MAINBOARD}/`basename $ccwrap`
449 echo '#!/bin/sh' > $ccwrap
450 echo $CC' "$@"' >> $ccwrap
453 MAKE="scan-build --use-cc=$ccwrap -o $TARGET/scan-build-results-tmp -analyze-headers $MAKE GCC=$ccwrap"
455 HOSTCC="CCC_CC=$HOSTCC \$(CC)"
458 built_successfully $VENDOR $MAINBOARD && \
460 printf " ( mainboard/$VENDOR/$MAINBOARD previously ok )\n\n"
461 xml " <status>previouslyok</status>"
467 build_broken $VENDOR $MAINBOARD || \
469 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
470 xml " <status>knownbroken</status>"
476 create_buildenv $VENDOR $MAINBOARD $CONFIG
477 if [ $? -eq 0 -a $configureonly -eq 0 ]; then
478 compile_target $VENDOR $MAINBOARD &&
479 xml " <status>ok</status>" ||
480 xml "<status>broken</status>"
481 if [ "$scanbuild" = "true" ]; then
482 mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
498 if [ "$hwtest" != "true" ]; then
502 # image does not exist. we silently skip the patch.
503 if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
507 which curl &> /dev/null
509 printf "curl is not installed but required for test submission. skipping test.\n\n"
514 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
515 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
518 # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
520 printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
522 curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
523 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
524 "http://qa.coreboot.org/deployment/send.php"
530 function remove_target
532 if [ "$remove" != "true" ]; then
539 # Save the generated coreboot.rom file of each board.
540 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
541 cp $TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom \
542 ${VENDOR}_${MAINBOARD}_coreboot.rom
545 printf "Removing build dir for board $VENDOR $MAINBOARD...\n"
546 rm -rf $TARGET/${VENDOR}_${MAINBOARD}
553 printf "Usage: $0 [-v] [-a] [-b] [-r] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
554 printf " $0 [-V|--version]\n"
555 printf " $0 [-h|--help]\n\n"
558 printf " [-v|--verbose] print more messages\n"
559 printf " [-a|--all] build previously succeeded ports as well\n"
560 printf " [-b|--broken] attempt to build ports that are known broken\n"
561 printf " [-r|--remove] remove output dir after build\n"
562 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
563 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
564 printf " [-V|--version] print version number and exit\n"
565 printf " [-h|--help] print this help and exit\n"
566 printf " [-x|--xml] write xml log file \n"
567 printf " (defaults to $XMLFILE)\n"
568 printf " [-T|--test] submit image(s) to automated test system\n"
569 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
570 printf " [-s|--silent] omit compiler calls in logs\n"
571 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
572 printf " [-sb|--scan-build] use clang's static analyzer\n"
573 printf " [-C|--config] configure-only mode\n"
574 printf " [-l|--loglevel <num>] set loglevel\n"
575 printf " [lbroot] absolute path to coreboot sources\n"
576 printf " (defaults to $LBROOT)\n\n"
583 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
585 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
586 Copyright (C) 2006-2008 by coresystems GmbH <info@coresystems.de>
588 This program is free software; you may redistribute it under the terms
589 of the GNU General Public License. This program has absolutely no
600 test -f util/newconfig/config.g && LBROOT=$( pwd )
601 test -f ../util/newconfig/config.g && LBROOT=$( cd ..; pwd )
602 test "$LBROOT" = "" && LBROOT=$( cd ../..; pwd )
604 # parse parameters.. try to find out whether we're running GNU getopt
605 getoptbrand="`getopt -V`"
606 if [ "${getoptbrand:0:6}" == "getopt" ]; then
607 # Detected GNU getopt that supports long options.
608 args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config,loglevel Vvhat:bp:Tc:sxCl: -- "$@"`
611 # Detected non-GNU getopt
612 args=`getopt Vvhat:bp:Tc:sxCl: $*`
623 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
624 -t|--target) shift; target="$1"; shift;;
625 -a|--all) shift; buildall=true;;
626 -b|--broken) shift; buildbroken=true;;
627 -r|--remove) shift; remove=true; shift;;
628 -v|--verbose) shift; verbose=true;;
629 -V|--version) shift; myversion; exit 0;;
630 -h|--help) shift; myversion; myhelp; exit 0;;
631 -p|--payloads) shift; payloads="$1"; shift;;
632 -T|--test) shift; hwtest=true;;
633 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
634 -s|--silent) shift; silent="-s";;
635 -ns|--nostackprotect) shift; stackprotect=true;;
636 -sb|--scan-build) shift; scanbuild=true;;
637 -C|--config) shift; configureonly=1;;
638 -l|--loglevel) shift; loglevel="$1"; shift;;
640 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
645 # /path/to/freebios2/
646 test -z "$1" || LBROOT=$1
648 debug "LBROOT=$LBROOT"
650 xml '<?xml version="1.0" encoding="utf-8"?>'
653 if [ "$target" != "" ]; then
654 # build a single board
655 VENDOR=`printf $target|cut -f1 -d/`
656 MAINBOARD=`printf $target|cut -f2 -d/`
657 CONFIG=`printf $target|cut -f3 -d/`
658 build_target $VENDOR $MAINBOARD $CONFIG
659 test_target $VENDOR $MAINBOARD
661 # build all boards per default
662 for VENDOR in $( vendors ); do
663 for MAINBOARD in $( mainboards $VENDOR ); do
664 build_target $VENDOR $MAINBOARD
665 test_target $VENDOR $MAINBOARD
666 remove_target $VENDOR $MAINBOARD