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
177 if [ "$scanbuild" = "true" ]; then
178 printf "(scan-build enabled) "
179 echo "CONFIG_SCANBUILD_ENABLE=y" >> .config
180 echo "CONFIG_SCANBUILD_REPORT_LOCATION=\"$TARGET/scan-build-results-tmp\"" >> .config
184 yes "" | $MAKE oldconfig obj=${build_dir} > ${build_dir}/config.log
186 mv .config.old $TARGET/${VENDOR}_${MAINBOARD}/config.in
187 if [ $ret -eq 0 ]; then
189 xml " <builddir>ok</builddir>"
191 xmlfile $build_dir/config.log
196 printf "FAILED! Log excerpt:\n"
197 xml " <builddir>failed</builddir>"
199 xmlfile $build_dir/config.log
202 tail -n $CONTEXT $build_dir/config.log 2> /dev/null || tail -$CONTEXT $build_dir/config.log
207 function create_buildenv
212 create_config $VENDOR $MAINBOARD $CONFIG
214 # Allow simple "make" in the target directory
215 MAKEFILE=$TARGET/${VENDOR}_${MAINBOARD}/Makefile
216 echo "# autogenerated makefile" > $MAKEFILE
217 echo "TOP=$ROOT" >> $MAKEFILE
218 echo "OUT=$TARGET/${VENDOR}_${MAINBOARD}" >> $MAKEFILE
219 echo "coreboot.rom:" >> $MAKEFILE
220 echo " cp config.build \$(TOP)/.config" >> $MAKEFILE
221 echo " cd \$(TOP); \$(MAKE) oldconfig obj=\$(OUT)" >> $MAKEFILE
222 echo " cd \$(TOP); \$(MAKE) obj=\$(OUT)" >> $MAKEFILE
225 function compile_target
230 printf " Compiling image "
231 test "$cpus" == "" && printf "in parallel .. "
232 test "$cpus" == "1" && printf "on 1 cpu .. "
233 test 0$cpus -gt 1 && printf "on %d cpus in parallel .. " $cpus
236 stime=`perl -e 'print time();' 2>/dev/null || date +%s`
237 build_dir=$TARGET/${VENDOR}_${MAINBOARD}
238 eval $MAKE $silent -j $cpus obj=${build_dir} \
239 &> ${build_dir}/make.log
241 mv .config ${build_dir}/config.build
242 mv .xcompile ${build_dir}/xcompile.build
243 cd $TARGET/${VENDOR}_${MAINBOARD}
244 etime=`perl -e 'print time();' 2>/dev/null || date +%s`
245 duration=$(( $etime - $stime ))
246 if [ $ret -eq 0 ]; then
247 xml " <compile>ok</compile>"
248 xml " <compiletime>${duration}s</compiletime>"
252 printf "ok\n" > compile.status
253 printf "ok. (took ${duration}s)\n"
257 xml " <compile>failed</compile>"
258 xml " <compiletime>${duration}s</compiletime>"
263 printf "FAILED after ${duration}s! Log excerpt:\n"
264 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
270 function built_successfully
274 if [ -d "$TARGET/${VENDOR}_${MAINBOARD}" ]; then
275 cd $TARGET/${VENDOR}_${MAINBOARD}
276 if [ -r compile.status ] ; then
277 status=`cat compile.status`
281 [ "$buildall" != "true" -a "$status" == "ok" ]
284 function build_broken
288 [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/BROKEN" ] && status="no"
289 [ "$buildbroken" == "true" -o "$status" == "yes" ]
292 function build_target
297 TARCH=$( architecture $VENDOR $MAINBOARD )
299 # Allow architecture override in an abuild.info file.
300 # This is used for the Motorola Sandpoint, which is not a real target
301 # but a skeleton target for the Sandpoint X3.
302 [ -r "$ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info" ] && \
303 source $ROOT/src/mainboard/${VENDOR}/${MAINBOARD}/abuild.info
307 CC="${CROSS_COMPILE}gcc"
309 found_crosscompiler=false
310 if which $TARCH-elf-gcc 2>/dev/null >/dev/null; then
311 # i386-elf target needs --divide, for i386-linux, that's the default
312 if [ "$TARCH" = "i386" ]; then
313 CC="$CC -Wa,--divide"
315 CROSS_COMPILE="$TARCH-elf-"
317 echo using $CROSS_COMPILE$CC
318 found_crosscompiler=true
323 printf "Processing mainboard/$VENDOR/$MAINBOARD"
327 xml " <vendor>$VENDOR</vendor>"
328 xml " <device>$MAINBOARD</device>"
330 xml " <architecture>$TARCH</architecture>"
333 if [ "$ARCH" = "$TARCH" -o $found_crosscompiler = true ]; then
334 printf " ($TARCH: ok)\n"
336 found_crosscompiler=false
337 if [ "$ARCH" == amd64 -a "$TARCH" == i386 ]; then
339 found_crosscompiler=true
341 if [ "$ARCH" == ppc64 -a "$TARCH" == ppc ]; then
343 found_crosscompiler=true
345 if [ "$found_crosscompiler" == "false" -a "$TARCH" == ppc ];then
346 for prefix in powerpc-eabi- powerpc-linux- ppc_74xx- \
347 powerpc-7450-linux-gnu- powerpc-elf-; do
348 if ${prefix}gcc --version > /dev/null 2> /dev/null ; then
349 found_crosscompiler=true
350 CROSS_COMPILE=$prefix
356 # TBD: look for suitable cross compiler suite
357 # cross-$TARCH-gcc and cross-$TARCH-ld
360 if [ $found_crosscompiler == "false" ]; then
361 printf " ($TARCH: skipped, we're $ARCH)\n\n"
362 xml " <status>notbuilt</status>"
368 printf " ($TARCH: ok, we're $ARCH with a ${CROSS_COMPILE} cross compiler)\n"
370 xml " <path>`which ${CROSS_COMPILE}gcc`</path>"
371 xml " <version>`${CROSS_COMPILE}gcc --version | head -1`</version>"
377 CC=${CROSS_COMPILE}$CC
379 if [ "$stackprotect" = "true" ]; then
380 CC="$CC -fno-stack-protector"
383 built_successfully $VENDOR $MAINBOARD && \
385 printf " ( mainboard/$VENDOR/$MAINBOARD previously ok )\n\n"
386 xml " <status>previouslyok</status>"
392 build_broken $VENDOR $MAINBOARD || \
394 printf " ( broken mainboard/$VENDOR/$MAINBOARD skipped )\n\n"
395 xml " <status>knownbroken</status>"
401 create_buildenv $VENDOR $MAINBOARD $CONFIG
402 if [ $? -eq 0 -a $configureonly -eq 0 ]; then
403 compile_target $VENDOR $MAINBOARD &&
404 xml " <status>ok</status>" ||
405 xml "<status>broken</status>"
406 if [ "$scanbuild" = "true" ]; then
407 mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
423 if [ "$hwtest" != "true" ]; then
427 # image does not exist. we silently skip the patch.
428 if [ ! -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
432 which curl &> /dev/null
434 printf "curl is not installed but required for test submission. skipping test.\n\n"
439 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/tested" ]; then
440 printf "Testing image for board $VENDOR $MAINBOARD skipped (previously submitted).\n\n"
443 # touch $TARGET/${VENDOR}_${MAINBOARD}/tested
445 printf "Submitting image for board $VENDOR $MAINBOARD to test system...\n"
447 curl -f -F "romfile=@$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" \
448 -F "mode=abuild" -F "mainboard=${VENDOR}_${MAINBOARD}" -F "submit=Upload" \
449 "http://qa.coreboot.org/deployment/send.php"
455 function remove_target
457 if [ "$remove" != "true" ]; then
464 # Save the generated coreboot.rom file of each board.
465 if [ -r "$TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom" ]; then
466 cp $TARGET/${VENDOR}_${MAINBOARD}/coreboot.rom \
467 ${VENDOR}_${MAINBOARD}_coreboot.rom
470 printf "Removing build dir for board $VENDOR $MAINBOARD...\n"
471 rm -rf $TARGET/${VENDOR}_${MAINBOARD}
478 printf "Usage: $0 [-v] [-a] [-b] [-r] [-t <vendor/board>] [-p <dir>] [lbroot]\n"
479 printf " $0 [-V|--version]\n"
480 printf " $0 [-h|--help]\n\n"
483 printf " [-v|--verbose] print more messages\n"
484 printf " [-a|--all] build previously succeeded ports as well\n"
485 printf " [-b|--broken] attempt to build ports that are known broken\n"
486 printf " [-r|--remove] remove output dir after build\n"
487 printf " [-t|--target <vendor/board>] attempt to build target vendor/board only\n"
488 printf " [-p|--payloads <dir>] use payloads in <dir> to build images\n"
489 printf " [-V|--version] print version number and exit\n"
490 printf " [-h|--help] print this help and exit\n"
491 printf " [-x|--xml] write xml log file \n"
492 printf " (defaults to $XMLFILE)\n"
493 printf " [-T|--test] submit image(s) to automated test system\n"
494 printf " [-c|--cpus <numcpus>] build on <numcpus> at the same time\n"
495 printf " [-s|--silent] omit compiler calls in logs\n"
496 printf " [-ns|--nostackprotect] use gcc -fno-stack-protector option\n"
497 printf " [-sb|--scan-build] use clang's static analyzer\n"
498 printf " [-C|--config] configure-only mode\n"
499 printf " [-l|--loglevel <num>] set loglevel\n"
500 printf " [lbroot] absolute path to coreboot sources\n"
501 printf " (defaults to $ROOT)\n\n"
508 coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
510 Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
511 Copyright (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
513 This program is free software; you may redistribute it under the terms
514 of the GNU General Public License. This program has absolutely no
525 test -f util/sconfig/config.g && ROOT=$( pwd )
526 test -f ../util/sconfig/config.g && ROOT=$( cd ..; pwd )
527 test "$ROOT" = "" && ROOT=$( cd ../..; pwd )
529 # parse parameters.. try to find out whether we're running GNU getopt
530 getoptbrand="`getopt -V`"
531 if [ "${getoptbrand:0:6}" == "getopt" ]; then
532 # Detected GNU getopt that supports long options.
533 args=`getopt -l version,verbose,help,all,target:,broken,payloads:,test,cpus:,silent,xml,config,loglevel: Vvhat:bp:Tc:sxCl: -- "$@"`
536 # Detected non-GNU getopt
537 args=`getopt Vvhat:bp:Tc:sxCl:o $*`
548 -x|--xml) shift; mode=xml; rm -f $XMLFILE ;;
549 -t|--target) shift; target="$1"; shift;;
550 -a|--all) shift; buildall=true;;
551 -b|--broken) shift; buildbroken=true;;
552 -r|--remove) shift; remove=true; shift;;
553 -v|--verbose) shift; verbose=true; silent='V=1';;
554 -V|--version) shift; myversion; exit 0;;
555 -h|--help) shift; myversion; myhelp; exit 0;;
556 -p|--payloads) shift; payloads="$1"; shift;;
557 -T|--test) shift; hwtest=true;;
558 -c|--cpus) shift; cpus="$1"; test "$cpus" == "max" && cpus=""; shift;;
559 -s|--silent) shift; silent="-s";;
560 -ns|--nostackprotect) shift; stackprotect=true;;
561 -sb|--scan-build) shift; scanbuild=true;;
562 -C|--config) shift; configureonly=1;;
563 -l|--loglevel) shift; loglevel="$1"; shift;;
565 -*) printf "Invalid option\n\n"; myhelp; exit 1;;
570 # /path/to/freebios2/
571 test -z "$1" || ROOT=$1
575 xml '<?xml version="1.0" encoding="utf-8"?>'
578 if [ "$target" != "" ]; then
579 # build a single board
580 VENDOR=`printf $target|cut -f1 -d/`
581 MAINBOARD=`printf $target|cut -f2 -d/`
582 CONFIG=`printf $target|cut -f3 -d/`
583 build_target $VENDOR $MAINBOARD $CONFIG
584 test_target $VENDOR $MAINBOARD
586 # build all boards per default
587 for VENDOR in $( vendors ); do
588 for MAINBOARD in $( mainboards $VENDOR ); do
589 build_target $VENDOR $MAINBOARD
590 test_target $VENDOR $MAINBOARD
591 remove_target $VENDOR $MAINBOARD