blob: f5254f1a91f53d8c3946d21632ecd772bd19f7f3 [file] [log] [blame]
Martin Roth0ad5fbd2020-12-24 12:06:38 -07001#!/usr/bin/env sh
David Hendricks6583a812013-11-01 19:37:44 -07002#
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
Idwer Vollering22bcb562021-01-11 13:44:24 +010029case $(uname) in
30 FreeBSD)
31 if [ ! -x /usr/local/bin/gmake ]; then
32 echo "Please install gmake, or build and install devel/gmake from ports."
33 exit $EXIT_FAILURE
34 else
Alexey Vazhnov15f84cc2021-02-13 20:22:53 +010035 MAKE='gmake'
Idwer Vollering22bcb562021-01-11 13:44:24 +010036 fi
37 ;;
38 *)
Alexey Vazhnov15f84cc2021-02-13 20:22:53 +010039 MAKE='make'
Idwer Vollering22bcb562021-01-11 13:44:24 +010040 ;;
41esac
42
David Hendricks6583a812013-11-01 19:37:44 -070043# test a command
44#
Martin Rothbcd09932014-07-10 15:02:19 -060045# $1: 0 ($LOCAL) to run command locally,
46# 1 ($REMOTE) to run remotely if remote host defined
David Hendricks6583a812013-11-01 19:37:44 -070047# $2: command to test
Martin Rothbe5340b2014-06-22 21:46:24 -060048# $3: 0 ($FATAL) Exit with an error if the command fails
49# 1 ($NONFATAL) Don't exit on command test failure
David Hendricks6583a812013-11-01 19:37:44 -070050test_cmd()
51{
52 local rc
53
54 if [ -e "$2" ]; then
55 return
56 fi
57
Vladimir Serbinenko77005b42014-01-21 02:39:46 +010058 if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +020059 ssh $REMOTE_PORT_OPTION root@${REMOTE_HOST} command -v "$2" > /dev/null
David Hendricks6583a812013-11-01 19:37:44 -070060 rc=$?
61 else
Patrick Georgi1cbef1c2015-08-10 10:21:14 +020062 command -v "$2" >/dev/null
David Hendricks6583a812013-11-01 19:37:44 -070063 rc=$?
64 fi
65
66 if [ $rc -eq 0 ]; then
Martin Rothbe5340b2014-06-22 21:46:24 -060067 return 0
68 fi
69
Patrick Georgi4ef309e2014-08-10 15:44:04 +020070 if [ "$3" = "1" ]; then
Martin Rothbe5340b2014-06-22 21:46:24 -060071 return 1
David Hendricks6583a812013-11-01 19:37:44 -070072 fi
73
74 echo "$2 not found"
75 exit $EXIT_FAILURE
76}
77
David Hendricksf8b90e42013-11-12 17:24:42 -080078_cmd()
David Hendricks6583a812013-11-01 19:37:44 -070079{
80 if [ -e "$2" ]; then
David Hendricksf8b90e42013-11-12 17:24:42 -080081 return $EXIT_FAILURE
David Hendricks6583a812013-11-01 19:37:44 -070082 fi
83
Martin Roth22461772014-07-10 14:57:34 -060084 if [ -n "$3" ]; then
85 pipe_location="${3}"
David Hendricks6583a812013-11-01 19:37:44 -070086 else
Martin Roth22461772014-07-10 14:57:34 -060087 pipe_location="/dev/null"
88 fi
89
90 if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +020091 ssh $REMOTE_PORT_OPTION "root@${REMOTE_HOST}" "$2" > "$pipe_location" 2>&1
Martin Roth22461772014-07-10 14:57:34 -060092 else
93 $2 > "$pipe_location" 2>&1
David Hendricks6583a812013-11-01 19:37:44 -070094 fi
David Hendricks406ce8a2013-11-12 18:10:23 -080095
96 return $?
David Hendricksf8b90e42013-11-12 17:24:42 -080097}
98
99# run a command
100#
Martin Rothbcd09932014-07-10 15:02:19 -0600101# $1: 0 ($LOCAL) to run command locally,
102# 1 ($REMOTE) to run remotely if remote host defined
David Hendricksf8b90e42013-11-12 17:24:42 -0800103# $2: command
David Hendricks406ce8a2013-11-12 18:10:23 -0800104# $3: filename to direct output of command into
David Hendricksf8b90e42013-11-12 17:24:42 -0800105cmd()
106{
David Hendricks406ce8a2013-11-12 18:10:23 -0800107 _cmd $1 "$2" "$3"
David Hendricks6583a812013-11-01 19:37:44 -0700108
109 if [ $? -eq 0 ]; then
110 return
111 fi
Zheng Bao86655cf2013-11-07 18:03:05 +0800112
David Hendricks406ce8a2013-11-12 18:10:23 -0800113 echo "Failed to run \"$2\", aborting"
114 rm -f "$3" # don't leave an empty file
David Hendricks6583a812013-11-01 19:37:44 -0700115 exit $EXIT_FAILURE
116}
117
David Hendricksf8b90e42013-11-12 17:24:42 -0800118# run a command where failure is considered to be non-fatal
119#
Martin Rothbcd09932014-07-10 15:02:19 -0600120# $1: 0 ($LOCAL) to run command locally,
121# 1 ($REMOTE) to run remotely if remote host defined
David Hendricksf8b90e42013-11-12 17:24:42 -0800122# $2: command
David Hendricks406ce8a2013-11-12 18:10:23 -0800123# $3: filename to direct output of command into
David Hendricksf8b90e42013-11-12 17:24:42 -0800124cmd_nonfatal()
125{
David Hendricks406ce8a2013-11-12 18:10:23 -0800126 _cmd $1 "$2" "$3"
David Hendricksf8b90e42013-11-12 17:24:42 -0800127
128 if [ $? -eq 0 ]; then
129 return
130 fi
131
David Hendricks406ce8a2013-11-12 18:10:23 -0800132 echo "Failed to run \"$2\", ignoring"
133 rm -f "$3" # don't leave an empty file
David Hendricksf8b90e42013-11-12 17:24:42 -0800134}
135
Martin Roth8e0071b2014-07-10 15:00:35 -0600136# read from a serial port device
137#
138# $1: serial device to read from
139# $2: serial port speed
140# $3: filename to direct output of command into
141get_serial_bootlog () {
142
Martin Rothd0128df2015-12-17 12:02:45 -0700143 local TTY=$1
144 local SPEED=$2
145 local FILENAME=$3
146
147 if [ ! -c "$TTY" ]; then
148 echo "$TTY is not a valid serial device"
Martin Roth8e0071b2014-07-10 15:00:35 -0600149 exit $EXIT_FAILURE
150 fi
151
152 # make the text more noticible
153 test_cmd $LOCAL "tput" $NONFATAL
154 tput_not_available=$?
155 if [ $tput_not_available -eq 0 ]; then
156 tput bold
157 tput setaf 10 # set bright green
158 fi
159
160 echo
Martin Rothd0128df2015-12-17 12:02:45 -0700161 echo "Waiting to receive boot log from $TTY"
David Hendricks0dcfb592017-09-16 18:43:08 -0700162 echo "Press [Enter] when the boot is complete."
Martin Rothd0128df2015-12-17 12:02:45 -0700163 echo
Martin Roth8e0071b2014-07-10 15:00:35 -0600164
165 if [ $tput_not_available -eq 0 ]; then
166 tput sgr0
167 fi
168
169 # set up the serial port
Martin Rothd0128df2015-12-17 12:02:45 -0700170 stty -F $TTY $SPEED cs8 -cstopb -parenb clocal
Martin Roth8e0071b2014-07-10 15:00:35 -0600171
172 # read from the serial port - user must press enter when complete
173 test_cmd $LOCAL "tee"
Martin Rothd0128df2015-12-17 12:02:45 -0700174 while read LINE; do
175 echo "$LINE" | tee -a "$FILENAME"
176 done < "$SERIAL_DEVICE" &
Martin Roth8e0071b2014-07-10 15:00:35 -0600177 PID=$!
178
Martin Rothd0128df2015-12-17 12:02:45 -0700179 read foo
180 kill "$PID" 2>/dev/null
Martin Roth8e0071b2014-07-10 15:00:35 -0600181
Martin Rothd0128df2015-12-17 12:02:45 -0700182 echo "Finished reading boot log."
Martin Roth8e0071b2014-07-10 15:00:35 -0600183}
184
David Hendricks1fc65f72013-11-12 16:49:45 -0800185show_help() {
186 echo "Usage:
187 ${0} <option>
188
189Options
David Hendricksc863be72017-09-16 12:59:23 -0700190 -c, --cbmem
191 Path to cbmem on device under test (DUT).
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300192 -n, --nvramtool
193 Path to nvramtool on device under test (DUT).
David Hendricksb2aa5282016-05-07 11:44:05 -0700194 -C, --clobber
David Hendricks1fc65f72013-11-12 16:49:45 -0800195 Clobber temporary output when finished. Useful for debugging.
David Hendricksb2aa5282016-05-07 11:44:05 -0700196 -h, --help
197 Show this message.
198 -i, --image <image>
David Hendricks1173bf32015-11-19 13:04:27 -0800199 Path to coreboot image (Default is $COREBOOT_IMAGE).
David Hendricksb2aa5282016-05-07 11:44:05 -0700200 -r, --remote-host <host>
David Hendricks1fc65f72013-11-12 16:49:45 -0800201 Obtain machine information from remote host (using ssh).
David Hendricksb2aa5282016-05-07 11:44:05 -0700202 -s, --serial-device </dev/xxx>
203 Obtain boot log via serial device.
204 -S, --serial-speed <speed>
205 Set the port speed for the serial device (Default is $SERIAL_PORT_SPEED).
206 -u, --upload-results
207 Upload results to coreboot.org.
208
209Long options:
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +0200210 --ssh-port <port>
211 Use a specific SSH port.
David Hendricks1fc65f72013-11-12 16:49:45 -0800212"
213}
214
Idwer Vollering3c707742021-01-11 14:02:29 +0100215case $(uname) in
216 FreeBSD)
217 if [ ! -x /usr/local/bin/getopt ]; then
218 echo "Please install getopt, or build and install misc/getopt from ports."
219 exit $EXIT_FAILURE
220 else
221 GETOPT=/usr/local/bin/getopt
222 fi
223 ;;
224 *)
225 GETOPT=/usr/bin/getopt
226 ;;
227esac
228
229$GETOPT -T
David Hendricks292be872016-04-26 14:07:42 -0700230if [ $? -ne 4 ]; then
231 echo "GNU-compatible getopt(1) required."
232 exit $EXIT_FAILURE
233fi
234
David Hendricksc863be72017-09-16 12:59:23 -0700235LONGOPTS="cbmem:,clobber,help,image:,remote-host:,upload-results"
David Hendricksb2aa5282016-05-07 11:44:05 -0700236LONGOPTS="${LONGOPTS},serial-device:,serial-speed:"
237LONGOPTS="${LONGOPTS},ssh-port:"
238
Idwer Vollering3c707742021-01-11 14:02:29 +0100239ARGS=$($GETOPT -o c:n:Chi:r:s:S:u -l "$LONGOPTS" -n "$0" -- "$@");
David Hendricks292be872016-04-26 14:07:42 -0700240if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
241eval set -- "$ARGS"
242while true ; do
243 case "$1" in
David Hendricksb2aa5282016-05-07 11:44:05 -0700244 # generic options
David Hendricksc863be72017-09-16 12:59:23 -0700245 -c|--cbmem)
246 shift
247 CBMEM_PATH="$1"
248 ;;
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300249 -n|--nvramtool)
250 shift
251 NVRAMTOOL_PATH="$1"
252 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700253 -C|--clobber)
254 CLOBBER_OUTPUT=1
255 ;;
256 -h|--help)
David Hendricks6583a812013-11-01 19:37:44 -0700257 show_help
258 exit $EXIT_SUCCESS
259 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700260 -i|--image)
David Hendricks292be872016-04-26 14:07:42 -0700261 shift
262 COREBOOT_IMAGE="$1"
David Hendricks1173bf32015-11-19 13:04:27 -0800263 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700264 -r|--remote-host)
David Hendricks292be872016-04-26 14:07:42 -0700265 shift
266 REMOTE_HOST="$1"
David Hendricks6583a812013-11-01 19:37:44 -0700267 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700268 -u|--upload-results)
269 UPLOAD_RESULTS=1
270 ;;
271
272 # serial port options
273 -s|--serial-device)
274 shift
275 SERIAL_DEVICE="$1"
276 ;;
277 -S|--serial-speed)
278 shift
279 SERIAL_PORT_SPEED="$1"
280 ;;
281
282 # ssh options
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +0200283 --ssh-port)
284 shift
285 REMOTE_PORT_OPTION="-p $1"
286 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700287
288 # error handling
David Hendricks292be872016-04-26 14:07:42 -0700289 --)
290 shift
291 if [ -n "$*" ]; then
292 echo "Non-option parameters detected: '$*'"
293 exit $EXIT_FAILURE
294 fi
295 break
296 ;;
297 *)
298 echo "error processing options at '$1'"
299 exit $EXIT_FAILURE
David Hendricks6583a812013-11-01 19:37:44 -0700300 esac
David Hendricks292be872016-04-26 14:07:42 -0700301 shift
David Hendricks6583a812013-11-01 19:37:44 -0700302done
303
David Hendricks1b6e7a62013-11-11 18:44:05 -0800304grep -rH 'coreboot.org' .git/config >/dev/null 2>&1
305if [ $? -ne 0 ]; then
306 echo "Script must be run from root of coreboot directory"
David Hendricks6583a812013-11-01 19:37:44 -0700307 exit $EXIT_FAILURE
308fi
309
Jonathan Neuschäfer0e962ee2016-05-17 17:38:10 +0200310if [ ! -e "$COREBOOT_IMAGE" ]; then
311 echo "board_status needs $COREBOOT_IMAGE, but it does not exist."
312 echo "Use \"-i IMAGE_FILE\" to select a different image, or \"--help\" for more options."
313 exit $EXIT_FAILURE
314fi
315
David Hendricks1b6e7a62013-11-11 18:44:05 -0800316# Results will be placed in a temporary location until we're ready to upload.
317# If the user does not wish to upload, results will remain in /tmp.
Idwer Volleringa3c44d82021-01-11 14:07:21 +0100318case $(uname) in
319 FreeBSD)
320 tmpdir=$(mktemp -d -t coreboot_board_status)
321 ;;
322 *)
323 tmpdir=$(mktemp -d --tmpdir coreboot_board_status.XXXXXXXX)
324 ;;
325esac
David Hendricks1b6e7a62013-11-11 18:44:05 -0800326
David Hendricks9f542972015-11-19 13:08:51 -0800327# Obtain coreboot config by running cbfstool on the ROM image. cbfstool may
328# already exist in build/ or util/cbfstool/, but if not then we'll build it
329# now and clean it when we're done.
Idwer Volleringb37ee1e2014-07-16 22:22:59 +0200330cbfstool_cmd="build/cbfstool"
David Hendricks9f542972015-11-19 13:08:51 -0800331do_clean_cbfstool=0
332if [ ! -x $cbfstool_cmd ]; then
333 cbfstool_cmd="util/cbfstool/cbfstool"
334 if [ -e $cbfstool_cmd ]; then
335 if test ! -x $cbfstool_cmd; then
336 echo "Cannot execute $cbfstool_cmd."
337 exit $EXIT_FAILURE
338 fi
339 else
Idwer Vollering22bcb562021-01-11 13:44:24 +0100340 $MAKE -C util/cbfstool/
David Hendricks9f542972015-11-19 13:08:51 -0800341 do_clean_cbfstool=1
342 fi
Idwer Volleringb37ee1e2014-07-16 22:22:59 +0200343fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800344test_cmd $LOCAL "$cbfstool_cmd"
David Hendricks9f542972015-11-19 13:08:51 -0800345
346tmpcfg=$(mktemp coreboot_config.XXXXXX)
David Hendricks1173bf32015-11-19 13:04:27 -0800347echo "Extracting config.txt from $COREBOOT_IMAGE"
348$cbfstool_cmd "$COREBOOT_IMAGE" extract -n config -f "${tmpdir}/config.txt" >/dev/null 2>&1
Martin Roth9f25da12015-12-17 12:49:15 -0700349mv "${tmpdir}/config.txt" "${tmpdir}/config.short.txt"
350cp "${tmpdir}/config.short.txt" "${tmpcfg}"
Idwer Vollering22bcb562021-01-11 13:44:24 +0100351yes "" | $MAKE "DOTCONFIG=${tmpcfg}" oldconfig 2>/dev/null >/dev/null
Martin Roth9f25da12015-12-17 12:49:15 -0700352mv "${tmpcfg}" "${tmpdir}/config.txt"
353rm -f "${tmpcfg}.old"
David Hendricks1173bf32015-11-19 13:04:27 -0800354$cbfstool_cmd "$COREBOOT_IMAGE" print > "${tmpdir}/cbfs.txt"
355rom_contents=$($cbfstool_cmd "$COREBOOT_IMAGE" print 2>&1)
Martin Roth2e44ea22015-12-17 12:33:39 -0700356if [ -n "$(echo $rom_contents | grep payload_config)" ]; then
David Hendricks1173bf32015-11-19 13:04:27 -0800357 echo "Extracting payload_config from $COREBOOT_IMAGE"
358 $cbfstool_cmd "$COREBOOT_IMAGE" extract -n payload_config -f "${tmpdir}/payload_config.txt" >/dev/null 2>&1
Martin Roth2e44ea22015-12-17 12:33:39 -0700359fi
360if [ -n "$(echo $rom_contents | grep payload_version)" ]; then
David Hendricks1173bf32015-11-19 13:04:27 -0800361 echo "Extracting payload_version from $COREBOOT_IMAGE"
362 $cbfstool_cmd "$COREBOOT_IMAGE" extract -n payload_version -f "${tmpdir}/payload_version.txt" >/dev/null 2>&1
Martin Roth2e44ea22015-12-17 12:33:39 -0700363fi
Idwer Volleringf0712792021-01-11 14:08:39 +0100364case $(uname) in
365 FreeBSD)
366 md5 "$COREBOOT_IMAGE" > "${tmpdir}/rom_checksum.txt"
367 ;;
368 *)
369 md5sum -b "$COREBOOT_IMAGE" > "${tmpdir}/rom_checksum.txt"
370 ;;
371esac
Paul Menzel1cc77e02015-02-19 19:35:58 +0100372
David Hendricks9f542972015-11-19 13:08:51 -0800373if test $do_clean_cbfstool -eq 1; then
Idwer Vollering22bcb562021-01-11 13:44:24 +0100374 $MAKE -C util/cbfstool clean
David Hendricks9f542972015-11-19 13:08:51 -0800375fi
376
Paul Menzel1cc77e02015-02-19 19:35:58 +0100377# Obtain board and revision info to form the directory structure:
378# <vendor>/<board>/<revision>/<timestamp>
Martin Roth9f25da12015-12-17 12:49:15 -0700379mainboard_dir="$(grep CONFIG_MAINBOARD_DIR "${tmpdir}/config.txt" | awk -F '"' '{ print $2 }')"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800380vendor=$(echo "$mainboard_dir" | awk -F '/' '{ print $1 }')
381mainboard=$(echo "$mainboard_dir" | awk -F '/' '{ print $2 }')
David Hendricks6583a812013-11-01 19:37:44 -0700382
David Hendricksc5e947ef2013-11-11 18:43:39 -0800383getrevision="util/board_status/getrevision.sh"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800384test_cmd $LOCAL $getrevision
385tagged_version=$($getrevision -T)
386timestamp=$($getrevision -t)
David Hendricks6583a812013-11-01 19:37:44 -0700387
David Hendricks1b6e7a62013-11-11 18:44:05 -0800388results="${vendor}/${mainboard}/${tagged_version}/${timestamp}"
David Hendricks6583a812013-11-01 19:37:44 -0700389
Paul Menzelc724ac12017-10-15 10:56:36 +0200390if [ -n "$(echo $tagged_version | grep dirty)" ]; then
391 echo "The repository is in a dirty state. Please see the output of"
392 echo "'git status' below."
393 git status
394 exit $EXIT_FAILURE
395fi
396
David Hendricks1b6e7a62013-11-11 18:44:05 -0800397echo "Temporarily placing output in ${tmpdir}/${results}"
398mkdir -p "${tmpdir}/${results}"
David Hendricks6583a812013-11-01 19:37:44 -0700399
David Hendricks1b6e7a62013-11-11 18:44:05 -0800400mv "${tmpdir}/config.txt" "${tmpdir}/${results}"
Martin Roth2e44ea22015-12-17 12:33:39 -0700401test -f "${tmpdir}/payload_config.txt" && mv "${tmpdir}/payload_config.txt" "${tmpdir}/${results}"
402test -f "${tmpdir}/payload_version.txt" && mv "${tmpdir}/payload_version.txt" "${tmpdir}/${results}"
Patrick Georgi368488a2015-06-12 11:35:10 +0200403mv "${tmpdir}/config.short.txt" "${tmpdir}/${results}"
Paul Menzel4b10bb72014-05-30 09:26:46 +0200404mv "${tmpdir}/cbfs.txt" "${tmpdir}/${results}"
Martin Roth072b5aa2015-12-17 12:44:35 -0700405mv "${tmpdir}/rom_checksum.txt" "${tmpdir}/${results}"
David Hendricks6583a812013-11-01 19:37:44 -0700406
Martin Roth9f25da12015-12-17 12:49:15 -0700407touch "${tmpdir}/${results}/revision.txt"
408printf "Local revision: %s\n" "$($getrevision -l)" >> "${tmpdir}/${results}/revision.txt"
409printf "Tagged revision: %s\n" "${tagged_version}" >> "${tmpdir}/${results}/revision.txt"
410printf "Upstream revision: %s\n" "$($getrevision -u)" >> "${tmpdir}/${results}/revision.txt"
411printf "Upstream URL: %s\n" "$($getrevision -U)" >> "${tmpdir}/${results}/revision.txt"
412printf "Timestamp: %s\n" "$timestamp" >> "${tmpdir}/${results}/revision.txt"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800413
David Hendricksc863be72017-09-16 12:59:23 -0700414if [ -n "$CBMEM_PATH" ]; then
415 cbmem_cmd="$CBMEM_PATH"
416else
417 cbmem_cmd="cbmem"
418fi
419
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300420cmos_enabled=0
421if grep -q "CONFIG_USE_OPTION_TABLE=y" "${tmpdir}/${results}/config.short.txt" > /dev/null; then
422 cmos_enabled=1
423fi
424
425if [ -n "$NVRAMTOOL_PATH" ]; then
426 nvramtool_cmd="$NVRAMTOOL_PATH"
427else
428 nvramtool_cmd="nvramtool"
429fi
430
David Hendricksbb90fb52017-09-16 13:01:13 -0700431if [ -n "$SERIAL_DEVICE" ]; then
432 get_serial_bootlog "$SERIAL_DEVICE" "$SERIAL_PORT_SPEED" "${tmpdir}/${results}/coreboot_console.txt"
433elif [ -n "$REMOTE_HOST" ]; then
Martin Roth574d1652015-12-17 12:38:45 -0700434 echo "Verifying that CBMEM is available on remote device"
David Hendricksc863be72017-09-16 12:59:23 -0700435 test_cmd $REMOTE "$cbmem_cmd"
Martin Roth574d1652015-12-17 12:38:45 -0700436 echo "Getting coreboot boot log"
Paul Menzelb7b085d2018-09-06 17:32:58 +0200437 cmd $REMOTE "$cbmem_cmd -1" "${tmpdir}/${results}/coreboot_console.txt"
Martin Roth574d1652015-12-17 12:38:45 -0700438 echo "Getting timestamp data"
David Hendricksc863be72017-09-16 12:59:23 -0700439 cmd_nonfatal $REMOTE "$cbmem_cmd -t" "${tmpdir}/${results}/coreboot_timestamps.txt"
David Hendricks0dcfb592017-09-16 18:43:08 -0700440
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300441 if [ "$cmos_enabled" -eq 1 ]; then
442 echo "Verifying that nvramtool is available on remote device"
443 test_cmd $REMOTE "$nvramtool_cmd"
444 echo "Getting all CMOS values"
445 cmd $REMOTE "$nvramtool_cmd -a" "${tmpdir}/${results}/cmos_values.txt"
446 fi
447
David Hendricks0dcfb592017-09-16 18:43:08 -0700448 echo "Getting remote dmesg"
Arthur Heymans7ccb2822018-12-16 22:38:58 +0100449 cmd $REMOTE dmesg "${tmpdir}/${results}/kernel_log.txt"
Martin Roth8e0071b2014-07-10 15:00:35 -0600450else
David Hendricksbb90fb52017-09-16 13:01:13 -0700451 echo "Verifying that CBMEM is available"
452 if [ $(id -u) -ne 0 ]; then
Matthias Gazzari25c7e322018-05-02 15:43:27 +0200453 command -v "$cbmem_cmd" >/dev/null
David Hendricksbb90fb52017-09-16 13:01:13 -0700454 if [ $? -ne 0 ]; then
Matthias Gazzari25c7e322018-05-02 15:43:27 +0200455 echo "Failed to run $cbmem_cmd. Check \$PATH or" \
456 "use -c to specify path to cbmem binary."
David Hendricksbb90fb52017-09-16 13:01:13 -0700457 exit $EXIT_FAILURE
458 else
459 cbmem_cmd="sudo $cbmem_cmd"
460 fi
461 else
462 test_cmd $LOCAL "$cbmem_cmd"
463 fi
464
465 echo "Getting coreboot boot log"
Paul Menzelb7b085d2018-09-06 17:32:58 +0200466 cmd $LOCAL "$cbmem_cmd -1" "${tmpdir}/${results}/coreboot_console.txt"
Paul Menzel5e20c1c2020-03-14 17:36:10 +0100467
David Hendricksbb90fb52017-09-16 13:01:13 -0700468 echo "Getting timestamp data"
469 cmd_nonfatal $LOCAL "$cbmem_cmd -t" "${tmpdir}/${results}/coreboot_timestamps.txt"
470
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300471 if [ "$cmos_enabled" -eq 1 ]; then
472 echo "Verifying that nvramtool is available"
473 if [ $(id -u) -ne 0 ]; then
474 command -v "$nvramtool_cmd" >/dev/null
475 if [ $? -ne 0 ]; then
476 echo "Failed to run $nvramtool_cmd. Check \$PATH or" \
477 "use -n to specify path to nvramtool binary."
478 exit $EXIT_FAILURE
479 else
480 nvramtool_cmd="sudo $nvramtool_cmd"
481 fi
482 else
483 test_cmd $LOCAL "$nvramtool_cmd"
484 fi
485
486 echo "Getting all CMOS values"
487 cmd $LOCAL "$nvramtool_cmd -a" "${tmpdir}/${results}/cmos_values.txt"
488 fi
489
David Hendricksbb90fb52017-09-16 13:01:13 -0700490 echo "Getting local dmesg"
Arthur Heymans7ccb2822018-12-16 22:38:58 +0100491 cmd $LOCAL "sudo dmesg" "${tmpdir}/${results}/kernel_log.txt"
Martin Roth8e0071b2014-07-10 15:00:35 -0600492fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800493
David Hendricksa4affe12013-11-12 18:17:19 -0800494#
Paul Menzel2c486622020-05-29 13:52:12 +0200495# Check files
496#
497if [ $(grep -- -dirty "${tmpdir}/${results}/coreboot_console.txt") ]; then
498 echo "coreboot or the payload are built from a source tree in a" \
499 "dirty state, making it hard to reproduce the result. Please" \
500 "check in your source tree with 'git status'."
501 exit $EXIT_FAILURE
502fi
503
Paul Menzeladface72021-07-03 15:44:05 +0200504if [ $(grep -- unknown "${tmpdir}/${results}/coreboot_timestamps.txt" >/dev/null 2>&1) ]; then
Paul Menzeldf5571d2020-05-29 02:24:09 +0200505 echo "Unknown timestamps found in 'coreboot_timestamps.txt'." \
506 "Please rebuild the 'cbmem' utility and try again."
507 exit $EXIT_FAILURE
508fi
509
Paul Menzel2c486622020-05-29 13:52:12 +0200510#
David Hendricksa4affe12013-11-12 18:17:19 -0800511# Finish up.
512#
Martin Rothbcd09932014-07-10 15:02:19 -0600513coreboot_dir=$(pwd)
David Hendricks1b6e7a62013-11-11 18:44:05 -0800514if [ $UPLOAD_RESULTS -eq 1 ]; then
515 # extract username from ssh://<username>@review.coreboot.org/blah
Patrick Georgi77b182a2014-08-10 15:18:22 +0200516 bsrepo=$(git config --get remote.origin.url | sed "s,\(.*\)/coreboot,\1/board-status,")
David Hendricks1b6e7a62013-11-11 18:44:05 -0800517
518 cd "util/board_status/"
519 if [ ! -e "board-status" ]; then
David Hendricksa4affe12013-11-12 18:17:19 -0800520 # FIXME: the board-status directory might get big over time.
521 # Is there a way we can push the results without fetching the
522 # whole repo?
Martin Roth9f25da12015-12-17 12:49:15 -0700523 git clone "$bsrepo"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800524 if [ $? -ne 0 ]; then
Paul Menzel749e0752015-05-20 22:32:15 +0200525 echo "Error cloning board-status repo, aborting."
David Hendricks1b6e7a62013-11-11 18:44:05 -0800526 exit $EXIT_FAILURE
527 fi
528 fi
529
530 cd "board-status"
Huimin Zhang2fb24832016-03-30 00:54:16 -0700531
532 echo "Checking for duplicate results"
533 # get any updates to board-status
534 git pull
535
536 echo "${tagged_version}" | grep dirty >/dev/null 2>&1
537 clean_version=$?
538 existing_results=$(git ls-files "${mainboard_dir}/${tagged_version}")
539
540 # reject duplicate results of non-dirty versions
541 if [ "${clean_version}" -eq 1 ] && [ -n "${existing_results}" ] ; then
542 echo "Result is a duplicate, aborting"
543 exit $EXIT_FAILURE
544 fi
545
David Hendricks1b6e7a62013-11-11 18:44:05 -0800546 echo "Copying results to $(pwd)/${results}"
547
548 # Note: Result directory should be unique due to the timestamp.
549 cp -R "${tmpdir}/${vendor}" .
550
551 echo "Uploading results"
552 git add "${vendor}"
Paul Menzel04eb2e82014-02-09 10:24:22 +0100553 git commit -a -m "${mainboard_dir}/${tagged_version}/${timestamp}"
Paul Menzel54e6aa72015-05-20 07:35:56 +0200554 count=0
Jonathan Neuschäfer478c8892016-05-10 17:43:53 +0200555 until git push origin master || test $count -eq 3; do
Paul Menzel54e6aa72015-05-20 07:35:56 +0200556 git pull --rebase
557 count=$((count + 1))
558 done
David Hendricks1b6e7a62013-11-11 18:44:05 -0800559
560 # Results have been uploaded so it's pointless to keep the
561 # temporary files around.
562 rm -rf "${tmpdir}"
Paul Menzel54e6aa72015-05-20 07:35:56 +0200563 if test $count -eq 3; then
564 echo "Error uploading to board-status repo, aborting."
565 exit $EXIT_FAILURE
566 fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800567fi
568cd "$coreboot_dir"
David Hendricks6583a812013-11-01 19:37:44 -0700569
570if [ $CLOBBER_OUTPUT -eq 1 ]; then
Martin Roth9f25da12015-12-17 12:49:15 -0700571 rm -rf "${tmpdir}"
Martin Roth13c7db82014-07-10 14:59:11 -0600572else
David Hendricks588a7222017-09-05 23:38:03 -0700573 if [ $UPLOAD_RESULTS -eq 1 ]; then
574 echo
575 echo "output files are in $(dirname $0)/board-status/${mainboard_dir}/${tagged_version}/${timestamp}"
576 else
577 echo
578 echo "output files are in ${tmpdir}/${results}"
579 fi
David Hendricks6583a812013-11-01 19:37:44 -0700580fi
581
582exit $EXIT_SUCCESS