2013-11-02 03:37:44 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# This file is part of the coreboot project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2013 Google Inc.
|
2014-07-10 23:00:35 +02:00
|
|
|
# Copyright (C) 2014 Sage Electronic Engineering, LLC.
|
2013-11-07 11:03:05 +01:00
|
|
|
#
|
2013-11-02 03:37:44 +01:00
|
|
|
|
|
|
|
EXIT_SUCCESS=0
|
|
|
|
EXIT_FAILURE=1
|
|
|
|
|
|
|
|
# Stuff from command-line switches
|
|
|
|
REMOTE_HOST=""
|
|
|
|
CLOBBER_OUTPUT=0
|
|
|
|
UPLOAD_RESULTS=0
|
2014-07-10 23:00:35 +02:00
|
|
|
SERIAL_PORT_SPEED=115200
|
2013-11-02 03:37:44 +01:00
|
|
|
|
2013-11-12 03:44:05 +01:00
|
|
|
# Used to specify whether a command should always be run locally or
|
|
|
|
# if command should be run remoteley when a remote host is specified.
|
|
|
|
LOCAL=0
|
|
|
|
REMOTE=1
|
2014-06-23 05:46:24 +02:00
|
|
|
FATAL=0
|
|
|
|
NONFATAL=1
|
2013-11-12 03:44:05 +01:00
|
|
|
|
2013-11-02 03:37:44 +01:00
|
|
|
# test a command
|
|
|
|
#
|
2014-07-10 23:02:19 +02:00
|
|
|
# $1: 0 ($LOCAL) to run command locally,
|
|
|
|
# 1 ($REMOTE) to run remotely if remote host defined
|
2013-11-02 03:37:44 +01:00
|
|
|
# $2: command to test
|
2014-06-23 05:46:24 +02:00
|
|
|
# $3: 0 ($FATAL) Exit with an error if the command fails
|
|
|
|
# 1 ($NONFATAL) Don't exit on command test failure
|
2013-11-02 03:37:44 +01:00
|
|
|
test_cmd()
|
|
|
|
{
|
|
|
|
local rc
|
|
|
|
|
|
|
|
if [ -e "$2" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2014-01-21 02:39:46 +01:00
|
|
|
if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
|
2014-07-10 23:02:19 +02:00
|
|
|
ssh root@${REMOTE_HOST} which "$2" > /dev/null
|
2013-11-02 03:37:44 +01:00
|
|
|
rc=$?
|
|
|
|
else
|
|
|
|
which "$2" >/dev/null
|
|
|
|
rc=$?
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $rc -eq 0 ]; then
|
2014-06-23 05:46:24 +02:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2014-08-10 15:44:04 +02:00
|
|
|
if [ "$3" = "1" ]; then
|
2014-06-23 05:46:24 +02:00
|
|
|
return 1
|
2013-11-02 03:37:44 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$2 not found"
|
|
|
|
exit $EXIT_FAILURE
|
|
|
|
}
|
|
|
|
|
2013-11-13 02:24:42 +01:00
|
|
|
_cmd()
|
2013-11-02 03:37:44 +01:00
|
|
|
{
|
|
|
|
if [ -e "$2" ]; then
|
2013-11-13 02:24:42 +01:00
|
|
|
return $EXIT_FAILURE
|
2013-11-02 03:37:44 +01:00
|
|
|
fi
|
|
|
|
|
2014-07-10 22:57:34 +02:00
|
|
|
if [ -n "$3" ]; then
|
|
|
|
pipe_location="${3}"
|
|
|
|
else
|
|
|
|
pipe_location="/dev/null"
|
|
|
|
fi
|
|
|
|
|
2014-01-21 02:39:46 +01:00
|
|
|
if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
|
2014-07-10 22:57:34 +02:00
|
|
|
ssh root@${REMOTE_HOST} "$2" > "$pipe_location" 2>&1
|
2013-11-02 03:37:44 +01:00
|
|
|
else
|
2014-07-10 22:57:34 +02:00
|
|
|
$2 > "$pipe_location" 2>&1
|
2013-11-02 03:37:44 +01:00
|
|
|
fi
|
2013-11-13 03:10:23 +01:00
|
|
|
|
|
|
|
return $?
|
2013-11-13 02:24:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# run a command
|
|
|
|
#
|
2014-07-10 23:02:19 +02:00
|
|
|
# $1: 0 ($LOCAL) to run command locally,
|
|
|
|
# 1 ($REMOTE) to run remotely if remote host defined
|
2013-11-13 02:24:42 +01:00
|
|
|
# $2: command
|
2013-11-13 03:10:23 +01:00
|
|
|
# $3: filename to direct output of command into
|
2013-11-13 02:24:42 +01:00
|
|
|
cmd()
|
|
|
|
{
|
2013-11-13 03:10:23 +01:00
|
|
|
_cmd $1 "$2" "$3"
|
2013-11-02 03:37:44 +01:00
|
|
|
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
return
|
|
|
|
fi
|
2013-11-07 11:03:05 +01:00
|
|
|
|
2013-11-13 03:10:23 +01:00
|
|
|
echo "Failed to run \"$2\", aborting"
|
|
|
|
rm -f "$3" # don't leave an empty file
|
2013-11-02 03:37:44 +01:00
|
|
|
exit $EXIT_FAILURE
|
|
|
|
}
|
|
|
|
|
2013-11-13 02:24:42 +01:00
|
|
|
# run a command where failure is considered to be non-fatal
|
|
|
|
#
|
2014-07-10 23:02:19 +02:00
|
|
|
# $1: 0 ($LOCAL) to run command locally,
|
|
|
|
# 1 ($REMOTE) to run remotely if remote host defined
|
2013-11-13 02:24:42 +01:00
|
|
|
# $2: command
|
2013-11-13 03:10:23 +01:00
|
|
|
# $3: filename to direct output of command into
|
2013-11-13 02:24:42 +01:00
|
|
|
cmd_nonfatal()
|
|
|
|
{
|
2013-11-13 03:10:23 +01:00
|
|
|
_cmd $1 "$2" "$3"
|
2013-11-13 02:24:42 +01:00
|
|
|
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2013-11-13 03:10:23 +01:00
|
|
|
echo "Failed to run \"$2\", ignoring"
|
|
|
|
rm -f "$3" # don't leave an empty file
|
2013-11-13 02:24:42 +01:00
|
|
|
}
|
|
|
|
|
2014-07-10 23:00:35 +02:00
|
|
|
# read from a serial port device
|
|
|
|
#
|
|
|
|
# $1: serial device to read from
|
|
|
|
# $2: serial port speed
|
|
|
|
# $3: filename to direct output of command into
|
|
|
|
get_serial_bootlog () {
|
|
|
|
|
|
|
|
if [ ! -c "$1" ]; then
|
|
|
|
echo "$1 is not a valid serial device"
|
|
|
|
exit $EXIT_FAILURE
|
|
|
|
fi
|
|
|
|
|
|
|
|
# make the text more noticible
|
|
|
|
test_cmd $LOCAL "tput" $NONFATAL
|
|
|
|
tput_not_available=$?
|
|
|
|
if [ $tput_not_available -eq 0 ]; then
|
|
|
|
tput bold
|
|
|
|
tput setaf 10 # set bright green
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Waiting to receive boot log from $1"
|
|
|
|
echo "Press [Enter] when the boot is complete and the"
|
|
|
|
echo "system is ready for ssh to get the dmesg log."
|
|
|
|
|
|
|
|
if [ $tput_not_available -eq 0 ]; then
|
|
|
|
tput sgr0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# set up the serial port
|
|
|
|
cmd $LOCAL "stty -F $1 $2 cs8 -cstopb"
|
|
|
|
|
|
|
|
# read from the serial port - user must press enter when complete
|
|
|
|
test_cmd $LOCAL "tee"
|
|
|
|
cat "$SERIAL_DEVICE" | tee "$3" &
|
|
|
|
PID=$!
|
|
|
|
|
|
|
|
read
|
|
|
|
kill "$PID" 2>/dev/null &
|
|
|
|
|
|
|
|
# remove the binary zero value that gets inserted into the file.
|
|
|
|
sed -i 's/\x00//' "$3"
|
|
|
|
}
|
|
|
|
|
2013-11-13 01:49:45 +01:00
|
|
|
show_help() {
|
|
|
|
echo "Usage:
|
|
|
|
${0} <option>
|
|
|
|
|
|
|
|
Options
|
|
|
|
-h
|
|
|
|
Show this message.
|
|
|
|
-C
|
|
|
|
Clobber temporary output when finished. Useful for debugging.
|
|
|
|
-r <host>
|
|
|
|
Obtain machine information from remote host (using ssh).
|
2014-07-10 23:00:35 +02:00
|
|
|
-s </dev/xxx>
|
|
|
|
Obtain boot log via serial device.
|
|
|
|
-S <speed>
|
|
|
|
Set the port speed for the serial device (Default is 115200).
|
2013-11-13 01:49:45 +01:00
|
|
|
-u
|
|
|
|
Upload results to coreboot.org.
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
2014-07-10 23:00:35 +02:00
|
|
|
while getopts "Chr:s:S:u" opt; do
|
2013-11-02 03:37:44 +01:00
|
|
|
case "$opt" in
|
|
|
|
h)
|
|
|
|
show_help
|
|
|
|
exit $EXIT_SUCCESS
|
|
|
|
;;
|
2013-11-13 01:45:37 +01:00
|
|
|
C)
|
2013-11-02 03:37:44 +01:00
|
|
|
CLOBBER_OUTPUT=1
|
|
|
|
;;
|
|
|
|
r)
|
|
|
|
REMOTE_HOST="$OPTARG"
|
|
|
|
;;
|
2014-07-10 23:00:35 +02:00
|
|
|
s)
|
|
|
|
SERIAL_DEVICE="$OPTARG"
|
|
|
|
;;
|
|
|
|
S)
|
|
|
|
SERIAL_PORT_SPEED="$OPTARG"
|
|
|
|
;;
|
2013-11-02 03:37:44 +01:00
|
|
|
u)
|
|
|
|
UPLOAD_RESULTS=1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2013-11-12 03:44:05 +01:00
|
|
|
grep -rH 'coreboot.org' .git/config >/dev/null 2>&1
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Script must be run from root of coreboot directory"
|
2013-11-02 03:37:44 +01:00
|
|
|
exit $EXIT_FAILURE
|
|
|
|
fi
|
|
|
|
|
2013-11-12 03:44:05 +01:00
|
|
|
# Results will be placed in a temporary location until we're ready to upload.
|
|
|
|
# If the user does not wish to upload, results will remain in /tmp.
|
2014-07-10 22:59:11 +02:00
|
|
|
tmpdir=$(mktemp -d --tmpdir coreboot_board_status.XXXXXXXX)
|
2013-11-12 03:44:05 +01:00
|
|
|
|
|
|
|
# Obtain board and revision info to form the directory structure:
|
|
|
|
# <vendor>/<board>/<revision>/<timestamp>
|
2014-07-16 22:22:59 +02:00
|
|
|
cbfstool_cmd="build/cbfstool"
|
|
|
|
if test ! -x build/cbfstool; then
|
|
|
|
make -C util/cbfstool/ && cp util/cbfstool/cbfstool build/cbfstool
|
|
|
|
fi
|
2013-11-12 03:44:05 +01:00
|
|
|
test_cmd $LOCAL "$cbfstool_cmd"
|
|
|
|
$cbfstool_cmd build/coreboot.rom extract -n config -f ${tmpdir}/config.txt
|
2014-05-25 12:20:51 +02:00
|
|
|
$cbfstool_cmd build/coreboot.rom print > ${tmpdir}/cbfs.txt
|
2013-11-12 03:44:05 +01:00
|
|
|
mainboard_dir="$(grep CONFIG_MAINBOARD_DIR ${tmpdir}/config.txt | awk -F '"' '{ print $2 }')"
|
|
|
|
vendor=$(echo "$mainboard_dir" | awk -F '/' '{ print $1 }')
|
|
|
|
mainboard=$(echo "$mainboard_dir" | awk -F '/' '{ print $2 }')
|
2013-11-02 03:37:44 +01:00
|
|
|
|
2013-11-12 03:43:39 +01:00
|
|
|
getrevision="util/board_status/getrevision.sh"
|
2013-11-12 03:44:05 +01:00
|
|
|
test_cmd $LOCAL $getrevision
|
|
|
|
tagged_version=$($getrevision -T)
|
|
|
|
timestamp=$($getrevision -t)
|
|
|
|
|
|
|
|
results="${vendor}/${mainboard}/${tagged_version}/${timestamp}"
|
|
|
|
|
|
|
|
echo "Temporarily placing output in ${tmpdir}/${results}"
|
|
|
|
mkdir -p "${tmpdir}/${results}"
|
|
|
|
|
|
|
|
mv "${tmpdir}/config.txt" "${tmpdir}/${results}"
|
2014-05-30 09:26:46 +02:00
|
|
|
mv "${tmpdir}/cbfs.txt" "${tmpdir}/${results}"
|
2013-11-12 03:44:05 +01:00
|
|
|
|
|
|
|
touch ${tmpdir}/${results}/revision.txt
|
|
|
|
printf "Local revision: %s\n" "$($getrevision -l)" >> ${tmpdir}/${results}/revision.txt
|
|
|
|
printf "Tagged revision: %s\n" "${tagged_version}" >> ${tmpdir}/${results}/revision.txt
|
|
|
|
printf "Upstream revision: %s\n" $($getrevision -u) >> ${tmpdir}/${results}/revision.txt
|
|
|
|
printf "Upstream URL: %s\n" $($getrevision -U)>> ${tmpdir}/${results}/revision.txt
|
|
|
|
printf "Timestamp: %s\n" "$timestamp" >> ${tmpdir}/${results}/revision.txt
|
|
|
|
|
2014-07-10 23:00:35 +02:00
|
|
|
if [ -z "$SERIAL_DEVICE" ]; then
|
|
|
|
test_cmd $REMOTE "cbmem"
|
|
|
|
cmd $REMOTE "cbmem -c" "${tmpdir}/${results}/coreboot_console.txt"
|
|
|
|
cmd_nonfatal $REMOTE "cbmem -t" "${tmpdir}/${results}/coreboot_timestamps.txt"
|
|
|
|
else
|
|
|
|
get_serial_bootlog "$SERIAL_DEVICE" "$SERIAL_PORT_SPEED" "${tmpdir}/${results}/coreboot_console.txt"
|
|
|
|
fi
|
2013-11-12 03:44:05 +01:00
|
|
|
|
2013-11-13 03:10:23 +01:00
|
|
|
cmd $REMOTE dmesg "${tmpdir}/${results}/kernel_log.txt"
|
2013-11-12 03:44:05 +01:00
|
|
|
|
2013-11-13 03:17:19 +01:00
|
|
|
#
|
|
|
|
# Finish up.
|
|
|
|
#
|
2014-07-10 23:02:19 +02:00
|
|
|
coreboot_dir=$(pwd)
|
2013-11-12 03:44:05 +01:00
|
|
|
if [ $UPLOAD_RESULTS -eq 1 ]; then
|
|
|
|
# extract username from ssh://<username>@review.coreboot.org/blah
|
|
|
|
username=$(git config --get remote.origin.url | sed 's/ssh\:\/\///' | sed 's/@.*//')
|
|
|
|
|
|
|
|
cd "util/board_status/"
|
|
|
|
if [ ! -e "board-status" ]; then
|
2013-11-13 03:17:19 +01:00
|
|
|
# FIXME: the board-status directory might get big over time.
|
|
|
|
# Is there a way we can push the results without fetching the
|
|
|
|
# whole repo?
|
2013-11-12 03:44:05 +01:00
|
|
|
git clone "ssh://${username}@review.coreboot.org:29418/board-status"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
"Error cloning board-status repo, aborting."
|
|
|
|
exit $EXIT_FAILURE
|
|
|
|
fi
|
|
|
|
fi
|
2013-11-02 03:37:44 +01:00
|
|
|
|
2013-11-12 03:44:05 +01:00
|
|
|
cd "board-status"
|
|
|
|
echo "Copying results to $(pwd)/${results}"
|
2013-11-02 03:37:44 +01:00
|
|
|
|
2013-11-12 03:44:05 +01:00
|
|
|
# Note: Result directory should be unique due to the timestamp.
|
|
|
|
cp -R "${tmpdir}/${vendor}" .
|
2013-11-02 03:37:44 +01:00
|
|
|
|
2013-11-12 03:44:05 +01:00
|
|
|
echo "Uploading results"
|
|
|
|
git add "${vendor}"
|
2014-02-09 10:24:22 +01:00
|
|
|
git commit -a -m "${mainboard_dir}/${tagged_version}/${timestamp}"
|
2013-11-12 03:44:05 +01:00
|
|
|
git push origin
|
2013-11-02 03:37:44 +01:00
|
|
|
|
2013-11-12 03:44:05 +01:00
|
|
|
# Results have been uploaded so it's pointless to keep the
|
|
|
|
# temporary files around.
|
|
|
|
rm -rf "${tmpdir}"
|
|
|
|
fi
|
|
|
|
cd "$coreboot_dir"
|
2013-11-02 03:37:44 +01:00
|
|
|
|
|
|
|
if [ $CLOBBER_OUTPUT -eq 1 ]; then
|
2013-11-12 03:44:05 +01:00
|
|
|
rm -rf ${tmpdir}
|
2014-07-10 22:59:11 +02:00
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo "output files are in ${tmpdir}/${results}"
|
2013-11-02 03:37:44 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
exit $EXIT_SUCCESS
|