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
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.
48 # this can be changed to xml by -x
51 # silent mode.. no compiler calls, only warnings in the log files.
52 # this is disabled per default but can be enabled with -s
55 # clang mode enabled by -sb option.
58 # stackprotect mode enabled by -ns option.
61 # loglevel changed with -l / --loglevel option
64 ARCH=`uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
66 -e s/arm.*/arm/ -e s/sa110/arm/ -e s/x86_64/amd64/ \
67 -e "s/Power Macintosh/ppc/"`
73 printf "\n$0: execution interrupted manually.\n"
74 if [ "$mode" == "xml" ]; then
75 printf "$0: deleting incomplete xml output file.\n"
82 test "$verbose" == "true" && printf "$*\n"
87 test "$mode" == "xml" && printf "$*\n" >> $XMLFILE
92 test "$mode" == "xml" && {
103 # make this a function so we can easily select
104 # without breaking readability
105 ls -1 "$ROOT/src/mainboard" | grep -v Kconfig | grep -v Makefile
110 # make this a function so we can easily select
111 # without breaking readability
115 ls -1 $ROOT/src/mainboard/$VENDOR | grep -v Kconfig
118 function architecture
122 ARCH=`cat $ROOT/src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
123 grep "select ARCH_"|cut -f2- -d_`
124 echo $ARCH | sed s/X86/i386/
127 function create_config
133 build_dir=$TARGET/${VENDOR}_${MAINBOARD}
135 # get a working payload for the board if we have one.
136 # the --payload option expects a directory containing
137 # a shell script payload.sh
138 # Usage: payload.sh [VENDOR] [DEVICE]
139 # the script returns an absolute path to the payload binary.
141 if [ -f $payloads/payload.sh ]; then
142 PAYLOAD=`sh $payloads/payload.sh $VENDOR $MAINBOARD`
143 printf "Using payload $PAYLOAD\n"
146 $MAKE distclean obj=${build_dir}
147 mkdir -p ${build_dir}
149 if [ "$CONFIG" != "" ]; then
150 printf " Using existing configuration $CONFIG ... "
151 xml " <config>$CONFIG</config>"
154 printf " Creating config file... "
155 xml " <config>autogenerated</config>"
156 grep "depends[\t ]on[\t ]*VENDOR" src/mainboard/$VENDOR/$MAINBOARD/../Kconfig | \
157 sed "s,^.*\(VENDOR_.*\)[^A-Z0-9_]*,CONFIG_\1=y," > .config
158 grep "config[\t ]*BOARD" src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
159 sed "s,^.*\(BOARD_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> .config
160 grep "select[\t ]*ARCH" src/mainboard/$VENDOR/$MAINBOARD/Kconfig | \
161 sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> .config
162 echo "CONFIG_MAINBOARD_DIR=\"$VENDOR/$MAINBOARD\"" >> .config
163 if [ "$PAYLOAD" != "/dev/null" ]; then
164 echo "# CONFIG_PAYLOAD_NONE is not set" >> .config
165 echo "CONFIG_PAYLOAD_ELF=y" >> .config
166 echo "CONFIG_FALLBACK_PAYLOAD_FILE=\"$PAYLOAD\"" >> .config
169 if [ "$loglevel" != "default" ]; then
170 printf "(loglevel override) "
171 echo "CONFIG_MAXIMUM_CONSOLE_LOGLEVEL_$loglevel=y" >> .config
172 echo "CONFIG_MAXIMUM_CONSOLE_LOGLEVEL=$loglevel" >> .config
173 echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL_$loglevel=y" >> .config
174 echo "CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$loglevel" >> .config
178 yes "" | $MAKE oldconfig obj=${build_dir} > ${build_dir}/config.log
180 mv .config.old $TARGET/${VENDOR}_${MAINBOARD}/config.in
181 if [ $ret -eq 0 ]; then
183 xml " <builddir>ok</builddir>"
185 xmlfile $build_dir/config.log
190 printf "FAILED! Log excerpt:\n"
191 xml " <builddir>failed</builddir>"
193 xmlfile $build_dir/config.log
196 tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log
201 function create_buildenv
206 create_config $VENDOR $MAINBOARD $CONFIG
209 function compile_target
214 printf " Compiling image "
215 test "$cpus" == "" && printf "in parallel .. "
216 test "$cpus" == "1" && printf "on 1 cpu .. "
217 test 0$cpus -gt 1 && printf "on %d cpus in parallel .. " $cpus
220 stime=`perl -e 'print time();' 2>/dev/null || date +%s`
221 build_dir=$TARGET/${VENDOR}_${MAINBOARD}
222 eval $MAKE $silent -j $cpus obj=${build_dir} \
223 &> ${build_dir}/make.log
225 mv .config ${build_dir}/config.build
226 mv .xcompile ${build_dir}/xcompile.build
227 cd $TARGET/${VENDOR}_${MAINBOARD}
228 etime=`perl -e 'print time();' 2>/dev/null || date +%s`
229 duration=$(( $etime - $stime ))
230 if [ $ret -eq 0 ]; then
231 xml " <compile>ok</compile>"
232 xml " <compiletime>${duration}s</compiletime>"
236 printf "ok\n" > compile.status
237 printf "ok. (took ${duration}s)\n"
241 xml " <compile>failed</compile>"
242 xml " <compiletime>${duration}s</compiletime>"
247 printf "FAILED after ${duration}s! Log excerpt:\n"
248 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
254 function built_successfully
258 if [ -d "$TARGET/${VENDOR}_${MAINBOARD}" ]; then
259 cd $TARGET/${VENDOR}_${MAINBOARD}
260 if [ -r compile.status ] ; then
261 status=`cat compile.status`
265 [ "$buildall" != "true" -a "$status" == "ok" ]
268 function build_broken
272 [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
273 [ "$buildbroken" == "true" -o "$status" == "yes" ]
276 function build_target
281 TARCH=$( architecture $VENDOR $MAINBOARD )
283 # Allow architecture override in an abuild.info file.
284 # This is used for the Motorola Sandpoint, which is not a real target
285 # but a skeleton target for the Sandpoint X3.
286 [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
287 source $ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
291 CC="${CROSS_COMPILE}gcc"
293 found_crosscompiler=false
294 if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
295 # i386-elf target needs --divide, for i386-linux, that's the default
296 if [ "$TARCH" = "i386" ]; then
297 CC="$CC -Wa,--divide"
299 CROSS_COMPILE="$TARCH-elf-"
301 echo using $CROSS_COMPILE$CC
302 found_crosscompiler=true
307 printf "Processing mainboard/$VENDOR/$MAINBOARD"
311 xml " <vendor>$VENDOR</vendor>"
312 xml " <device>$MAINBOARD</device>"
314 xml " <architecture>$TARCH</architecture>"
317 if [ "$ARCH" = "$TARCH" -o $found_crosscompiler = true ]; then
318 printf " ($TARCH: ok)\n"
320 found_crosscompiler=false
321 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
323 found_crosscompiler=true
325 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
327 found_crosscompiler=true
329 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
330 for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
331 powerpc-7450-linux-gnu- powerpc-elf-; do
332 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
333 found_crosscompiler=true
334 CROSS_COMPILE=$prefix
340 # TBD: look for suitable cross compiler suite
341 # cross-$TARCH-gcc and cross-$TARCH-ld
344 if [ $found_crosscompiler == "false" ]; then
345 printf " ($TARCH: skipped, we're $ARCH)\n\n"
346 xml " <status>notbuilt</status>"
352 printf " ($TARCH: ok, we're $ARCH with a ${CROSS_COMPILE} cross compiler)\n"
354 xml " <path>`which ${CROSS_COMPILE}gcc`</path>"
355 xml " <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
361 CC=${CROSS_COMPILE}$CC
363 if [ "$stackprotect" = "true" ]; then
364 CC="$CC -fno-stack-protector"
367 if [ "$scanbuild" = "true" ]; then
369 mkdir -p $TARGET/${VENDOR}_${MAINBOARD}
370 mkdir -p $TARGET/scan-build-results-tmp
371 mv $ccwrap $TARGET/${VENDOR}_${MAINBOARD}
372 ccwrap=$TARGET/${VENDOR}_${MAINBOARD}/`basename $ccwrap`
373 echo '#!/bin/sh' > $ccwrap
374 echo $CC' "$@"' >> $ccwrap
377 MAKE="scan-build --use-cc=$ccwrap -o $TARGET/scan-build-results-tmp -analyze-headers $MAKE GCC=$ccwrap"
379 HOSTCC="CCC_CC=$HOSTCC \$(CC)"
382 built_successfully $VENDOR $MAINBOARD && \
384 printf " ( mainboard/$VENDOR/$MAINBOARD previously ok )\n\n"
385 xml " <status>previouslyok</status>"
391 build_broken $VENDOR $MAINBOARD || \
393 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
394 xml " <status>knownbroken</status>"
400 create_buildenv $VENDOR $MAINBOARD $CONFIG
401 if [ $? -eq 0 -a $configureonly -eq 0 ]; then
402 compile_target $VENDOR $MAINBOARD &&
403 xml " <status>ok</status>" ||
404 xml "<status>broken</status>"
405 if [ "$scanbuild" = "true" ]; then
406 mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
422 if [ "$hwtest" != "true" ]; then
426 # image does not exist. we silently skip the patch.
427 if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
431 which curl &> /dev/null
433 printf "curl is not installed but required for test submission. skipping test.\n\n"
438 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
439 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
442 # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
444 printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
446 curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
447 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
448 "http://qa.coreboot.org/deployment/send.php"
454 function remove_target
456 if [ "$remove" != "true" ]; then
463 # Save the generated coreboot.rom file of each board.
464 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
465 cp $TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom \
466 ${VENDOR}_${MAINBOARD}_coreboot.rom
469 printf "Removing build dir for board $VENDOR $MAINBOARD...\n"
470 rm -rf $TARGET/${VENDOR}_${MAINBOARD}
477 printf "Usage: $0 [-v] [-a] [-b] [-r] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
478 printf " $0 [-V|--version]\n"
479 printf " $0 [-h|--help]\n\n"
482 printf " [-v|--verbose] print more messages\n"
483 printf " [-a|--all] build previously succeeded ports as well\n"
484 printf " [-b|--broken] attempt to build ports that are known broken\n"
485 printf " [-r|--remove] remove output dir after build\n"
486 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
487 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
488 printf " [-V|--version] print version number and exit\n"
489 printf " [-h|--help] print this help and exit\n"
490 printf " [-x|--xml] write xml log file \n"
491 printf " (defaults to $XMLFILE)\n"
492 printf " [-T|--test] submit image(s) to automated test system\n"
493 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
494 printf " [-s|--silent] omit compiler calls in logs\n"
495 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
496 printf " [-sb|--scan-build] use clang's static analyzer\n"
497 printf " [-C|--config] configure-only mode\n"
498 printf " [-l|--loglevel <num>] set loglevel\n"
499 printf " [lbroot] absolute path to coreboot sources\n"
500 printf " (defaults to $ROOT)\n\n"
507 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
509 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
510 Copyright (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
512 This program is free software; you may redistribute it under the terms
513 of the GNU General Public License. This program has absolutely no
524 test -f util/sconfig/config.g && ROOT=$( pwd )
525 test -f ../util/sconfig/config.g && ROOT=$( cd ..; pwd )
526 test "$ROOT" = "" && ROOT=$( cd ../..; pwd )
528 # parse parameters.. try to find out whether we're running GNU getopt
529 getoptbrand="`getopt -V`"
530 if [ "${getoptbrand:0:6}" == "getopt" ]; then
531 # Detected GNU getopt that supports long options.
532 args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config,loglevel: Vvhat:bp:Tc:sxCl: -- "$@"`
535 # Detected non-GNU getopt
536 args=`getopt Vvhat:bp:Tc:sxCl:o $*`
547 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
548 -t|--target) shift; target="$1"; shift;;
549 -a|--all) shift; buildall=true;;
550 -b|--broken) shift; buildbroken=true;;
551 -r|--remove) shift; remove=true; shift;;
552 -v|--verbose) shift; verbose=true;;
553 -V|--version) shift; myversion; exit 0;;
554 -h|--help) shift; myversion; myhelp; exit 0;;
555 -p|--payloads) shift; payloads="$1"; shift;;
556 -T|--test) shift; hwtest=true;;
557 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
558 -s|--silent) shift; silent="-s";;
559 -ns|--nostackprotect) shift; stackprotect=true;;
560 -sb|--scan-build) shift; scanbuild=true;;
561 -C|--config) shift; configureonly=1;;
562 -l|--loglevel) shift; loglevel="$1"; shift;;
564 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
569 # /path/to/freebios2/
570 test -z "$1" || ROOT=$1
574 xml '<?xml version="1.0" encoding="utf-8"?>'
577 if [ "$target" != "" ]; then
578 # build a single board
579 VENDOR=`printf $target|cut -f1 -d/`
580 MAINBOARD=`printf $target|cut -f2 -d/`
581 CONFIG=`printf $target|cut -f3 -d/`
582 build_target $VENDOR $MAINBOARD $CONFIG
583 test_target $VENDOR $MAINBOARD
585 # build all boards per default
586 for VENDOR in $( vendors ); do
587 for MAINBOARD in $( mainboards $VENDOR ); do
588 build_target $VENDOR $MAINBOARD
589 test_target $VENDOR $MAINBOARD
590 remove_target $VENDOR $MAINBOARD