blob: 9afd3644b737bb6272b6d388f72b0ebc26e9c5cd [file] [log] [blame]
Martin Rothb69ae972018-08-27 07:10:03 -06001#!/usr/bin/env bash
Stefan Reinauer9f12caa2004-10-19 07:00:47 +00002#
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 Roth5b7c6f52018-07-22 10:54:11 -0600169 # TODO: Change 'targets' variable to an array
Martin Roth02c93b92016-11-30 16:32:20 -0700170 local targets
Martin Roth5b7c6f52018-07-22 10:54:11 -0600171 local VARIANT_UC
Martin Roth02c93b92016-11-30 16:32:20 -0700172
Martin Roth5b7c6f52018-07-22 10:54:11 -0600173 VARIANT_UC=$(echo "${variant}" | tr '[:lower:]' '[:upper:]')
Furquan Shaikh57ccb9c2018-06-23 01:00:32 -0700174
Martin Roth02c93b92016-11-30 16:32:20 -0700175 targets=$(get_mainboards "$1")
Patrick Georgif6dc5442015-10-31 09:13:26 +0100176 if [ -n "$targets" ]; then
Martin Roth5b7c6f52018-07-22 10:54:11 -0600177 # shellcheck disable=SC2086
178 targets="$(grep "${VARIANT_UC}\$" <<< ${targets})"
Martin Roth02c93b92016-11-30 16:32:20 -0700179 echo "$targets"
Patrick Georgif6dc5442015-10-31 09:13:26 +0100180 return
Patrick Georgic2050f02015-10-31 00:35:44 +0100181 fi
Patrick Georgif6dc5442015-10-31 09:13:26 +0100182
Martin Roth02c93b92016-11-30 16:32:20 -0700183 targets=$(echo "$1" | tr ',' ' ')
Patrick Georgif6dc5442015-10-31 09:13:26 +0100184 for i in $targets; do
Martin Roth02c93b92016-11-30 16:32:20 -0700185 if [ -n "$(mainboard_directory "$i")" ]; then
186 echo "$i"
Patrick Georgif6dc5442015-10-31 09:13:26 +0100187 else
188 echo "$i is not a valid target" >&2
189 exit 1
190 fi
191 done
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000192}
193
Martin Roth02c93b92016-11-30 16:32:20 -0700194# shellcheck disable=SC2129
Stefan Reinauer68003b82010-01-30 10:44:28 +0000195function create_config
196{
Martin Roth26174c92016-11-23 18:47:53 -0700197 local BUILD_NAME=$1
198 local build_dir=$2
Martin Roth02c93b92016-11-30 16:32:20 -0700199 local board_srcdir
Stefan Reinauer68003b82010-01-30 10:44:28 +0000200
Martin Roth02c93b92016-11-30 16:32:20 -0700201 local config_file="${build_dir}/config.build"
202 board_srcdir="$(mainboard_directory "${BUILD_NAME}")"
Stefan Reinauer68003b82010-01-30 10:44:28 +0000203
Martin Roth02c93b92016-11-30 16:32:20 -0700204 mkdir -p "${build_dir}"
205 mkdir -p "$TARGET/sharedutils"
Stefan Reinauer68003b82010-01-30 10:44:28 +0000206
Martin Roth02c93b92016-11-30 16:32:20 -0700207 if [ "$quiet" == "false" ]; then echo " Creating config file for $BUILD_NAME..."; fi
208 echo "CONFIG_VENDOR_$(mainboard_vendor "${BUILD_NAME}")=y" > "${config_file}"
209 echo "CONFIG_BOARD_${BUILD_NAME}=y" >> "${config_file}"
210 grep "select[\t ]*ARCH" "${ROOT}/src/mainboard/${board_srcdir}/Kconfig" | \
211 sed "s,^.*\(ARCH_.*\)[^A-Z0-9_]*,CONFIG_\1=y," >> "${config_file}"
212 echo "CONFIG_MAINBOARD_DIR=\"${board_srcdir}\"" >> "${config_file}"
Stefan Reinauer68003b82010-01-30 10:44:28 +0000213
Martin Roth26174c92016-11-23 18:47:53 -0700214 update_config "$BUILD_NAME" "$build_dir" "$config_file"
Patrick Georgie6adabd2015-10-30 22:59:30 +0100215
Stefan Reinauer68003b82010-01-30 10:44:28 +0000216 ret=$?
Stefan Reinauer68003b82010-01-30 10:44:28 +0000217 if [ $ret -eq 0 ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700218 if [ "$quiet" == "false" ]; then echo " $BUILD_NAME config created."; fi
Stefan Reinauer68003b82010-01-30 10:44:28 +0000219 return 0
220 else
Stefan Reinauerabdf8482010-03-30 14:02:19 +0000221 # Does this ever happen?
Martin Roth02c93b92016-11-30 16:32:20 -0700222 if [ "$quiet" == "false" ]; then printf "%s config creation FAILED!\nLog excerpt:\n" "$BUILD_NAME"; fi
223 tail -n $CONTEXT "$build_dir/config.log" 2> /dev/null || tail -$CONTEXT "$build_dir/config.log"
Stefan Reinauer68003b82010-01-30 10:44:28 +0000224 return 1
225 fi
226}
227
Martin Roth26174c92016-11-23 18:47:53 -0700228function update_config
229{
230 local BUILD_NAME=$1
231 local build_dir=$2
232 local config_file=$3
233
Martin Roth02c93b92016-11-30 16:32:20 -0700234 local PAYLOAD
Martin Roth26174c92016-11-23 18:47:53 -0700235 local defconfig_file
236 defconfig_file=${build_dir}/config.$(echo "${BUILD_NAME}" | tr '[:upper:]' '[:lower:]').default
237
238 # get a working payload for the board if we have one.
239 # the --payload option expects a directory containing
240 # a shell script payload.sh
241 # Usage: payload.sh [BOARD]
242 # the script returns an absolute path to the payload binary.
243
244 if [ -f "$payloads/payload.sh" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700245 PAYLOAD=$(sh "$payloads/payload.sh" "$BUILD_NAME")
246 local PAYLOAD_OK=$?
247 if [ $PAYLOAD_OK -gt 0 ]; then
Martin Roth26174c92016-11-23 18:47:53 -0700248 echo "problem with payload"
249 exit 1
250 fi
251 if [ "$quiet" == "false" ]; then printf "Using payload %s\n" "$PAYLOAD"; fi
252 elif [ "$payloads" = "none" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700253 PAYLOAD=none
Martin Roth26174c92016-11-23 18:47:53 -0700254 fi
255
256 if [ "$PAYLOAD" = "none" ]; then
257 {
258 echo "CONFIG_PAYLOAD_NONE=y"
Martin Roth26174c92016-11-23 18:47:53 -0700259 echo "# CONFIG_PAYLOAD_ELF is not set"
Martin Roth26174c92016-11-23 18:47:53 -0700260 } >> "${config_file}"
261 elif [ "$PAYLOAD" != "/dev/null" ]; then
262 {
263 echo "# CONFIG_PAYLOAD_NONE is not set"
Martin Roth26174c92016-11-23 18:47:53 -0700264 echo "CONFIG_PAYLOAD_ELF=y"
265 echo "CONFIG_PAYLOAD_FILE=\"$PAYLOAD\""
266 } >> "${config_file}"
267 fi
Martin Roth735b9a02018-05-07 21:44:37 -0500268 # Disable all other payload config options
269 {
270 echo "# CONFIG_PAYLOAD_SEABIOS is not set"
271 echo "# CONFIG_PAYLOAD_BAYOU is not set"
272 echo "# CONFIG_PAYLOAD_FILO is not set"
273 echo "# CONFIG_PAYLOAD_GRUB2 is not set"
274 echo "# CONFIG_PAYLOAD_OPENBIOS is not set"
275 echo "# CONFIG_PAYLOAD_DEPTHCHARGE is not set"
Philipp Deppenwiese0f0e4e62018-06-19 20:22:32 +0200276 echo "# CONFIG_PAYLOAD_LINUXBOOT is not set"
Martin Roth735b9a02018-05-07 21:44:37 -0500277 echo "# CONFIG_PAYLOAD_UBOOT is not set"
278 echo "# CONFIG_PAYLOAD_TIANOCORE is not set"
279 echo "# CONFIG_PXE is not set"
280 echo "# CONFIG_BUILD_IPXE is not set"
281 echo "# CONFIG_MEMTEST_SECONDARY_PAYLOAD is not set"
282 echo "# CONFIG_COREINFO_SECONDARY_PAYLOAD is not set"
283 echo "# CONFIG_NVRAMCUI_SECONDARY_PAYLOAD is not set"
284 echo "# CONFIG_TINT_SECONDARY_PAYLOAD is not set"
285 } >> "${config_file}"
Martin Roth26174c92016-11-23 18:47:53 -0700286
287 if [ "$quiet" == "false" ]; then echo " $MAINBOARD ($customizing)"; fi
Martin Roth6bc44162016-12-13 15:29:30 -0700288 # shellcheck disable=SC2059
289 printf "$configoptions" >> "${config_file}"
Martin Roth26174c92016-11-23 18:47:53 -0700290
Patrick Georgi55ea0132017-06-27 14:02:18 +0200291 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 -0700292 CONFIG_OK=$?
293 if [ $CONFIG_OK -eq 0 ]; then
Patrick Georgi55ea0132017-06-27 14:02:18 +0200294 $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 -0700295 return $?
296 else
297 return 1
298 fi
299}
300
Martin Roth02c93b92016-11-30 16:32:20 -0700301# shellcheck disable=SC2129
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000302function create_buildenv
303{
Martin Roth26174c92016-11-23 18:47:53 -0700304 local BUILD_NAME=$1
305 local build_dir=$2
306 local config_file=$3
Stefan Reinauer0ed0b7c2010-03-30 15:49:14 +0000307
Martin Roth26174c92016-11-23 18:47:53 -0700308 if [ -z "$config_file" ]; then
309 create_config "$BUILD_NAME" "$build_dir"
310 else
311 local new_config_file="${build_dir}/config.build"
312 cp "$config_file" "$new_config_file"
313 update_config "$BUILD_NAME" "$build_dir" "$new_config_file"
314 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700315 local ret=$?
Stefan Reinauer86dbe152010-03-25 14:18:57 +0000316
317 # Allow simple "make" in the target directory
Martin Roth26174c92016-11-23 18:47:53 -0700318 local MAKEFILE=$TARGET/${BUILD_NAME}/Makefile
Martin Roth02c93b92016-11-30 16:32:20 -0700319 echo "# autogenerated" > "$MAKEFILE"
320 echo "TOP=$ROOT" >> "$MAKEFILE"
321 echo "BUILD=$TARGET" >> "$MAKEFILE"
322 echo "OBJ=\$(BUILD)/${MAINBOARD}" >> "$MAKEFILE"
323 echo "OBJUTIL=\$(BUILD)/sharedutils" >> "$MAKEFILE"
324 echo "all:" >> "$MAKEFILE"
325 echo " @cp -a config.h config.h.bak" >> "$MAKEFILE"
326 echo " @cd \$(TOP); \$(MAKE) oldconfig DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> "$MAKEFILE"
327 echo " @tail -n+6 config.h > config.new; tail -n+6 config.h.bak > config.old" >> "$MAKEFILE"
328 echo " @cmp -s config.new config.old && cp -a config.h.bak config.h || echo \"Config file changed\"" >> "$MAKEFILE"
329 echo " @rm config.h.bak config.new config.old" >> "$MAKEFILE"
330 echo " @cd \$(TOP); \$(MAKE) DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> "$MAKEFILE"
Stefan Reinauer0ed0b7c2010-03-30 15:49:14 +0000331
332 return $ret
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000333}
334
Martin Roth26174c92016-11-23 18:47:53 -0700335function check_config
336{
337 local BUILD_DIR="$1"
338 local TEST_TYPE="$2"
339 local TEST_STRING="$3"
340
341 local CONFIG_FILE="$BUILD_DIR/config.build"
342 local CONFIG_LOG="$BUILD_DIR/config.log"
343
344 if ! grep -q "$TEST_STRING" "$CONFIG_FILE"; then
345 echo "config file: $CONFIG_FILE has incorrect $TEST_TYPE"
346 echo "Error: Expected '$TEST_STRING' in config file." >> "$CONFIG_LOG"
347 return 1
348 fi
349
350 return 0
351}
352
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000353function compile_target
Stefan Reinauer14e22772010-04-27 06:56:47 +0000354{
Martin Roth26174c92016-11-23 18:47:53 -0700355 local BUILD_NAME=$1
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000356
Martin Roth02c93b92016-11-30 16:32:20 -0700357 if [ "$quiet" == "false" ]; then echo " Compiling $MAINBOARD image$cpuconfig..."; fi
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000358
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000359 CURR=$( pwd )
Stefan Reinauerabdf8482010-03-30 14:02:19 +0000360 #stime=`perl -e 'print time();' 2>/dev/null || date +%s`
Martin Roth5b7c6f52018-07-22 10:54:11 -0600361 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 -0700362 &> "${build_dir}/make.log" ; \
363 MAKE_FAILED=$?
Martin Roth5b7c6f52018-07-22 10:54:11 -0600364 cp "${ROOT}/.xcompile" "${build_dir}/xcompile.build"
Martin Roth02c93b92016-11-30 16:32:20 -0700365 cd "${build_dir}" || return $?
Stefan Reinauerabdf8482010-03-30 14:02:19 +0000366
Martin Roth02c93b92016-11-30 16:32:20 -0700367 etime=$(perl -e 'print time();' 2>/dev/null || date +%s)
368 duration=$(( etime - stime ))
Martin Roth26174c92016-11-23 18:47:53 -0700369 junit " <testcase classname='board${testclass/#/.}' name='$BUILD_NAME' time='$duration' >"
Stefan Reinauerabdf8482010-03-30 14:02:19 +0000370
Martin Roth02c93b92016-11-30 16:32:20 -0700371 if [ $MAKE_FAILED -eq 0 ]; then
Patrick Georgi140a9902011-06-03 21:56:13 +0200372 junit "<system-out>"
373 junitfile make.log
374 junit "</system-out>"
Stefan Reinauer3a140572006-10-25 19:02:34 +0000375 printf "ok\n" > compile.status
Martin Roth02c93b92016-11-30 16:32:20 -0700376 printf "%s built successfully. (took %ss)\n" "$BUILD_NAME" "${duration}"
Martin Rothd16022b2017-06-25 14:21:09 -0600377 echo "$BUILD_NAME" >> "$PASSED_BOARDS"
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000378 else
Patrick Georgi140a9902011-06-03 21:56:13 +0200379 junit "<failure type='BuildFailed'>"
380 junitfile make.log
381 junit "</failure>"
Patrick Georgi8bf5c152015-04-22 18:24:01 +0200382 printf "failed\n" > compile.status
Martin Roth02c93b92016-11-30 16:32:20 -0700383 printf "%s build FAILED after %ss!\nLog excerpt:\n" "$BUILD_NAME" "${duration}"
Patrick Georgia84a99b2009-05-26 14:03:51 +0000384 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
Martin Roth7a985912018-07-22 10:31:19 -0600385 if [ "$clean_work" = "true" ]; then
386 echo "$BUILD_NAME" >> "$FAILED_BOARDS"
387 else
388 echo "$BUILD_NAME - Log: ${build_dir}/make.log" >> "$FAILED_BOARDS"
389 fi
Patrick Georgif9d19f22011-06-01 19:29:48 +0000390 failed=1
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000391 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700392 cd "$CURR" || return $?
Martin Rothc7e6ad72017-03-26 18:23:51 -0600393 if [ -n "$checksum_file" ]; then
394 sha256sum "${build_dir}/coreboot.rom" >> "${checksum_file}_platform"
395 sort "${build_dir}/config.h" | grep CONFIG_ > "${build_dir}/config.h.sorted"
396 sha256sum "${build_dir}/config.h.sorted" >> "${checksum_file}_config"
397 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700398 if [ "$clean_work" = "true" ]; then
399 rm -rf "${build_dir}"
Patrick Georgib0bc63b2014-05-21 22:47:05 +0200400 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700401 return $MAKE_FAILED
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000402}
403
Martin Roth26174c92016-11-23 18:47:53 -0700404function build_config
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000405{
Patrick Georgic2050f02015-10-31 00:35:44 +0100406 local MAINBOARD=$1
Martin Roth26174c92016-11-23 18:47:53 -0700407 local build_dir=$2
408 local BUILD_NAME=$3
409 local config_file=$4
Martin Roth02c93b92016-11-30 16:32:20 -0700410 local board_srcdir
411 local ret
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000412
Martin Roth02c93b92016-11-30 16:32:20 -0700413 board_srcdir=$(mainboard_directory "${MAINBOARD}")
Martin Roth26174c92016-11-23 18:47:53 -0700414
Martin Roth02c93b92016-11-30 16:32:20 -0700415 if [ "$(cat "${build_dir}/compile.status" 2>/dev/null)" = "ok" ] && \
416 [ "$buildall" = "false" ]; then
Martin Roth26174c92016-11-23 18:47:53 -0700417 echo "Skipping $BUILD_NAME; (already successful)"
Patrick Georgi1a5301d2012-11-22 14:19:43 +0100418 return
419 fi
420
Paul Menzeld2bbaff2016-12-09 08:47:45 +0100421 export HOSTCC='gcc'
Eric Biederman709850a2004-11-05 10:48:04 +0000422
Martin Roth26174c92016-11-23 18:47:53 -0700423 if [ "$chromeos" = true ] && [ "$(grep -c "^[[:space:]]*select[[:space:]]*MAINBOARD_HAS_CHROMEOS\>" "${ROOT}/src/mainboard/${board_srcdir}/Kconfig")" -eq 0 ]; then
424 echo "${BUILD_NAME} doesn't support Chrome OS, skipping."
Patrick Georgif43b06d2015-07-31 16:26:19 +0200425 return
426 fi
427
Martin Roth26174c92016-11-23 18:47:53 -0700428 if [ -f "src/mainboard/${board_srcdir}/abuild.disabled" ]; then
429 echo "${BUILD_NAME} disabled:"
430 cat "src/mainboard/${board_srcdir}/abuild.disabled"
Patrick Georgi3ac3c4eb2015-07-14 20:20:13 +0200431 return
432 fi
433
Martin Roth26174c92016-11-23 18:47:53 -0700434 if [ "$quiet" == "false" ]; then echo "Building $BUILD_NAME"; fi
435 mkdir -p "$TARGET/${BUILD_NAME}" "$TARGET/abuild"
Martin Roth02c93b92016-11-30 16:32:20 -0700436 ABSPATH="$(cd "$TARGET/abuild" && pwd)"
Martin Roth26174c92016-11-23 18:47:53 -0700437 XMLFILE="$ABSPATH/${BUILD_NAME}.xml"
438 rm -f "${XMLFILE}"
439
440 stime=$(perl -e 'print time();' 2>/dev/null || date +%s)
441 create_buildenv "$BUILD_NAME" "$build_dir" "$config_file"
442 local BUILDENV_CREATED=$?
443
444 check_config "$build_dir" "mainboard" "CONFIG_BOARD_${MAINBOARD}=y"
445 local MAINBOARD_OK=$?
446
447 check_config "$build_dir" "vendor" "CONFIG_VENDOR_$(mainboard_vendor "${MAINBOARD}")=y"
448 local VENDOR_OK=$?
449
450 if [ $BUILDENV_CREATED -ne 0 ] || [ $MAINBOARD_OK -ne 0 ] || [ $VENDOR_OK -ne 0 ]; then
Martin Roth16c49b52017-05-23 22:06:30 -0600451 junit " <testcase classname='board${testclass/#/.}' name='$BUILD_NAME' >"
Martin Roth26174c92016-11-23 18:47:53 -0700452
453 junit "<failure type='BuildFailed'>"
454 junitfile "$build_dir/config.log"
455 junit "</failure>"
456 printf "failed\n" > compile.status
Martin Roth02c93b92016-11-30 16:32:20 -0700457 printf "%s build configuration FAILED!\nLog excerpt:\n" "$BUILD_NAME"
Martin Roth26174c92016-11-23 18:47:53 -0700458 tail -n $CONTEXT "$build_dir/config.log" 2> /dev/null || tail -$CONTEXT "$build_dir/config.log"
459
460 junit "</testcase>"
Martin Rothd16022b2017-06-25 14:21:09 -0600461 echo "$BUILD_NAME - Log: ${TOP}/$build_dir/config.log" >> "$FAILED_BOARDS"
Martin Roth26174c92016-11-23 18:47:53 -0700462 return
463 fi
Stefan Reinauer192b7bc2006-05-27 00:22:02 +0000464
Martin Roth5b7c6f52018-07-22 10:54:11 -0600465 required_arches=$(grep -E "^CONFIG_ARCH_(BOOTBLOCK|R.MSTAGE|VERSTAGE)" "$TARGET/${BUILD_NAME}/config.build" | \
Martin Roth02c93b92016-11-30 16:32:20 -0700466 sed "s,^CONFIG_ARCH_[^_]*_\([^=]*\)=.*$,\1," |sort -u |tr 'A-Z\n\r' 'a-z ')
467 # shellcheck disable=SC2016,SC2059
Arthur Heymans4dfb5f12018-06-13 22:30:10 +0200468 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 +0200469 if [ -n "$missing_arches" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700470 printf "skipping %s because we're missing compilers for (%s)\n" "$BUILD_NAME" "$missing_arches"
Patrick Georgi02802df2014-10-18 11:57:11 +0200471 return
472 fi
473
Martin Roth02c93b92016-11-30 16:32:20 -0700474 if [ $BUILDENV_CREATED -eq 0 ] && [ $configureonly -eq 0 ]; then
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200475 BUILDPREFIX=
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000476 if [ "$scanbuild" = "true" ]; then
Martin Roth26174c92016-11-23 18:47:53 -0700477 scanbuild_out=$TARGET/${BUILD_NAME}-scanbuild
Martin Roth02c93b92016-11-30 16:32:20 -0700478 rm -rf "${scanbuild_out}"
Martin Roth21e09b12018-07-22 10:11:26 -0600479 BUILDPREFIX="scan-build ${SCANBUILD_ARGS} -o ${scanbuild_out}tmp"
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000480 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700481 compile_target "${BUILD_NAME}"
Patrick Georgid2296772009-03-11 15:43:02 +0000482 if [ "$scanbuild" = "true" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700483 mv "${scanbuild_out}"tmp/* "${scanbuild_out}"
484 rmdir "${scanbuild_out}tmp"
Patrick Georgid2296772009-03-11 15:43:02 +0000485 fi
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000486 fi
Stefan Reinauer2f285ae2004-11-05 14:06:24 +0000487
Patrick Georgi140a9902011-06-03 21:56:13 +0200488 junit "</testcase>"
Stefan Reinauer3a140572006-10-25 19:02:34 +0000489}
490
Martin Roth26174c92016-11-23 18:47:53 -0700491# One target may build several configs
492function build_target
493{
494 local MAINBOARD=$1
Martin Roth02c93b92016-11-30 16:32:20 -0700495 local MAINBOARD_LC
496 MAINBOARD_LC=$(echo "$MAINBOARD" | tr '[:upper:]' '[:lower:]')
Martin Roth26174c92016-11-23 18:47:53 -0700497
498 # look for config files in the config directory that match the boardname
499 if [ -n "$( find "$configdir" -maxdepth 1 -name "config.${MAINBOARD_LC}*" -print -quit )" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700500 for config in "$configdir/config.${MAINBOARD_LC}"*; do
Martin Roth26174c92016-11-23 18:47:53 -0700501 BUILD_NAME="${config##*/}"
502 BUILD_NAME="${BUILD_NAME##config.}"
503 BUILD_NAME=$(echo "${BUILD_NAME}" | tr '[:lower:]' '[:upper:]')
504 echo "Building config $BUILD_NAME"
505 build_dir=$TARGET/${BUILD_NAME}
506 build_config "$MAINBOARD" "$build_dir" "$BUILD_NAME" "$config"
507 remove_target "$BUILD_NAME"
508
509 done
510 else
511 echo "Building board $MAINBOARD (using default config)"
512 build_dir=$TARGET/${MAINBOARD}
513
514 build_config "$MAINBOARD" "$build_dir" "$MAINBOARD"
515 remove_target "$MAINBOARD"
516 fi
517
518}
519
Uwe Hermann4e006402009-04-15 16:07:27 +0000520function remove_target
521{
522 if [ "$remove" != "true" ]; then
Martin Roth26174c92016-11-23 18:47:53 -0700523 return
Uwe Hermann4e006402009-04-15 16:07:27 +0000524 fi
525
Martin Roth26174c92016-11-23 18:47:53 -0700526 local BUILD_NAME=$1
Uwe Hermann4e006402009-04-15 16:07:27 +0000527
528 # Save the generated coreboot.rom file of each board.
Martin Roth26174c92016-11-23 18:47:53 -0700529 if [ -r "$TARGET/${BUILD_NAME}/coreboot.rom" ]; then
530 cp "$TARGET/${BUILD_NAME}/coreboot.rom" \
531 "${BUILD_NAME}_coreboot.rom"
Uwe Hermann4e006402009-04-15 16:07:27 +0000532 fi
533
Martin Roth26174c92016-11-23 18:47:53 -0700534 echo "Removing build dir for $BUILD_NAME..."
Martin Roth02c93b92016-11-30 16:32:20 -0700535 rm -rf "${TARGET:?}/${BUILD_NAME}"
Uwe Hermann4e006402009-04-15 16:07:27 +0000536
Martin Roth26174c92016-11-23 18:47:53 -0700537 return
Uwe Hermann4e006402009-04-15 16:07:27 +0000538}
539
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000540function myhelp
541{
Patrick Georgi86980bb2015-07-31 16:14:43 +0200542cat << __END_OF_HELP
Martin Roth5b0d2db2016-12-06 09:18:36 -0700543Usage: $0 [options]
Patrick Georgi86980bb2015-07-31 16:14:43 +0200544 $0 [-V|--version]
545 $0 [-h|--help]
Stefan Reinauerca631202006-11-10 13:30:28 +0000546
Patrick Georgi86980bb2015-07-31 16:14:43 +0200547Options:\n"
Martin Rothb06bfa42016-12-05 09:15:33 -0700548 [-a|--all] Build previously succeeded ports as well
Damien Zammitb40c72a2017-09-02 15:02:04 +1000549 [-A|--any-toolchain] Use any toolchain
Furquan Shaikh57ccb9c2018-06-23 01:00:32 -0700550 [-b|--board-variant <name>] Build specific board variant under the
551 given target.
Patrick Georgi86980bb2015-07-31 16:14:43 +0200552 [-B|--blobs] Allow using binary files
Martin Rothc7e6ad72017-03-26 18:23:51 -0600553 [--checksum <path/basefile>] Store checksums at path/basefile
Martin Rothb06bfa42016-12-05 09:15:33 -0700554 [-c|--cpus <numcpus>] Build on <numcpus> at the same time
555 [-C|--config] Configure-only mode
556 [-d|--dir <dir>] Directory containing config files
Martin Rothba973bd2017-07-19 14:13:07 -0600557 [-e|--exitcode] Exit with a non-zero errorlevel on failure
Martin Rothb06bfa42016-12-05 09:15:33 -0700558 [-J|--junit] Write JUnit formatted xml log file
559 [-K|--kconfig <name>] Prepend file to generated Kconfig
560 [-l|--loglevel <num>] Set loglevel
Patrick Georgi86980bb2015-07-31 16:14:43 +0200561 [-L|--clang] Use clang
Martin Rothb06bfa42016-12-05 09:15:33 -0700562 [-o|--outdir <path>] Store build results in path
563 (defaults to $TARGET)
564 [-p|--payloads <dir>] Use payloads in <dir> to build images
565 [-P|--prefix <name>] File name prefix in CBFS
566 [-q|--quiet] Print fewer messages
567 [-r|--remove] Remove output dir after build
Martin Roth5b0d2db2016-12-06 09:18:36 -0700568 [-R|--root <path>] Absolute path to coreboot sources
569 (defaults to $ROOT)
Martin Rothb06bfa42016-12-05 09:15:33 -0700570 [--scan-build] Use clang's static analyzer
Martin Roth33314262017-03-27 23:45:31 -0600571 [--timeless] Generate timeless builds
Martin Rothb06bfa42016-12-05 09:15:33 -0700572 [-t|--target <vendor/board>] Attempt to build target vendor/board only
573 [-T|--test] Submit image(s) to automated test system
574 [-u|--update] Update existing image
575 [-v|--verbose] Print more messages
Patrick Georgi86980bb2015-07-31 16:14:43 +0200576 [-x|--chromeos] Build with CHROMEOS enabled
Patrick Georgif43b06d2015-07-31 16:26:19 +0200577 Skip boards without Chrome OS support
Martin Rothb06bfa42016-12-05 09:15:33 -0700578 [-X|--xmlfile <name>] Set JUnit XML log file filename
579 (defaults to $XMLFILE)
580 [-y|--ccache] Use ccache
581 [-z|--clean] Remove build results when finished
582
Martin Rothb06bfa42016-12-05 09:15:33 -0700583 [-V|--version] Print version number and exit
584 [-h|--help] Print this help and exit
Patrick Georgi86980bb2015-07-31 16:14:43 +0200585
Patrick Georgi55ea0132017-06-27 14:02:18 +0200586 [-s|--silent] obsolete
Patrick Georgi86980bb2015-07-31 16:14:43 +0200587__END_OF_HELP
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000588}
589
Stefan Reinauer14e22772010-04-27 06:56:47 +0000590function myversion
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000591{
592 cat << EOF
593
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000594coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000595
Stefan Reinauer192b7bc2006-05-27 00:22:02 +0000596Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
Stefan Reinauer68003b82010-01-30 10:44:28 +0000597Copyright (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
Stefan Reinauer3a140572006-10-25 19:02:34 +0000598
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000599This program is free software; you may redistribute it under the terms
600of the GNU General Public License. This program has absolutely no
601warranty.
602
603EOF
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000604}
605
606# default options
607target=""
608buildall=false
Stefan Reinauer173f13b2004-11-05 11:57:00 +0000609verbose=false
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000610
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +0000611test -f util/sconfig/sconfig.l && ROOT=$( pwd )
Martin Roth02c93b92016-11-30 16:32:20 -0700612test -f ../util/sconfig/sconfig.l && ROOT=$( cd .. && pwd )
613test "$ROOT" = "" && ROOT=$( cd ../.. && pwd )
Stefan Reinauer0d4a08e2009-07-01 12:26:11 +0000614
Patrick Georgi92cfe182012-04-05 11:17:01 +0200615# Look if we have getopt. If not, build it.
616export PATH=$PATH:util/abuild
617getopt - > /dev/null 2>/dev/null || gcc -o util/abuild/getopt util/abuild/getopt.c
618
Julius Werner893eda02017-03-20 15:33:23 -0700619# Save command line for xargs parallelization.
620cmdline=("$@")
Patrick Georgi43105d62011-11-05 14:44:41 +0100621
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000622# parse parameters.. try to find out whether we're running GNU getopt
Martin Roth02c93b92016-11-30 16:32:20 -0700623getoptbrand="$(getopt -V)"
624
625# shellcheck disable=SC2086
Stefan Reinauer39d4e5f2008-05-28 08:40:23 +0000626if [ "${getoptbrand:0:6}" == "getopt" ]; then
627 # Detected GNU getopt that supports long options.
Furquan Shaikh57ccb9c2018-06-23 01:00:32 -0700628 args=$(getopt -l version,verbose,quiet,help,all,target:,board-variant:,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:b:p:c:sJCl:rP:uyBLAzo:xX:K:d:R:Ie -- "$@") || exit 1
Warren Turkal0e8f2042010-09-27 21:14:19 +0000629 eval set -- $args
Martin Roth02c93b92016-11-30 16:32:20 -0700630 retval=$?
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000631else
632 # Detected non-GNU getopt
Furquan Shaikh57ccb9c2018-06-23 01:00:32 -0700633 args=$(getopt Vvqhat:b:p:c:sJCl:rP:uyBLAzo:xX:K:d:R:Ie "$@")
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000634 set -- $args
Martin Roth02c93b92016-11-30 16:32:20 -0700635 retval=$?
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000636fi
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000637
Martin Roth02c93b92016-11-30 16:32:20 -0700638if [ $retval != 0 ]; then
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000639 myhelp
640 exit 1
641fi
642
Patrick Georgif43b06d2015-07-31 16:26:19 +0200643chromeos=false
Patrick Georgib0bc63b2014-05-21 22:47:05 +0200644clean_work=false
Patrick Georgi55ea0132017-06-27 14:02:18 +0200645verboseopt='V=0'
Patrick Georgi64d9a772012-05-01 15:14:46 +0200646customizing=""
647configoptions=""
Patrick Georgi098c4a82015-09-15 16:57:04 +0200648# testclass needs to be undefined if not used for variable expansion to work
649unset testclass
Eric Biedermanc1492102004-11-05 08:50:54 +0000650while true ; do
Eric Biedermanca883c92004-11-05 11:24:57 +0000651 case "$1" in
Martin Roth02c93b92016-11-30 16:32:20 -0700652 -J|--junit) shift; mode=junit; rm -f "$XMLFILE" ;;
Stefan Reinauer2f285ae2004-11-05 14:06:24 +0000653 -t|--target) shift; target="$1"; shift;;
Furquan Shaikh57ccb9c2018-06-23 01:00:32 -0700654 -b|--board-variant) shift; variant="$1"; shift;;
Eric Biedermanc1492102004-11-05 08:50:54 +0000655 -a|--all) shift; buildall=true;;
Martin Roth26174c92016-11-23 18:47:53 -0700656 -d|--dir) shift; configdir="$1"; shift;;
Martin Rothba973bd2017-07-19 14:13:07 -0600657 -e|--exitcode) shift; exitcode=1;;
Warren Turkal0e8f2042010-09-27 21:14:19 +0000658 -r|--remove) shift; remove=true;;
Patrick Georgi55ea0132017-06-27 14:02:18 +0200659 -v|--verbose) shift; verbose=true; verboseopt='V=1';;
Martin Rothddb7a9d2014-12-08 01:57:52 -0700660 -q|--quiet) shift; quiet=true;;
Stefan Reinauerd4c68462004-11-05 11:47:41 +0000661 -V|--version) shift; myversion; exit 0;;
Stefan Reinauer3a140572006-10-25 19:02:34 +0000662 -h|--help) shift; myversion; myhelp; exit 0;;
Stefan Reinauer7fe2b7c2006-09-15 17:00:11 +0000663 -p|--payloads) shift; payloads="$1"; shift;;
Arthur Heymans4dfb5f12018-06-13 22:30:10 +0200664 -R|--root) shift; ROOT="$1"; MAKE="$MAKE -C $1"; shift;;
Patrick Georgi64d9a772012-05-01 15:14:46 +0200665 -c|--cpus) shift
666 export MAKEFLAGS="-j $1"
Patrick Georgi58955512013-12-05 19:53:04 +0100667 cpus=$1
Martin Rothddb7a9d2014-12-08 01:57:52 -0700668 test "$MAKEFLAGS" == "-j max" && export MAKEFLAGS="-j" && cpuconfig=" in parallel"
669 test "$1" == "1" && cpuconfig=" on 1 cpu"
Martin Roth02c93b92016-11-30 16:32:20 -0700670 expr "$1" : '-\?[0-9]\+$' > /dev/null && test "0$1" -gt 1 && cpuconfig=" on $1 cpus in parallel"
Patrick Georgi64d9a772012-05-01 15:14:46 +0200671 shift;;
Patrick Georgi55ea0132017-06-27 14:02:18 +0200672 # obsolete option
673 -s|--silent) shift;;
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200674 --scan-build) shift
Patrick Georgi64d9a772012-05-01 15:14:46 +0200675 scanbuild=true
676 customizing="${customizing}, scan-build"
Martin Roth21e09b12018-07-22 10:11:26 -0600677 SCANBUILD_ARGS=${SCANBUILD_ARGS:-'-k'}
Patrick Georgi64d9a772012-05-01 15:14:46 +0200678 ;;
679 -y|--ccache) shift
680 customizing="${customizing}, ccache"
681 configoptions="${configoptions}CONFIG_CCACHE=y\n"
682 ;;
Stefan Reinauercc44b062009-03-11 15:00:50 +0000683 -C|--config) shift; configureonly=1;;
Patrick Georgi64d9a772012-05-01 15:14:46 +0200684 -l|--loglevel) shift
685 customizing="${customizing}, loglevel $1"
Patrick Georgi64d9a772012-05-01 15:14:46 +0200686 configoptions="${configoptions}CONFIG_DEFAULT_CONSOLE_LOGLEVEL_$1=y\n"
687 configoptions="${configoptions}CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$1\n"
688 shift;;
689 -u|--update) shift
690 customizing="${customizing}, update"
691 configoptions="${configoptions}CONFIG_UPDATE_IMAGE=y\n"
692 ;;
693 -P|--prefix) shift
694 customizing="${customizing}, cbfs prefix $1"
695 configoptions="${configoptions}CONFIG_CBFS_PREFIX=\"$1\""
696 shift;;
697 -B|--blobs) shift
698 customizing="${customizing}, blobs"
Patrick Georgic366f902018-09-27 21:24:44 +0200699 configoptions="${configoptions}CONFIG_USE_BLOBS=y\nCONFIG_ADD_FSP_BINARIES=y\nCONFIG_FSP_USE_REPO=y\n"
Patrick Georgi64d9a772012-05-01 15:14:46 +0200700 ;;
Damien Zammitb40c72a2017-09-02 15:02:04 +1000701 -A|--any-toolchain) shift
702 customizing="${customizing}, any-toolchain"
703 configoptions="${configoptions}CONFIG_ANY_TOOLCHAIN=y\n"
704 ;;
Patrick Georgie9fe6542014-05-14 13:43:58 +0200705 -L|--clang) shift
706 customizing="${customizing}, clang"
Patrick Georgi02ac6c32014-11-28 23:08:51 +0100707 configoptions="${configoptions}CONFIG_COMPILER_LLVM_CLANG=y\n# CONFIG_COMPILER_GCC is not set\n"
Patrick Georgie9fe6542014-05-14 13:43:58 +0200708 ;;
Patrick Georgib0bc63b2014-05-21 22:47:05 +0200709 -z|--clean) shift
710 customizing="${customizing}, clean"
711 clean_work=true
712 ;;
Patrick Georgiad273222014-05-21 23:00:32 +0200713 -o|--outdir) shift
714 TARGET=$1; shift
715 ;;
Patrick Georgidd787362015-04-22 18:38:10 +0200716 -x|--chromeos) shift
Patrick Georgif43b06d2015-07-31 16:26:19 +0200717 chromeos=true
Patrick Georgi58474df2015-07-31 16:30:04 +0200718 testclass=chromeos
Patrick Georgif43b06d2015-07-31 16:26:19 +0200719 customizing="${customizing}, chrome os"
Patrick Georgidd787362015-04-22 18:38:10 +0200720 configoptions="${configoptions}CONFIG_CHROMEOS=y\n"
721 ;;
Martin Roth21ca9be2015-10-13 12:27:56 -0600722 -X|--xmlfile) shift; XMLFILE=$1; REAL_XMLFILE=$1; shift;;
Martin Roth047c2f42016-12-14 10:16:26 -0700723 -I|--recursive) shift; recursive=true;;
Martin Roth10008102016-03-09 13:12:10 -0700724 -K|--kconfig) shift
Martin Roth02c93b92016-11-30 16:32:20 -0700725 testclass="$(basename "$1" | tr '.' '_' )"
Martin Roth10008102016-03-09 13:12:10 -0700726 customizing="${customizing}, $1 config"
727 configoptions="$(cat "$1")${configoptions}\n"
728 shift;;
Martin Rothc7e6ad72017-03-26 18:23:51 -0600729 --checksum) shift; checksum_file="$1"; shift;;
Martin Roth33314262017-03-27 23:45:31 -0600730 --timeless) shift; TIMELESS=1;;
Eric Biedermanc1492102004-11-05 08:50:54 +0000731 --) shift; break;;
Martin Roth9fdb41a2016-12-06 09:51:54 -0700732 -*) printf "Invalid option '%s'\n\n" "$1"; myhelp; exit 1;;
Eric Biedermanca883c92004-11-05 11:24:57 +0000733 *) break;;
Eric Biedermanc1492102004-11-05 08:50:54 +0000734 esac
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000735done
Martin Roth9fdb41a2016-12-06 09:51:54 -0700736if [ -n "$1" ]; then
737 printf "Invalid option '%s'\n\n" "$1"; myhelp; exit 1;
738fi
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000739
Martin Roth02c93b92016-11-30 16:32:20 -0700740if [ -z "$TARGET" ] || [ "$TARGET" = "/" ]; then
Patrick Georgiad273222014-05-21 23:00:32 +0200741 echo "Please specify a valid, non-root build directory."
742 exit 1
743fi
744
Martin Roth02c93b92016-11-30 16:32:20 -0700745customizing=$(echo "$customizing" | cut -c3-)
Patrick Georgi64d9a772012-05-01 15:14:46 +0200746if [ "$customizing" = "" ]; then
747 customizing="default configuration"
748fi
749
Martin Roth7a985912018-07-22 10:31:19 -0600750FAILED_BOARDS="${TARGET}/failed_boards"
751PASSED_BOARDS="${TARGET}/passing_boards"
Martin Roth047c2f42016-12-14 10:16:26 -0700752
753if [ "$recursive" = "false" ]; then
Martin Rothd16022b2017-06-25 14:21:09 -0600754 rm -f "$FAILED_BOARDS" "$PASSED_BOARDS"
Martin Roth047c2f42016-12-14 10:16:26 -0700755fi
756
Patrick Georgi43105d62011-11-05 14:44:41 +0100757USE_XARGS=0
Patrick Georgif49f7c82011-11-05 12:55:18 +0100758if [ "$cpus" != "1" ]; then
Patrick Georgi58955512013-12-05 19:53:04 +0100759 # Limit to 32 parallel builds for now.
760 # Thrashing all caches because we run
761 # 160 abuilds in parallel is no fun.
762 if [ "$cpus" = "max" ]; then
763 cpus=32
764 fi
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100765 # Test if xargs supports the non-standard -P flag
766 # FIXME: disabled until we managed to eliminate all the make(1) quirks
767 echo | xargs -P ${cpus:-0} -n 1 echo 2>/dev/null >/dev/null && USE_XARGS=1
Patrick Georgi43105d62011-11-05 14:44:41 +0100768fi
769
770if [ "$USE_XARGS" = "0" ]; then
Raymond Danksc95da252012-05-30 16:03:48 -0600771test "$MAKEFLAGS" == "" && test "$cpus" != "" && export MAKEFLAGS="-j $cpus"
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100772build_targets()
Patrick Georgi43105d62011-11-05 14:44:41 +0100773{
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100774 local targets=${*-$(get_mainboards)}
775 for MAINBOARD in $targets; do
Martin Roth02c93b92016-11-30 16:32:20 -0700776 build_target "${MAINBOARD}"
Patrick Georgi43105d62011-11-05 14:44:41 +0100777 done
778}
779else
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100780build_targets()
Patrick Georgi43105d62011-11-05 14:44:41 +0100781{
Martin Roth02c93b92016-11-30 16:32:20 -0700782 local ABSPATH
783 local stime
784 local etime
Julius Werner893eda02017-03-20 15:33:23 -0700785 local num_targets
786 local cpus_per_target
Martin Roth02c93b92016-11-30 16:32:20 -0700787
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100788 local targets=${*-$(get_mainboards)}
Patrick Georgi43105d62011-11-05 14:44:41 +0100789 # seed shared utils
Martin Roth02c93b92016-11-30 16:32:20 -0700790 TMPCFG=$(mktemp)
791 printf "%s" "$configoptions" > "$TMPCFG"
792 $MAKE -j "$cpus" DOTCONFIG="$TMPCFG" obj="$TARGET/temp" objutil="$TARGET/sharedutils" allnoconfig
793 printf "%s" "$configoptions" >> "$TMPCFG"
794 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 +0200795 BUILDPREFIX=
796 if [ "$scanbuild" = "true" ]; then
797 scanbuild_out=$TARGET/sharedutils-scanbuild
Martin Roth02c93b92016-11-30 16:32:20 -0700798 rm -rf "${scanbuild_out}"
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200799 BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
800 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700801 mkdir -p "$TARGET/abuild"
802 ABSPATH="$(cd "$TARGET/abuild" && pwd)"
803 local XMLFILE="$ABSPATH/__util.xml"
804 rm -f "${XMLFILE}"
805 stime=$(perl -e 'print time();' 2>/dev/null || date +%s)
Martin Roth5b7c6f52018-07-22 10:54:11 -0600806 $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 +0200807 local ret=$?
Martin Roth02c93b92016-11-30 16:32:20 -0700808 etime=$(perl -e 'print time();' 2>/dev/null || date +%s)
809 local duration=$(( etime - stime ))
Patrick Georgi053322f2015-09-15 17:30:52 +0200810
811 junit " <testcase classname='util' name='all' time='$duration' >"
812 if [ $ret -eq 0 ]; then
813 junit "<system-out>"
Martin Roth02c93b92016-11-30 16:32:20 -0700814 junitfile "$TARGET/sharedutils/make.log"
Patrick Georgi053322f2015-09-15 17:30:52 +0200815 junit "</system-out>"
816 junit "</testcase>"
817 else
818 junit "<failure type='BuildFailed'>"
Martin Roth02c93b92016-11-30 16:32:20 -0700819 junitfile "$TARGET/sharedutils/make.log"
Patrick Georgi053322f2015-09-15 17:30:52 +0200820 junit "</failure>"
821 junit "</testcase>"
Martin Roth6228b9e2017-07-16 17:02:47 -0700822 echo "Shared Utilities - Log: $TARGET/sharedutils/make.log" >> "$FAILED_BOARDS"
Patrick Georgi053322f2015-09-15 17:30:52 +0200823 return
824 fi
825
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200826 if [ "$scanbuild" = "true" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700827 mv "${scanbuild_out}tmp/"* "${scanbuild_out}"
828 rmdir "${scanbuild_out}tmp"
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200829 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700830 rm -rf "$TARGET/temp" "$TMPCFG"
Julius Werner893eda02017-03-20 15:33:23 -0700831 num_targets=$(wc -w <<<"$targets")
832 cpus_per_target=$(((${cpus:-1} + num_targets - 1) / num_targets))
833 echo "$targets" | xargs -P ${cpus:-0} -n 1 "$0" "${cmdline[@]}" -I -c "$cpus_per_target" -t
Patrick Georgi43105d62011-11-05 14:44:41 +0100834}
Patrick Georgif49f7c82011-11-05 12:55:18 +0100835fi
836
Patrick Georgi140a9902011-06-03 21:56:13 +0200837junit '<?xml version="1.0" encoding="utf-8"?>'
838junit '<testsuite>'
839
Stefan Reinauer3779f6a2004-11-05 00:26:31 +0000840if [ "$target" != "" ]; then
Eric Biederman709850a2004-11-05 10:48:04 +0000841 # build a single board
Martin Roth02c93b92016-11-30 16:32:20 -0700842 MAINBOARD=$(normalize_target "${target}")
Patrick Georgic2050f02015-10-31 00:35:44 +0100843 if [ -z "${MAINBOARD}" ]; then
Furquan Shaikh57ccb9c2018-06-23 01:00:32 -0700844 printf "No such target: %s" "${target}"
845 if [ -n "${variant}" ]; then
846 printf ", variant: %s" "${variant}"
847 fi
848 printf "\n"
Patrick Georgic2050f02015-10-31 00:35:44 +0100849 exit 1
850 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700851 build_srcdir="$(mainboard_directory "${MAINBOARD}")"
852 if [ "$(echo "${MAINBOARD}" | wc -w)" -gt 1 ]; then
853 build_targets "${MAINBOARD}"
854 elif [ ! -r "$ROOT/src/mainboard/${build_srcdir}" ]; then
855 echo "No such target: ${MAINBOARD}"
Patrick Georgic2050f02015-10-31 00:35:44 +0100856 exit 1
Patrick Georgi43105d62011-11-05 14:44:41 +0100857 else
Martin Roth02c93b92016-11-30 16:32:20 -0700858 build_target "${MAINBOARD}"
Patrick Georgia0e77382015-09-15 19:32:28 +0200859 test "$mode" != "text" && \
Martin Roth02c93b92016-11-30 16:32:20 -0700860 test -f "$TARGET/abuild/${MAINBOARD}.xml" && \
861 cat "$TARGET/abuild/${MAINBOARD}.xml" >> "$REAL_XMLFILE"
Patrick Georgi43105d62011-11-05 14:44:41 +0100862 XMLFILE=$REAL_XMLFILE
Stefan Reinauer002c9ff2010-03-29 16:23:42 +0000863 fi
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000864else
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100865 build_targets
Martin Roth02c93b92016-11-30 16:32:20 -0700866 rm -f "$REAL_XMLFILE"
867 XMLFILE="$REAL_XMLFILE"
Patrick Georgi43105d62011-11-05 14:44:41 +0100868 junit '<?xml version="1.0" encoding="utf-8"?>'
869 junit '<testsuite>'
Patrick Georgi3fd44c32011-11-07 19:01:54 +0100870 if [ "$mode" != "text" ]; then
Patrick Georgid03d69b2013-12-19 20:13:23 +0100871 for xmlfile in $TARGET/abuild/*_*.xml; do
Martin Roth02c93b92016-11-30 16:32:20 -0700872 cat "$xmlfile" >> "$REAL_XMLFILE"
Patrick Georgi3fd44c32011-11-07 19:01:54 +0100873 done
874 fi
Patrick Georgi3db85f32011-11-05 13:21:14 +0100875 XMLFILE=$REAL_XMLFILE
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000876fi
Patrick Georgi140a9902011-06-03 21:56:13 +0200877junit '</testsuite>'
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000878
Martin Roth047c2f42016-12-14 10:16:26 -0700879if [ "$recursive" = "false" ]; then
880
Martin Rothd16022b2017-06-25 14:21:09 -0600881 # Print the list of failed configurations
Martin Roth047c2f42016-12-14 10:16:26 -0700882 if [ -f "$FAILED_BOARDS" ]; then
Martin Rothd16022b2017-06-25 14:21:09 -0600883 printf "%s configuration(s) failed:\n" "$( wc -l < "$FAILED_BOARDS" )"
Martin Roth047c2f42016-12-14 10:16:26 -0700884 cat "$FAILED_BOARDS"
Martin Rothd16022b2017-06-25 14:21:09 -0600885 echo
Martin Rothba973bd2017-07-19 14:13:07 -0600886 if [ "$exitcode" != "0" ]; then
887 failed=1
888 fi
Martin Roth047c2f42016-12-14 10:16:26 -0700889 else
Martin Rothd16022b2017-06-25 14:21:09 -0600890 printf "All %s tested configurations passed.\n" "$( wc -l < "$PASSED_BOARDS" )"
Martin Roth047c2f42016-12-14 10:16:26 -0700891 fi
892fi
893
Patrick Georgif9d19f22011-06-01 19:29:48 +0000894exit $failed