blob: 1fb599ed3b48c8b4d1201f3ecf97a8c128c45aef [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
13REMOTE_HOST=""
14CLOBBER_OUTPUT=0
15UPLOAD_RESULTS=0
Martin Roth8e0071b2014-07-10 15:00:35 -060016SERIAL_PORT_SPEED=115200
David Hendricks6583a812013-11-01 19:37:44 -070017
David Hendricks1b6e7a62013-11-11 18:44:05 -080018# Used to specify whether a command should always be run locally or
19# if command should be run remoteley when a remote host is specified.
20LOCAL=0
21REMOTE=1
Martin Rothbe5340b2014-06-22 21:46:24 -060022FATAL=0
23NONFATAL=1
David Hendricks1b6e7a62013-11-11 18:44:05 -080024
David Hendricks6583a812013-11-01 19:37:44 -070025# test a command
26#
Martin Rothbcd09932014-07-10 15:02:19 -060027# $1: 0 ($LOCAL) to run command locally,
28# 1 ($REMOTE) to run remotely if remote host defined
David Hendricks6583a812013-11-01 19:37:44 -070029# $2: command to test
Martin Rothbe5340b2014-06-22 21:46:24 -060030# $3: 0 ($FATAL) Exit with an error if the command fails
31# 1 ($NONFATAL) Don't exit on command test failure
David Hendricks6583a812013-11-01 19:37:44 -070032test_cmd()
33{
34 local rc
35
36 if [ -e "$2" ]; then
37 return
38 fi
39
Vladimir Serbinenko77005b42014-01-21 02:39:46 +010040 if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
Patrick Georgi1cbef1c2015-08-10 10:21:14 +020041 ssh root@${REMOTE_HOST} command -v "$2" > /dev/null
David Hendricks6583a812013-11-01 19:37:44 -070042 rc=$?
43 else
Patrick Georgi1cbef1c2015-08-10 10:21:14 +020044 command -v "$2" >/dev/null
David Hendricks6583a812013-11-01 19:37:44 -070045 rc=$?
46 fi
47
48 if [ $rc -eq 0 ]; then
Martin Rothbe5340b2014-06-22 21:46:24 -060049 return 0
50 fi
51
Patrick Georgi4ef309e2014-08-10 15:44:04 +020052 if [ "$3" = "1" ]; then
Martin Rothbe5340b2014-06-22 21:46:24 -060053 return 1
David Hendricks6583a812013-11-01 19:37:44 -070054 fi
55
56 echo "$2 not found"
57 exit $EXIT_FAILURE
58}
59
David Hendricksf8b90e42013-11-12 17:24:42 -080060_cmd()
David Hendricks6583a812013-11-01 19:37:44 -070061{
62 if [ -e "$2" ]; then
David Hendricksf8b90e42013-11-12 17:24:42 -080063 return $EXIT_FAILURE
David Hendricks6583a812013-11-01 19:37:44 -070064 fi
65
Martin Roth22461772014-07-10 14:57:34 -060066 if [ -n "$3" ]; then
67 pipe_location="${3}"
David Hendricks6583a812013-11-01 19:37:44 -070068 else
Martin Roth22461772014-07-10 14:57:34 -060069 pipe_location="/dev/null"
70 fi
71
72 if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
Martin Roth9f25da12015-12-17 12:49:15 -070073 ssh "root@${REMOTE_HOST}" "$2" > "$pipe_location" 2>&1
Martin Roth22461772014-07-10 14:57:34 -060074 else
75 $2 > "$pipe_location" 2>&1
David Hendricks6583a812013-11-01 19:37:44 -070076 fi
David Hendricks406ce8a2013-11-12 18:10:23 -080077
78 return $?
David Hendricksf8b90e42013-11-12 17:24:42 -080079}
80
81# run a command
82#
Martin Rothbcd09932014-07-10 15:02:19 -060083# $1: 0 ($LOCAL) to run command locally,
84# 1 ($REMOTE) to run remotely if remote host defined
David Hendricksf8b90e42013-11-12 17:24:42 -080085# $2: command
David Hendricks406ce8a2013-11-12 18:10:23 -080086# $3: filename to direct output of command into
David Hendricksf8b90e42013-11-12 17:24:42 -080087cmd()
88{
David Hendricks406ce8a2013-11-12 18:10:23 -080089 _cmd $1 "$2" "$3"
David Hendricks6583a812013-11-01 19:37:44 -070090
91 if [ $? -eq 0 ]; then
92 return
93 fi
Zheng Bao86655cf2013-11-07 18:03:05 +080094
David Hendricks406ce8a2013-11-12 18:10:23 -080095 echo "Failed to run \"$2\", aborting"
96 rm -f "$3" # don't leave an empty file
David Hendricks6583a812013-11-01 19:37:44 -070097 exit $EXIT_FAILURE
98}
99
David Hendricksf8b90e42013-11-12 17:24:42 -0800100# run a command where failure is considered to be non-fatal
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_nonfatal()
107{
David Hendricks406ce8a2013-11-12 18:10:23 -0800108 _cmd $1 "$2" "$3"
David Hendricksf8b90e42013-11-12 17:24:42 -0800109
110 if [ $? -eq 0 ]; then
111 return
112 fi
113
David Hendricks406ce8a2013-11-12 18:10:23 -0800114 echo "Failed to run \"$2\", ignoring"
115 rm -f "$3" # don't leave an empty file
David Hendricksf8b90e42013-11-12 17:24:42 -0800116}
117
Martin Roth8e0071b2014-07-10 15:00:35 -0600118# read from a serial port device
119#
120# $1: serial device to read from
121# $2: serial port speed
122# $3: filename to direct output of command into
123get_serial_bootlog () {
124
Martin Rothd0128df2015-12-17 12:02:45 -0700125 local TTY=$1
126 local SPEED=$2
127 local FILENAME=$3
128
129 if [ ! -c "$TTY" ]; then
130 echo "$TTY is not a valid serial device"
Martin Roth8e0071b2014-07-10 15:00:35 -0600131 exit $EXIT_FAILURE
132 fi
133
134 # make the text more noticible
135 test_cmd $LOCAL "tput" $NONFATAL
136 tput_not_available=$?
137 if [ $tput_not_available -eq 0 ]; then
138 tput bold
139 tput setaf 10 # set bright green
140 fi
141
142 echo
Martin Rothd0128df2015-12-17 12:02:45 -0700143 echo "Waiting to receive boot log from $TTY"
Martin Roth8e0071b2014-07-10 15:00:35 -0600144 echo "Press [Enter] when the boot is complete and the"
145 echo "system is ready for ssh to get the dmesg log."
Martin Rothd0128df2015-12-17 12:02:45 -0700146 echo
Martin Roth8e0071b2014-07-10 15:00:35 -0600147
148 if [ $tput_not_available -eq 0 ]; then
149 tput sgr0
150 fi
151
152 # set up the serial port
Martin Rothd0128df2015-12-17 12:02:45 -0700153 stty -F $TTY $SPEED cs8 -cstopb -parenb clocal
Martin Roth8e0071b2014-07-10 15:00:35 -0600154
155 # read from the serial port - user must press enter when complete
156 test_cmd $LOCAL "tee"
Martin Rothd0128df2015-12-17 12:02:45 -0700157 while read LINE; do
158 echo "$LINE" | tee -a "$FILENAME"
159 done < "$SERIAL_DEVICE" &
Martin Roth8e0071b2014-07-10 15:00:35 -0600160 PID=$!
161
Martin Rothd0128df2015-12-17 12:02:45 -0700162 read foo
163 kill "$PID" 2>/dev/null
Martin Roth8e0071b2014-07-10 15:00:35 -0600164
Martin Rothd0128df2015-12-17 12:02:45 -0700165 echo "Finished reading boot log."
Martin Roth8e0071b2014-07-10 15:00:35 -0600166}
167
David Hendricks1fc65f72013-11-12 16:49:45 -0800168show_help() {
169 echo "Usage:
170 ${0} <option>
171
172Options
173 -h
174 Show this message.
175 -C
176 Clobber temporary output when finished. Useful for debugging.
177 -r <host>
178 Obtain machine information from remote host (using ssh).
Martin Roth8e0071b2014-07-10 15:00:35 -0600179 -s </dev/xxx>
180 Obtain boot log via serial device.
181 -S <speed>
Martin Rothd0128df2015-12-17 12:02:45 -0700182 Set the port speed for the serial device (Default is $SERIAL_PORT_SPEED).
David Hendricks1fc65f72013-11-12 16:49:45 -0800183 -u
184 Upload results to coreboot.org.
185"
186}
187
Martin Roth8e0071b2014-07-10 15:00:35 -0600188while getopts "Chr:s:S:u" opt; do
David Hendricks6583a812013-11-01 19:37:44 -0700189 case "$opt" in
190 h)
191 show_help
192 exit $EXIT_SUCCESS
193 ;;
David Hendricks16955fd2013-11-12 16:45:37 -0800194 C)
David Hendricks6583a812013-11-01 19:37:44 -0700195 CLOBBER_OUTPUT=1
196 ;;
197 r)
198 REMOTE_HOST="$OPTARG"
199 ;;
Martin Roth8e0071b2014-07-10 15:00:35 -0600200 s)
201 SERIAL_DEVICE="$OPTARG"
202 ;;
203 S)
204 SERIAL_PORT_SPEED="$OPTARG"
205 ;;
David Hendricks6583a812013-11-01 19:37:44 -0700206 u)
207 UPLOAD_RESULTS=1
208 ;;
209 esac
210done
211
David Hendricks1b6e7a62013-11-11 18:44:05 -0800212grep -rH 'coreboot.org' .git/config >/dev/null 2>&1
213if [ $? -ne 0 ]; then
214 echo "Script must be run from root of coreboot directory"
David Hendricks6583a812013-11-01 19:37:44 -0700215 exit $EXIT_FAILURE
216fi
217
David Hendricks1b6e7a62013-11-11 18:44:05 -0800218# Results will be placed in a temporary location until we're ready to upload.
219# If the user does not wish to upload, results will remain in /tmp.
Patrick Georgiaa7dcef2015-08-13 07:57:26 +0200220tmpdir=$(mktemp -d --tmpdir coreboot_board_status.XXXXXXXX)
221tmpcfg=$(mktemp coreboot_config.XXXXXX)
David Hendricks1b6e7a62013-11-11 18:44:05 -0800222
Idwer Volleringb37ee1e2014-07-16 22:22:59 +0200223cbfstool_cmd="build/cbfstool"
224if test ! -x build/cbfstool; then
225 make -C util/cbfstool/ && cp util/cbfstool/cbfstool build/cbfstool
226fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800227test_cmd $LOCAL "$cbfstool_cmd"
Martin Roth574d1652015-12-17 12:38:45 -0700228echo "Extracting config.txt from build/coreboot.rom"
229$cbfstool_cmd build/coreboot.rom extract -n config -f "${tmpdir}/config.txt" >/dev/null 2>&1
Martin Roth9f25da12015-12-17 12:49:15 -0700230mv "${tmpdir}/config.txt" "${tmpdir}/config.short.txt"
231cp "${tmpdir}/config.short.txt" "${tmpcfg}"
232yes "" | make "DOTCONFIG=${tmpcfg}" oldconfig 2>/dev/null >/dev/null
233mv "${tmpcfg}" "${tmpdir}/config.txt"
234rm -f "${tmpcfg}.old"
235$cbfstool_cmd build/coreboot.rom print > "${tmpdir}/cbfs.txt"
Martin Roth2e44ea22015-12-17 12:33:39 -0700236rom_contents=$($cbfstool_cmd build/coreboot.rom print 2>&1)
237if [ -n "$(echo $rom_contents | grep payload_config)" ]; then
238 echo "Extracting payload_config from build/coreboot.rom"
239 $cbfstool_cmd build/coreboot.rom extract -n payload_config -f "${tmpdir}/payload_config.txt" >/dev/null 2>&1
240fi
241if [ -n "$(echo $rom_contents | grep payload_version)" ]; then
242 echo "Extracting payload_version from build/coreboot.rom"
243 $cbfstool_cmd build/coreboot.rom extract -n payload_version -f "${tmpdir}/payload_version.txt" >/dev/null 2>&1
244fi
Martin Roth072b5aa2015-12-17 12:44:35 -0700245md5sum -b build/coreboot.rom > "${tmpdir}/rom_checksum.txt"
Paul Menzel1cc77e02015-02-19 19:35:58 +0100246
247# Obtain board and revision info to form the directory structure:
248# <vendor>/<board>/<revision>/<timestamp>
Martin Roth9f25da12015-12-17 12:49:15 -0700249mainboard_dir="$(grep CONFIG_MAINBOARD_DIR "${tmpdir}/config.txt" | awk -F '"' '{ print $2 }')"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800250vendor=$(echo "$mainboard_dir" | awk -F '/' '{ print $1 }')
251mainboard=$(echo "$mainboard_dir" | awk -F '/' '{ print $2 }')
David Hendricks6583a812013-11-01 19:37:44 -0700252
David Hendricksc5e947ef2013-11-11 18:43:39 -0800253getrevision="util/board_status/getrevision.sh"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800254test_cmd $LOCAL $getrevision
255tagged_version=$($getrevision -T)
256timestamp=$($getrevision -t)
David Hendricks6583a812013-11-01 19:37:44 -0700257
David Hendricks1b6e7a62013-11-11 18:44:05 -0800258results="${vendor}/${mainboard}/${tagged_version}/${timestamp}"
David Hendricks6583a812013-11-01 19:37:44 -0700259
David Hendricks1b6e7a62013-11-11 18:44:05 -0800260echo "Temporarily placing output in ${tmpdir}/${results}"
261mkdir -p "${tmpdir}/${results}"
David Hendricks6583a812013-11-01 19:37:44 -0700262
David Hendricks1b6e7a62013-11-11 18:44:05 -0800263mv "${tmpdir}/config.txt" "${tmpdir}/${results}"
Martin Roth2e44ea22015-12-17 12:33:39 -0700264test -f "${tmpdir}/payload_config.txt" && mv "${tmpdir}/payload_config.txt" "${tmpdir}/${results}"
265test -f "${tmpdir}/payload_version.txt" && mv "${tmpdir}/payload_version.txt" "${tmpdir}/${results}"
Patrick Georgi368488a2015-06-12 11:35:10 +0200266mv "${tmpdir}/config.short.txt" "${tmpdir}/${results}"
Paul Menzel4b10bb72014-05-30 09:26:46 +0200267mv "${tmpdir}/cbfs.txt" "${tmpdir}/${results}"
Martin Roth072b5aa2015-12-17 12:44:35 -0700268mv "${tmpdir}/rom_checksum.txt" "${tmpdir}/${results}"
David Hendricks6583a812013-11-01 19:37:44 -0700269
Martin Roth9f25da12015-12-17 12:49:15 -0700270touch "${tmpdir}/${results}/revision.txt"
271printf "Local revision: %s\n" "$($getrevision -l)" >> "${tmpdir}/${results}/revision.txt"
272printf "Tagged revision: %s\n" "${tagged_version}" >> "${tmpdir}/${results}/revision.txt"
273printf "Upstream revision: %s\n" "$($getrevision -u)" >> "${tmpdir}/${results}/revision.txt"
274printf "Upstream URL: %s\n" "$($getrevision -U)" >> "${tmpdir}/${results}/revision.txt"
275printf "Timestamp: %s\n" "$timestamp" >> "${tmpdir}/${results}/revision.txt"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800276
Martin Roth8e0071b2014-07-10 15:00:35 -0600277if [ -z "$SERIAL_DEVICE" ]; then
Martin Roth574d1652015-12-17 12:38:45 -0700278 echo "Verifying that CBMEM is available on remote device"
Martin Roth8e0071b2014-07-10 15:00:35 -0600279 test_cmd $REMOTE "cbmem"
Martin Roth574d1652015-12-17 12:38:45 -0700280 echo "Getting coreboot boot log"
Martin Roth8e0071b2014-07-10 15:00:35 -0600281 cmd $REMOTE "cbmem -c" "${tmpdir}/${results}/coreboot_console.txt"
Martin Roth574d1652015-12-17 12:38:45 -0700282 echo "Getting timestamp data"
Martin Roth8e0071b2014-07-10 15:00:35 -0600283 cmd_nonfatal $REMOTE "cbmem -t" "${tmpdir}/${results}/coreboot_timestamps.txt"
284else
285 get_serial_bootlog "$SERIAL_DEVICE" "$SERIAL_PORT_SPEED" "${tmpdir}/${results}/coreboot_console.txt"
286fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800287
Martin Roth574d1652015-12-17 12:38:45 -0700288echo "Getting remote dmesg"
David Hendricks406ce8a2013-11-12 18:10:23 -0800289cmd $REMOTE dmesg "${tmpdir}/${results}/kernel_log.txt"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800290
David Hendricksa4affe12013-11-12 18:17:19 -0800291#
292# Finish up.
293#
Martin Rothbcd09932014-07-10 15:02:19 -0600294coreboot_dir=$(pwd)
David Hendricks1b6e7a62013-11-11 18:44:05 -0800295if [ $UPLOAD_RESULTS -eq 1 ]; then
296 # extract username from ssh://<username>@review.coreboot.org/blah
Patrick Georgi77b182a2014-08-10 15:18:22 +0200297 bsrepo=$(git config --get remote.origin.url | sed "s,\(.*\)/coreboot,\1/board-status,")
David Hendricks1b6e7a62013-11-11 18:44:05 -0800298
299 cd "util/board_status/"
300 if [ ! -e "board-status" ]; then
David Hendricksa4affe12013-11-12 18:17:19 -0800301 # FIXME: the board-status directory might get big over time.
302 # Is there a way we can push the results without fetching the
303 # whole repo?
Martin Roth9f25da12015-12-17 12:49:15 -0700304 git clone "$bsrepo"
David Hendricks1b6e7a62013-11-11 18:44:05 -0800305 if [ $? -ne 0 ]; then
Paul Menzel749e0752015-05-20 22:32:15 +0200306 echo "Error cloning board-status repo, aborting."
David Hendricks1b6e7a62013-11-11 18:44:05 -0800307 exit $EXIT_FAILURE
308 fi
309 fi
310
311 cd "board-status"
312 echo "Copying results to $(pwd)/${results}"
313
314 # Note: Result directory should be unique due to the timestamp.
315 cp -R "${tmpdir}/${vendor}" .
316
317 echo "Uploading results"
318 git add "${vendor}"
Paul Menzel04eb2e82014-02-09 10:24:22 +0100319 git commit -a -m "${mainboard_dir}/${tagged_version}/${timestamp}"
Paul Menzel54e6aa72015-05-20 07:35:56 +0200320 count=0
321 until git push origin || test $count -eq 3; do
322 git pull --rebase
323 count=$((count + 1))
324 done
David Hendricks1b6e7a62013-11-11 18:44:05 -0800325
326 # Results have been uploaded so it's pointless to keep the
327 # temporary files around.
328 rm -rf "${tmpdir}"
Paul Menzel54e6aa72015-05-20 07:35:56 +0200329 if test $count -eq 3; then
330 echo "Error uploading to board-status repo, aborting."
331 exit $EXIT_FAILURE
332 fi
David Hendricks1b6e7a62013-11-11 18:44:05 -0800333fi
334cd "$coreboot_dir"
David Hendricks6583a812013-11-01 19:37:44 -0700335
336if [ $CLOBBER_OUTPUT -eq 1 ]; then
Martin Roth9f25da12015-12-17 12:49:15 -0700337 rm -rf "${tmpdir}"
Martin Roth13c7db82014-07-10 14:59:11 -0600338else
339 echo
340 echo "output files are in ${tmpdir}/${results}"
David Hendricks6583a812013-11-01 19:37:44 -0700341fi
342
343exit $EXIT_SUCCESS