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 CVS
111 # make this a function so we can easily select
112 # without breaking readability
116 ls -1 $LBROOT/src/mainboard/$VENDOR | grep -v CVS
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 CROSS_COMPILE="CROSS_PREFIX"
169 option HOSTCC="CROSS_HOSTCC"
175 if [ "$TARCH" == i386 ] ; then
178 option USE_FALLBACK_IMAGE=0
179 option ROM_IMAGE_SIZE=0x17000
180 option COREBOOT_EXTRA_VERSION=".0-normal"
185 option USE_FALLBACK_IMAGE=1
186 option ROM_IMAGE_SIZE=0x17000
187 option COREBOOT_EXTRA_VERSION=".0-fallback"
190 buildrom ./coreboot.rom ROM_SIZE "normal" "fallback"
195 option COREBOOT_EXTRA_VERSION=".0"
198 buildrom ./coreboot.rom ROM_SIZE "only"
201 ) > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
204 if [ "$loglevel" != "default" ]; then
205 LOGLEVEL1="option MAXIMUM_CONSOLE_LOGLEVEL=$loglevel"
206 LOGLEVEL2="option DEFAULT_CONSOLE_LOGLEVEL=$loglevel"
208 LOGLEVEL1="# no loglevel override"
212 COMPRESSION="# no compression"
213 if which lzma >/dev/null 2>/dev/null; then
214 if [ "$PAYLOAD" != /dev/null ]; then
215 COMPRESSION="option CONFIG_COMPRESSED_PAYLOAD_LZMA=1"
219 cp $TARGET/Config-${VENDOR}_${MAINBOARD}.lb $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre
220 sed -e s:VENDOR:$VENDOR:g \
221 -e s:MAINBOARD:$MAINBOARD:g \
222 -e s:payload\ __PAYLOAD__:payload\ $PAYLOAD:g \
223 -e s:CROSSCC:"$CC":g \
224 -e s:CROSS_PREFIX:"$CROSS_COMPILE":g \
225 -e s:CROSS_HOSTCC:"$HOSTCC":g \
226 -e s:__COMPRESSION__:"$COMPRESSION":g \
227 -e s:__LOGLEVEL__:"$LOGLEVEL1"\
229 $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
233 function create_builddir
238 printf " Creating builddir..."
241 config_dir=$LBROOT/util/newconfig
242 yapps2_py=$config_dir/yapps2.py
243 config_g=$config_dir/config.g
244 config_lb=Config-${VENDOR}_${MAINBOARD}.lb
248 build_dir=${VENDOR}_${MAINBOARD}
249 config_py=$build_dir/config.py
251 if [ ! -d $build_dir ] ; then
254 if [ ! -f $config_py ]; then
255 $PYTHON $yapps2_py $config_g $config_py &> $build_dir/py.log
258 # make sure config.py is up-to-date
260 export PYTHONPATH=$config_dir
261 $PYTHON $config_py $config_lb $LBROOT &> $build_dir/config.log
262 if [ $? -eq 0 ]; then
264 xml " <builddir>ok</builddir>"
266 xmlfile $build_dir/config.log
271 printf "FAILED! Log excerpt:\n"
272 xml " <builddir>failed</builddir>"
274 xmlfile $build_dir/config.log
277 tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log
282 function create_buildenv
287 create_config $VENDOR $MAINBOARD $CONFIG
288 create_builddir $VENDOR $MAINBOARD
291 function compile_target
296 printf " Compiling image "
297 test "$cpus" == "" && printf "in parallel .. "
298 test "$cpus" == "1" && printf "on 1 cpu .. "
299 test 0$cpus -gt 1 && printf "on %d cpus in parallel .. " $cpus
302 cd $TARGET/${VENDOR}_${MAINBOARD}
303 stime=`perl -e 'print time();'`
304 eval $MAKE $silent -j $cpus &> make.log
306 etime=`perl -e 'print time();'`
307 duration=$(( $etime - $stime ))
308 if [ $ret -eq 0 ]; then
309 xml " <compile>ok</compile>"
310 xml " <compiletime>${duration}s</compiletime>"
314 printf "ok\n" > compile.status
315 printf "ok. (took ${duration}s)\n"
319 xml " <compile>failed</compile>"
320 xml " <compiletime>${duration}s</compiletime>"
325 printf "FAILED after ${duration}s! Log excerpt:\n"
326 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
332 function built_successfully
336 if [ -d "$TARGET/${VENDOR}_${MAINBOARD}" ]; then
337 cd $TARGET/${VENDOR}_${MAINBOARD}
338 if [ -r compile.status ] ; then
339 status=`cat compile.status`
343 [ "$buildall" != "true" -a "$status" == "ok" ]
346 function build_broken
350 [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
351 [ "$buildbroken" == "true" -o "$status" == "yes" ]
354 function build_target
359 TARCH=$( architecture $VENDOR $MAINBOARD )
361 # Allow architecture override in an abuild.info file.
362 # This is used for the Motorola Sandpoint, which is not a real target
363 # but a skeleton target for the Sandpoint X3.
364 [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
365 source $LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
369 CC="${CROSS_COMPILE}gcc"
371 found_crosscompiler=false
372 if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
373 # i386-elf target needs --divide, for i386-linux, that's the default
374 if [ "$TARCH" = "i386" ]; then
375 CC="$CC -Wa,--divide"
377 CROSS_COMPILE="$TARCH-elf-"
378 echo using $CROSS_COMPILE$CC
379 found_crosscompiler=true
384 printf "Processing mainboard/$VENDOR/$MAINBOARD"
388 xml " <vendor>$VENDOR</vendor>"
389 xml " <device>$MAINBOARD</device>"
391 xml " <architecture>$TARCH</architecture>"
394 if [ "$ARCH" = "$TARCH" -o $found_crosscompiler = true ]; then
395 printf " ($TARCH: ok)\n"
397 found_crosscompiler=false
398 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
400 found_crosscompiler=true
402 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
404 found_crosscompiler=true
406 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
407 for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
408 powerpc-7450-linux-gnu- powerpc-elf-; do
409 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
410 found_crosscompiler=true
411 CROSS_COMPILE=$prefix
417 # TBD: look for suitable cross compiler suite
418 # cross-$TARCH-gcc and cross-$TARCH-ld
421 if [ $found_crosscompiler == "false" ]; then
422 printf " ($TARCH: skipped, we're $ARCH)\n\n"
423 xml " <status>notbuilt</status>"
429 printf " ($TARCH: ok, we're $ARCH with a ${CROSS_COMPILE} cross compiler)\n"
431 xml " <path>`which ${CROSS_COMPILE}gcc`</path>"
432 xml " <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
438 CC=${CROSS_COMPILE}$CC
440 if [ "$stackprotect" = "true" ]; then
441 CC="$CC -fno-stack-protector"
444 if [ "$scanbuild" = "true" ]; then
446 mkdir -p $TARGET/${VENDOR}_${MAINBOARD}
447 mkdir -p $TARGET/scan-build-results-tmp
448 mv $ccwrap $TARGET/${VENDOR}_${MAINBOARD}
449 ccwrap=$TARGET/${VENDOR}_${MAINBOARD}/`basename $ccwrap`
450 echo '#!/bin/sh' > $ccwrap
451 echo $CC' "$@"' >> $ccwrap
454 MAKE="scan-build --use-cc=$ccwrap -o $TARGET/scan-build-results-tmp -analyze-headers $MAKE GCC=$ccwrap"
456 HOSTCC="CCC_CC=$HOSTCC \$(CC)"
459 built_successfully $VENDOR $MAINBOARD && \
461 printf " ( mainboard/$VENDOR/$MAINBOARD previously ok )\n\n"
462 xml " <status>previouslyok</status>"
468 build_broken $VENDOR $MAINBOARD || \
470 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
471 xml " <status>knownbroken</status>"
477 create_buildenv $VENDOR $MAINBOARD $CONFIG
478 if [ $? -eq 0 -a $configureonly -eq 0 ]; then
479 compile_target $VENDOR $MAINBOARD &&
480 xml " <status>ok</status>" ||
481 xml "<status>broken</status>"
482 if [ "$scanbuild" = "true" ]; then
483 mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
499 if [ "$hwtest" != "true" ]; then
503 # image does not exist. we silently skip the patch.
504 if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
508 which curl &> /dev/null
510 printf "curl is not installed but required for test submission. skipping test.\n\n"
515 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
516 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
519 # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
521 printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
523 curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
524 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
525 "http://qa.coreboot.org/deployment/send.php"
531 function remove_target
533 if [ "$remove" != "true" ]; then
540 # Save the generated coreboot.rom file of each board.
541 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
542 cp $TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom \
543 ${VENDOR}_${MAINBOARD}_coreboot.rom
546 printf "Removing build dir for board $VENDOR $MAINBOARD...\n"
547 rm -rf $TARGET/${VENDOR}_${MAINBOARD}
554 printf "Usage: $0 [-v] [-a] [-b] [-r] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
555 printf " $0 [-V|--version]\n"
556 printf " $0 [-h|--help]\n\n"
559 printf " [-v|--verbose] print more messages\n"
560 printf " [-a|--all] build previously succeeded ports as well\n"
561 printf " [-b|--broken] attempt to build ports that are known broken\n"
562 printf " [-r|--remove] remove output dir after build\n"
563 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
564 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
565 printf " [-V|--version] print version number and exit\n"
566 printf " [-h|--help] print this help and exit\n"
567 printf " [-x|--xml] write xml log file \n"
568 printf " (defaults to $XMLFILE)\n"
569 printf " [-T|--test] submit image(s) to automated test system\n"
570 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
571 printf " [-s|--silent] omit compiler calls in logs\n"
572 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
573 printf " [-sb|--scan-build] use clang's static analyzer\n"
574 printf " [-C|--config] configure-only mode\n"
575 printf " [-l|--loglevel <num>] set loglevel\n"
576 printf " [lbroot] absolute path to coreboot sources\n"
577 printf " (defaults to $LBROOT)\n\n"
584 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
586 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
587 Copyright (C) 2006-2008 by coresystems GmbH <info@coresystems.de>
589 This program is free software; you may redistribute it under the terms
590 of the GNU General Public License. This program has absolutely no
599 LBROOT=$( cd ../..; pwd )
602 # parse parameters.. try to find out whether we're running GNU getopt
603 getoptbrand="`getopt -V`"
604 if [ "${getoptbrand:0:6}" == "getopt" ]; then
605 # Detected GNU getopt that supports long options.
606 args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config,loglevel Vvhat:bp:Tc:sxCl: -- "$@"`
609 # Detected non-GNU getopt
610 args=`getopt Vvhat:bp:Tc:sxCl: $*`
621 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
622 -t|--target) shift; target="$1"; shift;;
623 -a|--all) shift; buildall=true;;
624 -b|--broken) shift; buildbroken=true;;
625 -r|--remove) shift; remove=true; shift;;
626 -v|--verbose) shift; verbose=true;;
627 -V|--version) shift; myversion; exit 0;;
628 -h|--help) shift; myversion; myhelp; exit 0;;
629 -p|--payloads) shift; payloads="$1"; shift;;
630 -T|--test) shift; hwtest=true;;
631 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
632 -s|--silent) shift; silent="-s";;
633 -ns|--nostackprotect) shift; stackprotect=true;;
634 -sb|--scan-build) shift; scanbuild=true;;
635 -C|--config) shift; configureonly=1;;
636 -l|--loglevel) shift; loglevel="$1"; shift;;
638 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
643 # /path/to/freebios2/
644 test -z "$1" || LBROOT=$1
646 debug "LBROOT=$LBROOT"
648 xml '<?xml version="1.0" encoding="utf-8"?>'
651 if [ "$target" != "" ]; then
652 # build a single board
653 VENDOR=`printf $target|cut -f1 -d/`
654 MAINBOARD=`printf $target|cut -f2 -d/`
655 CONFIG=`printf $target|cut -f3 -d/`
656 build_target $VENDOR $MAINBOARD $CONFIG
657 test_target $VENDOR $MAINBOARD
659 # build all boards per default
660 for VENDOR in $( vendors ); do
661 for MAINBOARD in $( mainboards $VENDOR ); do
662 build_target $VENDOR $MAINBOARD
663 test_target $VENDOR $MAINBOARD
664 remove_target $VENDOR $MAINBOARD