#!/bin/sh # # This file is part of the coreboot project. # # Copyright (C) 2013 Google Inc. # Copyright (C) 2014 Sage Electronic Engineering, LLC. # EXIT_SUCCESS=0 EXIT_FAILURE=1 # Stuff from command-line switches REMOTE_HOST="" CLOBBER_OUTPUT=0 UPLOAD_RESULTS=0 SERIAL_PORT_SPEED=115200 # 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 FATAL=0 NONFATAL=1 # test a command # # $1: 0 ($LOCAL) to run command locally, # 1 ($REMOTE) to run remotely if remote host defined # $2: command to test # $3: 0 ($FATAL) Exit with an error if the command fails # 1 ($NONFATAL) Don't exit on command test failure test_cmd() { local rc if [ -e "$2" ]; then return fi if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then ssh root@${REMOTE_HOST} command -v "$2" > /dev/null rc=$? else command -v "$2" >/dev/null rc=$? fi if [ $rc -eq 0 ]; then return 0 fi if [ "$3" = "1" ]; then return 1 fi echo "$2 not found" exit $EXIT_FAILURE } _cmd() { if [ -e "$2" ]; then return $EXIT_FAILURE fi if [ -n "$3" ]; then pipe_location="${3}" else pipe_location="/dev/null" fi if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then ssh root@${REMOTE_HOST} "$2" > "$pipe_location" 2>&1 else $2 > "$pipe_location" 2>&1 fi return $? } # run a command # # $1: 0 ($LOCAL) to run command locally, # 1 ($REMOTE) to run remotely if remote host defined # $2: command # $3: filename to direct output of command into cmd() { _cmd $1 "$2" "$3" if [ $? -eq 0 ]; then return fi echo "Failed to run \"$2\", aborting" rm -f "$3" # don't leave an empty file exit $EXIT_FAILURE } # run a command where failure is considered to be non-fatal # # $1: 0 ($LOCAL) to run command locally, # 1 ($REMOTE) to run remotely if remote host defined # $2: command # $3: filename to direct output of command into cmd_nonfatal() { _cmd $1 "$2" "$3" if [ $? -eq 0 ]; then return fi echo "Failed to run \"$2\", ignoring" rm -f "$3" # don't leave an empty file } # 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 () { local TTY=$1 local SPEED=$2 local FILENAME=$3 if [ ! -c "$TTY" ]; then echo "$TTY 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 $TTY" echo "Press [Enter] when the boot is complete and the" echo "system is ready for ssh to get the dmesg log." echo if [ $tput_not_available -eq 0 ]; then tput sgr0 fi # set up the serial port stty -F $TTY $SPEED cs8 -cstopb -parenb clocal # read from the serial port - user must press enter when complete test_cmd $LOCAL "tee" while read LINE; do echo "$LINE" | tee -a "$FILENAME" done < "$SERIAL_DEVICE" & PID=$! read foo kill "$PID" 2>/dev/null echo "Finished reading boot log." } show_help() { echo "Usage: ${0}