blob: d8f4882bbc26524428cf957dd9e32093e039aa1d [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"
Martin Roth26174c92016-11-23 18:47:53 -0700253 echo "# CONFIG_PAYLOAD_ELF is not set"
Martin Roth26174c92016-11-23 18:47:53 -0700254 } >> "${config_file}"
255 elif [ "$PAYLOAD" != "/dev/null" ]; then
256 {
257 echo "# CONFIG_PAYLOAD_NONE is not set"
Martin Roth26174c92016-11-23 18:47:53 -0700258 echo "CONFIG_PAYLOAD_ELF=y"
259 echo "CONFIG_PAYLOAD_FILE=\"$PAYLOAD\""
260 } >> "${config_file}"
261 fi
Martin Roth735b9a02018-05-07 21:44:37 -0500262 # Disable all other payload config options
263 {
264 echo "# CONFIG_PAYLOAD_SEABIOS is not set"
265 echo "# CONFIG_PAYLOAD_BAYOU is not set"
266 echo "# CONFIG_PAYLOAD_FILO is not set"
267 echo "# CONFIG_PAYLOAD_GRUB2 is not set"
268 echo "# CONFIG_PAYLOAD_OPENBIOS is not set"
269 echo "# CONFIG_PAYLOAD_DEPTHCHARGE is not set"
270 echo "# CONFIG_PAYLOAD_UBOOT is not set"
271 echo "# CONFIG_PAYLOAD_TIANOCORE is not set"
272 echo "# CONFIG_PXE is not set"
273 echo "# CONFIG_BUILD_IPXE is not set"
274 echo "# CONFIG_MEMTEST_SECONDARY_PAYLOAD is not set"
275 echo "# CONFIG_COREINFO_SECONDARY_PAYLOAD is not set"
276 echo "# CONFIG_NVRAMCUI_SECONDARY_PAYLOAD is not set"
277 echo "# CONFIG_TINT_SECONDARY_PAYLOAD is not set"
278 } >> "${config_file}"
Martin Roth26174c92016-11-23 18:47:53 -0700279
280 if [ "$quiet" == "false" ]; then echo " $MAINBOARD ($customizing)"; fi
Martin Roth6bc44162016-12-13 15:29:30 -0700281 # shellcheck disable=SC2059
282 printf "$configoptions" >> "${config_file}"
Martin Roth26174c92016-11-23 18:47:53 -0700283
Patrick Georgi55ea0132017-06-27 14:02:18 +0200284 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 -0700285 CONFIG_OK=$?
286 if [ $CONFIG_OK -eq 0 ]; then
Patrick Georgi55ea0132017-06-27 14:02:18 +0200287 $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 -0700288 return $?
289 else
290 return 1
291 fi
292}
293
Martin Roth02c93b92016-11-30 16:32:20 -0700294# shellcheck disable=SC2129
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000295function create_buildenv
296{
Martin Roth26174c92016-11-23 18:47:53 -0700297 local BUILD_NAME=$1
298 local build_dir=$2
299 local config_file=$3
Stefan Reinauer0ed0b7c2010-03-30 15:49:14 +0000300
Martin Roth26174c92016-11-23 18:47:53 -0700301 if [ -z "$config_file" ]; then
302 create_config "$BUILD_NAME" "$build_dir"
303 else
304 local new_config_file="${build_dir}/config.build"
305 cp "$config_file" "$new_config_file"
306 update_config "$BUILD_NAME" "$build_dir" "$new_config_file"
307 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700308 local ret=$?
Stefan Reinauer86dbe152010-03-25 14:18:57 +0000309
310 # Allow simple "make" in the target directory
Martin Roth26174c92016-11-23 18:47:53 -0700311 local MAKEFILE=$TARGET/${BUILD_NAME}/Makefile
Martin Roth02c93b92016-11-30 16:32:20 -0700312 echo "# autogenerated" > "$MAKEFILE"
313 echo "TOP=$ROOT" >> "$MAKEFILE"
314 echo "BUILD=$TARGET" >> "$MAKEFILE"
315 echo "OBJ=\$(BUILD)/${MAINBOARD}" >> "$MAKEFILE"
316 echo "OBJUTIL=\$(BUILD)/sharedutils" >> "$MAKEFILE"
317 echo "all:" >> "$MAKEFILE"
318 echo " @cp -a config.h config.h.bak" >> "$MAKEFILE"
319 echo " @cd \$(TOP); \$(MAKE) oldconfig DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> "$MAKEFILE"
320 echo " @tail -n+6 config.h > config.new; tail -n+6 config.h.bak > config.old" >> "$MAKEFILE"
321 echo " @cmp -s config.new config.old && cp -a config.h.bak config.h || echo \"Config file changed\"" >> "$MAKEFILE"
322 echo " @rm config.h.bak config.new config.old" >> "$MAKEFILE"
323 echo " @cd \$(TOP); \$(MAKE) DOTCONFIG=\$(OBJ)/config.build objutil=\$(OBJUTIL) obj=\$(OBJ)" >> "$MAKEFILE"
Stefan Reinauer0ed0b7c2010-03-30 15:49:14 +0000324
325 return $ret
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000326}
327
Martin Roth26174c92016-11-23 18:47:53 -0700328function check_config
329{
330 local BUILD_DIR="$1"
331 local TEST_TYPE="$2"
332 local TEST_STRING="$3"
333
334 local CONFIG_FILE="$BUILD_DIR/config.build"
335 local CONFIG_LOG="$BUILD_DIR/config.log"
336
337 if ! grep -q "$TEST_STRING" "$CONFIG_FILE"; then
338 echo "config file: $CONFIG_FILE has incorrect $TEST_TYPE"
339 echo "Error: Expected '$TEST_STRING' in config file." >> "$CONFIG_LOG"
340 return 1
341 fi
342
343 return 0
344}
345
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000346function compile_target
Stefan Reinauer14e22772010-04-27 06:56:47 +0000347{
Martin Roth26174c92016-11-23 18:47:53 -0700348 local BUILD_NAME=$1
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000349
Martin Roth02c93b92016-11-30 16:32:20 -0700350 if [ "$quiet" == "false" ]; then echo " Compiling $MAINBOARD image$cpuconfig..."; fi
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000351
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000352 CURR=$( pwd )
Stefan Reinauerabdf8482010-03-30 14:02:19 +0000353 #stime=`perl -e 'print time();' 2>/dev/null || date +%s`
Patrick Georgi55ea0132017-06-27 14:02:18 +0200354 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 -0700355 &> "${build_dir}/make.log" ; \
356 MAKE_FAILED=$?
357 cp .xcompile "${build_dir}/xcompile.build"
358 cd "${build_dir}" || return $?
Stefan Reinauerabdf8482010-03-30 14:02:19 +0000359
Martin Roth02c93b92016-11-30 16:32:20 -0700360 etime=$(perl -e 'print time();' 2>/dev/null || date +%s)
361 duration=$(( etime - stime ))
Martin Roth26174c92016-11-23 18:47:53 -0700362 junit " <testcase classname='board${testclass/#/.}' name='$BUILD_NAME' time='$duration' >"
Stefan Reinauerabdf8482010-03-30 14:02:19 +0000363
Martin Roth02c93b92016-11-30 16:32:20 -0700364 if [ $MAKE_FAILED -eq 0 ]; then
Patrick Georgi140a9902011-06-03 21:56:13 +0200365 junit "<system-out>"
366 junitfile make.log
367 junit "</system-out>"
Stefan Reinauer3a140572006-10-25 19:02:34 +0000368 printf "ok\n" > compile.status
Martin Roth02c93b92016-11-30 16:32:20 -0700369 printf "%s built successfully. (took %ss)\n" "$BUILD_NAME" "${duration}"
Martin Rothd16022b2017-06-25 14:21:09 -0600370 echo "$BUILD_NAME" >> "$PASSED_BOARDS"
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000371 else
Patrick Georgi140a9902011-06-03 21:56:13 +0200372 junit "<failure type='BuildFailed'>"
373 junitfile make.log
374 junit "</failure>"
Patrick Georgi8bf5c152015-04-22 18:24:01 +0200375 printf "failed\n" > compile.status
Martin Roth02c93b92016-11-30 16:32:20 -0700376 printf "%s build FAILED after %ss!\nLog excerpt:\n" "$BUILD_NAME" "${duration}"
Patrick Georgia84a99b2009-05-26 14:03:51 +0000377 tail -n $CONTEXT make.log 2> /dev/null || tail -$CONTEXT make.log
Martin Rothd16022b2017-06-25 14:21:09 -0600378 echo "$BUILD_NAME - Log: ${TOP}/${build_dir}/make.log" >> "$FAILED_BOARDS"
Patrick Georgif9d19f22011-06-01 19:29:48 +0000379 failed=1
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000380 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700381 cd "$CURR" || return $?
Martin Rothc7e6ad72017-03-26 18:23:51 -0600382 if [ -n "$checksum_file" ]; then
383 sha256sum "${build_dir}/coreboot.rom" >> "${checksum_file}_platform"
384 sort "${build_dir}/config.h" | grep CONFIG_ > "${build_dir}/config.h.sorted"
385 sha256sum "${build_dir}/config.h.sorted" >> "${checksum_file}_config"
386 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700387 if [ "$clean_work" = "true" ]; then
388 rm -rf "${build_dir}"
Patrick Georgib0bc63b2014-05-21 22:47:05 +0200389 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700390 return $MAKE_FAILED
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000391}
392
Martin Roth26174c92016-11-23 18:47:53 -0700393function build_config
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000394{
Patrick Georgic2050f02015-10-31 00:35:44 +0100395 local MAINBOARD=$1
Martin Roth26174c92016-11-23 18:47:53 -0700396 local build_dir=$2
397 local BUILD_NAME=$3
398 local config_file=$4
Martin Roth02c93b92016-11-30 16:32:20 -0700399 local board_srcdir
400 local ret
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000401
Martin Roth02c93b92016-11-30 16:32:20 -0700402 board_srcdir=$(mainboard_directory "${MAINBOARD}")
Martin Roth26174c92016-11-23 18:47:53 -0700403
Martin Roth02c93b92016-11-30 16:32:20 -0700404 if [ "$(cat "${build_dir}/compile.status" 2>/dev/null)" = "ok" ] && \
405 [ "$buildall" = "false" ]; then
Martin Roth26174c92016-11-23 18:47:53 -0700406 echo "Skipping $BUILD_NAME; (already successful)"
Patrick Georgi1a5301d2012-11-22 14:19:43 +0100407 return
408 fi
409
Paul Menzeld2bbaff2016-12-09 08:47:45 +0100410 export HOSTCC='gcc'
Eric Biederman709850a2004-11-05 10:48:04 +0000411
Martin Roth26174c92016-11-23 18:47:53 -0700412 if [ "$chromeos" = true ] && [ "$(grep -c "^[[:space:]]*select[[:space:]]*MAINBOARD_HAS_CHROMEOS\>" "${ROOT}/src/mainboard/${board_srcdir}/Kconfig")" -eq 0 ]; then
413 echo "${BUILD_NAME} doesn't support Chrome OS, skipping."
Patrick Georgif43b06d2015-07-31 16:26:19 +0200414 return
415 fi
416
Martin Roth26174c92016-11-23 18:47:53 -0700417 if [ -f "src/mainboard/${board_srcdir}/abuild.disabled" ]; then
418 echo "${BUILD_NAME} disabled:"
419 cat "src/mainboard/${board_srcdir}/abuild.disabled"
Patrick Georgi3ac3c4eb2015-07-14 20:20:13 +0200420 return
421 fi
422
Martin Roth26174c92016-11-23 18:47:53 -0700423 if [ "$quiet" == "false" ]; then echo "Building $BUILD_NAME"; fi
424 mkdir -p "$TARGET/${BUILD_NAME}" "$TARGET/abuild"
Martin Roth02c93b92016-11-30 16:32:20 -0700425 ABSPATH="$(cd "$TARGET/abuild" && pwd)"
Martin Roth26174c92016-11-23 18:47:53 -0700426 XMLFILE="$ABSPATH/${BUILD_NAME}.xml"
427 rm -f "${XMLFILE}"
428
429 stime=$(perl -e 'print time();' 2>/dev/null || date +%s)
430 create_buildenv "$BUILD_NAME" "$build_dir" "$config_file"
431 local BUILDENV_CREATED=$?
432
433 check_config "$build_dir" "mainboard" "CONFIG_BOARD_${MAINBOARD}=y"
434 local MAINBOARD_OK=$?
435
436 check_config "$build_dir" "vendor" "CONFIG_VENDOR_$(mainboard_vendor "${MAINBOARD}")=y"
437 local VENDOR_OK=$?
438
439 if [ $BUILDENV_CREATED -ne 0 ] || [ $MAINBOARD_OK -ne 0 ] || [ $VENDOR_OK -ne 0 ]; then
Martin Roth16c49b52017-05-23 22:06:30 -0600440 junit " <testcase classname='board${testclass/#/.}' name='$BUILD_NAME' >"
Martin Roth26174c92016-11-23 18:47:53 -0700441
442 junit "<failure type='BuildFailed'>"
443 junitfile "$build_dir/config.log"
444 junit "</failure>"
445 printf "failed\n" > compile.status
Martin Roth02c93b92016-11-30 16:32:20 -0700446 printf "%s build configuration FAILED!\nLog excerpt:\n" "$BUILD_NAME"
Martin Roth26174c92016-11-23 18:47:53 -0700447 tail -n $CONTEXT "$build_dir/config.log" 2> /dev/null || tail -$CONTEXT "$build_dir/config.log"
448
449 junit "</testcase>"
Martin Rothd16022b2017-06-25 14:21:09 -0600450 echo "$BUILD_NAME - Log: ${TOP}/$build_dir/config.log" >> "$FAILED_BOARDS"
Martin Roth26174c92016-11-23 18:47:53 -0700451 return
452 fi
Stefan Reinauer192b7bc2006-05-27 00:22:02 +0000453
Martin Roth02c93b92016-11-30 16:32:20 -0700454 required_arches=$(egrep "^CONFIG_ARCH_(BOOTBLOCK|R.MSTAGE|VERSTAGE)" "$TARGET/${BUILD_NAME}/config.build" | \
455 sed "s,^CONFIG_ARCH_[^_]*_\([^=]*\)=.*$,\1," |sort -u |tr 'A-Z\n\r' 'a-z ')
456 # shellcheck disable=SC2016,SC2059
457 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 +0200458 if [ -n "$missing_arches" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700459 printf "skipping %s because we're missing compilers for (%s)\n" "$BUILD_NAME" "$missing_arches"
Patrick Georgi02802df2014-10-18 11:57:11 +0200460 return
461 fi
462
Martin Roth02c93b92016-11-30 16:32:20 -0700463 if [ $BUILDENV_CREATED -eq 0 ] && [ $configureonly -eq 0 ]; then
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200464 BUILDPREFIX=
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000465 if [ "$scanbuild" = "true" ]; then
Martin Roth26174c92016-11-23 18:47:53 -0700466 scanbuild_out=$TARGET/${BUILD_NAME}-scanbuild
Martin Roth02c93b92016-11-30 16:32:20 -0700467 rm -rf "${scanbuild_out}"
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200468 BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000469 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700470 compile_target "${BUILD_NAME}"
Patrick Georgid2296772009-03-11 15:43:02 +0000471 if [ "$scanbuild" = "true" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700472 mv "${scanbuild_out}"tmp/* "${scanbuild_out}"
473 rmdir "${scanbuild_out}tmp"
Patrick Georgid2296772009-03-11 15:43:02 +0000474 fi
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000475 fi
Stefan Reinauer2f285ae2004-11-05 14:06:24 +0000476
Patrick Georgi140a9902011-06-03 21:56:13 +0200477 junit "</testcase>"
Stefan Reinauer3a140572006-10-25 19:02:34 +0000478}
479
Martin Roth26174c92016-11-23 18:47:53 -0700480# One target may build several configs
481function build_target
482{
483 local MAINBOARD=$1
Martin Roth02c93b92016-11-30 16:32:20 -0700484 local MAINBOARD_LC
485 MAINBOARD_LC=$(echo "$MAINBOARD" | tr '[:upper:]' '[:lower:]')
Martin Roth26174c92016-11-23 18:47:53 -0700486
487 # look for config files in the config directory that match the boardname
488 if [ -n "$( find "$configdir" -maxdepth 1 -name "config.${MAINBOARD_LC}*" -print -quit )" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700489 for config in "$configdir/config.${MAINBOARD_LC}"*; do
Martin Roth26174c92016-11-23 18:47:53 -0700490 BUILD_NAME="${config##*/}"
491 BUILD_NAME="${BUILD_NAME##config.}"
492 BUILD_NAME=$(echo "${BUILD_NAME}" | tr '[:lower:]' '[:upper:]')
493 echo "Building config $BUILD_NAME"
494 build_dir=$TARGET/${BUILD_NAME}
495 build_config "$MAINBOARD" "$build_dir" "$BUILD_NAME" "$config"
496 remove_target "$BUILD_NAME"
497
498 done
499 else
500 echo "Building board $MAINBOARD (using default config)"
501 build_dir=$TARGET/${MAINBOARD}
502
503 build_config "$MAINBOARD" "$build_dir" "$MAINBOARD"
504 remove_target "$MAINBOARD"
505 fi
506
507}
508
Uwe Hermann4e006402009-04-15 16:07:27 +0000509function remove_target
510{
511 if [ "$remove" != "true" ]; then
Martin Roth26174c92016-11-23 18:47:53 -0700512 return
Uwe Hermann4e006402009-04-15 16:07:27 +0000513 fi
514
Martin Roth26174c92016-11-23 18:47:53 -0700515 local BUILD_NAME=$1
Uwe Hermann4e006402009-04-15 16:07:27 +0000516
517 # Save the generated coreboot.rom file of each board.
Martin Roth26174c92016-11-23 18:47:53 -0700518 if [ -r "$TARGET/${BUILD_NAME}/coreboot.rom" ]; then
519 cp "$TARGET/${BUILD_NAME}/coreboot.rom" \
520 "${BUILD_NAME}_coreboot.rom"
Uwe Hermann4e006402009-04-15 16:07:27 +0000521 fi
522
Martin Roth26174c92016-11-23 18:47:53 -0700523 echo "Removing build dir for $BUILD_NAME..."
Martin Roth02c93b92016-11-30 16:32:20 -0700524 rm -rf "${TARGET:?}/${BUILD_NAME}"
Uwe Hermann4e006402009-04-15 16:07:27 +0000525
Martin Roth26174c92016-11-23 18:47:53 -0700526 return
Uwe Hermann4e006402009-04-15 16:07:27 +0000527}
528
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000529function myhelp
530{
Patrick Georgi86980bb2015-07-31 16:14:43 +0200531cat << __END_OF_HELP
Martin Roth5b0d2db2016-12-06 09:18:36 -0700532Usage: $0 [options]
Patrick Georgi86980bb2015-07-31 16:14:43 +0200533 $0 [-V|--version]
534 $0 [-h|--help]
Stefan Reinauerca631202006-11-10 13:30:28 +0000535
Patrick Georgi86980bb2015-07-31 16:14:43 +0200536Options:\n"
Martin Rothb06bfa42016-12-05 09:15:33 -0700537 [-a|--all] Build previously succeeded ports as well
Damien Zammitb40c72a2017-09-02 15:02:04 +1000538 [-A|--any-toolchain] Use any toolchain
Patrick Georgi86980bb2015-07-31 16:14:43 +0200539 [-B|--blobs] Allow using binary files
Martin Rothc7e6ad72017-03-26 18:23:51 -0600540 [--checksum <path/basefile>] Store checksums at path/basefile
Martin Rothb06bfa42016-12-05 09:15:33 -0700541 [-c|--cpus <numcpus>] Build on <numcpus> at the same time
542 [-C|--config] Configure-only mode
543 [-d|--dir <dir>] Directory containing config files
Martin Rothba973bd2017-07-19 14:13:07 -0600544 [-e|--exitcode] Exit with a non-zero errorlevel on failure
Martin Rothb06bfa42016-12-05 09:15:33 -0700545 [-J|--junit] Write JUnit formatted xml log file
546 [-K|--kconfig <name>] Prepend file to generated Kconfig
547 [-l|--loglevel <num>] Set loglevel
Patrick Georgi86980bb2015-07-31 16:14:43 +0200548 [-L|--clang] Use clang
Martin Rothb06bfa42016-12-05 09:15:33 -0700549 [-o|--outdir <path>] Store build results in path
550 (defaults to $TARGET)
551 [-p|--payloads <dir>] Use payloads in <dir> to build images
552 [-P|--prefix <name>] File name prefix in CBFS
553 [-q|--quiet] Print fewer messages
554 [-r|--remove] Remove output dir after build
Martin Roth5b0d2db2016-12-06 09:18:36 -0700555 [-R|--root <path>] Absolute path to coreboot sources
556 (defaults to $ROOT)
Martin Rothb06bfa42016-12-05 09:15:33 -0700557 [--scan-build] Use clang's static analyzer
Martin Roth33314262017-03-27 23:45:31 -0600558 [--timeless] Generate timeless builds
Martin Rothb06bfa42016-12-05 09:15:33 -0700559 [-t|--target <vendor/board>] Attempt to build target vendor/board only
560 [-T|--test] Submit image(s) to automated test system
561 [-u|--update] Update existing image
562 [-v|--verbose] Print more messages
Patrick Georgi86980bb2015-07-31 16:14:43 +0200563 [-x|--chromeos] Build with CHROMEOS enabled
Patrick Georgif43b06d2015-07-31 16:26:19 +0200564 Skip boards without Chrome OS support
Martin Rothb06bfa42016-12-05 09:15:33 -0700565 [-X|--xmlfile <name>] Set JUnit XML log file filename
566 (defaults to $XMLFILE)
567 [-y|--ccache] Use ccache
568 [-z|--clean] Remove build results when finished
569
Martin Rothb06bfa42016-12-05 09:15:33 -0700570 [-V|--version] Print version number and exit
571 [-h|--help] Print this help and exit
Patrick Georgi86980bb2015-07-31 16:14:43 +0200572
Patrick Georgi55ea0132017-06-27 14:02:18 +0200573 [-s|--silent] obsolete
Patrick Georgi86980bb2015-07-31 16:14:43 +0200574__END_OF_HELP
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000575}
576
Stefan Reinauer14e22772010-04-27 06:56:47 +0000577function myversion
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000578{
579 cat << EOF
580
Stefan Reinauerf8ee1802008-01-18 15:08:58 +0000581coreboot autobuild v$ABUILD_VERSION ($ABUILD_DATE)
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000582
Stefan Reinauer192b7bc2006-05-27 00:22:02 +0000583Copyright (C) 2004 by Stefan Reinauer <stepan@openbios.org>
Stefan Reinauer68003b82010-01-30 10:44:28 +0000584Copyright (C) 2006-2010 by coresystems GmbH <info@coresystems.de>
Stefan Reinauer3a140572006-10-25 19:02:34 +0000585
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000586This program is free software; you may redistribute it under the terms
587of the GNU General Public License. This program has absolutely no
588warranty.
589
590EOF
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000591}
592
593# default options
594target=""
595buildall=false
Stefan Reinauer173f13b2004-11-05 11:57:00 +0000596verbose=false
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000597
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +0000598test -f util/sconfig/sconfig.l && ROOT=$( pwd )
Martin Roth02c93b92016-11-30 16:32:20 -0700599test -f ../util/sconfig/sconfig.l && ROOT=$( cd .. && pwd )
600test "$ROOT" = "" && ROOT=$( cd ../.. && pwd )
Stefan Reinauer0d4a08e2009-07-01 12:26:11 +0000601
Patrick Georgi92cfe182012-04-05 11:17:01 +0200602# Look if we have getopt. If not, build it.
603export PATH=$PATH:util/abuild
604getopt - > /dev/null 2>/dev/null || gcc -o util/abuild/getopt util/abuild/getopt.c
605
Julius Werner893eda02017-03-20 15:33:23 -0700606# Save command line for xargs parallelization.
607cmdline=("$@")
Patrick Georgi43105d62011-11-05 14:44:41 +0100608
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000609# parse parameters.. try to find out whether we're running GNU getopt
Martin Roth02c93b92016-11-30 16:32:20 -0700610getoptbrand="$(getopt -V)"
611
612# shellcheck disable=SC2086
Stefan Reinauer39d4e5f2008-05-28 08:40:23 +0000613if [ "${getoptbrand:0:6}" == "getopt" ]; then
614 # Detected GNU getopt that supports long options.
Damien Zammitb40c72a2017-09-02 15:02:04 +1000615 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 +0000616 eval set -- $args
Martin Roth02c93b92016-11-30 16:32:20 -0700617 retval=$?
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000618else
619 # Detected non-GNU getopt
Damien Zammitb40c72a2017-09-02 15:02:04 +1000620 args=$(getopt Vvqhat:p:c:sJCl:rP:uyBLAzo:xX:K:d:R:Ie "$@")
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000621 set -- $args
Martin Roth02c93b92016-11-30 16:32:20 -0700622 retval=$?
Stefan Reinauer02a4e7f2008-05-27 18:29:26 +0000623fi
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000624
Martin Roth02c93b92016-11-30 16:32:20 -0700625if [ $retval != 0 ]; then
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000626 myhelp
627 exit 1
628fi
629
Patrick Georgif43b06d2015-07-31 16:26:19 +0200630chromeos=false
Patrick Georgib0bc63b2014-05-21 22:47:05 +0200631clean_work=false
Patrick Georgi55ea0132017-06-27 14:02:18 +0200632verboseopt='V=0'
Patrick Georgi64d9a772012-05-01 15:14:46 +0200633customizing=""
634configoptions=""
Patrick Georgi098c4a82015-09-15 16:57:04 +0200635# testclass needs to be undefined if not used for variable expansion to work
636unset testclass
Eric Biedermanc1492102004-11-05 08:50:54 +0000637while true ; do
Eric Biedermanca883c92004-11-05 11:24:57 +0000638 case "$1" in
Martin Roth02c93b92016-11-30 16:32:20 -0700639 -J|--junit) shift; mode=junit; rm -f "$XMLFILE" ;;
Stefan Reinauer2f285ae2004-11-05 14:06:24 +0000640 -t|--target) shift; target="$1"; shift;;
Eric Biedermanc1492102004-11-05 08:50:54 +0000641 -a|--all) shift; buildall=true;;
Martin Roth26174c92016-11-23 18:47:53 -0700642 -d|--dir) shift; configdir="$1"; shift;;
Martin Rothba973bd2017-07-19 14:13:07 -0600643 -e|--exitcode) shift; exitcode=1;;
Warren Turkal0e8f2042010-09-27 21:14:19 +0000644 -r|--remove) shift; remove=true;;
Patrick Georgi55ea0132017-06-27 14:02:18 +0200645 -v|--verbose) shift; verbose=true; verboseopt='V=1';;
Martin Rothddb7a9d2014-12-08 01:57:52 -0700646 -q|--quiet) shift; quiet=true;;
Stefan Reinauerd4c68462004-11-05 11:47:41 +0000647 -V|--version) shift; myversion; exit 0;;
Stefan Reinauer3a140572006-10-25 19:02:34 +0000648 -h|--help) shift; myversion; myhelp; exit 0;;
Stefan Reinauer7fe2b7c2006-09-15 17:00:11 +0000649 -p|--payloads) shift; payloads="$1"; shift;;
Martin Roth5b0d2db2016-12-06 09:18:36 -0700650 -R|--root) shift; ROOT="$1"; shift;;
Patrick Georgi64d9a772012-05-01 15:14:46 +0200651 -c|--cpus) shift
652 export MAKEFLAGS="-j $1"
Patrick Georgi58955512013-12-05 19:53:04 +0100653 cpus=$1
Martin Rothddb7a9d2014-12-08 01:57:52 -0700654 test "$MAKEFLAGS" == "-j max" && export MAKEFLAGS="-j" && cpuconfig=" in parallel"
655 test "$1" == "1" && cpuconfig=" on 1 cpu"
Martin Roth02c93b92016-11-30 16:32:20 -0700656 expr "$1" : '-\?[0-9]\+$' > /dev/null && test "0$1" -gt 1 && cpuconfig=" on $1 cpus in parallel"
Patrick Georgi64d9a772012-05-01 15:14:46 +0200657 shift;;
Patrick Georgi55ea0132017-06-27 14:02:18 +0200658 # obsolete option
659 -s|--silent) shift;;
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200660 --scan-build) shift
Patrick Georgi64d9a772012-05-01 15:14:46 +0200661 scanbuild=true
662 customizing="${customizing}, scan-build"
Patrick Georgi64d9a772012-05-01 15:14:46 +0200663 ;;
664 -y|--ccache) shift
665 customizing="${customizing}, ccache"
666 configoptions="${configoptions}CONFIG_CCACHE=y\n"
667 ;;
Stefan Reinauercc44b062009-03-11 15:00:50 +0000668 -C|--config) shift; configureonly=1;;
Patrick Georgi64d9a772012-05-01 15:14:46 +0200669 -l|--loglevel) shift
670 customizing="${customizing}, loglevel $1"
Patrick Georgi64d9a772012-05-01 15:14:46 +0200671 configoptions="${configoptions}CONFIG_DEFAULT_CONSOLE_LOGLEVEL_$1=y\n"
672 configoptions="${configoptions}CONFIG_DEFAULT_CONSOLE_LOGLEVEL=$1\n"
673 shift;;
674 -u|--update) shift
675 customizing="${customizing}, update"
676 configoptions="${configoptions}CONFIG_UPDATE_IMAGE=y\n"
677 ;;
678 -P|--prefix) shift
679 customizing="${customizing}, cbfs prefix $1"
680 configoptions="${configoptions}CONFIG_CBFS_PREFIX=\"$1\""
681 shift;;
682 -B|--blobs) shift
683 customizing="${customizing}, blobs"
684 configoptions="${configoptions}CONFIG_USE_BLOBS=y\n"
685 ;;
Damien Zammitb40c72a2017-09-02 15:02:04 +1000686 -A|--any-toolchain) shift
687 customizing="${customizing}, any-toolchain"
688 configoptions="${configoptions}CONFIG_ANY_TOOLCHAIN=y\n"
689 ;;
Patrick Georgie9fe6542014-05-14 13:43:58 +0200690 -L|--clang) shift
691 customizing="${customizing}, clang"
Patrick Georgi02ac6c32014-11-28 23:08:51 +0100692 configoptions="${configoptions}CONFIG_COMPILER_LLVM_CLANG=y\n# CONFIG_COMPILER_GCC is not set\n"
Patrick Georgie9fe6542014-05-14 13:43:58 +0200693 ;;
Patrick Georgib0bc63b2014-05-21 22:47:05 +0200694 -z|--clean) shift
695 customizing="${customizing}, clean"
696 clean_work=true
697 ;;
Patrick Georgiad273222014-05-21 23:00:32 +0200698 -o|--outdir) shift
699 TARGET=$1; shift
700 ;;
Patrick Georgidd787362015-04-22 18:38:10 +0200701 -x|--chromeos) shift
Patrick Georgif43b06d2015-07-31 16:26:19 +0200702 chromeos=true
Patrick Georgi58474df2015-07-31 16:30:04 +0200703 testclass=chromeos
Patrick Georgif43b06d2015-07-31 16:26:19 +0200704 customizing="${customizing}, chrome os"
Patrick Georgidd787362015-04-22 18:38:10 +0200705 configoptions="${configoptions}CONFIG_CHROMEOS=y\n"
706 ;;
Martin Roth21ca9be2015-10-13 12:27:56 -0600707 -X|--xmlfile) shift; XMLFILE=$1; REAL_XMLFILE=$1; shift;;
Martin Roth047c2f42016-12-14 10:16:26 -0700708 -I|--recursive) shift; recursive=true;;
Martin Roth10008102016-03-09 13:12:10 -0700709 -K|--kconfig) shift
Martin Roth02c93b92016-11-30 16:32:20 -0700710 testclass="$(basename "$1" | tr '.' '_' )"
Martin Roth10008102016-03-09 13:12:10 -0700711 customizing="${customizing}, $1 config"
712 configoptions="$(cat "$1")${configoptions}\n"
713 shift;;
Martin Rothc7e6ad72017-03-26 18:23:51 -0600714 --checksum) shift; checksum_file="$1"; shift;;
Martin Roth33314262017-03-27 23:45:31 -0600715 --timeless) shift; TIMELESS=1;;
Eric Biedermanc1492102004-11-05 08:50:54 +0000716 --) shift; break;;
Martin Roth9fdb41a2016-12-06 09:51:54 -0700717 -*) printf "Invalid option '%s'\n\n" "$1"; myhelp; exit 1;;
Eric Biedermanca883c92004-11-05 11:24:57 +0000718 *) break;;
Eric Biedermanc1492102004-11-05 08:50:54 +0000719 esac
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000720done
Martin Roth9fdb41a2016-12-06 09:51:54 -0700721if [ -n "$1" ]; then
722 printf "Invalid option '%s'\n\n" "$1"; myhelp; exit 1;
723fi
Stefan Reinauer9f12caa2004-10-19 07:00:47 +0000724
Martin Roth02c93b92016-11-30 16:32:20 -0700725if [ -z "$TARGET" ] || [ "$TARGET" = "/" ]; then
Patrick Georgiad273222014-05-21 23:00:32 +0200726 echo "Please specify a valid, non-root build directory."
727 exit 1
728fi
729
Martin Roth02c93b92016-11-30 16:32:20 -0700730customizing=$(echo "$customizing" | cut -c3-)
Patrick Georgi64d9a772012-05-01 15:14:46 +0200731if [ "$customizing" = "" ]; then
732 customizing="default configuration"
733fi
734
Martin Roth6d2cbb92017-07-19 19:33:34 -0600735FAILED_BOARDS="${COREBOOT_BUILD_DIR:-${TOP}/coreboot-builds}/failed_boards"
736PASSED_BOARDS="${COREBOOT_BUILD_DIR:-${TOP}/coreboot-builds}/passing_boards"
Martin Roth047c2f42016-12-14 10:16:26 -0700737
738if [ "$recursive" = "false" ]; then
Martin Rothd16022b2017-06-25 14:21:09 -0600739 rm -f "$FAILED_BOARDS" "$PASSED_BOARDS"
Martin Roth047c2f42016-12-14 10:16:26 -0700740fi
741
Patrick Georgi43105d62011-11-05 14:44:41 +0100742USE_XARGS=0
Patrick Georgif49f7c82011-11-05 12:55:18 +0100743if [ "$cpus" != "1" ]; then
Patrick Georgi58955512013-12-05 19:53:04 +0100744 # Limit to 32 parallel builds for now.
745 # Thrashing all caches because we run
746 # 160 abuilds in parallel is no fun.
747 if [ "$cpus" = "max" ]; then
748 cpus=32
749 fi
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100750 # Test if xargs supports the non-standard -P flag
751 # FIXME: disabled until we managed to eliminate all the make(1) quirks
752 echo | xargs -P ${cpus:-0} -n 1 echo 2>/dev/null >/dev/null && USE_XARGS=1
Patrick Georgi43105d62011-11-05 14:44:41 +0100753fi
754
755if [ "$USE_XARGS" = "0" ]; then
Raymond Danksc95da252012-05-30 16:03:48 -0600756test "$MAKEFLAGS" == "" && test "$cpus" != "" && export MAKEFLAGS="-j $cpus"
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100757build_targets()
Patrick Georgi43105d62011-11-05 14:44:41 +0100758{
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100759 local targets=${*-$(get_mainboards)}
760 for MAINBOARD in $targets; do
Martin Roth02c93b92016-11-30 16:32:20 -0700761 build_target "${MAINBOARD}"
Patrick Georgi43105d62011-11-05 14:44:41 +0100762 done
763}
764else
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100765build_targets()
Patrick Georgi43105d62011-11-05 14:44:41 +0100766{
Martin Roth02c93b92016-11-30 16:32:20 -0700767 local ABSPATH
768 local stime
769 local etime
Julius Werner893eda02017-03-20 15:33:23 -0700770 local num_targets
771 local cpus_per_target
Martin Roth02c93b92016-11-30 16:32:20 -0700772
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100773 local targets=${*-$(get_mainboards)}
Patrick Georgi43105d62011-11-05 14:44:41 +0100774 # seed shared utils
Martin Roth02c93b92016-11-30 16:32:20 -0700775 TMPCFG=$(mktemp)
776 printf "%s" "$configoptions" > "$TMPCFG"
777 $MAKE -j "$cpus" DOTCONFIG="$TMPCFG" obj="$TARGET/temp" objutil="$TARGET/sharedutils" allnoconfig
778 printf "%s" "$configoptions" >> "$TMPCFG"
779 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 +0200780 BUILDPREFIX=
781 if [ "$scanbuild" = "true" ]; then
782 scanbuild_out=$TARGET/sharedutils-scanbuild
Martin Roth02c93b92016-11-30 16:32:20 -0700783 rm -rf "${scanbuild_out}"
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200784 BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
785 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700786 mkdir -p "$TARGET/abuild"
787 ABSPATH="$(cd "$TARGET/abuild" && pwd)"
788 local XMLFILE="$ABSPATH/__util.xml"
789 rm -f "${XMLFILE}"
790 stime=$(perl -e 'print time();' 2>/dev/null || date +%s)
791 $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 +0200792 local ret=$?
Martin Roth02c93b92016-11-30 16:32:20 -0700793 etime=$(perl -e 'print time();' 2>/dev/null || date +%s)
794 local duration=$(( etime - stime ))
Patrick Georgi053322f2015-09-15 17:30:52 +0200795
796 junit " <testcase classname='util' name='all' time='$duration' >"
797 if [ $ret -eq 0 ]; then
798 junit "<system-out>"
Martin Roth02c93b92016-11-30 16:32:20 -0700799 junitfile "$TARGET/sharedutils/make.log"
Patrick Georgi053322f2015-09-15 17:30:52 +0200800 junit "</system-out>"
801 junit "</testcase>"
802 else
803 junit "<failure type='BuildFailed'>"
Martin Roth02c93b92016-11-30 16:32:20 -0700804 junitfile "$TARGET/sharedutils/make.log"
Patrick Georgi053322f2015-09-15 17:30:52 +0200805 junit "</failure>"
806 junit "</testcase>"
Martin Roth6228b9e2017-07-16 17:02:47 -0700807 echo "Shared Utilities - Log: $TARGET/sharedutils/make.log" >> "$FAILED_BOARDS"
Patrick Georgi053322f2015-09-15 17:30:52 +0200808 return
809 fi
810
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200811 if [ "$scanbuild" = "true" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700812 mv "${scanbuild_out}tmp/"* "${scanbuild_out}"
813 rmdir "${scanbuild_out}tmp"
Patrick Georgifadbe5f2014-05-17 18:26:38 +0200814 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700815 rm -rf "$TARGET/temp" "$TMPCFG"
Julius Werner893eda02017-03-20 15:33:23 -0700816 num_targets=$(wc -w <<<"$targets")
817 cpus_per_target=$(((${cpus:-1} + num_targets - 1) / num_targets))
818 echo "$targets" | xargs -P ${cpus:-0} -n 1 "$0" "${cmdline[@]}" -I -c "$cpus_per_target" -t
Patrick Georgi43105d62011-11-05 14:44:41 +0100819}
Patrick Georgif49f7c82011-11-05 12:55:18 +0100820fi
821
Stefan Reinauer68003b82010-01-30 10:44:28 +0000822debug "ROOT=$ROOT"
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000823
Patrick Georgi140a9902011-06-03 21:56:13 +0200824junit '<?xml version="1.0" encoding="utf-8"?>'
825junit '<testsuite>'
826
Stefan Reinauer3779f6a2004-11-05 00:26:31 +0000827if [ "$target" != "" ]; then
Eric Biederman709850a2004-11-05 10:48:04 +0000828 # build a single board
Martin Roth02c93b92016-11-30 16:32:20 -0700829 MAINBOARD=$(normalize_target "${target}")
Patrick Georgic2050f02015-10-31 00:35:44 +0100830 if [ -z "${MAINBOARD}" ]; then
Martin Roth02c93b92016-11-30 16:32:20 -0700831 printf "No such target: %s\n" "$target"
Patrick Georgic2050f02015-10-31 00:35:44 +0100832 exit 1
833 fi
Martin Roth02c93b92016-11-30 16:32:20 -0700834 build_srcdir="$(mainboard_directory "${MAINBOARD}")"
835 if [ "$(echo "${MAINBOARD}" | wc -w)" -gt 1 ]; then
836 build_targets "${MAINBOARD}"
837 elif [ ! -r "$ROOT/src/mainboard/${build_srcdir}" ]; then
838 echo "No such target: ${MAINBOARD}"
Patrick Georgic2050f02015-10-31 00:35:44 +0100839 exit 1
Patrick Georgi43105d62011-11-05 14:44:41 +0100840 else
Martin Roth02c93b92016-11-30 16:32:20 -0700841 build_target "${MAINBOARD}"
Patrick Georgia0e77382015-09-15 19:32:28 +0200842 test "$mode" != "text" && \
Martin Roth02c93b92016-11-30 16:32:20 -0700843 test -f "$TARGET/abuild/${MAINBOARD}.xml" && \
844 cat "$TARGET/abuild/${MAINBOARD}.xml" >> "$REAL_XMLFILE"
Patrick Georgi43105d62011-11-05 14:44:41 +0100845 XMLFILE=$REAL_XMLFILE
Stefan Reinauer002c9ff2010-03-29 16:23:42 +0000846 fi
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000847else
Patrick Georgi0c65dcc2015-10-31 00:42:50 +0100848 build_targets
Martin Roth02c93b92016-11-30 16:32:20 -0700849 rm -f "$REAL_XMLFILE"
850 XMLFILE="$REAL_XMLFILE"
Patrick Georgi43105d62011-11-05 14:44:41 +0100851 junit '<?xml version="1.0" encoding="utf-8"?>'
852 junit '<testsuite>'
Patrick Georgi3fd44c32011-11-07 19:01:54 +0100853 if [ "$mode" != "text" ]; then
Patrick Georgid03d69b2013-12-19 20:13:23 +0100854 for xmlfile in $TARGET/abuild/*_*.xml; do
Martin Roth02c93b92016-11-30 16:32:20 -0700855 cat "$xmlfile" >> "$REAL_XMLFILE"
Patrick Georgi3fd44c32011-11-07 19:01:54 +0100856 done
857 fi
Patrick Georgi3db85f32011-11-05 13:21:14 +0100858 XMLFILE=$REAL_XMLFILE
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000859fi
Patrick Georgi140a9902011-06-03 21:56:13 +0200860junit '</testsuite>'
Stefan Reinauerd87ce962004-11-05 00:25:19 +0000861
Martin Roth047c2f42016-12-14 10:16:26 -0700862if [ "$recursive" = "false" ]; then
863
Martin Rothd16022b2017-06-25 14:21:09 -0600864 # Print the list of failed configurations
Martin Roth047c2f42016-12-14 10:16:26 -0700865 if [ -f "$FAILED_BOARDS" ]; then
Martin Rothd16022b2017-06-25 14:21:09 -0600866 printf "%s configuration(s) failed:\n" "$( wc -l < "$FAILED_BOARDS" )"
Martin Roth047c2f42016-12-14 10:16:26 -0700867 cat "$FAILED_BOARDS"
Martin Rothd16022b2017-06-25 14:21:09 -0600868 echo
Martin Rothba973bd2017-07-19 14:13:07 -0600869 if [ "$exitcode" != "0" ]; then
870 failed=1
871 fi
Martin Roth047c2f42016-12-14 10:16:26 -0700872 else
Martin Rothd16022b2017-06-25 14:21:09 -0600873 printf "All %s tested configurations passed.\n" "$( wc -l < "$PASSED_BOARDS" )"
Martin Roth047c2f42016-12-14 10:16:26 -0700874 fi
875fi
876
Patrick Georgif9d19f22011-06-01 19:29:48 +0000877exit $failed