blob: a990ce505ec51a775f4d74436b3910fd48deeb32 [file] [log] [blame]
David Hendricks6583a812013-11-01 19:37:44 -07001#!/bin/sh
2#
3# This file is part of the coreboot project.
4#
5# Copyright (C) 2013 Google Inc.
Martin Roth8e0071b2014-07-10 15:00:35 -06006# Copyright (C) 2014 Sage Electronic Engineering, LLC.
Zheng Bao86655cf2013-11-07 18:03:05 +08007#
David Hendricks6583a812013-11-01 19:37:44 -07008
9EXIT_SUCCESS=0
10EXIT_FAILURE=1
David Hendricks6583a812013-11-01 19:37:44 -070011
12# Stuff from command-line switches
David Hendricks1173bf32015-11-19 13:04:27 -080013COREBOOT_IMAGE="build/coreboot.rom"
David Hendricks6583a812013-11-01 19:37:44 -070014REMOTE_HOST=""
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +020015REMOTE_PORT_OPTION=""
David Hendricks6583a812013-11-01 19:37:44 -070016CLOBBER_OUTPUT=0
17UPLOAD_RESULTS=0
Martin Roth8e0071b2014-07-10 15:00:35 -060018SERIAL_PORT_SPEED=115200
David Hendricks6583a812013-11-01 19:37:44 -070019
David Hendricks1b6e7a62013-11-11 18:44:05 -080020# Used to specify whether a command should always be run locally or
21# if command should be run remoteley when a remote host is specified.
22LOCAL=0
23REMOTE=1
Martin Rothbe5340b2014-06-22 21:46:24 -060024FATAL=0
25NONFATAL=1
David Hendricks1b6e7a62013-11-11 18:44:05 -080026
David Hendricksc863be72017-09-16 12:59:23 -070027# Used if cbmem is not in default $PATH, e.g. not installed or when using `sudo`
28CBMEM_PATH=""
29
Evgeny Zinovievb8634682018-09-11 00:02:36 +030030# Used if nvramtool is not in default $PATH, e.g. not installed or when using `sudo`
31NVRAMTOOL_PATH=""
32
David Hendricks6583a812013-11-01 19:37:44 -070033# test a command
34#
Martin Rothbcd09932014-07-10 15:02:19 -060035# $1: 0 ($LOCAL) to run command locally,
36# 1 ($REMOTE) to run remotely if remote host defined
David Hendricks6583a812013-11-01 19:37:44 -070037# $2: command to test
Martin Rothbe5340b2014-06-22 21:46:24 -060038# $3: 0 ($FATAL) Exit with an error if the command fails
39# 1 ($NONFATAL) Don't exit on command test failure
David Hendricks6583a812013-11-01 19:37:44 -070040test_cmd()
41{
42 local rc
43
44 if [ -e "$2" ]; then
45 return
46 fi
47
Vladimir Serbinenko77005b42014-01-21 02:39:46 +010048 if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +020049 ssh $REMOTE_PORT_OPTION root@${REMOTE_HOST} command -v "$2" > /dev/null
David Hendricks6583a812013-11-01 19:37:44 -070050 rc=$?
51 else
Patrick Georgi1cbef1c2015-08-10 10:21:14 +020052 command -v "$2" >/dev/null
David Hendricks6583a812013-11-01 19:37:44 -070053 rc=$?
54 fi
55
56 if [ $rc -eq 0 ]; then
Martin Rothbe5340b2014-06-22 21:46:24 -060057 return 0
58 fi
59
Patrick Georgi4ef309e2014-08-10 15:44:04 +020060 if [ "$3" = "1" ]; then
Martin Rothbe5340b2014-06-22 21:46:24 -060061 return 1
David Hendricks6583a812013-11-01 19:37:44 -070062 fi
63
64 echo "$2 not found"
65 exit $EXIT_FAILURE
66}
67
David Hendricksf8b90e42013-11-12 17:24:42 -080068_cmd()
David Hendricks6583a812013-11-01 19:37:44 -070069{
70 if [ -e "$2" ]; then
David Hendricksf8b90e42013-11-12 17:24:42 -080071 return $EXIT_FAILURE
David Hendricks6583a812013-11-01 19:37:44 -070072 fi
73
Martin Roth22461772014-07-10 14:57:34 -060074 if [ -n "$3" ]; then
75 pipe_location="${3}"
David Hendricks6583a812013-11-01 19:37:44 -070076 else
Martin Roth22461772014-07-10 14:57:34 -060077 pipe_location="/dev/null"
78 fi
79
80 if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +020081 ssh $REMOTE_PORT_OPTION "root@${REMOTE_HOST}" "$2" > "$pipe_location" 2>&1
Martin Roth22461772014-07-10 14:57:34 -060082 else
83 $2 > "$pipe_location" 2>&1
David Hendricks6583a812013-11-01 19:37:44 -070084 fi
David Hendricks406ce8a2013-11-12 18:10:23 -080085
86 return $?
David Hendricksf8b90e42013-11-12 17:24:42 -080087}
88
89# run a command
90#
Martin Rothbcd09932014-07-10 15:02:19 -060091# $1: 0 ($LOCAL) to run command locally,
92# 1 ($REMOTE) to run remotely if remote host defined
David Hendricksf8b90e42013-11-12 17:24:42 -080093# $2: command
David Hendricks406ce8a2013-11-12 18:10:23 -080094# $3: filename to direct output of command into
David Hendricksf8b90e42013-11-12 17:24:42 -080095cmd()
96{
David Hendricks406ce8a2013-11-12 18:10:23 -080097 _cmd $1 "$2" "$3"
David Hendricks6583a812013-11-01 19:37:44 -070098
99 if [ $? -eq 0 ]; then
100 return
101 fi
Zheng Bao86655cf2013-11-07 18:03:05 +0800102
David Hendricks406ce8a2013-11-12 18:10:23 -0800103 echo "Failed to run \"$2\", aborting"
104 rm -f "$3" # don't leave an empty file
David Hendricks6583a812013-11-01 19:37:44 -0700105 exit $EXIT_FAILURE
106}
107
David Hendricksf8b90e42013-11-12 17:24:42 -0800108# run a command where failure is considered to be non-fatal
109#
Martin Rothbcd09932014-07-10 15:02:19 -0600110# $1: 0 ($LOCAL) to run command locally,
111# 1 ($REMOTE) to run remotely if remote host defined
David Hendricksf8b90e42013-11-12 17:24:42 -0800112# $2: command
David Hendricks406ce8a2013-11-12 18:10:23 -0800113# $3: filename to direct output of command into
David Hendricksf8b90e42013-11-12 17:24:42 -0800114cmd_nonfatal()
115{
David Hendricks406ce8a2013-11-12 18:10:23 -0800116 _cmd $1 "$2" "$3"
David Hendricksf8b90e42013-11-12 17:24:42 -0800117
118 if [ $? -eq 0 ]; then
119 return
120 fi
121
David Hendricks406ce8a2013-11-12 18:10:23 -0800122 echo "Failed to run \"$2\", ignoring"
123 rm -f "$3" # don't leave an empty file
David Hendricksf8b90e42013-11-12 17:24:42 -0800124}
125
Martin Roth8e0071b2014-07-10 15:00:35 -0600126# read from a serial port device
127#
128# $1: serial device to read from
129# $2: serial port speed
130# $3: filename to direct output of command into
131get_serial_bootlog () {
132
Martin Rothd0128df2015-12-17 12:02:45 -0700133 local TTY=$1
134 local SPEED=$2
135 local FILENAME=$3
136
137 if [ ! -c "$TTY" ]; then
138 echo "$TTY is not a valid serial device"
Martin Roth8e0071b2014-07-10 15:00:35 -0600139 exit $EXIT_FAILURE
140 fi
141
142 # make the text more noticible
143 test_cmd $LOCAL "tput" $NONFATAL
144 tput_not_available=$?
145 if [ $tput_not_available -eq 0 ]; then
146 tput bold
147 tput setaf 10 # set bright green
148 fi
149
150 echo
Martin Rothd0128df2015-12-17 12:02:45 -0700151 echo "Waiting to receive boot log from $TTY"
David Hendricks0dcfb592017-09-16 18:43:08 -0700152 echo "Press [Enter] when the boot is complete."
Martin Rothd0128df2015-12-17 12:02:45 -0700153 echo
Martin Roth8e0071b2014-07-10 15:00:35 -0600154
155 if [ $tput_not_available -eq 0 ]; then
156 tput sgr0
157 fi
158
159 # set up the serial port
Martin Rothd0128df2015-12-17 12:02:45 -0700160 stty -F $TTY $SPEED cs8 -cstopb -parenb clocal
Martin Roth8e0071b2014-07-10 15:00:35 -0600161
162 # read from the serial port - user must press enter when complete
163 test_cmd $LOCAL "tee"
Martin Rothd0128df2015-12-17 12:02:45 -0700164 while read LINE; do
165 echo "$LINE" | tee -a "$FILENAME"
166 done < "$SERIAL_DEVICE" &
Martin Roth8e0071b2014-07-10 15:00:35 -0600167 PID=$!
168
Martin Rothd0128df2015-12-17 12:02:45 -0700169 read foo
170 kill "$PID" 2>/dev/null
Martin Roth8e0071b2014-07-10 15:00:35 -0600171
Martin Rothd0128df2015-12-17 12:02:45 -0700172 echo "Finished reading boot log."
Martin Roth8e0071b2014-07-10 15:00:35 -0600173}
174
David Hendricks1fc65f72013-11-12 16:49:45 -0800175show_help() {
176 echo "Usage:
177 ${0} <option>
178
179Options
David Hendricksc863be72017-09-16 12:59:23 -0700180 -c, --cbmem
181 Path to cbmem on device under test (DUT).
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300182 -n, --nvramtool
183 Path to nvramtool on device under test (DUT).
David Hendricksb2aa5282016-05-07 11:44:05 -0700184 -C, --clobber
David Hendricks1fc65f72013-11-12 16:49:45 -0800185 Clobber temporary output when finished. Useful for debugging.
David Hendricksb2aa5282016-05-07 11:44:05 -0700186 -h, --help
187 Show this message.
188 -i, --image <image>
David Hendricks1173bf32015-11-19 13:04:27 -0800189 Path to coreboot image (Default is $COREBOOT_IMAGE).
David Hendricksb2aa5282016-05-07 11:44:05 -0700190 -r, --remote-host <host>
David Hendricks1fc65f72013-11-12 16:49:45 -0800191 Obtain machine information from remote host (using ssh).
David Hendricksb2aa5282016-05-07 11:44:05 -0700192 -s, --serial-device </dev/xxx>
193 Obtain boot log via serial device.
194 -S, --serial-speed <speed>
195 Set the port speed for the serial device (Default is $SERIAL_PORT_SPEED).
196 -u, --upload-results
197 Upload results to coreboot.org.
198
199Long options:
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +0200200 --ssh-port <port>
201 Use a specific SSH port.
David Hendricks1fc65f72013-11-12 16:49:45 -0800202"
203}
204
David Hendricks292be872016-04-26 14:07:42 -0700205getopt -T
206if [ $? -ne 4 ]; then
207 echo "GNU-compatible getopt(1) required."
208 exit $EXIT_FAILURE
209fi
210
David Hendricksc863be72017-09-16 12:59:23 -0700211LONGOPTS="cbmem:,clobber,help,image:,remote-host:,upload-results"
David Hendricksb2aa5282016-05-07 11:44:05 -0700212LONGOPTS="${LONGOPTS},serial-device:,serial-speed:"
213LONGOPTS="${LONGOPTS},ssh-port:"
214
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300215ARGS=$(getopt -o c:n:Chi:r:s:S:u -l "$LONGOPTS" -n "$0" -- "$@");
David Hendricks292be872016-04-26 14:07:42 -0700216if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
217eval set -- "$ARGS"
218while true ; do
219 case "$1" in
David Hendricksb2aa5282016-05-07 11:44:05 -0700220 # generic options
David Hendricksc863be72017-09-16 12:59:23 -0700221 -c|--cbmem)
222 shift
223 CBMEM_PATH="$1"
224 ;;
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300225 -n|--nvramtool)
226 shift
227 NVRAMTOOL_PATH="$1"
228 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700229 -C|--clobber)
230 CLOBBER_OUTPUT=1
231 ;;
232 -h|--help)
David Hendricks6583a812013-11-01 19:37:44 -0700233 show_help
234 exit $EXIT_SUCCESS
235 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700236 -i|--image)
David Hendricks292be872016-04-26 14:07:42 -0700237 shift
238 COREBOOT_IMAGE="$1"
David Hendricks1173bf32015-11-19 13:04:27 -0800239 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700240 -r|--remote-host)
David Hendricks292be872016-04-26 14:07:42 -0700241 shift
242 REMOTE_HOST="$1"
David Hendricks6583a812013-11-01 19:37:44 -0700243 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700244 -u|--upload-results)
245 UPLOAD_RESULTS=1
246 ;;
247
248 # serial port options
249 -s|--serial-device)
250 shift
251 SERIAL_DEVICE="$1"
252 ;;
253 -S|--serial-speed)
254 shift
255 SERIAL_PORT_SPEED="$1"
256 ;;
257
258 # ssh options
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +0200259 --ssh-port)
260 shift
261 REMOTE_PORT_OPTION="-p $1"
262 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700263
264 # error handling
David Hendricks292be872016-04-26 14:07:42 -0700265 --)
266 shift
267 if [ -n "$*" ]; then
268 echo "Non-option parameters detected: '$*'"
269 exit $EXIT_FAILURE
270 fi
271 break
272 ;;
273 *)
274 echo "error processing options at '$1'"
275 exit $EXIT_FAILURE
David Hendricks6583a812013-11-01 19:37:44 -0700276 esac
David Hendricks292be872016-04-26 14:07:42 -0700277 shift
David Hendricks6583a812013-11-01 19:37:44 -0700278done
279
David Hendricks1b6e7a62013-11-11 18:44:05 -0800280grep -rH 'coreboot.org' .git/config >/dev/null 2>&1
281if [ $? -ne 0 ]; then
282 echo "Script must be run from root of coreboot directory"
David Hendricks6583a812013-11-01 19:37:44 -0700283 exit $EXIT_FAILURE
284fi
285
Jonathan Neuschäfer0e962ee2016-05-17 17:38:10 +0200286if [ ! -e "$COREBOOT_IMAGE" ]; then
287 echo "board_status needs $COREBOOT_IMAGE, but it does not exist."
288 echo "Use \"-i IMAGE_FILE\" to select a different image, or \"--help\" for more options."
289 exit $EXIT_FAILURE
290fi
291
David Hendricks1b6e7a62013-11-11 18:44:05 -0800292# Results will be placed in a temporary location until we're ready to upload.
293# If the user does not wish to upload, results will remain in /tmp.
Patrick Georgiaa7dcef2015-08-13 07:57:26 +0200294tmpdir=$(mktemp -d --tmpdir coreboot_board_status.XXXXXXXX)
David Hendricks1b6e7a62013-11-11 18:44:05 -0800295
David Hendricks9f542972015-11-19 13:08:51 -0800296# Obtain coreboot config by running cbfstool on the ROM image. cbfstool may
297# already exist in build/ or util/cbfstool/, but if not then we'll build it
298# now and clean it when we're done.
Idwer Volleringb37ee1e2014-07-16 22:22:59 +0200299cbfstool_cmd="build/cbfstool"
David Hendricks9f542972015-11-19 13:08:51 -0800300do_clean_cbfstool=0
301if [ ! -x $cbfstool_cmd ]; then
302 cbfstool_cmd="util/cbfstool/cbfstool"
303 if [ -e $cbfstool_cmd ]; then
304 if test ! -x $cbfstool_cmd; then
305 echo "Cannot execute $cbfstool_cmd."
306 exit $EXIT_FAILURE
307 fi
308 else
309 make -C util/cbfstool/
310 do_clean_cbfstool=1
311 fi
Idwer Volleringb37ee1e2014-07-16 22:22:59 +0200312fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800313test_cmd $LOCAL "$cbfstool_cmd"
David Hendricks9f542972015-11-19 13:08:51 -0800314
315tmpcfg=$(mktemp coreboot_config.XXXXXX)
David Hendricks1173bf32015-11-19 13:04:27 -0800316echo "Extracting config.txt from $COREBOOT_IMAGE"
317$cbfstool_cmd "$COREBOOT_IMAGE" extract -n config -f "${tmpdir}/config.txt" >/dev/null 2>&1
Martin Roth9f25da12015-12-17 12:49:15 -0700318mv "${tmpdir}/config.txt" "${tmpdir}/config.short.txt"
319cp "${tmpdir}/config.short.txt" "${tmpcfg}"
320yes "" | make "DOTCONFIG=${tmpcfg}" oldconfig 2>/dev/null >/dev/null
321mv "${tmpcfg}" "${tmpdir}/config.txt"
322rm -f "${tmpcfg}.old"
David Hendricks1173bf32015-11-19 13:04:27 -0800323$cbfstool_cmd "$COREBOOT_IMAGE" print > "${tmpdir}/cbfs.txt"
324rom_contents=$($cbfstool_cmd "$COREBOOT_IMAGE" print 2>&1)
Martin Roth2e44ea22015-12-17 12:33:39 -0700325if [ -n "$(echo $rom_contents | grep payload_config)" ]; then
David Hendricks1173bf32015-11-19 13:04:27 -0800326 echo "Extracting payload_config from $COREBOOT_IMAGE"
327 $cbfstool_cmd "$COREBOOT_IMAGE" extract -n payload_config -f "${tmpdir}/payload_config.txt" >/dev/null 2>&1
Martin Roth2e44ea22015-12-17 12:33:39 -0700328fi
329if [ -n "$(echo $rom_contents | grep payload_version)" ]; then
David Hendricks1173bf32015-11-19 13:04:27 -0800330 echo "Extracting payload_version from $COREBOOT_IMAGE"
331 $cbfstool_cmd "$COREBOOT_IMAGE" extract -n payload_version -f "${tmpdir}/payload_version.txt" >/dev/null 2>&1
Martin Roth2e44ea22015-12-17 12:33:39 -0700332fi
David Hendricks1173bf32015-11-19 13:04:27 -0800333md5sum -b "$COREBOOT_IMAGE" > "${tmpdir}/rom_checksum.txt"
Paul Menzel1cc77e02015-02-19 19:35:58 +0100334
David Hendricks9f542972015-11-19 13:08:51 -0800335if test $do_clean_cbfstool -eq 1; then
336 make -C util/cbfstool clean
337fi
338
Paul Menzel1cc77e02015-02-19 19:35:58 +0100339# Obtain board and revision info to form the directory structure:
340# <vendor>/<board>/<revision>/<timestamp>
Martin Roth9f25da12015-12-17 12:49:15 -0700341mainboard_dir="$(grep CONFIG_MAINBOARD_DIR "${tmpdir}/config.txt" | awk -F '"' '{ print $2 }')"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800342vendor=$(echo "$mainboard_dir" | awk -F '/' '{ print $1 }')
343mainboard=$(echo "$mainboard_dir" | awk -F '/' '{ print $2 }')
David Hendricks6583a812013-11-01 19:37:44 -0700344
David Hendricksc5e947ef2013-11-11 18:43:39 -0800345getrevision="util/board_status/getrevision.sh"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800346test_cmd $LOCAL $getrevision
347tagged_version=$($getrevision -T)
348timestamp=$($getrevision -t)
David Hendricks6583a812013-11-01 19:37:44 -0700349
David Hendricks1b6e7a62013-11-11 18:44:05 -0800350results="${vendor}/${mainboard}/${tagged_version}/${timestamp}"
David Hendricks6583a812013-11-01 19:37:44 -0700351
Paul Menzelc724ac12017-10-15 10:56:36 +0200352if [ -n "$(echo $tagged_version | grep dirty)" ]; then
353 echo "The repository is in a dirty state. Please see the output of"
354 echo "'git status' below."
355 git status
356 exit $EXIT_FAILURE
357fi
358
David Hendricks1b6e7a62013-11-11 18:44:05 -0800359echo "Temporarily placing output in ${tmpdir}/${results}"
360mkdir -p "${tmpdir}/${results}"
David Hendricks6583a812013-11-01 19:37:44 -0700361
David Hendricks1b6e7a62013-11-11 18:44:05 -0800362mv "${tmpdir}/config.txt" "${tmpdir}/${results}"
Martin Roth2e44ea22015-12-17 12:33:39 -0700363test -f "${tmpdir}/payload_config.txt" && mv "${tmpdir}/payload_config.txt" "${tmpdir}/${results}"
364test -f "${tmpdir}/payload_version.txt" && mv "${tmpdir}/payload_version.txt" "${tmpdir}/${results}"
Patrick Georgi368488a2015-06-12 11:35:10 +0200365mv "${tmpdir}/config.short.txt" "${tmpdir}/${results}"
Paul Menzel4b10bb72014-05-30 09:26:46 +0200366mv "${tmpdir}/cbfs.txt" "${tmpdir}/${results}"
Martin Roth072b5aa2015-12-17 12:44:35 -0700367mv "${tmpdir}/rom_checksum.txt" "${tmpdir}/${results}"
David Hendricks6583a812013-11-01 19:37:44 -0700368
Martin Roth9f25da12015-12-17 12:49:15 -0700369touch "${tmpdir}/${results}/revision.txt"
370printf "Local revision: %s\n" "$($getrevision -l)" >> "${tmpdir}/${results}/revision.txt"
371printf "Tagged revision: %s\n" "${tagged_version}" >> "${tmpdir}/${results}/revision.txt"
372printf "Upstream revision: %s\n" "$($getrevision -u)" >> "${tmpdir}/${results}/revision.txt"
373printf "Upstream URL: %s\n" "$($getrevision -U)" >> "${tmpdir}/${results}/revision.txt"
374printf "Timestamp: %s\n" "$timestamp" >> "${tmpdir}/${results}/revision.txt"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800375
David Hendricksc863be72017-09-16 12:59:23 -0700376if [ -n "$CBMEM_PATH" ]; then
377 cbmem_cmd="$CBMEM_PATH"
378else
379 cbmem_cmd="cbmem"
380fi
381
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300382cmos_enabled=0
383if grep -q "CONFIG_USE_OPTION_TABLE=y" "${tmpdir}/${results}/config.short.txt" > /dev/null; then
384 cmos_enabled=1
385fi
386
387if [ -n "$NVRAMTOOL_PATH" ]; then
388 nvramtool_cmd="$NVRAMTOOL_PATH"
389else
390 nvramtool_cmd="nvramtool"
391fi
392
David Hendricksbb90fb52017-09-16 13:01:13 -0700393if [ -n "$SERIAL_DEVICE" ]; then
394 get_serial_bootlog "$SERIAL_DEVICE" "$SERIAL_PORT_SPEED" "${tmpdir}/${results}/coreboot_console.txt"
395elif [ -n "$REMOTE_HOST" ]; then
Martin Roth574d1652015-12-17 12:38:45 -0700396 echo "Verifying that CBMEM is available on remote device"
David Hendricksc863be72017-09-16 12:59:23 -0700397 test_cmd $REMOTE "$cbmem_cmd"
Martin Roth574d1652015-12-17 12:38:45 -0700398 echo "Getting coreboot boot log"
Paul Menzelb7b085d2018-09-06 17:32:58 +0200399 cmd $REMOTE "$cbmem_cmd -1" "${tmpdir}/${results}/coreboot_console.txt"
Martin Roth574d1652015-12-17 12:38:45 -0700400 echo "Getting timestamp data"
David Hendricksc863be72017-09-16 12:59:23 -0700401 cmd_nonfatal $REMOTE "$cbmem_cmd -t" "${tmpdir}/${results}/coreboot_timestamps.txt"
David Hendricks0dcfb592017-09-16 18:43:08 -0700402
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300403 if [ "$cmos_enabled" -eq 1 ]; then
404 echo "Verifying that nvramtool is available on remote device"
405 test_cmd $REMOTE "$nvramtool_cmd"
406 echo "Getting all CMOS values"
407 cmd $REMOTE "$nvramtool_cmd -a" "${tmpdir}/${results}/cmos_values.txt"
408 fi
409
David Hendricks0dcfb592017-09-16 18:43:08 -0700410 echo "Getting remote dmesg"
Arthur Heymans7ccb2822018-12-16 22:38:58 +0100411 cmd $REMOTE dmesg "${tmpdir}/${results}/kernel_log.txt"
Martin Roth8e0071b2014-07-10 15:00:35 -0600412else
David Hendricksbb90fb52017-09-16 13:01:13 -0700413 echo "Verifying that CBMEM is available"
414 if [ $(id -u) -ne 0 ]; then
Matthias Gazzari25c7e322018-05-02 15:43:27 +0200415 command -v "$cbmem_cmd" >/dev/null
David Hendricksbb90fb52017-09-16 13:01:13 -0700416 if [ $? -ne 0 ]; then
Matthias Gazzari25c7e322018-05-02 15:43:27 +0200417 echo "Failed to run $cbmem_cmd. Check \$PATH or" \
418 "use -c to specify path to cbmem binary."
David Hendricksbb90fb52017-09-16 13:01:13 -0700419 exit $EXIT_FAILURE
420 else
421 cbmem_cmd="sudo $cbmem_cmd"
422 fi
423 else
424 test_cmd $LOCAL "$cbmem_cmd"
425 fi
426
427 echo "Getting coreboot boot log"
Paul Menzelb7b085d2018-09-06 17:32:58 +0200428 cmd $LOCAL "$cbmem_cmd -1" "${tmpdir}/${results}/coreboot_console.txt"
Paul Menzel5e20c1c2020-03-14 17:36:10 +0100429 if [ $(grep -- -dirty "${tmpdir}/${results}/coreboot_console.txt") ]; then
430 echo "coreboot or the payload are built from a source tree in a" \
431 "dirty state, making it hard to reproduce the result. Please" \
432 "check in your source tree with 'git status'."
433 exit $EXIT_FAILURE
434 fi
435
David Hendricksbb90fb52017-09-16 13:01:13 -0700436 echo "Getting timestamp data"
437 cmd_nonfatal $LOCAL "$cbmem_cmd -t" "${tmpdir}/${results}/coreboot_timestamps.txt"
438
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300439 if [ "$cmos_enabled" -eq 1 ]; then
440 echo "Verifying that nvramtool is available"
441 if [ $(id -u) -ne 0 ]; then
442 command -v "$nvramtool_cmd" >/dev/null
443 if [ $? -ne 0 ]; then
444 echo "Failed to run $nvramtool_cmd. Check \$PATH or" \
445 "use -n to specify path to nvramtool binary."
446 exit $EXIT_FAILURE
447 else
448 nvramtool_cmd="sudo $nvramtool_cmd"
449 fi
450 else
451 test_cmd $LOCAL "$nvramtool_cmd"
452 fi
453
454 echo "Getting all CMOS values"
455 cmd $LOCAL "$nvramtool_cmd -a" "${tmpdir}/${results}/cmos_values.txt"
456 fi
457
David Hendricksbb90fb52017-09-16 13:01:13 -0700458 echo "Getting local dmesg"
Arthur Heymans7ccb2822018-12-16 22:38:58 +0100459 cmd $LOCAL "sudo dmesg" "${tmpdir}/${results}/kernel_log.txt"
Martin Roth8e0071b2014-07-10 15:00:35 -0600460fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800461
David Hendricksa4affe12013-11-12 18:17:19 -0800462#
463# Finish up.
464#
Martin Rothbcd09932014-07-10 15:02:19 -0600465coreboot_dir=$(pwd)
David Hendricks1b6e7a62013-11-11 18:44:05 -0800466if [ $UPLOAD_RESULTS -eq 1 ]; then
467 # extract username from ssh://<username>@review.coreboot.org/blah
Patrick Georgi77b182a2014-08-10 15:18:22 +0200468 bsrepo=$(git config --get remote.origin.url | sed "s,\(.*\)/coreboot,\1/board-status,")
David Hendricks1b6e7a62013-11-11 18:44:05 -0800469
470 cd "util/board_status/"
471 if [ ! -e "board-status" ]; then
David Hendricksa4affe12013-11-12 18:17:19 -0800472 # FIXME: the board-status directory might get big over time.
473 # Is there a way we can push the results without fetching the
474 # whole repo?
Martin Roth9f25da12015-12-17 12:49:15 -0700475 git clone "$bsrepo"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800476 if [ $? -ne 0 ]; then
Paul Menzel749e0752015-05-20 22:32:15 +0200477 echo "Error cloning board-status repo, aborting."
David Hendricks1b6e7a62013-11-11 18:44:05 -0800478 exit $EXIT_FAILURE
479 fi
480 fi
481
482 cd "board-status"
Huimin Zhang2fb24832016-03-30 00:54:16 -0700483
484 echo "Checking for duplicate results"
485 # get any updates to board-status
486 git pull
487
488 echo "${tagged_version}" | grep dirty >/dev/null 2>&1
489 clean_version=$?
490 existing_results=$(git ls-files "${mainboard_dir}/${tagged_version}")
491
492 # reject duplicate results of non-dirty versions
493 if [ "${clean_version}" -eq 1 ] && [ -n "${existing_results}" ] ; then
494 echo "Result is a duplicate, aborting"
495 exit $EXIT_FAILURE
496 fi
497
David Hendricks1b6e7a62013-11-11 18:44:05 -0800498 echo "Copying results to $(pwd)/${results}"
499
500 # Note: Result directory should be unique due to the timestamp.
501 cp -R "${tmpdir}/${vendor}" .
502
503 echo "Uploading results"
504 git add "${vendor}"
Paul Menzel04eb2e82014-02-09 10:24:22 +0100505 git commit -a -m "${mainboard_dir}/${tagged_version}/${timestamp}"
Paul Menzel54e6aa72015-05-20 07:35:56 +0200506 count=0
Jonathan Neuschäfer478c8892016-05-10 17:43:53 +0200507 until git push origin master || test $count -eq 3; do
Paul Menzel54e6aa72015-05-20 07:35:56 +0200508 git pull --rebase
509 count=$((count + 1))
510 done
David Hendricks1b6e7a62013-11-11 18:44:05 -0800511
512 # Results have been uploaded so it's pointless to keep the
513 # temporary files around.
514 rm -rf "${tmpdir}"
Paul Menzel54e6aa72015-05-20 07:35:56 +0200515 if test $count -eq 3; then
516 echo "Error uploading to board-status repo, aborting."
517 exit $EXIT_FAILURE
518 fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800519fi
520cd "$coreboot_dir"
David Hendricks6583a812013-11-01 19:37:44 -0700521
522if [ $CLOBBER_OUTPUT -eq 1 ]; then
Martin Roth9f25da12015-12-17 12:49:15 -0700523 rm -rf "${tmpdir}"
Martin Roth13c7db82014-07-10 14:59:11 -0600524else
David Hendricks588a7222017-09-05 23:38:03 -0700525 if [ $UPLOAD_RESULTS -eq 1 ]; then
526 echo
527 echo "output files are in $(dirname $0)/board-status/${mainboard_dir}/${tagged_version}/${timestamp}"
528 else
529 echo
530 echo "output files are in ${tmpdir}/${results}"
531 fi
David Hendricks6583a812013-11-01 19:37:44 -0700532fi
533
534exit $EXIT_SUCCESS