blob: 31c3e7c483d4fa9df43dfca16b3ddaf3bcab4bb2 [file] [log] [blame]
David Hendricks6583a812013-11-01 19:37:44 -07001#!/bin/sh
2#
David Hendricks6583a812013-11-01 19:37:44 -07003#
David Hendricks6583a812013-11-01 19:37:44 -07004
5EXIT_SUCCESS=0
6EXIT_FAILURE=1
David Hendricks6583a812013-11-01 19:37:44 -07007
8# Stuff from command-line switches
David Hendricks1173bf32015-11-19 13:04:27 -08009COREBOOT_IMAGE="build/coreboot.rom"
David Hendricks6583a812013-11-01 19:37:44 -070010REMOTE_HOST=""
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +020011REMOTE_PORT_OPTION=""
David Hendricks6583a812013-11-01 19:37:44 -070012CLOBBER_OUTPUT=0
13UPLOAD_RESULTS=0
Martin Roth8e0071b2014-07-10 15:00:35 -060014SERIAL_PORT_SPEED=115200
David Hendricks6583a812013-11-01 19:37:44 -070015
David Hendricks1b6e7a62013-11-11 18:44:05 -080016# Used to specify whether a command should always be run locally or
17# if command should be run remoteley when a remote host is specified.
18LOCAL=0
19REMOTE=1
Martin Rothbe5340b2014-06-22 21:46:24 -060020FATAL=0
21NONFATAL=1
David Hendricks1b6e7a62013-11-11 18:44:05 -080022
David Hendricksc863be72017-09-16 12:59:23 -070023# Used if cbmem is not in default $PATH, e.g. not installed or when using `sudo`
24CBMEM_PATH=""
25
Evgeny Zinovievb8634682018-09-11 00:02:36 +030026# Used if nvramtool is not in default $PATH, e.g. not installed or when using `sudo`
27NVRAMTOOL_PATH=""
28
David Hendricks6583a812013-11-01 19:37:44 -070029# test a command
30#
Martin Rothbcd09932014-07-10 15:02:19 -060031# $1: 0 ($LOCAL) to run command locally,
32# 1 ($REMOTE) to run remotely if remote host defined
David Hendricks6583a812013-11-01 19:37:44 -070033# $2: command to test
Martin Rothbe5340b2014-06-22 21:46:24 -060034# $3: 0 ($FATAL) Exit with an error if the command fails
35# 1 ($NONFATAL) Don't exit on command test failure
David Hendricks6583a812013-11-01 19:37:44 -070036test_cmd()
37{
38 local rc
39
40 if [ -e "$2" ]; then
41 return
42 fi
43
Vladimir Serbinenko77005b42014-01-21 02:39:46 +010044 if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +020045 ssh $REMOTE_PORT_OPTION root@${REMOTE_HOST} command -v "$2" > /dev/null
David Hendricks6583a812013-11-01 19:37:44 -070046 rc=$?
47 else
Patrick Georgi1cbef1c2015-08-10 10:21:14 +020048 command -v "$2" >/dev/null
David Hendricks6583a812013-11-01 19:37:44 -070049 rc=$?
50 fi
51
52 if [ $rc -eq 0 ]; then
Martin Rothbe5340b2014-06-22 21:46:24 -060053 return 0
54 fi
55
Patrick Georgi4ef309e2014-08-10 15:44:04 +020056 if [ "$3" = "1" ]; then
Martin Rothbe5340b2014-06-22 21:46:24 -060057 return 1
David Hendricks6583a812013-11-01 19:37:44 -070058 fi
59
60 echo "$2 not found"
61 exit $EXIT_FAILURE
62}
63
David Hendricksf8b90e42013-11-12 17:24:42 -080064_cmd()
David Hendricks6583a812013-11-01 19:37:44 -070065{
66 if [ -e "$2" ]; then
David Hendricksf8b90e42013-11-12 17:24:42 -080067 return $EXIT_FAILURE
David Hendricks6583a812013-11-01 19:37:44 -070068 fi
69
Martin Roth22461772014-07-10 14:57:34 -060070 if [ -n "$3" ]; then
71 pipe_location="${3}"
David Hendricks6583a812013-11-01 19:37:44 -070072 else
Martin Roth22461772014-07-10 14:57:34 -060073 pipe_location="/dev/null"
74 fi
75
76 if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +020077 ssh $REMOTE_PORT_OPTION "root@${REMOTE_HOST}" "$2" > "$pipe_location" 2>&1
Martin Roth22461772014-07-10 14:57:34 -060078 else
79 $2 > "$pipe_location" 2>&1
David Hendricks6583a812013-11-01 19:37:44 -070080 fi
David Hendricks406ce8a2013-11-12 18:10:23 -080081
82 return $?
David Hendricksf8b90e42013-11-12 17:24:42 -080083}
84
85# run a command
86#
Martin Rothbcd09932014-07-10 15:02:19 -060087# $1: 0 ($LOCAL) to run command locally,
88# 1 ($REMOTE) to run remotely if remote host defined
David Hendricksf8b90e42013-11-12 17:24:42 -080089# $2: command
David Hendricks406ce8a2013-11-12 18:10:23 -080090# $3: filename to direct output of command into
David Hendricksf8b90e42013-11-12 17:24:42 -080091cmd()
92{
David Hendricks406ce8a2013-11-12 18:10:23 -080093 _cmd $1 "$2" "$3"
David Hendricks6583a812013-11-01 19:37:44 -070094
95 if [ $? -eq 0 ]; then
96 return
97 fi
Zheng Bao86655cf2013-11-07 18:03:05 +080098
David Hendricks406ce8a2013-11-12 18:10:23 -080099 echo "Failed to run \"$2\", aborting"
100 rm -f "$3" # don't leave an empty file
David Hendricks6583a812013-11-01 19:37:44 -0700101 exit $EXIT_FAILURE
102}
103
David Hendricksf8b90e42013-11-12 17:24:42 -0800104# run a command where failure is considered to be non-fatal
105#
Martin Rothbcd09932014-07-10 15:02:19 -0600106# $1: 0 ($LOCAL) to run command locally,
107# 1 ($REMOTE) to run remotely if remote host defined
David Hendricksf8b90e42013-11-12 17:24:42 -0800108# $2: command
David Hendricks406ce8a2013-11-12 18:10:23 -0800109# $3: filename to direct output of command into
David Hendricksf8b90e42013-11-12 17:24:42 -0800110cmd_nonfatal()
111{
David Hendricks406ce8a2013-11-12 18:10:23 -0800112 _cmd $1 "$2" "$3"
David Hendricksf8b90e42013-11-12 17:24:42 -0800113
114 if [ $? -eq 0 ]; then
115 return
116 fi
117
David Hendricks406ce8a2013-11-12 18:10:23 -0800118 echo "Failed to run \"$2\", ignoring"
119 rm -f "$3" # don't leave an empty file
David Hendricksf8b90e42013-11-12 17:24:42 -0800120}
121
Martin Roth8e0071b2014-07-10 15:00:35 -0600122# read from a serial port device
123#
124# $1: serial device to read from
125# $2: serial port speed
126# $3: filename to direct output of command into
127get_serial_bootlog () {
128
Martin Rothd0128df2015-12-17 12:02:45 -0700129 local TTY=$1
130 local SPEED=$2
131 local FILENAME=$3
132
133 if [ ! -c "$TTY" ]; then
134 echo "$TTY is not a valid serial device"
Martin Roth8e0071b2014-07-10 15:00:35 -0600135 exit $EXIT_FAILURE
136 fi
137
138 # make the text more noticible
139 test_cmd $LOCAL "tput" $NONFATAL
140 tput_not_available=$?
141 if [ $tput_not_available -eq 0 ]; then
142 tput bold
143 tput setaf 10 # set bright green
144 fi
145
146 echo
Martin Rothd0128df2015-12-17 12:02:45 -0700147 echo "Waiting to receive boot log from $TTY"
David Hendricks0dcfb592017-09-16 18:43:08 -0700148 echo "Press [Enter] when the boot is complete."
Martin Rothd0128df2015-12-17 12:02:45 -0700149 echo
Martin Roth8e0071b2014-07-10 15:00:35 -0600150
151 if [ $tput_not_available -eq 0 ]; then
152 tput sgr0
153 fi
154
155 # set up the serial port
Martin Rothd0128df2015-12-17 12:02:45 -0700156 stty -F $TTY $SPEED cs8 -cstopb -parenb clocal
Martin Roth8e0071b2014-07-10 15:00:35 -0600157
158 # read from the serial port - user must press enter when complete
159 test_cmd $LOCAL "tee"
Martin Rothd0128df2015-12-17 12:02:45 -0700160 while read LINE; do
161 echo "$LINE" | tee -a "$FILENAME"
162 done < "$SERIAL_DEVICE" &
Martin Roth8e0071b2014-07-10 15:00:35 -0600163 PID=$!
164
Martin Rothd0128df2015-12-17 12:02:45 -0700165 read foo
166 kill "$PID" 2>/dev/null
Martin Roth8e0071b2014-07-10 15:00:35 -0600167
Martin Rothd0128df2015-12-17 12:02:45 -0700168 echo "Finished reading boot log."
Martin Roth8e0071b2014-07-10 15:00:35 -0600169}
170
David Hendricks1fc65f72013-11-12 16:49:45 -0800171show_help() {
172 echo "Usage:
173 ${0} <option>
174
175Options
David Hendricksc863be72017-09-16 12:59:23 -0700176 -c, --cbmem
177 Path to cbmem on device under test (DUT).
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300178 -n, --nvramtool
179 Path to nvramtool on device under test (DUT).
David Hendricksb2aa5282016-05-07 11:44:05 -0700180 -C, --clobber
David Hendricks1fc65f72013-11-12 16:49:45 -0800181 Clobber temporary output when finished. Useful for debugging.
David Hendricksb2aa5282016-05-07 11:44:05 -0700182 -h, --help
183 Show this message.
184 -i, --image <image>
David Hendricks1173bf32015-11-19 13:04:27 -0800185 Path to coreboot image (Default is $COREBOOT_IMAGE).
David Hendricksb2aa5282016-05-07 11:44:05 -0700186 -r, --remote-host <host>
David Hendricks1fc65f72013-11-12 16:49:45 -0800187 Obtain machine information from remote host (using ssh).
David Hendricksb2aa5282016-05-07 11:44:05 -0700188 -s, --serial-device </dev/xxx>
189 Obtain boot log via serial device.
190 -S, --serial-speed <speed>
191 Set the port speed for the serial device (Default is $SERIAL_PORT_SPEED).
192 -u, --upload-results
193 Upload results to coreboot.org.
194
195Long options:
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +0200196 --ssh-port <port>
197 Use a specific SSH port.
David Hendricks1fc65f72013-11-12 16:49:45 -0800198"
199}
200
David Hendricks292be872016-04-26 14:07:42 -0700201getopt -T
202if [ $? -ne 4 ]; then
203 echo "GNU-compatible getopt(1) required."
204 exit $EXIT_FAILURE
205fi
206
David Hendricksc863be72017-09-16 12:59:23 -0700207LONGOPTS="cbmem:,clobber,help,image:,remote-host:,upload-results"
David Hendricksb2aa5282016-05-07 11:44:05 -0700208LONGOPTS="${LONGOPTS},serial-device:,serial-speed:"
209LONGOPTS="${LONGOPTS},ssh-port:"
210
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300211ARGS=$(getopt -o c:n:Chi:r:s:S:u -l "$LONGOPTS" -n "$0" -- "$@");
David Hendricks292be872016-04-26 14:07:42 -0700212if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
213eval set -- "$ARGS"
214while true ; do
215 case "$1" in
David Hendricksb2aa5282016-05-07 11:44:05 -0700216 # generic options
David Hendricksc863be72017-09-16 12:59:23 -0700217 -c|--cbmem)
218 shift
219 CBMEM_PATH="$1"
220 ;;
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300221 -n|--nvramtool)
222 shift
223 NVRAMTOOL_PATH="$1"
224 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700225 -C|--clobber)
226 CLOBBER_OUTPUT=1
227 ;;
228 -h|--help)
David Hendricks6583a812013-11-01 19:37:44 -0700229 show_help
230 exit $EXIT_SUCCESS
231 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700232 -i|--image)
David Hendricks292be872016-04-26 14:07:42 -0700233 shift
234 COREBOOT_IMAGE="$1"
David Hendricks1173bf32015-11-19 13:04:27 -0800235 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700236 -r|--remote-host)
David Hendricks292be872016-04-26 14:07:42 -0700237 shift
238 REMOTE_HOST="$1"
David Hendricks6583a812013-11-01 19:37:44 -0700239 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700240 -u|--upload-results)
241 UPLOAD_RESULTS=1
242 ;;
243
244 # serial port options
245 -s|--serial-device)
246 shift
247 SERIAL_DEVICE="$1"
248 ;;
249 -S|--serial-speed)
250 shift
251 SERIAL_PORT_SPEED="$1"
252 ;;
253
254 # ssh options
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +0200255 --ssh-port)
256 shift
257 REMOTE_PORT_OPTION="-p $1"
258 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700259
260 # error handling
David Hendricks292be872016-04-26 14:07:42 -0700261 --)
262 shift
263 if [ -n "$*" ]; then
264 echo "Non-option parameters detected: '$*'"
265 exit $EXIT_FAILURE
266 fi
267 break
268 ;;
269 *)
270 echo "error processing options at '$1'"
271 exit $EXIT_FAILURE
David Hendricks6583a812013-11-01 19:37:44 -0700272 esac
David Hendricks292be872016-04-26 14:07:42 -0700273 shift
David Hendricks6583a812013-11-01 19:37:44 -0700274done
275
David Hendricks1b6e7a62013-11-11 18:44:05 -0800276grep -rH 'coreboot.org' .git/config >/dev/null 2>&1
277if [ $? -ne 0 ]; then
278 echo "Script must be run from root of coreboot directory"
David Hendricks6583a812013-11-01 19:37:44 -0700279 exit $EXIT_FAILURE
280fi
281
Jonathan Neuschäfer0e962ee2016-05-17 17:38:10 +0200282if [ ! -e "$COREBOOT_IMAGE" ]; then
283 echo "board_status needs $COREBOOT_IMAGE, but it does not exist."
284 echo "Use \"-i IMAGE_FILE\" to select a different image, or \"--help\" for more options."
285 exit $EXIT_FAILURE
286fi
287
David Hendricks1b6e7a62013-11-11 18:44:05 -0800288# Results will be placed in a temporary location until we're ready to upload.
289# If the user does not wish to upload, results will remain in /tmp.
Patrick Georgiaa7dcef2015-08-13 07:57:26 +0200290tmpdir=$(mktemp -d --tmpdir coreboot_board_status.XXXXXXXX)
David Hendricks1b6e7a62013-11-11 18:44:05 -0800291
David Hendricks9f542972015-11-19 13:08:51 -0800292# Obtain coreboot config by running cbfstool on the ROM image. cbfstool may
293# already exist in build/ or util/cbfstool/, but if not then we'll build it
294# now and clean it when we're done.
Idwer Volleringb37ee1e2014-07-16 22:22:59 +0200295cbfstool_cmd="build/cbfstool"
David Hendricks9f542972015-11-19 13:08:51 -0800296do_clean_cbfstool=0
297if [ ! -x $cbfstool_cmd ]; then
298 cbfstool_cmd="util/cbfstool/cbfstool"
299 if [ -e $cbfstool_cmd ]; then
300 if test ! -x $cbfstool_cmd; then
301 echo "Cannot execute $cbfstool_cmd."
302 exit $EXIT_FAILURE
303 fi
304 else
305 make -C util/cbfstool/
306 do_clean_cbfstool=1
307 fi
Idwer Volleringb37ee1e2014-07-16 22:22:59 +0200308fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800309test_cmd $LOCAL "$cbfstool_cmd"
David Hendricks9f542972015-11-19 13:08:51 -0800310
311tmpcfg=$(mktemp coreboot_config.XXXXXX)
David Hendricks1173bf32015-11-19 13:04:27 -0800312echo "Extracting config.txt from $COREBOOT_IMAGE"
313$cbfstool_cmd "$COREBOOT_IMAGE" extract -n config -f "${tmpdir}/config.txt" >/dev/null 2>&1
Martin Roth9f25da12015-12-17 12:49:15 -0700314mv "${tmpdir}/config.txt" "${tmpdir}/config.short.txt"
315cp "${tmpdir}/config.short.txt" "${tmpcfg}"
316yes "" | make "DOTCONFIG=${tmpcfg}" oldconfig 2>/dev/null >/dev/null
317mv "${tmpcfg}" "${tmpdir}/config.txt"
318rm -f "${tmpcfg}.old"
David Hendricks1173bf32015-11-19 13:04:27 -0800319$cbfstool_cmd "$COREBOOT_IMAGE" print > "${tmpdir}/cbfs.txt"
320rom_contents=$($cbfstool_cmd "$COREBOOT_IMAGE" print 2>&1)
Martin Roth2e44ea22015-12-17 12:33:39 -0700321if [ -n "$(echo $rom_contents | grep payload_config)" ]; then
David Hendricks1173bf32015-11-19 13:04:27 -0800322 echo "Extracting payload_config from $COREBOOT_IMAGE"
323 $cbfstool_cmd "$COREBOOT_IMAGE" extract -n payload_config -f "${tmpdir}/payload_config.txt" >/dev/null 2>&1
Martin Roth2e44ea22015-12-17 12:33:39 -0700324fi
325if [ -n "$(echo $rom_contents | grep payload_version)" ]; then
David Hendricks1173bf32015-11-19 13:04:27 -0800326 echo "Extracting payload_version from $COREBOOT_IMAGE"
327 $cbfstool_cmd "$COREBOOT_IMAGE" extract -n payload_version -f "${tmpdir}/payload_version.txt" >/dev/null 2>&1
Martin Roth2e44ea22015-12-17 12:33:39 -0700328fi
David Hendricks1173bf32015-11-19 13:04:27 -0800329md5sum -b "$COREBOOT_IMAGE" > "${tmpdir}/rom_checksum.txt"
Paul Menzel1cc77e02015-02-19 19:35:58 +0100330
David Hendricks9f542972015-11-19 13:08:51 -0800331if test $do_clean_cbfstool -eq 1; then
332 make -C util/cbfstool clean
333fi
334
Paul Menzel1cc77e02015-02-19 19:35:58 +0100335# Obtain board and revision info to form the directory structure:
336# <vendor>/<board>/<revision>/<timestamp>
Martin Roth9f25da12015-12-17 12:49:15 -0700337mainboard_dir="$(grep CONFIG_MAINBOARD_DIR "${tmpdir}/config.txt" | awk -F '"' '{ print $2 }')"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800338vendor=$(echo "$mainboard_dir" | awk -F '/' '{ print $1 }')
339mainboard=$(echo "$mainboard_dir" | awk -F '/' '{ print $2 }')
David Hendricks6583a812013-11-01 19:37:44 -0700340
David Hendricksc5e947ef2013-11-11 18:43:39 -0800341getrevision="util/board_status/getrevision.sh"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800342test_cmd $LOCAL $getrevision
343tagged_version=$($getrevision -T)
344timestamp=$($getrevision -t)
David Hendricks6583a812013-11-01 19:37:44 -0700345
David Hendricks1b6e7a62013-11-11 18:44:05 -0800346results="${vendor}/${mainboard}/${tagged_version}/${timestamp}"
David Hendricks6583a812013-11-01 19:37:44 -0700347
Paul Menzelc724ac12017-10-15 10:56:36 +0200348if [ -n "$(echo $tagged_version | grep dirty)" ]; then
349 echo "The repository is in a dirty state. Please see the output of"
350 echo "'git status' below."
351 git status
352 exit $EXIT_FAILURE
353fi
354
David Hendricks1b6e7a62013-11-11 18:44:05 -0800355echo "Temporarily placing output in ${tmpdir}/${results}"
356mkdir -p "${tmpdir}/${results}"
David Hendricks6583a812013-11-01 19:37:44 -0700357
David Hendricks1b6e7a62013-11-11 18:44:05 -0800358mv "${tmpdir}/config.txt" "${tmpdir}/${results}"
Martin Roth2e44ea22015-12-17 12:33:39 -0700359test -f "${tmpdir}/payload_config.txt" && mv "${tmpdir}/payload_config.txt" "${tmpdir}/${results}"
360test -f "${tmpdir}/payload_version.txt" && mv "${tmpdir}/payload_version.txt" "${tmpdir}/${results}"
Patrick Georgi368488a2015-06-12 11:35:10 +0200361mv "${tmpdir}/config.short.txt" "${tmpdir}/${results}"
Paul Menzel4b10bb72014-05-30 09:26:46 +0200362mv "${tmpdir}/cbfs.txt" "${tmpdir}/${results}"
Martin Roth072b5aa2015-12-17 12:44:35 -0700363mv "${tmpdir}/rom_checksum.txt" "${tmpdir}/${results}"
David Hendricks6583a812013-11-01 19:37:44 -0700364
Martin Roth9f25da12015-12-17 12:49:15 -0700365touch "${tmpdir}/${results}/revision.txt"
366printf "Local revision: %s\n" "$($getrevision -l)" >> "${tmpdir}/${results}/revision.txt"
367printf "Tagged revision: %s\n" "${tagged_version}" >> "${tmpdir}/${results}/revision.txt"
368printf "Upstream revision: %s\n" "$($getrevision -u)" >> "${tmpdir}/${results}/revision.txt"
369printf "Upstream URL: %s\n" "$($getrevision -U)" >> "${tmpdir}/${results}/revision.txt"
370printf "Timestamp: %s\n" "$timestamp" >> "${tmpdir}/${results}/revision.txt"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800371
David Hendricksc863be72017-09-16 12:59:23 -0700372if [ -n "$CBMEM_PATH" ]; then
373 cbmem_cmd="$CBMEM_PATH"
374else
375 cbmem_cmd="cbmem"
376fi
377
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300378cmos_enabled=0
379if grep -q "CONFIG_USE_OPTION_TABLE=y" "${tmpdir}/${results}/config.short.txt" > /dev/null; then
380 cmos_enabled=1
381fi
382
383if [ -n "$NVRAMTOOL_PATH" ]; then
384 nvramtool_cmd="$NVRAMTOOL_PATH"
385else
386 nvramtool_cmd="nvramtool"
387fi
388
David Hendricksbb90fb52017-09-16 13:01:13 -0700389if [ -n "$SERIAL_DEVICE" ]; then
390 get_serial_bootlog "$SERIAL_DEVICE" "$SERIAL_PORT_SPEED" "${tmpdir}/${results}/coreboot_console.txt"
391elif [ -n "$REMOTE_HOST" ]; then
Martin Roth574d1652015-12-17 12:38:45 -0700392 echo "Verifying that CBMEM is available on remote device"
David Hendricksc863be72017-09-16 12:59:23 -0700393 test_cmd $REMOTE "$cbmem_cmd"
Martin Roth574d1652015-12-17 12:38:45 -0700394 echo "Getting coreboot boot log"
Paul Menzelb7b085d2018-09-06 17:32:58 +0200395 cmd $REMOTE "$cbmem_cmd -1" "${tmpdir}/${results}/coreboot_console.txt"
Martin Roth574d1652015-12-17 12:38:45 -0700396 echo "Getting timestamp data"
David Hendricksc863be72017-09-16 12:59:23 -0700397 cmd_nonfatal $REMOTE "$cbmem_cmd -t" "${tmpdir}/${results}/coreboot_timestamps.txt"
David Hendricks0dcfb592017-09-16 18:43:08 -0700398
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300399 if [ "$cmos_enabled" -eq 1 ]; then
400 echo "Verifying that nvramtool is available on remote device"
401 test_cmd $REMOTE "$nvramtool_cmd"
402 echo "Getting all CMOS values"
403 cmd $REMOTE "$nvramtool_cmd -a" "${tmpdir}/${results}/cmos_values.txt"
404 fi
405
David Hendricks0dcfb592017-09-16 18:43:08 -0700406 echo "Getting remote dmesg"
Arthur Heymans7ccb2822018-12-16 22:38:58 +0100407 cmd $REMOTE dmesg "${tmpdir}/${results}/kernel_log.txt"
Martin Roth8e0071b2014-07-10 15:00:35 -0600408else
David Hendricksbb90fb52017-09-16 13:01:13 -0700409 echo "Verifying that CBMEM is available"
410 if [ $(id -u) -ne 0 ]; then
Matthias Gazzari25c7e322018-05-02 15:43:27 +0200411 command -v "$cbmem_cmd" >/dev/null
David Hendricksbb90fb52017-09-16 13:01:13 -0700412 if [ $? -ne 0 ]; then
Matthias Gazzari25c7e322018-05-02 15:43:27 +0200413 echo "Failed to run $cbmem_cmd. Check \$PATH or" \
414 "use -c to specify path to cbmem binary."
David Hendricksbb90fb52017-09-16 13:01:13 -0700415 exit $EXIT_FAILURE
416 else
417 cbmem_cmd="sudo $cbmem_cmd"
418 fi
419 else
420 test_cmd $LOCAL "$cbmem_cmd"
421 fi
422
423 echo "Getting coreboot boot log"
Paul Menzelb7b085d2018-09-06 17:32:58 +0200424 cmd $LOCAL "$cbmem_cmd -1" "${tmpdir}/${results}/coreboot_console.txt"
Paul Menzel5e20c1c2020-03-14 17:36:10 +0100425
David Hendricksbb90fb52017-09-16 13:01:13 -0700426 echo "Getting timestamp data"
427 cmd_nonfatal $LOCAL "$cbmem_cmd -t" "${tmpdir}/${results}/coreboot_timestamps.txt"
428
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300429 if [ "$cmos_enabled" -eq 1 ]; then
430 echo "Verifying that nvramtool is available"
431 if [ $(id -u) -ne 0 ]; then
432 command -v "$nvramtool_cmd" >/dev/null
433 if [ $? -ne 0 ]; then
434 echo "Failed to run $nvramtool_cmd. Check \$PATH or" \
435 "use -n to specify path to nvramtool binary."
436 exit $EXIT_FAILURE
437 else
438 nvramtool_cmd="sudo $nvramtool_cmd"
439 fi
440 else
441 test_cmd $LOCAL "$nvramtool_cmd"
442 fi
443
444 echo "Getting all CMOS values"
445 cmd $LOCAL "$nvramtool_cmd -a" "${tmpdir}/${results}/cmos_values.txt"
446 fi
447
David Hendricksbb90fb52017-09-16 13:01:13 -0700448 echo "Getting local dmesg"
Arthur Heymans7ccb2822018-12-16 22:38:58 +0100449 cmd $LOCAL "sudo dmesg" "${tmpdir}/${results}/kernel_log.txt"
Martin Roth8e0071b2014-07-10 15:00:35 -0600450fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800451
David Hendricksa4affe12013-11-12 18:17:19 -0800452#
Paul Menzel2c486622020-05-29 13:52:12 +0200453# Check files
454#
455if [ $(grep -- -dirty "${tmpdir}/${results}/coreboot_console.txt") ]; then
456 echo "coreboot or the payload are built from a source tree in a" \
457 "dirty state, making it hard to reproduce the result. Please" \
458 "check in your source tree with 'git status'."
459 exit $EXIT_FAILURE
460fi
461
Paul Menzeldf5571d2020-05-29 02:24:09 +0200462if [ $(grep -- unknown "${tmpdir}/${results}/coreboot_timestamps.txt") ]; then
463 echo "Unknown timestamps found in 'coreboot_timestamps.txt'." \
464 "Please rebuild the 'cbmem' utility and try again."
465 exit $EXIT_FAILURE
466fi
467
Paul Menzel2c486622020-05-29 13:52:12 +0200468#
David Hendricksa4affe12013-11-12 18:17:19 -0800469# Finish up.
470#
Martin Rothbcd09932014-07-10 15:02:19 -0600471coreboot_dir=$(pwd)
David Hendricks1b6e7a62013-11-11 18:44:05 -0800472if [ $UPLOAD_RESULTS -eq 1 ]; then
473 # extract username from ssh://<username>@review.coreboot.org/blah
Patrick Georgi77b182a2014-08-10 15:18:22 +0200474 bsrepo=$(git config --get remote.origin.url | sed "s,\(.*\)/coreboot,\1/board-status,")
David Hendricks1b6e7a62013-11-11 18:44:05 -0800475
476 cd "util/board_status/"
477 if [ ! -e "board-status" ]; then
David Hendricksa4affe12013-11-12 18:17:19 -0800478 # FIXME: the board-status directory might get big over time.
479 # Is there a way we can push the results without fetching the
480 # whole repo?
Martin Roth9f25da12015-12-17 12:49:15 -0700481 git clone "$bsrepo"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800482 if [ $? -ne 0 ]; then
Paul Menzel749e0752015-05-20 22:32:15 +0200483 echo "Error cloning board-status repo, aborting."
David Hendricks1b6e7a62013-11-11 18:44:05 -0800484 exit $EXIT_FAILURE
485 fi
486 fi
487
488 cd "board-status"
Huimin Zhang2fb24832016-03-30 00:54:16 -0700489
490 echo "Checking for duplicate results"
491 # get any updates to board-status
492 git pull
493
494 echo "${tagged_version}" | grep dirty >/dev/null 2>&1
495 clean_version=$?
496 existing_results=$(git ls-files "${mainboard_dir}/${tagged_version}")
497
498 # reject duplicate results of non-dirty versions
499 if [ "${clean_version}" -eq 1 ] && [ -n "${existing_results}" ] ; then
500 echo "Result is a duplicate, aborting"
501 exit $EXIT_FAILURE
502 fi
503
David Hendricks1b6e7a62013-11-11 18:44:05 -0800504 echo "Copying results to $(pwd)/${results}"
505
506 # Note: Result directory should be unique due to the timestamp.
507 cp -R "${tmpdir}/${vendor}" .
508
509 echo "Uploading results"
510 git add "${vendor}"
Paul Menzel04eb2e82014-02-09 10:24:22 +0100511 git commit -a -m "${mainboard_dir}/${tagged_version}/${timestamp}"
Paul Menzel54e6aa72015-05-20 07:35:56 +0200512 count=0
Jonathan Neuschäfer478c8892016-05-10 17:43:53 +0200513 until git push origin master || test $count -eq 3; do
Paul Menzel54e6aa72015-05-20 07:35:56 +0200514 git pull --rebase
515 count=$((count + 1))
516 done
David Hendricks1b6e7a62013-11-11 18:44:05 -0800517
518 # Results have been uploaded so it's pointless to keep the
519 # temporary files around.
520 rm -rf "${tmpdir}"
Paul Menzel54e6aa72015-05-20 07:35:56 +0200521 if test $count -eq 3; then
522 echo "Error uploading to board-status repo, aborting."
523 exit $EXIT_FAILURE
524 fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800525fi
526cd "$coreboot_dir"
David Hendricks6583a812013-11-01 19:37:44 -0700527
528if [ $CLOBBER_OUTPUT -eq 1 ]; then
Martin Roth9f25da12015-12-17 12:49:15 -0700529 rm -rf "${tmpdir}"
Martin Roth13c7db82014-07-10 14:59:11 -0600530else
David Hendricks588a7222017-09-05 23:38:03 -0700531 if [ $UPLOAD_RESULTS -eq 1 ]; then
532 echo
533 echo "output files are in $(dirname $0)/board-status/${mainboard_dir}/${tagged_version}/${timestamp}"
534 else
535 echo
536 echo "output files are in ${tmpdir}/${results}"
537 fi
David Hendricks6583a812013-11-01 19:37:44 -0700538fi
539
540exit $EXIT_SUCCESS