blob: da199406693e4983fc45e066574cbdbe6d5b7fd2 [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 Hendricks09b573f2017-09-16 19:56:08 -07004# See README and https://www.coreboot.org/Board_Status for instructions.
David Hendricks6583a812013-11-01 19:37:44 -07005
6EXIT_SUCCESS=0
7EXIT_FAILURE=1
David Hendricks6583a812013-11-01 19:37:44 -07008
9# Stuff from command-line switches
David Hendricks1173bf32015-11-19 13:04:27 -080010COREBOOT_IMAGE="build/coreboot.rom"
David Hendricks6583a812013-11-01 19:37:44 -070011REMOTE_HOST=""
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +020012REMOTE_PORT_OPTION=""
David Hendricks6583a812013-11-01 19:37:44 -070013CLOBBER_OUTPUT=0
14UPLOAD_RESULTS=0
Martin Roth8e0071b2014-07-10 15:00:35 -060015SERIAL_PORT_SPEED=115200
David Hendricks6583a812013-11-01 19:37:44 -070016
David Hendricks1b6e7a62013-11-11 18:44:05 -080017# Used to specify whether a command should always be run locally or
18# if command should be run remoteley when a remote host is specified.
19LOCAL=0
20REMOTE=1
Martin Rothbe5340b2014-06-22 21:46:24 -060021FATAL=0
22NONFATAL=1
David Hendricks1b6e7a62013-11-11 18:44:05 -080023
David Hendricksc863be72017-09-16 12:59:23 -070024# Used if cbmem is not in default $PATH, e.g. not installed or when using `sudo`
25CBMEM_PATH=""
26
Evgeny Zinovievb8634682018-09-11 00:02:36 +030027# Used if nvramtool is not in default $PATH, e.g. not installed or when using `sudo`
28NVRAMTOOL_PATH=""
29
Idwer Vollering22bcb562021-01-11 13:44:24 +010030case $(uname) in
31 FreeBSD)
32 if [ ! -x /usr/local/bin/gmake ]; then
33 echo "Please install gmake, or build and install devel/gmake from ports."
34 exit $EXIT_FAILURE
35 else
Alexey Vazhnov15f84cc2021-02-13 20:22:53 +010036 MAKE='gmake'
Idwer Vollering22bcb562021-01-11 13:44:24 +010037 fi
38 ;;
39 *)
Alexey Vazhnov15f84cc2021-02-13 20:22:53 +010040 MAKE='make'
Idwer Vollering22bcb562021-01-11 13:44:24 +010041 ;;
42esac
43
David Hendricks6583a812013-11-01 19:37:44 -070044# test a command
45#
Martin Rothbcd09932014-07-10 15:02:19 -060046# $1: 0 ($LOCAL) to run command locally,
47# 1 ($REMOTE) to run remotely if remote host defined
David Hendricks6583a812013-11-01 19:37:44 -070048# $2: command to test
Martin Rothbe5340b2014-06-22 21:46:24 -060049# $3: 0 ($FATAL) Exit with an error if the command fails
50# 1 ($NONFATAL) Don't exit on command test failure
David Hendricks6583a812013-11-01 19:37:44 -070051test_cmd()
52{
53 local rc
54
55 if [ -e "$2" ]; then
56 return
57 fi
58
Vladimir Serbinenko77005b42014-01-21 02:39:46 +010059 if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +020060 ssh $REMOTE_PORT_OPTION root@${REMOTE_HOST} command -v "$2" > /dev/null
David Hendricks6583a812013-11-01 19:37:44 -070061 rc=$?
62 else
Patrick Georgi1cbef1c2015-08-10 10:21:14 +020063 command -v "$2" >/dev/null
David Hendricks6583a812013-11-01 19:37:44 -070064 rc=$?
65 fi
66
67 if [ $rc -eq 0 ]; then
Martin Rothbe5340b2014-06-22 21:46:24 -060068 return 0
69 fi
70
Patrick Georgi4ef309e2014-08-10 15:44:04 +020071 if [ "$3" = "1" ]; then
Martin Rothbe5340b2014-06-22 21:46:24 -060072 return 1
David Hendricks6583a812013-11-01 19:37:44 -070073 fi
74
75 echo "$2 not found"
76 exit $EXIT_FAILURE
77}
78
David Hendricksf8b90e42013-11-12 17:24:42 -080079_cmd()
David Hendricks6583a812013-11-01 19:37:44 -070080{
81 if [ -e "$2" ]; then
David Hendricksf8b90e42013-11-12 17:24:42 -080082 return $EXIT_FAILURE
David Hendricks6583a812013-11-01 19:37:44 -070083 fi
84
Martin Roth22461772014-07-10 14:57:34 -060085 if [ -n "$3" ]; then
86 pipe_location="${3}"
David Hendricks6583a812013-11-01 19:37:44 -070087 else
Martin Roth22461772014-07-10 14:57:34 -060088 pipe_location="/dev/null"
89 fi
90
91 if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +020092 ssh $REMOTE_PORT_OPTION "root@${REMOTE_HOST}" "$2" > "$pipe_location" 2>&1
Martin Roth22461772014-07-10 14:57:34 -060093 else
94 $2 > "$pipe_location" 2>&1
David Hendricks6583a812013-11-01 19:37:44 -070095 fi
David Hendricks406ce8a2013-11-12 18:10:23 -080096
97 return $?
David Hendricksf8b90e42013-11-12 17:24:42 -080098}
99
100# run a command
101#
Martin Rothbcd09932014-07-10 15:02:19 -0600102# $1: 0 ($LOCAL) to run command locally,
103# 1 ($REMOTE) to run remotely if remote host defined
David Hendricksf8b90e42013-11-12 17:24:42 -0800104# $2: command
David Hendricks406ce8a2013-11-12 18:10:23 -0800105# $3: filename to direct output of command into
David Hendricksf8b90e42013-11-12 17:24:42 -0800106cmd()
107{
David Hendricks406ce8a2013-11-12 18:10:23 -0800108 _cmd $1 "$2" "$3"
David Hendricks6583a812013-11-01 19:37:44 -0700109
110 if [ $? -eq 0 ]; then
111 return
112 fi
Zheng Bao86655cf2013-11-07 18:03:05 +0800113
David Hendricks406ce8a2013-11-12 18:10:23 -0800114 echo "Failed to run \"$2\", aborting"
115 rm -f "$3" # don't leave an empty file
David Hendricks6583a812013-11-01 19:37:44 -0700116 exit $EXIT_FAILURE
117}
118
David Hendricksf8b90e42013-11-12 17:24:42 -0800119# run a command where failure is considered to be non-fatal
120#
Martin Rothbcd09932014-07-10 15:02:19 -0600121# $1: 0 ($LOCAL) to run command locally,
122# 1 ($REMOTE) to run remotely if remote host defined
David Hendricksf8b90e42013-11-12 17:24:42 -0800123# $2: command
David Hendricks406ce8a2013-11-12 18:10:23 -0800124# $3: filename to direct output of command into
David Hendricksf8b90e42013-11-12 17:24:42 -0800125cmd_nonfatal()
126{
David Hendricks406ce8a2013-11-12 18:10:23 -0800127 _cmd $1 "$2" "$3"
David Hendricksf8b90e42013-11-12 17:24:42 -0800128
129 if [ $? -eq 0 ]; then
130 return
131 fi
132
David Hendricks406ce8a2013-11-12 18:10:23 -0800133 echo "Failed to run \"$2\", ignoring"
134 rm -f "$3" # don't leave an empty file
David Hendricksf8b90e42013-11-12 17:24:42 -0800135}
136
Martin Roth8e0071b2014-07-10 15:00:35 -0600137# read from a serial port device
138#
139# $1: serial device to read from
140# $2: serial port speed
141# $3: filename to direct output of command into
142get_serial_bootlog () {
143
Martin Rothd0128df2015-12-17 12:02:45 -0700144 local TTY=$1
145 local SPEED=$2
146 local FILENAME=$3
147
148 if [ ! -c "$TTY" ]; then
149 echo "$TTY is not a valid serial device"
Martin Roth8e0071b2014-07-10 15:00:35 -0600150 exit $EXIT_FAILURE
151 fi
152
153 # make the text more noticible
154 test_cmd $LOCAL "tput" $NONFATAL
155 tput_not_available=$?
156 if [ $tput_not_available -eq 0 ]; then
157 tput bold
158 tput setaf 10 # set bright green
159 fi
160
161 echo
Martin Rothd0128df2015-12-17 12:02:45 -0700162 echo "Waiting to receive boot log from $TTY"
David Hendricks0dcfb592017-09-16 18:43:08 -0700163 echo "Press [Enter] when the boot is complete."
Martin Rothd0128df2015-12-17 12:02:45 -0700164 echo
Martin Roth8e0071b2014-07-10 15:00:35 -0600165
166 if [ $tput_not_available -eq 0 ]; then
167 tput sgr0
168 fi
169
170 # set up the serial port
Martin Rothd0128df2015-12-17 12:02:45 -0700171 stty -F $TTY $SPEED cs8 -cstopb -parenb clocal
Martin Roth8e0071b2014-07-10 15:00:35 -0600172
173 # read from the serial port - user must press enter when complete
174 test_cmd $LOCAL "tee"
Martin Rothd0128df2015-12-17 12:02:45 -0700175 while read LINE; do
176 echo "$LINE" | tee -a "$FILENAME"
177 done < "$SERIAL_DEVICE" &
Martin Roth8e0071b2014-07-10 15:00:35 -0600178 PID=$!
179
Martin Rothd0128df2015-12-17 12:02:45 -0700180 read foo
181 kill "$PID" 2>/dev/null
Martin Roth8e0071b2014-07-10 15:00:35 -0600182
Martin Rothd0128df2015-12-17 12:02:45 -0700183 echo "Finished reading boot log."
Martin Roth8e0071b2014-07-10 15:00:35 -0600184}
185
David Hendricks1fc65f72013-11-12 16:49:45 -0800186show_help() {
187 echo "Usage:
188 ${0} <option>
189
190Options
David Hendricksc863be72017-09-16 12:59:23 -0700191 -c, --cbmem
192 Path to cbmem on device under test (DUT).
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300193 -n, --nvramtool
194 Path to nvramtool on device under test (DUT).
David Hendricksb2aa5282016-05-07 11:44:05 -0700195 -C, --clobber
David Hendricks1fc65f72013-11-12 16:49:45 -0800196 Clobber temporary output when finished. Useful for debugging.
David Hendricksb2aa5282016-05-07 11:44:05 -0700197 -h, --help
198 Show this message.
199 -i, --image <image>
David Hendricks1173bf32015-11-19 13:04:27 -0800200 Path to coreboot image (Default is $COREBOOT_IMAGE).
David Hendricksb2aa5282016-05-07 11:44:05 -0700201 -r, --remote-host <host>
David Hendricks1fc65f72013-11-12 16:49:45 -0800202 Obtain machine information from remote host (using ssh).
David Hendricksb2aa5282016-05-07 11:44:05 -0700203 -s, --serial-device </dev/xxx>
204 Obtain boot log via serial device.
205 -S, --serial-speed <speed>
206 Set the port speed for the serial device (Default is $SERIAL_PORT_SPEED).
207 -u, --upload-results
208 Upload results to coreboot.org.
209
210Long options:
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +0200211 --ssh-port <port>
212 Use a specific SSH port.
David Hendricks1fc65f72013-11-12 16:49:45 -0800213"
214}
215
Idwer Vollering3c707742021-01-11 14:02:29 +0100216case $(uname) in
217 FreeBSD)
218 if [ ! -x /usr/local/bin/getopt ]; then
219 echo "Please install getopt, or build and install misc/getopt from ports."
220 exit $EXIT_FAILURE
221 else
222 GETOPT=/usr/local/bin/getopt
223 fi
224 ;;
225 *)
226 GETOPT=/usr/bin/getopt
227 ;;
228esac
229
230$GETOPT -T
David Hendricks292be872016-04-26 14:07:42 -0700231if [ $? -ne 4 ]; then
232 echo "GNU-compatible getopt(1) required."
233 exit $EXIT_FAILURE
234fi
235
David Hendricksc863be72017-09-16 12:59:23 -0700236LONGOPTS="cbmem:,clobber,help,image:,remote-host:,upload-results"
David Hendricksb2aa5282016-05-07 11:44:05 -0700237LONGOPTS="${LONGOPTS},serial-device:,serial-speed:"
238LONGOPTS="${LONGOPTS},ssh-port:"
239
Idwer Vollering3c707742021-01-11 14:02:29 +0100240ARGS=$($GETOPT -o c:n:Chi:r:s:S:u -l "$LONGOPTS" -n "$0" -- "$@");
David Hendricks292be872016-04-26 14:07:42 -0700241if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
242eval set -- "$ARGS"
243while true ; do
244 case "$1" in
David Hendricksb2aa5282016-05-07 11:44:05 -0700245 # generic options
David Hendricksc863be72017-09-16 12:59:23 -0700246 -c|--cbmem)
247 shift
248 CBMEM_PATH="$1"
249 ;;
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300250 -n|--nvramtool)
251 shift
252 NVRAMTOOL_PATH="$1"
253 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700254 -C|--clobber)
255 CLOBBER_OUTPUT=1
256 ;;
257 -h|--help)
David Hendricks6583a812013-11-01 19:37:44 -0700258 show_help
259 exit $EXIT_SUCCESS
260 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700261 -i|--image)
David Hendricks292be872016-04-26 14:07:42 -0700262 shift
263 COREBOOT_IMAGE="$1"
David Hendricks1173bf32015-11-19 13:04:27 -0800264 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700265 -r|--remote-host)
David Hendricks292be872016-04-26 14:07:42 -0700266 shift
267 REMOTE_HOST="$1"
David Hendricks6583a812013-11-01 19:37:44 -0700268 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700269 -u|--upload-results)
270 UPLOAD_RESULTS=1
271 ;;
272
273 # serial port options
274 -s|--serial-device)
275 shift
276 SERIAL_DEVICE="$1"
277 ;;
278 -S|--serial-speed)
279 shift
280 SERIAL_PORT_SPEED="$1"
281 ;;
282
283 # ssh options
Jonathan Neuschäfer4aef6822016-05-10 17:43:53 +0200284 --ssh-port)
285 shift
286 REMOTE_PORT_OPTION="-p $1"
287 ;;
David Hendricksb2aa5282016-05-07 11:44:05 -0700288
289 # error handling
David Hendricks292be872016-04-26 14:07:42 -0700290 --)
291 shift
292 if [ -n "$*" ]; then
293 echo "Non-option parameters detected: '$*'"
294 exit $EXIT_FAILURE
295 fi
296 break
297 ;;
298 *)
299 echo "error processing options at '$1'"
300 exit $EXIT_FAILURE
David Hendricks6583a812013-11-01 19:37:44 -0700301 esac
David Hendricks292be872016-04-26 14:07:42 -0700302 shift
David Hendricks6583a812013-11-01 19:37:44 -0700303done
304
David Hendricks1b6e7a62013-11-11 18:44:05 -0800305grep -rH 'coreboot.org' .git/config >/dev/null 2>&1
306if [ $? -ne 0 ]; then
307 echo "Script must be run from root of coreboot directory"
David Hendricks6583a812013-11-01 19:37:44 -0700308 exit $EXIT_FAILURE
309fi
310
Jonathan Neuschäfer0e962ee2016-05-17 17:38:10 +0200311if [ ! -e "$COREBOOT_IMAGE" ]; then
312 echo "board_status needs $COREBOOT_IMAGE, but it does not exist."
313 echo "Use \"-i IMAGE_FILE\" to select a different image, or \"--help\" for more options."
314 exit $EXIT_FAILURE
315fi
316
David Hendricks1b6e7a62013-11-11 18:44:05 -0800317# Results will be placed in a temporary location until we're ready to upload.
318# If the user does not wish to upload, results will remain in /tmp.
Idwer Volleringa3c44d82021-01-11 14:07:21 +0100319case $(uname) in
320 FreeBSD)
321 tmpdir=$(mktemp -d -t coreboot_board_status)
322 ;;
323 *)
324 tmpdir=$(mktemp -d --tmpdir coreboot_board_status.XXXXXXXX)
325 ;;
326esac
David Hendricks1b6e7a62013-11-11 18:44:05 -0800327
David Hendricks9f542972015-11-19 13:08:51 -0800328# Obtain coreboot config by running cbfstool on the ROM image. cbfstool may
329# already exist in build/ or util/cbfstool/, but if not then we'll build it
330# now and clean it when we're done.
Idwer Volleringb37ee1e2014-07-16 22:22:59 +0200331cbfstool_cmd="build/cbfstool"
David Hendricks9f542972015-11-19 13:08:51 -0800332do_clean_cbfstool=0
333if [ ! -x $cbfstool_cmd ]; then
334 cbfstool_cmd="util/cbfstool/cbfstool"
335 if [ -e $cbfstool_cmd ]; then
336 if test ! -x $cbfstool_cmd; then
337 echo "Cannot execute $cbfstool_cmd."
338 exit $EXIT_FAILURE
339 fi
340 else
Idwer Vollering22bcb562021-01-11 13:44:24 +0100341 $MAKE -C util/cbfstool/
David Hendricks9f542972015-11-19 13:08:51 -0800342 do_clean_cbfstool=1
343 fi
Idwer Volleringb37ee1e2014-07-16 22:22:59 +0200344fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800345test_cmd $LOCAL "$cbfstool_cmd"
David Hendricks9f542972015-11-19 13:08:51 -0800346
347tmpcfg=$(mktemp coreboot_config.XXXXXX)
David Hendricks1173bf32015-11-19 13:04:27 -0800348echo "Extracting config.txt from $COREBOOT_IMAGE"
349$cbfstool_cmd "$COREBOOT_IMAGE" extract -n config -f "${tmpdir}/config.txt" >/dev/null 2>&1
Martin Roth9f25da12015-12-17 12:49:15 -0700350mv "${tmpdir}/config.txt" "${tmpdir}/config.short.txt"
351cp "${tmpdir}/config.short.txt" "${tmpcfg}"
Idwer Vollering22bcb562021-01-11 13:44:24 +0100352yes "" | $MAKE "DOTCONFIG=${tmpcfg}" oldconfig 2>/dev/null >/dev/null
Martin Roth9f25da12015-12-17 12:49:15 -0700353mv "${tmpcfg}" "${tmpdir}/config.txt"
354rm -f "${tmpcfg}.old"
David Hendricks1173bf32015-11-19 13:04:27 -0800355$cbfstool_cmd "$COREBOOT_IMAGE" print > "${tmpdir}/cbfs.txt"
356rom_contents=$($cbfstool_cmd "$COREBOOT_IMAGE" print 2>&1)
Martin Roth2e44ea22015-12-17 12:33:39 -0700357if [ -n "$(echo $rom_contents | grep payload_config)" ]; then
David Hendricks1173bf32015-11-19 13:04:27 -0800358 echo "Extracting payload_config from $COREBOOT_IMAGE"
359 $cbfstool_cmd "$COREBOOT_IMAGE" extract -n payload_config -f "${tmpdir}/payload_config.txt" >/dev/null 2>&1
Martin Roth2e44ea22015-12-17 12:33:39 -0700360fi
361if [ -n "$(echo $rom_contents | grep payload_version)" ]; then
David Hendricks1173bf32015-11-19 13:04:27 -0800362 echo "Extracting payload_version from $COREBOOT_IMAGE"
363 $cbfstool_cmd "$COREBOOT_IMAGE" extract -n payload_version -f "${tmpdir}/payload_version.txt" >/dev/null 2>&1
Martin Roth2e44ea22015-12-17 12:33:39 -0700364fi
Idwer Volleringf0712792021-01-11 14:08:39 +0100365case $(uname) in
366 FreeBSD)
367 md5 "$COREBOOT_IMAGE" > "${tmpdir}/rom_checksum.txt"
368 ;;
369 *)
370 md5sum -b "$COREBOOT_IMAGE" > "${tmpdir}/rom_checksum.txt"
371 ;;
372esac
Paul Menzel1cc77e02015-02-19 19:35:58 +0100373
David Hendricks9f542972015-11-19 13:08:51 -0800374if test $do_clean_cbfstool -eq 1; then
Idwer Vollering22bcb562021-01-11 13:44:24 +0100375 $MAKE -C util/cbfstool clean
David Hendricks9f542972015-11-19 13:08:51 -0800376fi
377
Paul Menzel1cc77e02015-02-19 19:35:58 +0100378# Obtain board and revision info to form the directory structure:
379# <vendor>/<board>/<revision>/<timestamp>
Martin Roth9f25da12015-12-17 12:49:15 -0700380mainboard_dir="$(grep CONFIG_MAINBOARD_DIR "${tmpdir}/config.txt" | awk -F '"' '{ print $2 }')"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800381vendor=$(echo "$mainboard_dir" | awk -F '/' '{ print $1 }')
382mainboard=$(echo "$mainboard_dir" | awk -F '/' '{ print $2 }')
David Hendricks6583a812013-11-01 19:37:44 -0700383
David Hendricksc5e947ef2013-11-11 18:43:39 -0800384getrevision="util/board_status/getrevision.sh"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800385test_cmd $LOCAL $getrevision
386tagged_version=$($getrevision -T)
387timestamp=$($getrevision -t)
David Hendricks6583a812013-11-01 19:37:44 -0700388
David Hendricks1b6e7a62013-11-11 18:44:05 -0800389results="${vendor}/${mainboard}/${tagged_version}/${timestamp}"
David Hendricks6583a812013-11-01 19:37:44 -0700390
Paul Menzelc724ac12017-10-15 10:56:36 +0200391if [ -n "$(echo $tagged_version | grep dirty)" ]; then
392 echo "The repository is in a dirty state. Please see the output of"
393 echo "'git status' below."
394 git status
395 exit $EXIT_FAILURE
396fi
397
David Hendricks1b6e7a62013-11-11 18:44:05 -0800398echo "Temporarily placing output in ${tmpdir}/${results}"
399mkdir -p "${tmpdir}/${results}"
David Hendricks6583a812013-11-01 19:37:44 -0700400
David Hendricks1b6e7a62013-11-11 18:44:05 -0800401mv "${tmpdir}/config.txt" "${tmpdir}/${results}"
Martin Roth2e44ea22015-12-17 12:33:39 -0700402test -f "${tmpdir}/payload_config.txt" && mv "${tmpdir}/payload_config.txt" "${tmpdir}/${results}"
403test -f "${tmpdir}/payload_version.txt" && mv "${tmpdir}/payload_version.txt" "${tmpdir}/${results}"
Patrick Georgi368488a2015-06-12 11:35:10 +0200404mv "${tmpdir}/config.short.txt" "${tmpdir}/${results}"
Paul Menzel4b10bb72014-05-30 09:26:46 +0200405mv "${tmpdir}/cbfs.txt" "${tmpdir}/${results}"
Martin Roth072b5aa2015-12-17 12:44:35 -0700406mv "${tmpdir}/rom_checksum.txt" "${tmpdir}/${results}"
David Hendricks6583a812013-11-01 19:37:44 -0700407
Martin Roth9f25da12015-12-17 12:49:15 -0700408touch "${tmpdir}/${results}/revision.txt"
409printf "Local revision: %s\n" "$($getrevision -l)" >> "${tmpdir}/${results}/revision.txt"
410printf "Tagged revision: %s\n" "${tagged_version}" >> "${tmpdir}/${results}/revision.txt"
411printf "Upstream revision: %s\n" "$($getrevision -u)" >> "${tmpdir}/${results}/revision.txt"
412printf "Upstream URL: %s\n" "$($getrevision -U)" >> "${tmpdir}/${results}/revision.txt"
413printf "Timestamp: %s\n" "$timestamp" >> "${tmpdir}/${results}/revision.txt"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800414
David Hendricksc863be72017-09-16 12:59:23 -0700415if [ -n "$CBMEM_PATH" ]; then
416 cbmem_cmd="$CBMEM_PATH"
417else
418 cbmem_cmd="cbmem"
419fi
420
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300421cmos_enabled=0
422if grep -q "CONFIG_USE_OPTION_TABLE=y" "${tmpdir}/${results}/config.short.txt" > /dev/null; then
423 cmos_enabled=1
424fi
425
426if [ -n "$NVRAMTOOL_PATH" ]; then
427 nvramtool_cmd="$NVRAMTOOL_PATH"
428else
429 nvramtool_cmd="nvramtool"
430fi
431
David Hendricksbb90fb52017-09-16 13:01:13 -0700432if [ -n "$SERIAL_DEVICE" ]; then
433 get_serial_bootlog "$SERIAL_DEVICE" "$SERIAL_PORT_SPEED" "${tmpdir}/${results}/coreboot_console.txt"
434elif [ -n "$REMOTE_HOST" ]; then
Martin Roth574d1652015-12-17 12:38:45 -0700435 echo "Verifying that CBMEM is available on remote device"
David Hendricksc863be72017-09-16 12:59:23 -0700436 test_cmd $REMOTE "$cbmem_cmd"
Martin Roth574d1652015-12-17 12:38:45 -0700437 echo "Getting coreboot boot log"
Paul Menzelb7b085d2018-09-06 17:32:58 +0200438 cmd $REMOTE "$cbmem_cmd -1" "${tmpdir}/${results}/coreboot_console.txt"
Martin Roth574d1652015-12-17 12:38:45 -0700439 echo "Getting timestamp data"
David Hendricksc863be72017-09-16 12:59:23 -0700440 cmd_nonfatal $REMOTE "$cbmem_cmd -t" "${tmpdir}/${results}/coreboot_timestamps.txt"
David Hendricks0dcfb592017-09-16 18:43:08 -0700441
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300442 if [ "$cmos_enabled" -eq 1 ]; then
443 echo "Verifying that nvramtool is available on remote device"
444 test_cmd $REMOTE "$nvramtool_cmd"
445 echo "Getting all CMOS values"
446 cmd $REMOTE "$nvramtool_cmd -a" "${tmpdir}/${results}/cmos_values.txt"
447 fi
448
David Hendricks0dcfb592017-09-16 18:43:08 -0700449 echo "Getting remote dmesg"
Arthur Heymans7ccb2822018-12-16 22:38:58 +0100450 cmd $REMOTE dmesg "${tmpdir}/${results}/kernel_log.txt"
Martin Roth8e0071b2014-07-10 15:00:35 -0600451else
David Hendricksbb90fb52017-09-16 13:01:13 -0700452 echo "Verifying that CBMEM is available"
453 if [ $(id -u) -ne 0 ]; then
Matthias Gazzari25c7e322018-05-02 15:43:27 +0200454 command -v "$cbmem_cmd" >/dev/null
David Hendricksbb90fb52017-09-16 13:01:13 -0700455 if [ $? -ne 0 ]; then
Matthias Gazzari25c7e322018-05-02 15:43:27 +0200456 echo "Failed to run $cbmem_cmd. Check \$PATH or" \
457 "use -c to specify path to cbmem binary."
David Hendricksbb90fb52017-09-16 13:01:13 -0700458 exit $EXIT_FAILURE
459 else
460 cbmem_cmd="sudo $cbmem_cmd"
461 fi
462 else
463 test_cmd $LOCAL "$cbmem_cmd"
464 fi
465
466 echo "Getting coreboot boot log"
Paul Menzelb7b085d2018-09-06 17:32:58 +0200467 cmd $LOCAL "$cbmem_cmd -1" "${tmpdir}/${results}/coreboot_console.txt"
Paul Menzel5e20c1c2020-03-14 17:36:10 +0100468
David Hendricksbb90fb52017-09-16 13:01:13 -0700469 echo "Getting timestamp data"
470 cmd_nonfatal $LOCAL "$cbmem_cmd -t" "${tmpdir}/${results}/coreboot_timestamps.txt"
471
Evgeny Zinovievb8634682018-09-11 00:02:36 +0300472 if [ "$cmos_enabled" -eq 1 ]; then
473 echo "Verifying that nvramtool is available"
474 if [ $(id -u) -ne 0 ]; then
475 command -v "$nvramtool_cmd" >/dev/null
476 if [ $? -ne 0 ]; then
477 echo "Failed to run $nvramtool_cmd. Check \$PATH or" \
478 "use -n to specify path to nvramtool binary."
479 exit $EXIT_FAILURE
480 else
481 nvramtool_cmd="sudo $nvramtool_cmd"
482 fi
483 else
484 test_cmd $LOCAL "$nvramtool_cmd"
485 fi
486
487 echo "Getting all CMOS values"
488 cmd $LOCAL "$nvramtool_cmd -a" "${tmpdir}/${results}/cmos_values.txt"
489 fi
490
David Hendricksbb90fb52017-09-16 13:01:13 -0700491 echo "Getting local dmesg"
Arthur Heymans7ccb2822018-12-16 22:38:58 +0100492 cmd $LOCAL "sudo dmesg" "${tmpdir}/${results}/kernel_log.txt"
Martin Roth8e0071b2014-07-10 15:00:35 -0600493fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800494
David Hendricksa4affe12013-11-12 18:17:19 -0800495#
Paul Menzel2c486622020-05-29 13:52:12 +0200496# Check files
497#
498if [ $(grep -- -dirty "${tmpdir}/${results}/coreboot_console.txt") ]; then
499 echo "coreboot or the payload are built from a source tree in a" \
500 "dirty state, making it hard to reproduce the result. Please" \
501 "check in your source tree with 'git status'."
502 exit $EXIT_FAILURE
503fi
504
Paul Menzeladface72021-07-03 15:44:05 +0200505if [ $(grep -- unknown "${tmpdir}/${results}/coreboot_timestamps.txt" >/dev/null 2>&1) ]; then
Paul Menzeldf5571d2020-05-29 02:24:09 +0200506 echo "Unknown timestamps found in 'coreboot_timestamps.txt'." \
507 "Please rebuild the 'cbmem' utility and try again."
508 exit $EXIT_FAILURE
509fi
510
Paul Menzel2c486622020-05-29 13:52:12 +0200511#
David Hendricksa4affe12013-11-12 18:17:19 -0800512# Finish up.
513#
Martin Rothbcd09932014-07-10 15:02:19 -0600514coreboot_dir=$(pwd)
David Hendricks1b6e7a62013-11-11 18:44:05 -0800515if [ $UPLOAD_RESULTS -eq 1 ]; then
516 # extract username from ssh://<username>@review.coreboot.org/blah
Patrick Georgi77b182a2014-08-10 15:18:22 +0200517 bsrepo=$(git config --get remote.origin.url | sed "s,\(.*\)/coreboot,\1/board-status,")
David Hendricks1b6e7a62013-11-11 18:44:05 -0800518
519 cd "util/board_status/"
520 if [ ! -e "board-status" ]; then
David Hendricksa4affe12013-11-12 18:17:19 -0800521 # FIXME: the board-status directory might get big over time.
522 # Is there a way we can push the results without fetching the
523 # whole repo?
Martin Roth9f25da12015-12-17 12:49:15 -0700524 git clone "$bsrepo"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800525 if [ $? -ne 0 ]; then
Paul Menzel749e0752015-05-20 22:32:15 +0200526 echo "Error cloning board-status repo, aborting."
David Hendricks1b6e7a62013-11-11 18:44:05 -0800527 exit $EXIT_FAILURE
528 fi
529 fi
530
531 cd "board-status"
Huimin Zhang2fb24832016-03-30 00:54:16 -0700532
533 echo "Checking for duplicate results"
534 # get any updates to board-status
535 git pull
536
537 echo "${tagged_version}" | grep dirty >/dev/null 2>&1
538 clean_version=$?
539 existing_results=$(git ls-files "${mainboard_dir}/${tagged_version}")
540
541 # reject duplicate results of non-dirty versions
542 if [ "${clean_version}" -eq 1 ] && [ -n "${existing_results}" ] ; then
543 echo "Result is a duplicate, aborting"
544 exit $EXIT_FAILURE
545 fi
546
David Hendricks1b6e7a62013-11-11 18:44:05 -0800547 echo "Copying results to $(pwd)/${results}"
548
549 # Note: Result directory should be unique due to the timestamp.
550 cp -R "${tmpdir}/${vendor}" .
551
552 echo "Uploading results"
553 git add "${vendor}"
Paul Menzel04eb2e82014-02-09 10:24:22 +0100554 git commit -a -m "${mainboard_dir}/${tagged_version}/${timestamp}"
Paul Menzel54e6aa72015-05-20 07:35:56 +0200555 count=0
Nicholas Chin8d45f9a2023-08-19 22:07:15 -0600556 until git push origin main || test $count -eq 3; do
Paul Menzel54e6aa72015-05-20 07:35:56 +0200557 git pull --rebase
558 count=$((count + 1))
559 done
David Hendricks1b6e7a62013-11-11 18:44:05 -0800560
561 # Results have been uploaded so it's pointless to keep the
562 # temporary files around.
563 rm -rf "${tmpdir}"
Paul Menzel54e6aa72015-05-20 07:35:56 +0200564 if test $count -eq 3; then
565 echo "Error uploading to board-status repo, aborting."
566 exit $EXIT_FAILURE
567 fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800568fi
569cd "$coreboot_dir"
David Hendricks6583a812013-11-01 19:37:44 -0700570
571if [ $CLOBBER_OUTPUT -eq 1 ]; then
Martin Roth9f25da12015-12-17 12:49:15 -0700572 rm -rf "${tmpdir}"
Martin Roth13c7db82014-07-10 14:59:11 -0600573else
David Hendricks588a7222017-09-05 23:38:03 -0700574 if [ $UPLOAD_RESULTS -eq 1 ]; then
575 echo
576 echo "output files are in $(dirname $0)/board-status/${mainboard_dir}/${tagged_version}/${timestamp}"
577 else
578 echo
579 echo "output files are in ${tmpdir}/${results}"
580 fi
David Hendricks6583a812013-11-01 19:37:44 -0700581fi
582
583exit $EXIT_SUCCESS