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 CONFIG_CROSS_COMPILE="CROSS_PREFIX"
169 option HOSTCC="CROSS_HOSTCC"
175 if [ "$TARCH" == i386 ] ; then
178 option CONFIG_USE_FALLBACK_IMAGE=0
181 option CONFIG_ROM_IMAGE_SIZE=0x17000
183 option COREBOOT_EXTRA_VERSION=".0-normal"
188 option CONFIG_USE_FALLBACK_IMAGE=1
191 option CONFIG_ROM_IMAGE_SIZE=0x17000
193 option COREBOOT_EXTRA_VERSION=".0-fallback"
196 buildrom ./coreboot.rom CONFIG_ROM_SIZE "normal" "fallback"
201 option COREBOOT_EXTRA_VERSION=".0"
204 buildrom ./coreboot.rom CONFIG_ROM_SIZE "only"
207 ) > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
210 if [ "$loglevel" != "default" ]; then
211 LOGLEVEL1="option CONFIG_MAXIMUM_CONSOLE_LOGLEVEL=$loglevel"
212 LOGLEVEL2="option CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$loglevel"
214 LOGLEVEL1="# no loglevel override"
218 COMPRESSION="# no compression"
219 if which lzma >/dev/null 2>/dev/null; then
220 if [ "$PAYLOAD" != /dev/null ]; then
221 COMPRESSION="option CONFIG_COMPRESSED_PAYLOAD_LZMA=1"
225 cp $TARGET/Config-${VENDOR}_${MAINBOARD}.lb $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre
226 sed -e s:VENDOR:$VENDOR:g \
227 -e s:MAINBOARD:$MAINBOARD:g \
228 -e s:payload\ __PAYLOAD__:payload\ $PAYLOAD:g \
229 -e s:CROSSCC:"$CC":g \
230 -e s:CROSS_PREFIX:"$CROSS_COMPILE":g \
231 -e s:CROSS_HOSTCC:"$HOSTCC":g \
232 -e s:__COMPRESSION__:"$COMPRESSION":g \
233 -e s:__LOGLEVEL__:"$LOGLEVEL1"\
235 $TARGET/Config-${VENDOR}_${MAINBOARD}.lb.pre > $TARGET/Config-${VENDOR}_${MAINBOARD}.lb
239 function create_builddir
244 printf " Creating builddir..."
247 config_dir=$LBROOT/util/newconfig
248 yapps2_py=$config_dir/yapps2.py
249 config_g=$config_dir/config.g
250 config_lb=Config-${VENDOR}_${MAINBOARD}.lb
254 build_dir=${VENDOR}_${MAINBOARD}
255 config_py=$build_dir/config.py
257 if [ ! -d $build_dir ] ; then
260 if [ ! -f $config_py ]; then
261 $PYTHON $yapps2_py $config_g $config_py &> $build_dir/py.log
264 # make sure config.py is up-to-date
266 export PYTHONPATH=$config_dir
267 $PYTHON $config_py $config_lb $LBROOT &> $build_dir/config.log
268 if [ $? -eq 0 ]; then
270 xml " <builddir>ok</builddir>"
272 xmlfile $build_dir/config.log
277 printf "FAILED! Log excerpt:\n"
278 xml " <builddir>failed</builddir>"
280 xmlfile $build_dir/config.log
283 tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log
288 function create_buildenv
293 create_config $VENDOR $MAINBOARD $CONFIG
294 create_builddir $VENDOR $MAINBOARD
297 function compile_target
302 printf " Compiling image "
303 test "$cpus" == "" && printf "in parallel .. "
304 test "$cpus" == "1" && printf "on 1 cpu .. "
305 test 0$cpus -gt 1 && printf "on %d cpus in parallel .. " $cpus
308 cd $TARGET/${VENDOR}_${MAINBOARD}
309 stime=`perl -e 'print time();'`
310 eval $MAKE $silent -j $cpus &> make.log
312 etime=`perl -e 'print time();'`
313 duration=$(( $etime - $stime ))
314 if [ $ret -eq 0 ]; then
315 xml " <compile>ok</compile>"
316 xml " <compiletime>${duration}s</compiletime>"
320 printf "ok\n" > compile.status
321 printf "ok. (took ${duration}s)\n"
325 xml " <compile>failed</compile>"
326 xml " <compiletime>${duration}s</compiletime>"
331 printf "FAILED after ${duration}s! Log excerpt:\n"
332 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
338 function built_successfully
342 if [ -d "$TARGET/${VENDOR}_${MAINBOARD}" ]; then
343 cd $TARGET/${VENDOR}_${MAINBOARD}
344 if [ -r compile.status ] ; then
345 status=`cat compile.status`
349 [ "$buildall" != "true" -a "$status" == "ok" ]
352 function build_broken
356 [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
357 [ "$buildbroken" == "true" -o "$status" == "yes" ]
360 function build_target
365 TARCH=$( architecture $VENDOR $MAINBOARD )
367 # Allow architecture override in an abuild.info file.
368 # This is used for the Motorola Sandpoint, which is not a real target
369 # but a skeleton target for the Sandpoint X3.
370 [ -r "$LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
371 source $LBROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
375 CC="${CROSS_COMPILE}gcc"
377 found_crosscompiler=false
378 if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
379 # i386-elf target needs --divide, for i386-linux, that's the default
380 if [ "$TARCH" = "i386" ]; then
381 CC="$CC -Wa,--divide"
383 CROSS_COMPILE="$TARCH-elf-"
385 echo using $CROSS_COMPILE$CC
386 found_crosscompiler=true
391 printf "Processing mainboard/$VENDOR/$MAINBOARD"
395 xml " <vendor>$VENDOR</vendor>"
396 xml " <device>$MAINBOARD</device>"
398 xml " <architecture>$TARCH</architecture>"
401 if [ "$ARCH" = "$TARCH" -o $found_crosscompiler = true ]; then
402 printf " ($TARCH: ok)\n"
404 found_crosscompiler=false
405 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
407 found_crosscompiler=true
409 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
411 found_crosscompiler=true
413 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
414 for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
415 powerpc-7450-linux-gnu- powerpc-elf-; do
416 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
417 found_crosscompiler=true
418 CROSS_COMPILE=$prefix
424 # TBD: look for suitable cross compiler suite
425 # cross-$TARCH-gcc and cross-$TARCH-ld
428 if [ $found_crosscompiler == "false" ]; then
429 printf " ($TARCH: skipped, we're $ARCH)\n\n"
430 xml " <status>notbuilt</status>"
436 printf " ($TARCH: ok, we're $ARCH with a ${CROSS_COMPILE} cross compiler)\n"
438 xml " <path>`which ${CROSS_COMPILE}gcc`</path>"
439 xml " <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
445 CC=${CROSS_COMPILE}$CC
447 if [ "$stackprotect" = "true" ]; then
448 CC="$CC -fno-stack-protector"
451 if [ "$scanbuild" = "true" ]; then
453 mkdir -p $TARGET/${VENDOR}_${MAINBOARD}
454 mkdir -p $TARGET/scan-build-results-tmp
455 mv $ccwrap $TARGET/${VENDOR}_${MAINBOARD}
456 ccwrap=$TARGET/${VENDOR}_${MAINBOARD}/`basename $ccwrap`
457 echo '#!/bin/sh' > $ccwrap
458 echo $CC' "$@"' >> $ccwrap
461 MAKE="scan-build --use-cc=$ccwrap -o $TARGET/scan-build-results-tmp -analyze-headers $MAKE GCC=$ccwrap"
463 HOSTCC="CCC_CC=$HOSTCC \$(CC)"
466 built_successfully $VENDOR $MAINBOARD && \
468 printf " ( mainboard/$VENDOR/$MAINBOARD previously ok )\n\n"
469 xml " <status>previouslyok</status>"
475 build_broken $VENDOR $MAINBOARD || \
477 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
478 xml " <status>knownbroken</status>"
484 create_buildenv $VENDOR $MAINBOARD $CONFIG
485 if [ $? -eq 0 -a $configureonly -eq 0 ]; then
486 compile_target $VENDOR $MAINBOARD &&
487 xml " <status>ok</status>" ||
488 xml "<status>broken</status>"
489 if [ "$scanbuild" = "true" ]; then
490 mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
506 if [ "$hwtest" != "true" ]; then
510 # image does not exist. we silently skip the patch.
511 if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
515 which curl &> /dev/null
517 printf "curl is not installed but required for test submission. skipping test.\n\n"
522 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
523 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
526 # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
528 printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
530 curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
531 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
532 "http://qa.coreboot.org/deployment/send.php"
538 function remove_target
540 if [ "$remove" != "true" ]; then
547 # Save the generated coreboot.rom file of each board.
548 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
549 cp $TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom \
550 ${VENDOR}_${MAINBOARD}_coreboot.rom
553 printf "Removing build dir for board $VENDOR $MAINBOARD...\n"
554 rm -rf $TARGET/${VENDOR}_${MAINBOARD}
561 printf "Usage: $0 [-v] [-a] [-b] [-r] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
562 printf " $0 [-V|--version]\n"
563 printf " $0 [-h|--help]\n\n"
566 printf " [-v|--verbose] print more messages\n"
567 printf " [-a|--all] build previously succeeded ports as well\n"
568 printf " [-b|--broken] attempt to build ports that are known broken\n"
569 printf " [-r|--remove] remove output dir after build\n"
570 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
571 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
572 printf " [-V|--version] print version number and exit\n"
573 printf " [-h|--help] print this help and exit\n"
574 printf " [-x|--xml] write xml log file \n"
575 printf " (defaults to $XMLFILE)\n"
576 printf " [-T|--test] submit image(s) to automated test system\n"
577 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
578 printf " [-s|--silent] omit compiler calls in logs\n"
579 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
580 printf " [-sb|--scan-build] use clang's static analyzer\n"
581 printf " [-C|--config] configure-only mode\n"
582 printf " [-l|--loglevel <num>] set loglevel\n"
583 printf " [lbroot] absolute path to coreboot sources\n"
584 printf " (defaults to $LBROOT)\n\n"
591 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
593 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
594 Copyright (C) 2006-2008 by coresystems GmbH <info@coresystems.de>
596 This program is free software; you may redistribute it under the terms
597 of the GNU General Public License. This program has absolutely no
608 test -f util/newconfig/config.g && LBROOT=$( pwd )
609 test -f ../util/newconfig/config.g && LBROOT=$( cd ..; pwd )
610 test "$LBROOT" = "" && LBROOT=$( cd ../..; pwd )
612 # parse parameters.. try to find out whether we're running GNU getopt
613 getoptbrand="`getopt -V`"
614 if [ "${getoptbrand:0:6}" == "getopt" ]; then
615 # Detected GNU getopt that supports long options.
616 args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config,loglevel Vvhat:bp:Tc:sxCl: -- "$@"`
619 # Detected non-GNU getopt
620 args=`getopt Vvhat:bp:Tc:sxCl: $*`
631 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
632 -t|--target) shift; target="$1"; shift;;
633 -a|--all) shift; buildall=true;;
634 -b|--broken) shift; buildbroken=true;;
635 -r|--remove) shift; remove=true; shift;;
636 -v|--verbose) shift; verbose=true;;
637 -V|--version) shift; myversion; exit 0;;
638 -h|--help) shift; myversion; myhelp; exit 0;;
639 -p|--payloads) shift; payloads="$1"; shift;;
640 -T|--test) shift; hwtest=true;;
641 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
642 -s|--silent) shift; silent="-s";;
643 -ns|--nostackprotect) shift; stackprotect=true;;
644 -sb|--scan-build) shift; scanbuild=true;;
645 -C|--config) shift; configureonly=1;;
646 -l|--loglevel) shift; loglevel="$1"; shift;;
648 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
653 # /path/to/freebios2/
654 test -z "$1" || LBROOT=$1
656 debug "LBROOT=$LBROOT"
658 xml '<?xml version="1.0" encoding="utf-8"?>'
661 if [ "$target" != "" ]; then
662 # build a single board
663 VENDOR=`printf $target|cut -f1 -d/`
664 MAINBOARD=`printf $target|cut -f2 -d/`
665 CONFIG=`printf $target|cut -f3 -d/`
666 build_target $VENDOR $MAINBOARD $CONFIG
667 test_target $VENDOR $MAINBOARD
669 # build all boards per default
670 for VENDOR in $( vendors ); do
671 for MAINBOARD in $( mainboards $VENDOR ); do
672 build_target $VENDOR $MAINBOARD
673 test_target $VENDOR $MAINBOARD
674 remove_target $VENDOR $MAINBOARD