blob: 91c5bf9f1e08b9992906e7c1db4732dfef90acc9 [file] [log] [blame]
Stefan Reinauer9f12caa2004-10-19 07:00:47 +00001#!/bin/bash
2#
Stefan Reinauerf8ee1802008-01-18 15:08:58 +00003# coreboot autobuild
Stefan Reinauer9f12caa2004-10-19 07:00:47 +00004#
Stefan Reinauerf8ee1802008-01-18 15:08:58 +00005# This script builds coreboot images for all available targets.
Stefan Reinauer9f12caa2004-10-19 07:00:47 +00006#
7# (C) 2004 by Stefan Reinauer <stepan@openbios.org>
Stefan Reinauer68003b82010-01-30 10:44:28 +00008# (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
Martin Rothddb7a9d2014-12-08 01:57:52 -07009# (C) 2013-2014 Sage Electronic Engineering, LLC
Patrick Georgi2d242792014-05-21 22:48:35 +020010# (C) 2014 Patrick Georgi <patrick@georgi-clan.de>
Stefan Reinauer9f12caa2004-10-19 07:00:47 +000011#
12# This file is subject to the terms and conditions of the GNU General
13# Public License. See the file COPYING in the main directory of this
14# archive for more details.
Stefan Reinauer14e22772010-04-27 06:56:47 +000015#
Stefan Reinauer9f12caa2004-10-19 07:00:47 +000016
Eric Biedermanc1492102004-11-05 08:50:54 +000017#set -x # Turn echo on....
Stefan Reinauer23c3d932004-10-21 21:41:57 +000018
Julius Werner893eda02017-03-20 15:33:23 -070019ABUILD_DATE="Mar 28, 2017"
Martin Roth33314262017-03-27 23:45:31 -060020ABUILD_VERSION="0.10.03"
Stefan Reinauer3a140572006-10-25 19:02:34 +000021
Patrick Georgi3db85f32011-11-05 13:21:14 +010022TOP=$PWD
23
Stefan Reinauer23c3d932004-10-21 21:41:57 +000024# Where shall we place all the build trees?
Patrick Georgiaab0cce2013-12-19 20:43:29 +010025TARGET=${COREBOOT_BUILD_DIR:-coreboot-builds}
Patrick Georgi3db85f32011-11-05 13:21:14 +010026XMLFILE=$TOP/abuild.xml
27REAL_XMLFILE=$XMLFILE
Stefan Reinauer9f12caa2004-10-19 07:00:47 +000028
Patrick Georgid03d69b2013-12-19 20:13:23 +010029export KCONFIG_OVERWRITECONFIG=1
30
Stefan Reinauer23c3d932004-10-21 21:41:57 +000031# path to payload. Should be more generic
Eric Biederman018d8dd2004-11-04 11:04:33 +000032PAYLOAD=/dev/null
Stefan Reinauer23c3d932004-10-21 21:41:57 +000033
Martin Roth14b9b932016-11-30 16:38:25 -070034# get path to coreboot XGCC if it's not already set
35if [ -z "$XGCCPATH" ]; then
36 XGCCPATH="${TOP}/util/crossgcc/xgcc/bin/"
37fi
Marc Jones66a68a22013-05-31 13:33:30 -060038
39# Add XGCC to the path.
40if [ -d "$XGCCPATH" ] && [[ ":$PATH:" != *":$XGCCPATH:"* ]]; then
41 PATH="$XGCCPATH:$PATH"
42fi
43
Stefan Reinauer23c3d932004-10-21 21:41:57 +000044# Lines of error context to be printed in FAILURE case
Stefan Reinauered564222015-12-14 16:36:45 -080045CONTEXT=12
Stefan Reinauer23c3d932004-10-21 21:41:57 +000046
Stefan Reinauercc44b062009-03-11 15:00:50 +000047# Configure-only mode
48configureonly=0
49
Patrick Georgif9d19f22011-06-01 19:29:48 +000050# Did any board fail to build?
51failed=0
52
Martin Rothba973bd2017-07-19 14:13:07 -060053# Exit with a non-zero errorlevel on failure
54exitcode=0
55
Martin Rothc7e6ad72017-03-26 18:23:51 -060056# default: don't save checksums
57checksum_file=""
58
Patrick Georgi58955512013-12-05 19:53:04 +010059# default: single CPU build
60cpus=1
61
Martin Roth26174c92016-11-23 18:47:53 -070062# change with -d <directory>
63configdir="$TOP/configs"
64
Martin Roth33314262017-03-27 23:45:31 -060065# Timeless builds
66TIMELESS=0
67
Stefan Reinauer23c3d932004-10-21 21:41:57 +000068# One might want to adjust these in case of cross compiling
Patrick Georgia84a99b2009-05-26 14:03:51 +000069for i in make gmake gnumake nonexistant_make; do
70 $i --version 2>/dev/null |grep "GNU Make" >/dev/null && break
71done
72if [ "$i" = "nonexistant_make" ]; then
73 echo No GNU Make found.
74 exit 1
75fi
76MAKE=$i
Stefan Reinauer9f12caa2004-10-19 07:00:47 +000077
Patrick Georgi6f0e1602013-12-05 19:36:31 +010078# this can be changed to junit by -J
Stefan Reinauer192b7bc2006-05-27 00:22:02 +000079mode=text
80
Martin Rothddb7a9d2014-12-08 01:57:52 -070081# quiet mode: only print pass, failure, and 'skipped' messages
82quiet=false
83
Patrick Georgid2296772009-03-11 15:43:02 +000084# clang mode enabled by -sb option.
85scanbuild=false
86
Martin Roth047c2f42016-12-14 10:16:26 -070087# Mark whether abuild was called recursively
88recursive=false
89
Stefan Reinauer3a140572006-10-25 19:02:34 +000090trap interrupt INT
91
92function interrupt
93{
Martin Roth02c93b92016-11-30 16:32:20 -070094 printf "\n%s: execution interrupted manually.\n" "$0"
Patrick Georgi6f0e1602013-12-05 19:36:31 +010095 if [ "$mode" == "junit" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -070096 printf "%s: deleting incomplete xml output file.\n" "$0"
Stefan Reinauer3a140572006-10-25 19:02:34 +000097 fi
98 exit 1
99}
100
Stefan Reinauer173f13b2004-11-05 11:57:00 +0000101function debug
102{
Martin Roth02c93b92016-11-30 16:32:20 -0700103 test "$verbose" == "true" && echo "$*"
Stefan Reinauer173f13b2004-11-05 11:57:00 +0000104}
Eric Biederman692f2c72004-11-05 19:55:06 +0000105
Patrick Georgi140a9902011-06-03 21:56:13 +0200106function junit
107{
Martin Roth02c93b92016-11-30 16:32:20 -0700108 test "$mode" == "junit" && echo "$*" >> "$XMLFILE"
Patrick Georgi140a9902011-06-03 21:56:13 +0200109 return 0
110}
111
112function junitfile
113{
114 test "$mode" == "junit" && {
115 printf '<![CDATA[\n'
Martin Roth02c93b92016-11-30 16:32:20 -0700116 cat "$1"
Patrick Georgi140a9902011-06-03 21:56:13 +0200117 printf ']]>\n'
Martin Roth02c93b92016-11-30 16:32:20 -0700118 } >> "$XMLFILE"
Patrick Georgi140a9902011-06-03 21:56:13 +0200119}
Stefan Reinauer192b7bc2006-05-27 00:22:02 +0000120
Patrick Georgic2050f02015-10-31 00:35:44 +0100121# Return mainboard descriptors.
122# By default all mainboards are listed, but when passing a two-level path
123# below src/mainboard, such as emulation/qemu-i440fx, or emulation/*, it
124# returns all board descriptors in that hierarchy.
125function get_mainboards
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000126{
Patrick Georgic2050f02015-10-31 00:35:44 +0100127 local search_space=${1-*/*}
Martin Roth02c93b92016-11-30 16:32:20 -0700128 # shellcheck disable=SC2086
Patrick Georgic2050f02015-10-31 00:35:44 +0100129 grep -h "^[[:space:]]*config\>[[:space:]]*\<BOARD_" \
Patrick Georgif6dc5442015-10-31 09:13:26 +0100130 ${ROOT}/src/mainboard/${search_space}/Kconfig.name 2>/dev/null | \
Patrick Georgic2050f02015-10-31 00:35:44 +0100131 sed "s,^.*\<BOARD_\([A-Z0-9_]*\)\>.*$,\1,"
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000132}
133
Patrick Georgic2050f02015-10-31 00:35:44 +0100134# Given a mainboard descriptor, return its directory below src/mainboard
135function mainboard_directory
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000136{
Patrick Georgic2050f02015-10-31 00:35:44 +0100137 local MAINBOARD=$1
Stefan Reinauer14e22772010-04-27 06:56:47 +0000138
Martin Roth02c93b92016-11-30 16:32:20 -0700139 # shellcheck disable=SC2086
Patrick Georgic2050f02015-10-31 00:35:44 +0100140 grep -l "^[[:space:]]*config\>[[:space:]]*\<BOARD_${MAINBOARD}\>" \
141 ${ROOT}/src/mainboard/*/*/Kconfig.name | \
142 sed "s:^$ROOT/src/mainboard/\(.*\)/Kconfig.name$:\1:"
143}
Stefan Reinauer14e22772010-04-27 06:56:47 +0000144
Patrick Georgic2050f02015-10-31 00:35:44 +0100145# Given a mainboard descriptor, return its vendor (CONFIG_VENDOR_*)
146function mainboard_vendor
147{
148 local MAINBOARD=$1
Martin Roth02c93b92016-11-30 16:32:20 -0700149 local kconfig_file
Patrick Georgic2050f02015-10-31 00:35:44 +0100150
Martin Roth02c93b92016-11-30 16:32:20 -0700151 # shellcheck disable=SC2086
152 kconfig_file=$( \
Patrick Georgic2050f02015-10-31 00:35:44 +0100153 grep -l "^[[:space:]]*config\>[[:space:]]*\<BOARD_${MAINBOARD}\>" \
154 ${ROOT}/src/mainboard/*/*/Kconfig.name | \
155 sed "s:^\(${ROOT}/src/mainboard/.*\)/.*/\(Kconfig.name\)$:\1/\2:" )
156 if [ ! -f "$kconfig_file" ]; then
157 exit 1
158 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700159 grep "^[[:space:]]*config\>[[:space:]]*\<VENDOR_" "$kconfig_file" | \
Patrick Georgic2050f02015-10-31 00:35:44 +0100160 sed "s,^.*\<VENDOR_\([A-Z0-9_]*\)\>.*$,\1,"
161}
162
163# Accepts directory names (eg. emulation/qemu-i440fx) and mainboard
164# descriptors (eg. EMULATION_QEMU_X86_I440F} and returns the latter
165# format.
166# If a directory contains multiple boards, returns them all.
167function normalize_target
168{
Martin Roth02c93b92016-11-30 16:32:20 -0700169 local targets
170
171 targets=$(get_mainboards "$1")
Patrick Georgif6dc5442015-10-31 09:13:26 +0100172 if [ -n "$targets" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700173 echo "$targets"
Patrick Georgif6dc5442015-10-31 09:13:26 +0100174 return
Patrick Georgic2050f02015-10-31 00:35:44 +0100175 fi
Patrick Georgif6dc5442015-10-31 09:13:26 +0100176
Martin Roth02c93b92016-11-30 16:32:20 -0700177 targets=$(echo "$1" | tr ',' ' ')
Patrick Georgif6dc5442015-10-31 09:13:26 +0100178 for i in $targets; do
Martin Roth02c93b92016-11-30 16:32:20 -0700179 if [ -n "$(mainboard_directory "$i")" ]; then
180 echo "$i"
Patrick Georgif6dc5442015-10-31 09:13:26 +0100181 else
182 echo "$i is not a valid target" >&2
183 exit 1
184 fi
185 done
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000186}
187
Martin Roth02c93b92016-11-30 16:32:20 -0700188# shellcheck disable=SC2129
Stefan Reinauer68003b82010-01-30 10:44:28 +0000189function create_config
190{
Martin Roth26174c92016-11-23 18:47:53 -0700191 local BUILD_NAME=$1
192 local build_dir=$2
Martin Roth02c93b92016-11-30 16:32:20 -0700193 local board_srcdir
Stefan Reinauer68003b82010-01-30 10:44:28 +0000194
Martin Roth02c93b92016-11-30 16:32:20 -0700195 local config_file="${build_dir}/config.build"
196 board_srcdir="$(mainboard_directory "${BUILD_NAME}")"
Stefan Reinauer68003b82010-01-30 10:44:28 +0000197
Martin Roth02c93b92016-11-30 16:32:20 -0700198 mkdir -p "${build_dir}"
199 mkdir -p "$TARGET/sharedutils"
Stefan Reinauer68003b82010-01-30 10:44:28 +0000200
Martin Roth02c93b92016-11-30 16:32:20 -0700201 if [ "$quiet" == "false" ]; then echo " Creating config file for $BUILD_NAME..."; fi
202 echo "CONFIG_VENDOR_$(mainboard_vendor "${BUILD_NAME}")=y" > "${config_file}"
203 echo "CONFIG_BOARD_${BUILD_NAME}=y" >> "${config_file}"
204 grep "select[\t ]*ARCH" "${ROOT}/src/mainboard/${board_srcdir}/Kconfig" | \
205 sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> "${config_file}"
206 echo "CONFIG_MAINBOARD_DIR=\"${board_srcdir}\"" >> "${config_file}"
Stefan Reinauer68003b82010-01-30 10:44:28 +0000207
Martin Roth26174c92016-11-23 18:47:53 -0700208 update_config "$BUILD_NAME" "$build_dir" "$config_file"
Patrick Georgie6adabd2015-10-30 22:59:30 +0100209
Stefan Reinauer68003b82010-01-30 10:44:28 +0000210 ret=$?
Stefan Reinauer68003b82010-01-30 10:44:28 +0000211 if [ $ret -eq 0 ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700212 if [ "$quiet" == "false" ]; then echo " $BUILD_NAME config created."; fi
Stefan Reinauer68003b82010-01-30 10:44:28 +0000213 return 0
214 else
Stefan Reinauerabdf8482010-03-30 14:02:19 +0000215 # Does this ever happen?
Martin Roth02c93b92016-11-30 16:32:20 -0700216 if [ "$quiet" == "false" ]; then printf "%s config creation FAILED!\nLog excerpt:\n" "$BUILD_NAME"; fi
217 tail -n $CONTEXT "$build_dir/config.log" 2> /dev/null || tail -$CONTEXT "$build_dir/config.log"
Stefan Reinauer68003b82010-01-30 10:44:28 +0000218 return 1
219 fi
220}
221
Martin Roth26174c92016-11-23 18:47:53 -0700222function update_config
223{
224 local BUILD_NAME=$1
225 local build_dir=$2
226 local config_file=$3
227
Martin Roth02c93b92016-11-30 16:32:20 -0700228 local PAYLOAD
Martin Roth26174c92016-11-23 18:47:53 -0700229 local defconfig_file
230 defconfig_file=${build_dir}/config.$(echo "${BUILD_NAME}" | tr '[:upper:]' '[:lower:]').default
231
232 # get a working payload for the board if we have one.
233 # the --payload option expects a directory containing
234 # a shell script payload.sh
235 # Usage: payload.sh [BOARD]
236 # the script returns an absolute path to the payload binary.
237
238 if [ -f "$payloads/payload.sh" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700239 PAYLOAD=$(sh "$payloads/payload.sh" "$BUILD_NAME")
240 local PAYLOAD_OK=$?
241 if [ $PAYLOAD_OK -gt 0 ]; then
Martin Roth26174c92016-11-23 18:47:53 -0700242 echo "problem with payload"
243 exit 1
244 fi
245 if [ "$quiet" == "false" ]; then printf "Using payload %s\n" "$PAYLOAD"; fi
246 elif [ "$payloads" = "none" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700247 PAYLOAD=none
Martin Roth26174c92016-11-23 18:47:53 -0700248 fi
249
250 if [ "$PAYLOAD" = "none" ]; then
251 {
252 echo "CONFIG_PAYLOAD_NONE=y"
253 echo "# CONFIG_PAYLOAD_SEABIOS is not set"
254 echo "# CONFIG_PAYLOAD_ELF is not set"
255 echo "# CONFIG_PAYLOAD_BAYOU is not set"
256 echo "# CONFIG_PAYLOAD_FILO is not set"
257 echo "# CONFIG_PAYLOAD_GRUB2 is not set"
258 echo "# CONFIG_PAYLOAD_OPENBIOS is not set"
259 echo "# CONFIG_PAYLOAD_DEPTHCHARGE is not set"
260 echo "# CONFIG_PAYLOAD_UBOOT is not set"
261 echo "# CONFIG_PAYLOAD_TIANOCORE is not set"
262 } >> "${config_file}"
263 elif [ "$PAYLOAD" != "/dev/null" ]; then
264 {
265 echo "# CONFIG_PAYLOAD_NONE is not set"
266 echo "# CONFIG_PAYLOAD_SEABIOS is not set"
267 echo "CONFIG_PAYLOAD_ELF=y"
268 echo "CONFIG_PAYLOAD_FILE=\"$PAYLOAD\""
269 } >> "${config_file}"
270 fi
271
272 if [ "$quiet" == "false" ]; then echo " $MAINBOARD ($customizing)"; fi
Martin Roth6bc44162016-12-13 15:29:30 -0700273 # shellcheck disable=SC2059
274 printf "$configoptions" >> "${config_file}"
Martin Roth26174c92016-11-23 18:47:53 -0700275
Patrick Georgi55ea0132017-06-27 14:02:18 +0200276 yes "" 2>/dev/null | $MAKE oldconfig "$verboseopt" "DOTCONFIG=${config_file}" "obj=${build_dir}" "objutil=$TARGET/sharedutils" &> "${build_dir}/config.log" ; \
Martin Roth02c93b92016-11-30 16:32:20 -0700277 CONFIG_OK=$?
278 if [ $CONFIG_OK -eq 0 ]; then
Patrick Georgi55ea0132017-06-27 14:02:18 +0200279 $MAKE savedefconfig "$verboseopt" DEFCONFIG="${defconfig_file}" DOTCONFIG="${config_file}" obj="${build_dir}" objutil="$TARGET/sharedutils" &>> "${build_dir}/config.log"
Martin Roth26174c92016-11-23 18:47:53 -0700280 return $?
281 else
282 return 1
283 fi
284}
285
Martin Roth02c93b92016-11-30 16:32:20 -0700286# shellcheck disable=SC2129
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000287function create_buildenv
288{
Martin Roth26174c92016-11-23 18:47:53 -0700289 local BUILD_NAME=$1
290 local build_dir=$2
291 local config_file=$3
Stefan Reinauer0ed0b7c2010-03-30 15:49:14 +0000292
Martin Roth26174c92016-11-23 18:47:53 -0700293 if [ -z "$config_file" ]; then
294 create_config "$BUILD_NAME" "$build_dir"
295 else
296 local new_config_file="${build_dir}/config.build"
297 cp "$config_file" "$new_config_file"
298 update_config "$BUILD_NAME" "$build_dir" "$new_config_file"
299 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700300 local ret=$?
Stefan Reinauer86dbe152010-03-25 14:18:57 +0000301
302 # Allow simple "make" in the target directory
Martin Roth26174c92016-11-23 18:47:53 -0700303 local MAKEFILE=$TARGET/${BUILD_NAME}/Makefile
Martin Roth02c93b92016-11-30 16:32:20 -0700304 echo "# autogenerated" > "$MAKEFILE"
305 echo "TOP=$ROOT" >> "$MAKEFILE"
306 echo "BUILD=$TARGET" >> "$MAKEFILE"
307 echo "OBJ=\$(BUILD)/${MAINBOARD}" >> "$MAKEFILE"
308 echo "OBJUTIL=\$(BUILD)/sharedutils" >> "$MAKEFILE"
309 echo "all:" >> "$MAKEFILE"
310 echo " @cp -a config.h config.h.bak" >> "$MAKEFILE"
311 echo " @cd \$(TOP); \$(MAKE) oldconfig DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> "$MAKEFILE"
312 echo " @tail -n+6 config.h > config.new; tail -n+6 config.h.bak > config.old" >> "$MAKEFILE"
313 echo " @cmp -s config.new config.old && cp -a config.h.bak config.h || echo \"Config file changed\"" >> "$MAKEFILE"
314 echo " @rm config.h.bak config.new config.old" >> "$MAKEFILE"
315 echo " @cd \$(TOP); \$(MAKE) DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> "$MAKEFILE"
Stefan Reinauer0ed0b7c2010-03-30 15:49:14 +0000316
317 return $ret
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000318}
319
Martin Roth26174c92016-11-23 18:47:53 -0700320function check_config
321{
322 local BUILD_DIR="$1"
323 local TEST_TYPE="$2"
324 local TEST_STRING="$3"
325
326 local CONFIG_FILE="$BUILD_DIR/config.build"
327 local CONFIG_LOG="$BUILD_DIR/config.log"
328
329 if ! grep -q "$TEST_STRING" "$CONFIG_FILE"; then
330 echo "config file: $CONFIG_FILE has incorrect $TEST_TYPE"
331 echo "Error: Expected '$TEST_STRING' in config file." >> "$CONFIG_LOG"
332 return 1
333 fi
334
335 return 0
336}
337
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000338function compile_target
Stefan Reinauer14e22772010-04-27 06:56:47 +0000339{
Martin Roth26174c92016-11-23 18:47:53 -0700340 local BUILD_NAME=$1
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000341
Martin Roth02c93b92016-11-30 16:32:20 -0700342 if [ "$quiet" == "false" ]; then echo " Compiling $MAINBOARD image$cpuconfig..."; fi
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000343
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000344 CURR=$( pwd )
Stefan Reinauerabdf8482010-03-30 14:02:19 +0000345 #stime=`perl -e 'print time();' 2>/dev/null || date +%s`
Patrick Georgi55ea0132017-06-27 14:02:18 +0200346 eval $BUILDPREFIX $MAKE "$verboseopt" DOTCONFIG="${build_dir}/config.build" obj="${build_dir}" objutil="$TARGET/sharedutils" BUILD_TIMELESS=$TIMELESS \
Martin Roth02c93b92016-11-30 16:32:20 -0700347 &> "${build_dir}/make.log" ; \
348 MAKE_FAILED=$?
349 cp .xcompile "${build_dir}/xcompile.build"
350 cd "${build_dir}" || return $?
Stefan Reinauerabdf8482010-03-30 14:02:19 +0000351
Martin Roth02c93b92016-11-30 16:32:20 -0700352 etime=$(perl -e 'print time();' 2>/dev/null || date +%s)
353 duration=$(( etime - stime ))
Martin Roth26174c92016-11-23 18:47:53 -0700354 junit " <testcase classname='board${testclass/#/.}' name='$BUILD_NAME' time='$duration' >"
Stefan Reinauerabdf8482010-03-30 14:02:19 +0000355
Martin Roth02c93b92016-11-30 16:32:20 -0700356 if [ $MAKE_FAILED -eq 0 ]; then
Patrick Georgi140a9902011-06-03 21:56:13 +0200357 junit "<system-out>"
358 junitfile make.log
359 junit "</system-out>"
Stefan Reinauer3a140572006-10-25 19:02:34 +0000360 printf "ok\n" > compile.status
Martin Roth02c93b92016-11-30 16:32:20 -0700361 printf "%s built successfully. (took %ss)\n" "$BUILD_NAME" "${duration}"
Martin Rothd16022b2017-06-25 14:21:09 -0600362 echo "$BUILD_NAME" >> "$PASSED_BOARDS"
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000363 else
Patrick Georgi140a9902011-06-03 21:56:13 +0200364 junit "<failure type='BuildFailed'>"
365 junitfile make.log
366 junit "</failure>"
Patrick Georgi8bf5c152015-04-22 18:24:01 +0200367 printf "failed\n" > compile.status
Martin Roth02c93b92016-11-30 16:32:20 -0700368 printf "%s build FAILED after %ss!\nLog excerpt:\n" "$BUILD_NAME" "${duration}"
Patrick Georgia84a99b2009-05-26 14:03:51 +0000369 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
Martin Rothd16022b2017-06-25 14:21:09 -0600370 echo "$BUILD_NAME - Log: ${TOP}/${build_dir}/make.log" >> "$FAILED_BOARDS"
Patrick Georgif9d19f22011-06-01 19:29:48 +0000371 failed=1
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000372 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700373 cd "$CURR" || return $?
Martin Rothc7e6ad72017-03-26 18:23:51 -0600374 if [ -n "$checksum_file" ]; then
375 sha256sum "${build_dir}/coreboot.rom" >> "${checksum_file}_platform"
376 sort "${build_dir}/config.h" | grep CONFIG_ > "${build_dir}/config.h.sorted"
377 sha256sum "${build_dir}/config.h.sorted" >> "${checksum_file}_config"
378 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700379 if [ "$clean_work" = "true" ]; then
380 rm -rf "${build_dir}"
Patrick Georgib0bc63b2014-05-21 22:47:05 +0200381 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700382 return $MAKE_FAILED
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000383}
384
Martin Roth26174c92016-11-23 18:47:53 -0700385function build_config
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000386{
Patrick Georgic2050f02015-10-31 00:35:44 +0100387 local MAINBOARD=$1
Martin Roth26174c92016-11-23 18:47:53 -0700388 local build_dir=$2
389 local BUILD_NAME=$3
390 local config_file=$4
Martin Roth02c93b92016-11-30 16:32:20 -0700391 local board_srcdir
392 local ret
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000393
Martin Roth02c93b92016-11-30 16:32:20 -0700394 board_srcdir=$(mainboard_directory "${MAINBOARD}")
Martin Roth26174c92016-11-23 18:47:53 -0700395
Martin Roth02c93b92016-11-30 16:32:20 -0700396 if [ "$(cat "${build_dir}/compile.status" 2>/dev/null)" = "ok" ] && \
397 [ "$buildall" = "false" ]; then
Martin Roth26174c92016-11-23 18:47:53 -0700398 echo "Skipping $BUILD_NAME; (already successful)"
Patrick Georgi1a5301d2012-11-22 14:19:43 +0100399 return
400 fi
401
Paul Menzeld2bbaff2016-12-09 08:47:45 +0100402 export HOSTCC='gcc'
Eric Biederman709850a2004-11-05 10:48:04 +0000403
Martin Roth26174c92016-11-23 18:47:53 -0700404 if [ "$chromeos" = true ] && [ "$(grep -c "^[[:space:]]*select[[:space:]]*MAINBOARD_HAS_CHROMEOS\>" "${ROOT}/src/mainboard/${board_srcdir}/Kconfig")" -eq 0 ]; then
405 echo "${BUILD_NAME} doesn't support Chrome OS, skipping."
Patrick Georgif43b06d2015-07-31 16:26:19 +0200406 return
407 fi
408
Martin Roth26174c92016-11-23 18:47:53 -0700409 if [ -f "src/mainboard/${board_srcdir}/abuild.disabled" ]; then
410 echo "${BUILD_NAME} disabled:"
411 cat "src/mainboard/${board_srcdir}/abuild.disabled"
Patrick Georgi3ac3c4eb2015-07-14 20:20:13 +0200412 return
413 fi
414
Martin Roth26174c92016-11-23 18:47:53 -0700415 if [ "$quiet" == "false" ]; then echo "Building $BUILD_NAME"; fi
416 mkdir -p "$TARGET/${BUILD_NAME}" "$TARGET/abuild"
Martin Roth02c93b92016-11-30 16:32:20 -0700417 ABSPATH="$(cd "$TARGET/abuild" && pwd)"
Martin Roth26174c92016-11-23 18:47:53 -0700418 XMLFILE="$ABSPATH/${BUILD_NAME}.xml"
419 rm -f "${XMLFILE}"
420
421 stime=$(perl -e 'print time();' 2>/dev/null || date +%s)
422 create_buildenv "$BUILD_NAME" "$build_dir" "$config_file"
423 local BUILDENV_CREATED=$?
424
425 check_config "$build_dir" "mainboard" "CONFIG_BOARD_${MAINBOARD}=y"
426 local MAINBOARD_OK=$?
427
428 check_config "$build_dir" "vendor" "CONFIG_VENDOR_$(mainboard_vendor "${MAINBOARD}")=y"
429 local VENDOR_OK=$?
430
431 if [ $BUILDENV_CREATED -ne 0 ] || [ $MAINBOARD_OK -ne 0 ] || [ $VENDOR_OK -ne 0 ]; then
Martin Roth16c49b52017-05-23 22:06:30 -0600432 junit " <testcase classname='board${testclass/#/.}' name='$BUILD_NAME' >"
Martin Roth26174c92016-11-23 18:47:53 -0700433
434 junit "<failure type='BuildFailed'>"
435 junitfile "$build_dir/config.log"
436 junit "</failure>"
437 printf "failed\n" > compile.status
Martin Roth02c93b92016-11-30 16:32:20 -0700438 printf "%s build configuration FAILED!\nLog excerpt:\n" "$BUILD_NAME"
Martin Roth26174c92016-11-23 18:47:53 -0700439 tail -n $CONTEXT "$build_dir/config.log" 2> /dev/null || tail -$CONTEXT "$build_dir/config.log"
440
441 junit "</testcase>"
Martin Rothd16022b2017-06-25 14:21:09 -0600442 echo "$BUILD_NAME - Log: ${TOP}/$build_dir/config.log" >> "$FAILED_BOARDS"
Martin Roth26174c92016-11-23 18:47:53 -0700443 return
444 fi
Stefan Reinauer192b7bc2006-05-27 00:22:02 +0000445
Martin Roth02c93b92016-11-30 16:32:20 -0700446 required_arches=$(egrep "^CONFIG_ARCH_(BOOTBLOCK|R.MSTAGE|VERSTAGE)" "$TARGET/${BUILD_NAME}/config.build" | \
447 sed "s,^CONFIG_ARCH_[^_]*_\([^=]*\)=.*$,\1," |sort -u |tr 'A-Z\n\r' 'a-z ')
448 # shellcheck disable=SC2016,SC2059
449 missing_arches=$(printf 'include .xcompile\nall: ; @echo $(foreach arch,'"$required_arches"',$(if $(filter $(arch),$(SUBARCH_SUPPORTED)),,$(arch)))' | make --no-print-directory -f -)
Patrick Georgi02802df2014-10-18 11:57:11 +0200450 if [ -n "$missing_arches" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700451 printf "skipping %s because we're missing compilers for (%s)\n" "$BUILD_NAME" "$missing_arches"
Patrick Georgi02802df2014-10-18 11:57:11 +0200452 return
453 fi
454
Martin Roth02c93b92016-11-30 16:32:20 -0700455 if [ $BUILDENV_CREATED -eq 0 ] && [ $configureonly -eq 0 ]; then
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200456 BUILDPREFIX=
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000457 if [ "$scanbuild" = "true" ]; then
Martin Roth26174c92016-11-23 18:47:53 -0700458 scanbuild_out=$TARGET/${BUILD_NAME}-scanbuild
Martin Roth02c93b92016-11-30 16:32:20 -0700459 rm -rf "${scanbuild_out}"
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200460 BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000461 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700462 compile_target "${BUILD_NAME}"
Patrick Georgid2296772009-03-11 15:43:02 +0000463 if [ "$scanbuild" = "true" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700464 mv "${scanbuild_out}"tmp/* "${scanbuild_out}"
465 rmdir "${scanbuild_out}tmp"
Patrick Georgid2296772009-03-11 15:43:02 +0000466 fi
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000467 fi
Stefan Reinauer2f285ae2004-11-05 14:06:24 +0000468
Patrick Georgi140a9902011-06-03 21:56:13 +0200469 junit "</testcase>"
Stefan Reinauer3a140572006-10-25 19:02:34 +0000470}
471
Martin Roth26174c92016-11-23 18:47:53 -0700472# One target may build several configs
473function build_target
474{
475 local MAINBOARD=$1
Martin Roth02c93b92016-11-30 16:32:20 -0700476 local MAINBOARD_LC
477 MAINBOARD_LC=$(echo "$MAINBOARD" | tr '[:upper:]' '[:lower:]')
Martin Roth26174c92016-11-23 18:47:53 -0700478
479 # look for config files in the config directory that match the boardname
480 if [ -n "$( find "$configdir" -maxdepth 1 -name "config.${MAINBOARD_LC}*" -print -quit )" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700481 for config in "$configdir/config.${MAINBOARD_LC}"*; do
Martin Roth26174c92016-11-23 18:47:53 -0700482 BUILD_NAME="${config##*/}"
483 BUILD_NAME="${BUILD_NAME##config.}"
484 BUILD_NAME=$(echo "${BUILD_NAME}" | tr '[:lower:]' '[:upper:]')
485 echo "Building config $BUILD_NAME"
486 build_dir=$TARGET/${BUILD_NAME}
487 build_config "$MAINBOARD" "$build_dir" "$BUILD_NAME" "$config"
488 remove_target "$BUILD_NAME"
489
490 done
491 else
492 echo "Building board $MAINBOARD (using default config)"
493 build_dir=$TARGET/${MAINBOARD}
494
495 build_config "$MAINBOARD" "$build_dir" "$MAINBOARD"
496 remove_target "$MAINBOARD"
497 fi
498
499}
500
Uwe Hermann4e006402009-04-15 16:07:27 +0000501function remove_target
502{
503 if [ "$remove" != "true" ]; then
Martin Roth26174c92016-11-23 18:47:53 -0700504 return
Uwe Hermann4e006402009-04-15 16:07:27 +0000505 fi
506
Martin Roth26174c92016-11-23 18:47:53 -0700507 local BUILD_NAME=$1
Uwe Hermann4e006402009-04-15 16:07:27 +0000508
509 # Save the generated coreboot.rom file of each board.
Martin Roth26174c92016-11-23 18:47:53 -0700510 if [ -r "$TARGET/${BUILD_NAME}/coreboot.rom" ]; then
511 cp "$TARGET/${BUILD_NAME}/coreboot.rom" \
512 "${BUILD_NAME}_coreboot.rom"
Uwe Hermann4e006402009-04-15 16:07:27 +0000513 fi
514
Martin Roth26174c92016-11-23 18:47:53 -0700515 echo "Removing build dir for $BUILD_NAME..."
Martin Roth02c93b92016-11-30 16:32:20 -0700516 rm -rf "${TARGET:?}/${BUILD_NAME}"
Uwe Hermann4e006402009-04-15 16:07:27 +0000517
Martin Roth26174c92016-11-23 18:47:53 -0700518 return
Uwe Hermann4e006402009-04-15 16:07:27 +0000519}
520
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000521function myhelp
522{
Patrick Georgi86980bb2015-07-31 16:14:43 +0200523cat << __END_OF_HELP
Martin Roth5b0d2db2016-12-06 09:18:36 -0700524Usage: $0 [options]
Patrick Georgi86980bb2015-07-31 16:14:43 +0200525 $0 [-V|--version]
526 $0 [-h|--help]
Stefan Reinauerca631202006-11-10 13:30:28 +0000527
Patrick Georgi86980bb2015-07-31 16:14:43 +0200528Options:\n"
Martin Rothb06bfa42016-12-05 09:15:33 -0700529 [-a|--all] Build previously succeeded ports as well
Damien Zammitb40c72a2017-09-02 15:02:04 +1000530 [-A|--any-toolchain] Use any toolchain
Patrick Georgi86980bb2015-07-31 16:14:43 +0200531 [-B|--blobs] Allow using binary files
Martin Rothc7e6ad72017-03-26 18:23:51 -0600532 [--checksum <path/basefile>] Store checksums at path/basefile
Martin Rothb06bfa42016-12-05 09:15:33 -0700533 [-c|--cpus <numcpus>] Build on <numcpus> at the same time
534 [-C|--config] Configure-only mode
535 [-d|--dir <dir>] Directory containing config files
Martin Rothba973bd2017-07-19 14:13:07 -0600536 [-e|--exitcode] Exit with a non-zero errorlevel on failure
Martin Rothb06bfa42016-12-05 09:15:33 -0700537 [-J|--junit] Write JUnit formatted xml log file
538 [-K|--kconfig <name>] Prepend file to generated Kconfig
539 [-l|--loglevel <num>] Set loglevel
Patrick Georgi86980bb2015-07-31 16:14:43 +0200540 [-L|--clang] Use clang
Martin Rothb06bfa42016-12-05 09:15:33 -0700541 [-o|--outdir <path>] Store build results in path
542 (defaults to $TARGET)
543 [-p|--payloads <dir>] Use payloads in <dir> to build images
544 [-P|--prefix <name>] File name prefix in CBFS
545 [-q|--quiet] Print fewer messages
546 [-r|--remove] Remove output dir after build
Martin Roth5b0d2db2016-12-06 09:18:36 -0700547 [-R|--root <path>] Absolute path to coreboot sources
548 (defaults to $ROOT)
Martin Rothb06bfa42016-12-05 09:15:33 -0700549 [--scan-build] Use clang's static analyzer
Martin Roth33314262017-03-27 23:45:31 -0600550 [--timeless] Generate timeless builds
Martin Rothb06bfa42016-12-05 09:15:33 -0700551 [-t|--target <vendor/board>] Attempt to build target vendor/board only
552 [-T|--test] Submit image(s) to automated test system
553 [-u|--update] Update existing image
554 [-v|--verbose] Print more messages
Patrick Georgi86980bb2015-07-31 16:14:43 +0200555 [-x|--chromeos] Build with CHROMEOS enabled
Patrick Georgif43b06d2015-07-31 16:26:19 +0200556 Skip boards without Chrome OS support
Martin Rothb06bfa42016-12-05 09:15:33 -0700557 [-X|--xmlfile <name>] Set JUnit XML log file filename
558 (defaults to $XMLFILE)
559 [-y|--ccache] Use ccache
560 [-z|--clean] Remove build results when finished
561
Martin Rothb06bfa42016-12-05 09:15:33 -0700562 [-V|--version] Print version number and exit
563 [-h|--help] Print this help and exit
Patrick Georgi86980bb2015-07-31 16:14:43 +0200564
Patrick Georgi55ea0132017-06-27 14:02:18 +0200565 [-s|--silent] obsolete
Patrick Georgi86980bb2015-07-31 16:14:43 +0200566__END_OF_HELP
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000567}
568
Stefan Reinauer14e22772010-04-27 06:56:47 +0000569function myversion
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000570{
571 cat << EOF
572
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000573coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000574
Stefan Reinauer192b7bc2006-05-27 00:22:02 +0000575Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
Stefan Reinauer68003b82010-01-30 10:44:28 +0000576Copyright (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
Stefan Reinauer3a140572006-10-25 19:02:34 +0000577
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000578This program is free software; you may redistribute it under the terms
579of the GNU General Public License. This program has absolutely no
580warranty.
581
582EOF
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000583}
584
585# default options
586target=""
587buildall=false
Stefan Reinauer173f13b2004-11-05 11:57:00 +0000588verbose=false
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000589
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +0000590test -f util/sconfig/sconfig.l && ROOT=$( pwd )
Martin Roth02c93b92016-11-30 16:32:20 -0700591test -f ../util/sconfig/sconfig.l && ROOT=$( cd .. && pwd )
592test "$ROOT" = "" && ROOT=$( cd ../.. && pwd )
Stefan Reinauer0d4a08e2009-07-01 12:26:11 +0000593
Patrick Georgi92cfe182012-04-05 11:17:01 +0200594# Look if we have getopt. If not, build it.
595export PATH=$PATH:util/abuild
596getopt - > /dev/null 2>/dev/null || gcc -o util/abuild/getopt util/abuild/getopt.c
597
Julius Werner893eda02017-03-20 15:33:23 -0700598# Save command line for xargs parallelization.
599cmdline=("$@")
Patrick Georgi43105d62011-11-05 14:44:41 +0100600
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000601# parse parameters.. try to find out whether we're running GNU getopt
Martin Roth02c93b92016-11-30 16:32:20 -0700602getoptbrand="$(getopt -V)"
603
604# shellcheck disable=SC2086
Stefan Reinauer39d4e5f2008-05-28 08:40:23 +0000605if [ "${getoptbrand:0:6}" == "getopt" ]; then
606 # Detected GNU getopt that supports long options.
Damien Zammitb40c72a2017-09-02 15:02:04 +1000607 args=$(getopt -l version,verbose,quiet,help,all,target:,payloads:,cpus:,silent,junit,config,loglevel:,remove,prefix:,update,scan-build,ccache,blobs,clang,any-toolchain,clean,outdir:,chromeos,xmlfile:,kconfig:,dir:,root:,recursive,checksum:,timeless,exitcode -o Vvqhat:p:c:sJCl:rP:uyBLAzo:xX:K:d:R:Ie -- "$@") || exit 1
Warren Turkal0e8f2042010-09-27 21:14:19 +0000608 eval set -- $args
Martin Roth02c93b92016-11-30 16:32:20 -0700609 retval=$?
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000610else
611 # Detected non-GNU getopt
Damien Zammitb40c72a2017-09-02 15:02:04 +1000612 args=$(getopt Vvqhat:p:c:sJCl:rP:uyBLAzo:xX:K:d:R:Ie "$@")
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000613 set -- $args
Martin Roth02c93b92016-11-30 16:32:20 -0700614 retval=$?
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000615fi
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000616
Martin Roth02c93b92016-11-30 16:32:20 -0700617if [ $retval != 0 ]; then
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000618 myhelp
619 exit 1
620fi
621
Patrick Georgif43b06d2015-07-31 16:26:19 +0200622chromeos=false
Patrick Georgib0bc63b2014-05-21 22:47:05 +0200623clean_work=false
Patrick Georgi55ea0132017-06-27 14:02:18 +0200624verboseopt='V=0'
Patrick Georgi64d9a772012-05-01 15:14:46 +0200625customizing=""
626configoptions=""
Patrick Georgi098c4a82015-09-15 16:57:04 +0200627# testclass needs to be undefined if not used for variable expansion to work
628unset testclass
Eric Biedermanc1492102004-11-05 08:50:54 +0000629while true ; do
Eric Biedermanca883c92004-11-05 11:24:57 +0000630 case "$1" in
Martin Roth02c93b92016-11-30 16:32:20 -0700631 -J|--junit) shift; mode=junit; rm -f "$XMLFILE" ;;
Stefan Reinauer2f285ae2004-11-05 14:06:24 +0000632 -t|--target) shift; target="$1"; shift;;
Eric Biedermanc1492102004-11-05 08:50:54 +0000633 -a|--all) shift; buildall=true;;
Martin Roth26174c92016-11-23 18:47:53 -0700634 -d|--dir) shift; configdir="$1"; shift;;
Martin Rothba973bd2017-07-19 14:13:07 -0600635 -e|--exitcode) shift; exitcode=1;;
Warren Turkal0e8f2042010-09-27 21:14:19 +0000636 -r|--remove) shift; remove=true;;
Patrick Georgi55ea0132017-06-27 14:02:18 +0200637 -v|--verbose) shift; verbose=true; verboseopt='V=1';;
Martin Rothddb7a9d2014-12-08 01:57:52 -0700638 -q|--quiet) shift; quiet=true;;
Stefan Reinauerd4c68462004-11-05 11:47:41 +0000639 -V|--version) shift; myversion; exit 0;;
Stefan Reinauer3a140572006-10-25 19:02:34 +0000640 -h|--help) shift; myversion; myhelp; exit 0;;
Stefan Reinauer7fe2b7c2006-09-15 17:00:11 +0000641 -p|--payloads) shift; payloads="$1"; shift;;
Martin Roth5b0d2db2016-12-06 09:18:36 -0700642 -R|--root) shift; ROOT="$1"; shift;;
Patrick Georgi64d9a772012-05-01 15:14:46 +0200643 -c|--cpus) shift
644 export MAKEFLAGS="-j $1"
Patrick Georgi58955512013-12-05 19:53:04 +0100645 cpus=$1
Martin Rothddb7a9d2014-12-08 01:57:52 -0700646 test "$MAKEFLAGS" == "-j max" && export MAKEFLAGS="-j" && cpuconfig=" in parallel"
647 test "$1" == "1" && cpuconfig=" on 1 cpu"
Martin Roth02c93b92016-11-30 16:32:20 -0700648 expr "$1" : '-\?[0-9]\+$' > /dev/null && test "0$1" -gt 1 && cpuconfig=" on $1 cpus in parallel"
Patrick Georgi64d9a772012-05-01 15:14:46 +0200649 shift;;
Patrick Georgi55ea0132017-06-27 14:02:18 +0200650 # obsolete option
651 -s|--silent) shift;;
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200652 --scan-build) shift
Patrick Georgi64d9a772012-05-01 15:14:46 +0200653 scanbuild=true
654 customizing="${customizing}, scan-build"
Patrick Georgi64d9a772012-05-01 15:14:46 +0200655 ;;
656 -y|--ccache) shift
657 customizing="${customizing}, ccache"
658 configoptions="${configoptions}CONFIG_CCACHE=y\n"
659 ;;
Stefan Reinauercc44b062009-03-11 15:00:50 +0000660 -C|--config) shift; configureonly=1;;
Patrick Georgi64d9a772012-05-01 15:14:46 +0200661 -l|--loglevel) shift
662 customizing="${customizing}, loglevel $1"
Patrick Georgi64d9a772012-05-01 15:14:46 +0200663 configoptions="${configoptions}CONFIG_DEFAULT_CONSOLE_LOGLEVEL_$1=y\n"
664 configoptions="${configoptions}CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$1\n"
665 shift;;
666 -u|--update) shift
667 customizing="${customizing}, update"
668 configoptions="${configoptions}CONFIG_UPDATE_IMAGE=y\n"
669 ;;
670 -P|--prefix) shift
671 customizing="${customizing}, cbfs prefix $1"
672 configoptions="${configoptions}CONFIG_CBFS_PREFIX=\"$1\""
673 shift;;
674 -B|--blobs) shift
675 customizing="${customizing}, blobs"
676 configoptions="${configoptions}CONFIG_USE_BLOBS=y\n"
677 ;;
Damien Zammitb40c72a2017-09-02 15:02:04 +1000678 -A|--any-toolchain) shift
679 customizing="${customizing}, any-toolchain"
680 configoptions="${configoptions}CONFIG_ANY_TOOLCHAIN=y\n"
681 ;;
Patrick Georgie9fe6542014-05-14 13:43:58 +0200682 -L|--clang) shift
683 customizing="${customizing}, clang"
Patrick Georgi02ac6c32014-11-28 23:08:51 +0100684 configoptions="${configoptions}CONFIG_COMPILER_LLVM_CLANG=y\n# CONFIG_COMPILER_GCC is not set\n"
Patrick Georgie9fe6542014-05-14 13:43:58 +0200685 ;;
Patrick Georgib0bc63b2014-05-21 22:47:05 +0200686 -z|--clean) shift
687 customizing="${customizing}, clean"
688 clean_work=true
689 ;;
Patrick Georgiad273222014-05-21 23:00:32 +0200690 -o|--outdir) shift
691 TARGET=$1; shift
692 ;;
Patrick Georgidd787362015-04-22 18:38:10 +0200693 -x|--chromeos) shift
Patrick Georgif43b06d2015-07-31 16:26:19 +0200694 chromeos=true
Patrick Georgi58474df2015-07-31 16:30:04 +0200695 testclass=chromeos
Patrick Georgif43b06d2015-07-31 16:26:19 +0200696 customizing="${customizing}, chrome os"
Patrick Georgidd787362015-04-22 18:38:10 +0200697 configoptions="${configoptions}CONFIG_CHROMEOS=y\n"
698 ;;
Martin Roth21ca9be2015-10-13 12:27:56 -0600699 -X|--xmlfile) shift; XMLFILE=$1; REAL_XMLFILE=$1; shift;;
Martin Roth047c2f42016-12-14 10:16:26 -0700700 -I|--recursive) shift; recursive=true;;
Martin Roth10008102016-03-09 13:12:10 -0700701 -K|--kconfig) shift
Martin Roth02c93b92016-11-30 16:32:20 -0700702 testclass="$(basename "$1" | tr '.' '_' )"
Martin Roth10008102016-03-09 13:12:10 -0700703 customizing="${customizing}, $1 config"
704 configoptions="$(cat "$1")${configoptions}\n"
705 shift;;
Martin Rothc7e6ad72017-03-26 18:23:51 -0600706 --checksum) shift; checksum_file="$1"; shift;;
Martin Roth33314262017-03-27 23:45:31 -0600707 --timeless) shift; TIMELESS=1;;
Eric Biedermanc1492102004-11-05 08:50:54 +0000708 --) shift; break;;
Martin Roth9fdb41a2016-12-06 09:51:54 -0700709 -*) printf "Invalid option '%s'\n\n" "$1"; myhelp; exit 1;;
Eric Biedermanca883c92004-11-05 11:24:57 +0000710 *) break;;
Eric Biedermanc1492102004-11-05 08:50:54 +0000711 esac
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000712done
Martin Roth9fdb41a2016-12-06 09:51:54 -0700713if [ -n "$1" ]; then
714 printf "Invalid option '%s'\n\n" "$1"; myhelp; exit 1;
715fi
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000716
Martin Roth02c93b92016-11-30 16:32:20 -0700717if [ -z "$TARGET" ] || [ "$TARGET" = "/" ]; then
Patrick Georgiad273222014-05-21 23:00:32 +0200718 echo "Please specify a valid, non-root build directory."
719 exit 1
720fi
721
Martin Roth02c93b92016-11-30 16:32:20 -0700722customizing=$(echo "$customizing" | cut -c3-)
Patrick Georgi64d9a772012-05-01 15:14:46 +0200723if [ "$customizing" = "" ]; then
724 customizing="default configuration"
725fi
726
Martin Roth6d2cbb92017-07-19 19:33:34 -0600727FAILED_BOARDS="${COREBOOT_BUILD_DIR:-${TOP}/coreboot-builds}/failed_boards"
728PASSED_BOARDS="${COREBOOT_BUILD_DIR:-${TOP}/coreboot-builds}/passing_boards"
Martin Roth047c2f42016-12-14 10:16:26 -0700729
730if [ "$recursive" = "false" ]; then
Martin Rothd16022b2017-06-25 14:21:09 -0600731 rm -f "$FAILED_BOARDS" "$PASSED_BOARDS"
Martin Roth047c2f42016-12-14 10:16:26 -0700732fi
733
Patrick Georgi43105d62011-11-05 14:44:41 +0100734USE_XARGS=0
Patrick Georgif49f7c82011-11-05 12:55:18 +0100735if [ "$cpus" != "1" ]; then
Patrick Georgi58955512013-12-05 19:53:04 +0100736 # Limit to 32 parallel builds for now.
737 # Thrashing all caches because we run
738 # 160 abuilds in parallel is no fun.
739 if [ "$cpus" = "max" ]; then
740 cpus=32
741 fi
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100742 # Test if xargs supports the non-standard -P flag
743 # FIXME: disabled until we managed to eliminate all the make(1) quirks
744 echo | xargs -P ${cpus:-0} -n 1 echo 2>/dev/null >/dev/null && USE_XARGS=1
Patrick Georgi43105d62011-11-05 14:44:41 +0100745fi
746
747if [ "$USE_XARGS" = "0" ]; then
Raymond Danksc95da252012-05-30 16:03:48 -0600748test "$MAKEFLAGS" == "" && test "$cpus" != "" && export MAKEFLAGS="-j $cpus"
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100749build_targets()
Patrick Georgi43105d62011-11-05 14:44:41 +0100750{
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100751 local targets=${*-$(get_mainboards)}
752 for MAINBOARD in $targets; do
Martin Roth02c93b92016-11-30 16:32:20 -0700753 build_target "${MAINBOARD}"
Patrick Georgi43105d62011-11-05 14:44:41 +0100754 done
755}
756else
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100757build_targets()
Patrick Georgi43105d62011-11-05 14:44:41 +0100758{
Martin Roth02c93b92016-11-30 16:32:20 -0700759 local ABSPATH
760 local stime
761 local etime
Julius Werner893eda02017-03-20 15:33:23 -0700762 local num_targets
763 local cpus_per_target
Martin Roth02c93b92016-11-30 16:32:20 -0700764
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100765 local targets=${*-$(get_mainboards)}
Patrick Georgi43105d62011-11-05 14:44:41 +0100766 # seed shared utils
Martin Roth02c93b92016-11-30 16:32:20 -0700767 TMPCFG=$(mktemp)
768 printf "%s" "$configoptions" > "$TMPCFG"
769 $MAKE -j "$cpus" DOTCONFIG="$TMPCFG" obj="$TARGET/temp" objutil="$TARGET/sharedutils" allnoconfig
770 printf "%s" "$configoptions" >> "$TMPCFG"
771 yes "" 2>/dev/null | $MAKE -j "$cpus" DOTCONFIG="$TMPCFG" obj="$TARGET/temp" objutil="$TARGET/sharedutils" oldconfig 2>/dev/null |head > /dev/null
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200772 BUILDPREFIX=
773 if [ "$scanbuild" = "true" ]; then
774 scanbuild_out=$TARGET/sharedutils-scanbuild
Martin Roth02c93b92016-11-30 16:32:20 -0700775 rm -rf "${scanbuild_out}"
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200776 BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
777 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700778 mkdir -p "$TARGET/abuild"
779 ABSPATH="$(cd "$TARGET/abuild" && pwd)"
780 local XMLFILE="$ABSPATH/__util.xml"
781 rm -f "${XMLFILE}"
782 stime=$(perl -e 'print time();' 2>/dev/null || date +%s)
783 $BUILDPREFIX $MAKE -j "$cpus" DOTCONFIG="$TMPCFG" obj="$TARGET/temp" objutil="$TARGET/sharedutils" tools > "$TARGET/sharedutils/make.log" 2>&1
Patrick Georgi053322f2015-09-15 17:30:52 +0200784 local ret=$?
Martin Roth02c93b92016-11-30 16:32:20 -0700785 etime=$(perl -e 'print time();' 2>/dev/null || date +%s)
786 local duration=$(( etime - stime ))
Patrick Georgi053322f2015-09-15 17:30:52 +0200787
788 junit " <testcase classname='util' name='all' time='$duration' >"
789 if [ $ret -eq 0 ]; then
790 junit "<system-out>"
Martin Roth02c93b92016-11-30 16:32:20 -0700791 junitfile "$TARGET/sharedutils/make.log"
Patrick Georgi053322f2015-09-15 17:30:52 +0200792 junit "</system-out>"
793 junit "</testcase>"
794 else
795 junit "<failure type='BuildFailed'>"
Martin Roth02c93b92016-11-30 16:32:20 -0700796 junitfile "$TARGET/sharedutils/make.log"
Patrick Georgi053322f2015-09-15 17:30:52 +0200797 junit "</failure>"
798 junit "</testcase>"
Martin Roth6228b9e2017-07-16 17:02:47 -0700799 echo "Shared Utilities - Log: $TARGET/sharedutils/make.log" >> "$FAILED_BOARDS"
Patrick Georgi053322f2015-09-15 17:30:52 +0200800 return
801 fi
802
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200803 if [ "$scanbuild" = "true" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700804 mv "${scanbuild_out}tmp/"* "${scanbuild_out}"
805 rmdir "${scanbuild_out}tmp"
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200806 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700807 rm -rf "$TARGET/temp" "$TMPCFG"
Julius Werner893eda02017-03-20 15:33:23 -0700808 num_targets=$(wc -w <<<"$targets")
809 cpus_per_target=$(((${cpus:-1} + num_targets - 1) / num_targets))
810 echo "$targets" | xargs -P ${cpus:-0} -n 1 "$0" "${cmdline[@]}" -I -c "$cpus_per_target" -t
Patrick Georgi43105d62011-11-05 14:44:41 +0100811}
Patrick Georgif49f7c82011-11-05 12:55:18 +0100812fi
813
Stefan Reinauer68003b82010-01-30 10:44:28 +0000814debug "ROOT=$ROOT"
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000815
Patrick Georgi140a9902011-06-03 21:56:13 +0200816junit '<?xml version="1.0" encoding="utf-8"?>'
817junit '<testsuite>'
818
Stefan Reinauer3779f6a2004-11-05 00:26:31 +0000819if [ "$target" != "" ]; then
Eric Biederman709850a2004-11-05 10:48:04 +0000820 # build a single board
Martin Roth02c93b92016-11-30 16:32:20 -0700821 MAINBOARD=$(normalize_target "${target}")
Patrick Georgic2050f02015-10-31 00:35:44 +0100822 if [ -z "${MAINBOARD}" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700823 printf "No such target: %s\n" "$target"
Patrick Georgic2050f02015-10-31 00:35:44 +0100824 exit 1
825 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700826 build_srcdir="$(mainboard_directory "${MAINBOARD}")"
827 if [ "$(echo "${MAINBOARD}" | wc -w)" -gt 1 ]; then
828 build_targets "${MAINBOARD}"
829 elif [ ! -r "$ROOT/src/mainboard/${build_srcdir}" ]; then
830 echo "No such target: ${MAINBOARD}"
Patrick Georgic2050f02015-10-31 00:35:44 +0100831 exit 1
Patrick Georgi43105d62011-11-05 14:44:41 +0100832 else
Martin Roth02c93b92016-11-30 16:32:20 -0700833 build_target "${MAINBOARD}"
Patrick Georgia0e77382015-09-15 19:32:28 +0200834 test "$mode" != "text" && \
Martin Roth02c93b92016-11-30 16:32:20 -0700835 test -f "$TARGET/abuild/${MAINBOARD}.xml" && \
836 cat "$TARGET/abuild/${MAINBOARD}.xml" >> "$REAL_XMLFILE"
Patrick Georgi43105d62011-11-05 14:44:41 +0100837 XMLFILE=$REAL_XMLFILE
Stefan Reinauer002c9ff2010-03-29 16:23:42 +0000838 fi
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000839else
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100840 build_targets
Martin Roth02c93b92016-11-30 16:32:20 -0700841 rm -f "$REAL_XMLFILE"
842 XMLFILE="$REAL_XMLFILE"
Patrick Georgi43105d62011-11-05 14:44:41 +0100843 junit '<?xml version="1.0" encoding="utf-8"?>'
844 junit '<testsuite>'
Patrick Georgi3fd44c32011-11-07 19:01:54 +0100845 if [ "$mode" != "text" ]; then
Patrick Georgid03d69b2013-12-19 20:13:23 +0100846 for xmlfile in $TARGET/abuild/*_*.xml; do
Martin Roth02c93b92016-11-30 16:32:20 -0700847 cat "$xmlfile" >> "$REAL_XMLFILE"
Patrick Georgi3fd44c32011-11-07 19:01:54 +0100848 done
849 fi
Patrick Georgi3db85f32011-11-05 13:21:14 +0100850 XMLFILE=$REAL_XMLFILE
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000851fi
Patrick Georgi140a9902011-06-03 21:56:13 +0200852junit '</testsuite>'
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000853
Martin Roth047c2f42016-12-14 10:16:26 -0700854if [ "$recursive" = "false" ]; then
855
Martin Rothd16022b2017-06-25 14:21:09 -0600856 # Print the list of failed configurations
Martin Roth047c2f42016-12-14 10:16:26 -0700857 if [ -f "$FAILED_BOARDS" ]; then
Martin Rothd16022b2017-06-25 14:21:09 -0600858 printf "%s configuration(s) failed:\n" "$( wc -l < "$FAILED_BOARDS" )"
Martin Roth047c2f42016-12-14 10:16:26 -0700859 cat "$FAILED_BOARDS"
Martin Rothd16022b2017-06-25 14:21:09 -0600860 echo
Martin Rothba973bd2017-07-19 14:13:07 -0600861 if [ "$exitcode" != "0" ]; then
862 failed=1
863 fi
Martin Roth047c2f42016-12-14 10:16:26 -0700864 else
Martin Rothd16022b2017-06-25 14:21:09 -0600865 printf "All %s tested configurations passed.\n" "$( wc -l < "$PASSED_BOARDS" )"
Martin Roth047c2f42016-12-14 10:16:26 -0700866 fi
867fi
868
Patrick Georgif9d19f22011-06-01 19:29:48 +0000869exit $failed