David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 3 | # |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 4 | |
| 5 | EXIT_SUCCESS=0 |
| 6 | EXIT_FAILURE=1 |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 7 | |
| 8 | # Stuff from command-line switches |
David Hendricks | 1173bf3 | 2015-11-19 13:04:27 -0800 | [diff] [blame] | 9 | COREBOOT_IMAGE="build/coreboot.rom" |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 10 | REMOTE_HOST="" |
Jonathan Neuschäfer | 4aef682 | 2016-05-10 17:43:53 +0200 | [diff] [blame] | 11 | REMOTE_PORT_OPTION="" |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 12 | CLOBBER_OUTPUT=0 |
| 13 | UPLOAD_RESULTS=0 |
Martin Roth | 8e0071b | 2014-07-10 15:00:35 -0600 | [diff] [blame] | 14 | SERIAL_PORT_SPEED=115200 |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 15 | |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 16 | # 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. |
| 18 | LOCAL=0 |
| 19 | REMOTE=1 |
Martin Roth | be5340b | 2014-06-22 21:46:24 -0600 | [diff] [blame] | 20 | FATAL=0 |
| 21 | NONFATAL=1 |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 22 | |
David Hendricks | c863be7 | 2017-09-16 12:59:23 -0700 | [diff] [blame] | 23 | # Used if cbmem is not in default $PATH, e.g. not installed or when using `sudo` |
| 24 | CBMEM_PATH="" |
| 25 | |
Evgeny Zinoviev | b863468 | 2018-09-11 00:02:36 +0300 | [diff] [blame] | 26 | # Used if nvramtool is not in default $PATH, e.g. not installed or when using `sudo` |
| 27 | NVRAMTOOL_PATH="" |
| 28 | |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 29 | # test a command |
| 30 | # |
Martin Roth | bcd0993 | 2014-07-10 15:02:19 -0600 | [diff] [blame] | 31 | # $1: 0 ($LOCAL) to run command locally, |
| 32 | # 1 ($REMOTE) to run remotely if remote host defined |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 33 | # $2: command to test |
Martin Roth | be5340b | 2014-06-22 21:46:24 -0600 | [diff] [blame] | 34 | # $3: 0 ($FATAL) Exit with an error if the command fails |
| 35 | # 1 ($NONFATAL) Don't exit on command test failure |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 36 | test_cmd() |
| 37 | { |
| 38 | local rc |
| 39 | |
| 40 | if [ -e "$2" ]; then |
| 41 | return |
| 42 | fi |
| 43 | |
Vladimir Serbinenko | 77005b4 | 2014-01-21 02:39:46 +0100 | [diff] [blame] | 44 | if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then |
Jonathan Neuschäfer | 4aef682 | 2016-05-10 17:43:53 +0200 | [diff] [blame] | 45 | ssh $REMOTE_PORT_OPTION root@${REMOTE_HOST} command -v "$2" > /dev/null |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 46 | rc=$? |
| 47 | else |
Patrick Georgi | 1cbef1c | 2015-08-10 10:21:14 +0200 | [diff] [blame] | 48 | command -v "$2" >/dev/null |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 49 | rc=$? |
| 50 | fi |
| 51 | |
| 52 | if [ $rc -eq 0 ]; then |
Martin Roth | be5340b | 2014-06-22 21:46:24 -0600 | [diff] [blame] | 53 | return 0 |
| 54 | fi |
| 55 | |
Patrick Georgi | 4ef309e | 2014-08-10 15:44:04 +0200 | [diff] [blame] | 56 | if [ "$3" = "1" ]; then |
Martin Roth | be5340b | 2014-06-22 21:46:24 -0600 | [diff] [blame] | 57 | return 1 |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 58 | fi |
| 59 | |
| 60 | echo "$2 not found" |
| 61 | exit $EXIT_FAILURE |
| 62 | } |
| 63 | |
David Hendricks | f8b90e4 | 2013-11-12 17:24:42 -0800 | [diff] [blame] | 64 | _cmd() |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 65 | { |
| 66 | if [ -e "$2" ]; then |
David Hendricks | f8b90e4 | 2013-11-12 17:24:42 -0800 | [diff] [blame] | 67 | return $EXIT_FAILURE |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 68 | fi |
| 69 | |
Martin Roth | 2246177 | 2014-07-10 14:57:34 -0600 | [diff] [blame] | 70 | if [ -n "$3" ]; then |
| 71 | pipe_location="${3}" |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 72 | else |
Martin Roth | 2246177 | 2014-07-10 14:57:34 -0600 | [diff] [blame] | 73 | pipe_location="/dev/null" |
| 74 | fi |
| 75 | |
| 76 | if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then |
Jonathan Neuschäfer | 4aef682 | 2016-05-10 17:43:53 +0200 | [diff] [blame] | 77 | ssh $REMOTE_PORT_OPTION "root@${REMOTE_HOST}" "$2" > "$pipe_location" 2>&1 |
Martin Roth | 2246177 | 2014-07-10 14:57:34 -0600 | [diff] [blame] | 78 | else |
| 79 | $2 > "$pipe_location" 2>&1 |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 80 | fi |
David Hendricks | 406ce8a | 2013-11-12 18:10:23 -0800 | [diff] [blame] | 81 | |
| 82 | return $? |
David Hendricks | f8b90e4 | 2013-11-12 17:24:42 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | # run a command |
| 86 | # |
Martin Roth | bcd0993 | 2014-07-10 15:02:19 -0600 | [diff] [blame] | 87 | # $1: 0 ($LOCAL) to run command locally, |
| 88 | # 1 ($REMOTE) to run remotely if remote host defined |
David Hendricks | f8b90e4 | 2013-11-12 17:24:42 -0800 | [diff] [blame] | 89 | # $2: command |
David Hendricks | 406ce8a | 2013-11-12 18:10:23 -0800 | [diff] [blame] | 90 | # $3: filename to direct output of command into |
David Hendricks | f8b90e4 | 2013-11-12 17:24:42 -0800 | [diff] [blame] | 91 | cmd() |
| 92 | { |
David Hendricks | 406ce8a | 2013-11-12 18:10:23 -0800 | [diff] [blame] | 93 | _cmd $1 "$2" "$3" |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 94 | |
| 95 | if [ $? -eq 0 ]; then |
| 96 | return |
| 97 | fi |
Zheng Bao | 86655cf | 2013-11-07 18:03:05 +0800 | [diff] [blame] | 98 | |
David Hendricks | 406ce8a | 2013-11-12 18:10:23 -0800 | [diff] [blame] | 99 | echo "Failed to run \"$2\", aborting" |
| 100 | rm -f "$3" # don't leave an empty file |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 101 | exit $EXIT_FAILURE |
| 102 | } |
| 103 | |
David Hendricks | f8b90e4 | 2013-11-12 17:24:42 -0800 | [diff] [blame] | 104 | # run a command where failure is considered to be non-fatal |
| 105 | # |
Martin Roth | bcd0993 | 2014-07-10 15:02:19 -0600 | [diff] [blame] | 106 | # $1: 0 ($LOCAL) to run command locally, |
| 107 | # 1 ($REMOTE) to run remotely if remote host defined |
David Hendricks | f8b90e4 | 2013-11-12 17:24:42 -0800 | [diff] [blame] | 108 | # $2: command |
David Hendricks | 406ce8a | 2013-11-12 18:10:23 -0800 | [diff] [blame] | 109 | # $3: filename to direct output of command into |
David Hendricks | f8b90e4 | 2013-11-12 17:24:42 -0800 | [diff] [blame] | 110 | cmd_nonfatal() |
| 111 | { |
David Hendricks | 406ce8a | 2013-11-12 18:10:23 -0800 | [diff] [blame] | 112 | _cmd $1 "$2" "$3" |
David Hendricks | f8b90e4 | 2013-11-12 17:24:42 -0800 | [diff] [blame] | 113 | |
| 114 | if [ $? -eq 0 ]; then |
| 115 | return |
| 116 | fi |
| 117 | |
David Hendricks | 406ce8a | 2013-11-12 18:10:23 -0800 | [diff] [blame] | 118 | echo "Failed to run \"$2\", ignoring" |
| 119 | rm -f "$3" # don't leave an empty file |
David Hendricks | f8b90e4 | 2013-11-12 17:24:42 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Martin Roth | 8e0071b | 2014-07-10 15:00:35 -0600 | [diff] [blame] | 122 | # read from a serial port device |
| 123 | # |
| 124 | # $1: serial device to read from |
| 125 | # $2: serial port speed |
| 126 | # $3: filename to direct output of command into |
| 127 | get_serial_bootlog () { |
| 128 | |
Martin Roth | d0128df | 2015-12-17 12:02:45 -0700 | [diff] [blame] | 129 | local TTY=$1 |
| 130 | local SPEED=$2 |
| 131 | local FILENAME=$3 |
| 132 | |
| 133 | if [ ! -c "$TTY" ]; then |
| 134 | echo "$TTY is not a valid serial device" |
Martin Roth | 8e0071b | 2014-07-10 15:00:35 -0600 | [diff] [blame] | 135 | exit $EXIT_FAILURE |
| 136 | fi |
| 137 | |
| 138 | # make the text more noticible |
| 139 | test_cmd $LOCAL "tput" $NONFATAL |
| 140 | tput_not_available=$? |
| 141 | if [ $tput_not_available -eq 0 ]; then |
| 142 | tput bold |
| 143 | tput setaf 10 # set bright green |
| 144 | fi |
| 145 | |
| 146 | echo |
Martin Roth | d0128df | 2015-12-17 12:02:45 -0700 | [diff] [blame] | 147 | echo "Waiting to receive boot log from $TTY" |
David Hendricks | 0dcfb59 | 2017-09-16 18:43:08 -0700 | [diff] [blame] | 148 | echo "Press [Enter] when the boot is complete." |
Martin Roth | d0128df | 2015-12-17 12:02:45 -0700 | [diff] [blame] | 149 | echo |
Martin Roth | 8e0071b | 2014-07-10 15:00:35 -0600 | [diff] [blame] | 150 | |
| 151 | if [ $tput_not_available -eq 0 ]; then |
| 152 | tput sgr0 |
| 153 | fi |
| 154 | |
| 155 | # set up the serial port |
Martin Roth | d0128df | 2015-12-17 12:02:45 -0700 | [diff] [blame] | 156 | stty -F $TTY $SPEED cs8 -cstopb -parenb clocal |
Martin Roth | 8e0071b | 2014-07-10 15:00:35 -0600 | [diff] [blame] | 157 | |
| 158 | # read from the serial port - user must press enter when complete |
| 159 | test_cmd $LOCAL "tee" |
Martin Roth | d0128df | 2015-12-17 12:02:45 -0700 | [diff] [blame] | 160 | while read LINE; do |
| 161 | echo "$LINE" | tee -a "$FILENAME" |
| 162 | done < "$SERIAL_DEVICE" & |
Martin Roth | 8e0071b | 2014-07-10 15:00:35 -0600 | [diff] [blame] | 163 | PID=$! |
| 164 | |
Martin Roth | d0128df | 2015-12-17 12:02:45 -0700 | [diff] [blame] | 165 | read foo |
| 166 | kill "$PID" 2>/dev/null |
Martin Roth | 8e0071b | 2014-07-10 15:00:35 -0600 | [diff] [blame] | 167 | |
Martin Roth | d0128df | 2015-12-17 12:02:45 -0700 | [diff] [blame] | 168 | echo "Finished reading boot log." |
Martin Roth | 8e0071b | 2014-07-10 15:00:35 -0600 | [diff] [blame] | 169 | } |
| 170 | |
David Hendricks | 1fc65f7 | 2013-11-12 16:49:45 -0800 | [diff] [blame] | 171 | show_help() { |
| 172 | echo "Usage: |
| 173 | ${0} <option> |
| 174 | |
| 175 | Options |
David Hendricks | c863be7 | 2017-09-16 12:59:23 -0700 | [diff] [blame] | 176 | -c, --cbmem |
| 177 | Path to cbmem on device under test (DUT). |
Evgeny Zinoviev | b863468 | 2018-09-11 00:02:36 +0300 | [diff] [blame] | 178 | -n, --nvramtool |
| 179 | Path to nvramtool on device under test (DUT). |
David Hendricks | b2aa528 | 2016-05-07 11:44:05 -0700 | [diff] [blame] | 180 | -C, --clobber |
David Hendricks | 1fc65f7 | 2013-11-12 16:49:45 -0800 | [diff] [blame] | 181 | Clobber temporary output when finished. Useful for debugging. |
David Hendricks | b2aa528 | 2016-05-07 11:44:05 -0700 | [diff] [blame] | 182 | -h, --help |
| 183 | Show this message. |
| 184 | -i, --image <image> |
David Hendricks | 1173bf3 | 2015-11-19 13:04:27 -0800 | [diff] [blame] | 185 | Path to coreboot image (Default is $COREBOOT_IMAGE). |
David Hendricks | b2aa528 | 2016-05-07 11:44:05 -0700 | [diff] [blame] | 186 | -r, --remote-host <host> |
David Hendricks | 1fc65f7 | 2013-11-12 16:49:45 -0800 | [diff] [blame] | 187 | Obtain machine information from remote host (using ssh). |
David Hendricks | b2aa528 | 2016-05-07 11:44:05 -0700 | [diff] [blame] | 188 | -s, --serial-device </dev/xxx> |
| 189 | Obtain boot log via serial device. |
| 190 | -S, --serial-speed <speed> |
| 191 | Set the port speed for the serial device (Default is $SERIAL_PORT_SPEED). |
| 192 | -u, --upload-results |
| 193 | Upload results to coreboot.org. |
| 194 | |
| 195 | Long options: |
Jonathan Neuschäfer | 4aef682 | 2016-05-10 17:43:53 +0200 | [diff] [blame] | 196 | --ssh-port <port> |
| 197 | Use a specific SSH port. |
David Hendricks | 1fc65f7 | 2013-11-12 16:49:45 -0800 | [diff] [blame] | 198 | " |
| 199 | } |
| 200 | |
David Hendricks | 292be87 | 2016-04-26 14:07:42 -0700 | [diff] [blame] | 201 | getopt -T |
| 202 | if [ $? -ne 4 ]; then |
| 203 | echo "GNU-compatible getopt(1) required." |
| 204 | exit $EXIT_FAILURE |
| 205 | fi |
| 206 | |
David Hendricks | c863be7 | 2017-09-16 12:59:23 -0700 | [diff] [blame] | 207 | LONGOPTS="cbmem:,clobber,help,image:,remote-host:,upload-results" |
David Hendricks | b2aa528 | 2016-05-07 11:44:05 -0700 | [diff] [blame] | 208 | LONGOPTS="${LONGOPTS},serial-device:,serial-speed:" |
| 209 | LONGOPTS="${LONGOPTS},ssh-port:" |
| 210 | |
Evgeny Zinoviev | b863468 | 2018-09-11 00:02:36 +0300 | [diff] [blame] | 211 | ARGS=$(getopt -o c:n:Chi:r:s:S:u -l "$LONGOPTS" -n "$0" -- "$@"); |
David Hendricks | 292be87 | 2016-04-26 14:07:42 -0700 | [diff] [blame] | 212 | if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi |
| 213 | eval set -- "$ARGS" |
| 214 | while true ; do |
| 215 | case "$1" in |
David Hendricks | b2aa528 | 2016-05-07 11:44:05 -0700 | [diff] [blame] | 216 | # generic options |
David Hendricks | c863be7 | 2017-09-16 12:59:23 -0700 | [diff] [blame] | 217 | -c|--cbmem) |
| 218 | shift |
| 219 | CBMEM_PATH="$1" |
| 220 | ;; |
Evgeny Zinoviev | b863468 | 2018-09-11 00:02:36 +0300 | [diff] [blame] | 221 | -n|--nvramtool) |
| 222 | shift |
| 223 | NVRAMTOOL_PATH="$1" |
| 224 | ;; |
David Hendricks | b2aa528 | 2016-05-07 11:44:05 -0700 | [diff] [blame] | 225 | -C|--clobber) |
| 226 | CLOBBER_OUTPUT=1 |
| 227 | ;; |
| 228 | -h|--help) |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 229 | show_help |
| 230 | exit $EXIT_SUCCESS |
| 231 | ;; |
David Hendricks | b2aa528 | 2016-05-07 11:44:05 -0700 | [diff] [blame] | 232 | -i|--image) |
David Hendricks | 292be87 | 2016-04-26 14:07:42 -0700 | [diff] [blame] | 233 | shift |
| 234 | COREBOOT_IMAGE="$1" |
David Hendricks | 1173bf3 | 2015-11-19 13:04:27 -0800 | [diff] [blame] | 235 | ;; |
David Hendricks | b2aa528 | 2016-05-07 11:44:05 -0700 | [diff] [blame] | 236 | -r|--remote-host) |
David Hendricks | 292be87 | 2016-04-26 14:07:42 -0700 | [diff] [blame] | 237 | shift |
| 238 | REMOTE_HOST="$1" |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 239 | ;; |
David Hendricks | b2aa528 | 2016-05-07 11:44:05 -0700 | [diff] [blame] | 240 | -u|--upload-results) |
| 241 | UPLOAD_RESULTS=1 |
| 242 | ;; |
| 243 | |
| 244 | # serial port options |
| 245 | -s|--serial-device) |
| 246 | shift |
| 247 | SERIAL_DEVICE="$1" |
| 248 | ;; |
| 249 | -S|--serial-speed) |
| 250 | shift |
| 251 | SERIAL_PORT_SPEED="$1" |
| 252 | ;; |
| 253 | |
| 254 | # ssh options |
Jonathan Neuschäfer | 4aef682 | 2016-05-10 17:43:53 +0200 | [diff] [blame] | 255 | --ssh-port) |
| 256 | shift |
| 257 | REMOTE_PORT_OPTION="-p $1" |
| 258 | ;; |
David Hendricks | b2aa528 | 2016-05-07 11:44:05 -0700 | [diff] [blame] | 259 | |
| 260 | # error handling |
David Hendricks | 292be87 | 2016-04-26 14:07:42 -0700 | [diff] [blame] | 261 | --) |
| 262 | shift |
| 263 | if [ -n "$*" ]; then |
| 264 | echo "Non-option parameters detected: '$*'" |
| 265 | exit $EXIT_FAILURE |
| 266 | fi |
| 267 | break |
| 268 | ;; |
| 269 | *) |
| 270 | echo "error processing options at '$1'" |
| 271 | exit $EXIT_FAILURE |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 272 | esac |
David Hendricks | 292be87 | 2016-04-26 14:07:42 -0700 | [diff] [blame] | 273 | shift |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 274 | done |
| 275 | |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 276 | grep -rH 'coreboot.org' .git/config >/dev/null 2>&1 |
| 277 | if [ $? -ne 0 ]; then |
| 278 | echo "Script must be run from root of coreboot directory" |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 279 | exit $EXIT_FAILURE |
| 280 | fi |
| 281 | |
Jonathan Neuschäfer | 0e962ee | 2016-05-17 17:38:10 +0200 | [diff] [blame] | 282 | if [ ! -e "$COREBOOT_IMAGE" ]; then |
| 283 | echo "board_status needs $COREBOOT_IMAGE, but it does not exist." |
| 284 | echo "Use \"-i IMAGE_FILE\" to select a different image, or \"--help\" for more options." |
| 285 | exit $EXIT_FAILURE |
| 286 | fi |
| 287 | |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 288 | # Results will be placed in a temporary location until we're ready to upload. |
| 289 | # If the user does not wish to upload, results will remain in /tmp. |
Patrick Georgi | aa7dcef | 2015-08-13 07:57:26 +0200 | [diff] [blame] | 290 | tmpdir=$(mktemp -d --tmpdir coreboot_board_status.XXXXXXXX) |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 291 | |
David Hendricks | 9f54297 | 2015-11-19 13:08:51 -0800 | [diff] [blame] | 292 | # Obtain coreboot config by running cbfstool on the ROM image. cbfstool may |
| 293 | # already exist in build/ or util/cbfstool/, but if not then we'll build it |
| 294 | # now and clean it when we're done. |
Idwer Vollering | b37ee1e | 2014-07-16 22:22:59 +0200 | [diff] [blame] | 295 | cbfstool_cmd="build/cbfstool" |
David Hendricks | 9f54297 | 2015-11-19 13:08:51 -0800 | [diff] [blame] | 296 | do_clean_cbfstool=0 |
| 297 | if [ ! -x $cbfstool_cmd ]; then |
| 298 | cbfstool_cmd="util/cbfstool/cbfstool" |
| 299 | if [ -e $cbfstool_cmd ]; then |
| 300 | if test ! -x $cbfstool_cmd; then |
| 301 | echo "Cannot execute $cbfstool_cmd." |
| 302 | exit $EXIT_FAILURE |
| 303 | fi |
| 304 | else |
| 305 | make -C util/cbfstool/ |
| 306 | do_clean_cbfstool=1 |
| 307 | fi |
Idwer Vollering | b37ee1e | 2014-07-16 22:22:59 +0200 | [diff] [blame] | 308 | fi |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 309 | test_cmd $LOCAL "$cbfstool_cmd" |
David Hendricks | 9f54297 | 2015-11-19 13:08:51 -0800 | [diff] [blame] | 310 | |
| 311 | tmpcfg=$(mktemp coreboot_config.XXXXXX) |
David Hendricks | 1173bf3 | 2015-11-19 13:04:27 -0800 | [diff] [blame] | 312 | echo "Extracting config.txt from $COREBOOT_IMAGE" |
| 313 | $cbfstool_cmd "$COREBOOT_IMAGE" extract -n config -f "${tmpdir}/config.txt" >/dev/null 2>&1 |
Martin Roth | 9f25da1 | 2015-12-17 12:49:15 -0700 | [diff] [blame] | 314 | mv "${tmpdir}/config.txt" "${tmpdir}/config.short.txt" |
| 315 | cp "${tmpdir}/config.short.txt" "${tmpcfg}" |
| 316 | yes "" | make "DOTCONFIG=${tmpcfg}" oldconfig 2>/dev/null >/dev/null |
| 317 | mv "${tmpcfg}" "${tmpdir}/config.txt" |
| 318 | rm -f "${tmpcfg}.old" |
David Hendricks | 1173bf3 | 2015-11-19 13:04:27 -0800 | [diff] [blame] | 319 | $cbfstool_cmd "$COREBOOT_IMAGE" print > "${tmpdir}/cbfs.txt" |
| 320 | rom_contents=$($cbfstool_cmd "$COREBOOT_IMAGE" print 2>&1) |
Martin Roth | 2e44ea2 | 2015-12-17 12:33:39 -0700 | [diff] [blame] | 321 | if [ -n "$(echo $rom_contents | grep payload_config)" ]; then |
David Hendricks | 1173bf3 | 2015-11-19 13:04:27 -0800 | [diff] [blame] | 322 | echo "Extracting payload_config from $COREBOOT_IMAGE" |
| 323 | $cbfstool_cmd "$COREBOOT_IMAGE" extract -n payload_config -f "${tmpdir}/payload_config.txt" >/dev/null 2>&1 |
Martin Roth | 2e44ea2 | 2015-12-17 12:33:39 -0700 | [diff] [blame] | 324 | fi |
| 325 | if [ -n "$(echo $rom_contents | grep payload_version)" ]; then |
David Hendricks | 1173bf3 | 2015-11-19 13:04:27 -0800 | [diff] [blame] | 326 | echo "Extracting payload_version from $COREBOOT_IMAGE" |
| 327 | $cbfstool_cmd "$COREBOOT_IMAGE" extract -n payload_version -f "${tmpdir}/payload_version.txt" >/dev/null 2>&1 |
Martin Roth | 2e44ea2 | 2015-12-17 12:33:39 -0700 | [diff] [blame] | 328 | fi |
David Hendricks | 1173bf3 | 2015-11-19 13:04:27 -0800 | [diff] [blame] | 329 | md5sum -b "$COREBOOT_IMAGE" > "${tmpdir}/rom_checksum.txt" |
Paul Menzel | 1cc77e0 | 2015-02-19 19:35:58 +0100 | [diff] [blame] | 330 | |
David Hendricks | 9f54297 | 2015-11-19 13:08:51 -0800 | [diff] [blame] | 331 | if test $do_clean_cbfstool -eq 1; then |
| 332 | make -C util/cbfstool clean |
| 333 | fi |
| 334 | |
Paul Menzel | 1cc77e0 | 2015-02-19 19:35:58 +0100 | [diff] [blame] | 335 | # Obtain board and revision info to form the directory structure: |
| 336 | # <vendor>/<board>/<revision>/<timestamp> |
Martin Roth | 9f25da1 | 2015-12-17 12:49:15 -0700 | [diff] [blame] | 337 | mainboard_dir="$(grep CONFIG_MAINBOARD_DIR "${tmpdir}/config.txt" | awk -F '"' '{ print $2 }')" |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 338 | vendor=$(echo "$mainboard_dir" | awk -F '/' '{ print $1 }') |
| 339 | mainboard=$(echo "$mainboard_dir" | awk -F '/' '{ print $2 }') |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 340 | |
David Hendricks | c5e947ef | 2013-11-11 18:43:39 -0800 | [diff] [blame] | 341 | getrevision="util/board_status/getrevision.sh" |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 342 | test_cmd $LOCAL $getrevision |
| 343 | tagged_version=$($getrevision -T) |
| 344 | timestamp=$($getrevision -t) |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 345 | |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 346 | results="${vendor}/${mainboard}/${tagged_version}/${timestamp}" |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 347 | |
Paul Menzel | c724ac1 | 2017-10-15 10:56:36 +0200 | [diff] [blame] | 348 | if [ -n "$(echo $tagged_version | grep dirty)" ]; then |
| 349 | echo "The repository is in a dirty state. Please see the output of" |
| 350 | echo "'git status' below." |
| 351 | git status |
| 352 | exit $EXIT_FAILURE |
| 353 | fi |
| 354 | |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 355 | echo "Temporarily placing output in ${tmpdir}/${results}" |
| 356 | mkdir -p "${tmpdir}/${results}" |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 357 | |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 358 | mv "${tmpdir}/config.txt" "${tmpdir}/${results}" |
Martin Roth | 2e44ea2 | 2015-12-17 12:33:39 -0700 | [diff] [blame] | 359 | test -f "${tmpdir}/payload_config.txt" && mv "${tmpdir}/payload_config.txt" "${tmpdir}/${results}" |
| 360 | test -f "${tmpdir}/payload_version.txt" && mv "${tmpdir}/payload_version.txt" "${tmpdir}/${results}" |
Patrick Georgi | 368488a | 2015-06-12 11:35:10 +0200 | [diff] [blame] | 361 | mv "${tmpdir}/config.short.txt" "${tmpdir}/${results}" |
Paul Menzel | 4b10bb7 | 2014-05-30 09:26:46 +0200 | [diff] [blame] | 362 | mv "${tmpdir}/cbfs.txt" "${tmpdir}/${results}" |
Martin Roth | 072b5aa | 2015-12-17 12:44:35 -0700 | [diff] [blame] | 363 | mv "${tmpdir}/rom_checksum.txt" "${tmpdir}/${results}" |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 364 | |
Martin Roth | 9f25da1 | 2015-12-17 12:49:15 -0700 | [diff] [blame] | 365 | touch "${tmpdir}/${results}/revision.txt" |
| 366 | printf "Local revision: %s\n" "$($getrevision -l)" >> "${tmpdir}/${results}/revision.txt" |
| 367 | printf "Tagged revision: %s\n" "${tagged_version}" >> "${tmpdir}/${results}/revision.txt" |
| 368 | printf "Upstream revision: %s\n" "$($getrevision -u)" >> "${tmpdir}/${results}/revision.txt" |
| 369 | printf "Upstream URL: %s\n" "$($getrevision -U)" >> "${tmpdir}/${results}/revision.txt" |
| 370 | printf "Timestamp: %s\n" "$timestamp" >> "${tmpdir}/${results}/revision.txt" |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 371 | |
David Hendricks | c863be7 | 2017-09-16 12:59:23 -0700 | [diff] [blame] | 372 | if [ -n "$CBMEM_PATH" ]; then |
| 373 | cbmem_cmd="$CBMEM_PATH" |
| 374 | else |
| 375 | cbmem_cmd="cbmem" |
| 376 | fi |
| 377 | |
Evgeny Zinoviev | b863468 | 2018-09-11 00:02:36 +0300 | [diff] [blame] | 378 | cmos_enabled=0 |
| 379 | if grep -q "CONFIG_USE_OPTION_TABLE=y" "${tmpdir}/${results}/config.short.txt" > /dev/null; then |
| 380 | cmos_enabled=1 |
| 381 | fi |
| 382 | |
| 383 | if [ -n "$NVRAMTOOL_PATH" ]; then |
| 384 | nvramtool_cmd="$NVRAMTOOL_PATH" |
| 385 | else |
| 386 | nvramtool_cmd="nvramtool" |
| 387 | fi |
| 388 | |
David Hendricks | bb90fb5 | 2017-09-16 13:01:13 -0700 | [diff] [blame] | 389 | if [ -n "$SERIAL_DEVICE" ]; then |
| 390 | get_serial_bootlog "$SERIAL_DEVICE" "$SERIAL_PORT_SPEED" "${tmpdir}/${results}/coreboot_console.txt" |
| 391 | elif [ -n "$REMOTE_HOST" ]; then |
Martin Roth | 574d165 | 2015-12-17 12:38:45 -0700 | [diff] [blame] | 392 | echo "Verifying that CBMEM is available on remote device" |
David Hendricks | c863be7 | 2017-09-16 12:59:23 -0700 | [diff] [blame] | 393 | test_cmd $REMOTE "$cbmem_cmd" |
Martin Roth | 574d165 | 2015-12-17 12:38:45 -0700 | [diff] [blame] | 394 | echo "Getting coreboot boot log" |
Paul Menzel | b7b085d | 2018-09-06 17:32:58 +0200 | [diff] [blame] | 395 | cmd $REMOTE "$cbmem_cmd -1" "${tmpdir}/${results}/coreboot_console.txt" |
Martin Roth | 574d165 | 2015-12-17 12:38:45 -0700 | [diff] [blame] | 396 | echo "Getting timestamp data" |
David Hendricks | c863be7 | 2017-09-16 12:59:23 -0700 | [diff] [blame] | 397 | cmd_nonfatal $REMOTE "$cbmem_cmd -t" "${tmpdir}/${results}/coreboot_timestamps.txt" |
David Hendricks | 0dcfb59 | 2017-09-16 18:43:08 -0700 | [diff] [blame] | 398 | |
Evgeny Zinoviev | b863468 | 2018-09-11 00:02:36 +0300 | [diff] [blame] | 399 | if [ "$cmos_enabled" -eq 1 ]; then |
| 400 | echo "Verifying that nvramtool is available on remote device" |
| 401 | test_cmd $REMOTE "$nvramtool_cmd" |
| 402 | echo "Getting all CMOS values" |
| 403 | cmd $REMOTE "$nvramtool_cmd -a" "${tmpdir}/${results}/cmos_values.txt" |
| 404 | fi |
| 405 | |
David Hendricks | 0dcfb59 | 2017-09-16 18:43:08 -0700 | [diff] [blame] | 406 | echo "Getting remote dmesg" |
Arthur Heymans | 7ccb282 | 2018-12-16 22:38:58 +0100 | [diff] [blame] | 407 | cmd $REMOTE dmesg "${tmpdir}/${results}/kernel_log.txt" |
Martin Roth | 8e0071b | 2014-07-10 15:00:35 -0600 | [diff] [blame] | 408 | else |
David Hendricks | bb90fb5 | 2017-09-16 13:01:13 -0700 | [diff] [blame] | 409 | echo "Verifying that CBMEM is available" |
| 410 | if [ $(id -u) -ne 0 ]; then |
Matthias Gazzari | 25c7e32 | 2018-05-02 15:43:27 +0200 | [diff] [blame] | 411 | command -v "$cbmem_cmd" >/dev/null |
David Hendricks | bb90fb5 | 2017-09-16 13:01:13 -0700 | [diff] [blame] | 412 | if [ $? -ne 0 ]; then |
Matthias Gazzari | 25c7e32 | 2018-05-02 15:43:27 +0200 | [diff] [blame] | 413 | echo "Failed to run $cbmem_cmd. Check \$PATH or" \ |
| 414 | "use -c to specify path to cbmem binary." |
David Hendricks | bb90fb5 | 2017-09-16 13:01:13 -0700 | [diff] [blame] | 415 | exit $EXIT_FAILURE |
| 416 | else |
| 417 | cbmem_cmd="sudo $cbmem_cmd" |
| 418 | fi |
| 419 | else |
| 420 | test_cmd $LOCAL "$cbmem_cmd" |
| 421 | fi |
| 422 | |
| 423 | echo "Getting coreboot boot log" |
Paul Menzel | b7b085d | 2018-09-06 17:32:58 +0200 | [diff] [blame] | 424 | cmd $LOCAL "$cbmem_cmd -1" "${tmpdir}/${results}/coreboot_console.txt" |
Paul Menzel | 5e20c1c | 2020-03-14 17:36:10 +0100 | [diff] [blame] | 425 | if [ $(grep -- -dirty "${tmpdir}/${results}/coreboot_console.txt") ]; then |
| 426 | echo "coreboot or the payload are built from a source tree in a" \ |
| 427 | "dirty state, making it hard to reproduce the result. Please" \ |
| 428 | "check in your source tree with 'git status'." |
| 429 | exit $EXIT_FAILURE |
| 430 | fi |
| 431 | |
David Hendricks | bb90fb5 | 2017-09-16 13:01:13 -0700 | [diff] [blame] | 432 | echo "Getting timestamp data" |
| 433 | cmd_nonfatal $LOCAL "$cbmem_cmd -t" "${tmpdir}/${results}/coreboot_timestamps.txt" |
| 434 | |
Evgeny Zinoviev | b863468 | 2018-09-11 00:02:36 +0300 | [diff] [blame] | 435 | if [ "$cmos_enabled" -eq 1 ]; then |
| 436 | echo "Verifying that nvramtool is available" |
| 437 | if [ $(id -u) -ne 0 ]; then |
| 438 | command -v "$nvramtool_cmd" >/dev/null |
| 439 | if [ $? -ne 0 ]; then |
| 440 | echo "Failed to run $nvramtool_cmd. Check \$PATH or" \ |
| 441 | "use -n to specify path to nvramtool binary." |
| 442 | exit $EXIT_FAILURE |
| 443 | else |
| 444 | nvramtool_cmd="sudo $nvramtool_cmd" |
| 445 | fi |
| 446 | else |
| 447 | test_cmd $LOCAL "$nvramtool_cmd" |
| 448 | fi |
| 449 | |
| 450 | echo "Getting all CMOS values" |
| 451 | cmd $LOCAL "$nvramtool_cmd -a" "${tmpdir}/${results}/cmos_values.txt" |
| 452 | fi |
| 453 | |
David Hendricks | bb90fb5 | 2017-09-16 13:01:13 -0700 | [diff] [blame] | 454 | echo "Getting local dmesg" |
Arthur Heymans | 7ccb282 | 2018-12-16 22:38:58 +0100 | [diff] [blame] | 455 | cmd $LOCAL "sudo dmesg" "${tmpdir}/${results}/kernel_log.txt" |
Martin Roth | 8e0071b | 2014-07-10 15:00:35 -0600 | [diff] [blame] | 456 | fi |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 457 | |
David Hendricks | a4affe1 | 2013-11-12 18:17:19 -0800 | [diff] [blame] | 458 | # |
| 459 | # Finish up. |
| 460 | # |
Martin Roth | bcd0993 | 2014-07-10 15:02:19 -0600 | [diff] [blame] | 461 | coreboot_dir=$(pwd) |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 462 | if [ $UPLOAD_RESULTS -eq 1 ]; then |
| 463 | # extract username from ssh://<username>@review.coreboot.org/blah |
Patrick Georgi | 77b182a | 2014-08-10 15:18:22 +0200 | [diff] [blame] | 464 | bsrepo=$(git config --get remote.origin.url | sed "s,\(.*\)/coreboot,\1/board-status,") |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 465 | |
| 466 | cd "util/board_status/" |
| 467 | if [ ! -e "board-status" ]; then |
David Hendricks | a4affe1 | 2013-11-12 18:17:19 -0800 | [diff] [blame] | 468 | # FIXME: the board-status directory might get big over time. |
| 469 | # Is there a way we can push the results without fetching the |
| 470 | # whole repo? |
Martin Roth | 9f25da1 | 2015-12-17 12:49:15 -0700 | [diff] [blame] | 471 | git clone "$bsrepo" |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 472 | if [ $? -ne 0 ]; then |
Paul Menzel | 749e075 | 2015-05-20 22:32:15 +0200 | [diff] [blame] | 473 | echo "Error cloning board-status repo, aborting." |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 474 | exit $EXIT_FAILURE |
| 475 | fi |
| 476 | fi |
| 477 | |
| 478 | cd "board-status" |
Huimin Zhang | 2fb2483 | 2016-03-30 00:54:16 -0700 | [diff] [blame] | 479 | |
| 480 | echo "Checking for duplicate results" |
| 481 | # get any updates to board-status |
| 482 | git pull |
| 483 | |
| 484 | echo "${tagged_version}" | grep dirty >/dev/null 2>&1 |
| 485 | clean_version=$? |
| 486 | existing_results=$(git ls-files "${mainboard_dir}/${tagged_version}") |
| 487 | |
| 488 | # reject duplicate results of non-dirty versions |
| 489 | if [ "${clean_version}" -eq 1 ] && [ -n "${existing_results}" ] ; then |
| 490 | echo "Result is a duplicate, aborting" |
| 491 | exit $EXIT_FAILURE |
| 492 | fi |
| 493 | |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 494 | echo "Copying results to $(pwd)/${results}" |
| 495 | |
| 496 | # Note: Result directory should be unique due to the timestamp. |
| 497 | cp -R "${tmpdir}/${vendor}" . |
| 498 | |
| 499 | echo "Uploading results" |
| 500 | git add "${vendor}" |
Paul Menzel | 04eb2e8 | 2014-02-09 10:24:22 +0100 | [diff] [blame] | 501 | git commit -a -m "${mainboard_dir}/${tagged_version}/${timestamp}" |
Paul Menzel | 54e6aa7 | 2015-05-20 07:35:56 +0200 | [diff] [blame] | 502 | count=0 |
Jonathan Neuschäfer | 478c889 | 2016-05-10 17:43:53 +0200 | [diff] [blame] | 503 | until git push origin master || test $count -eq 3; do |
Paul Menzel | 54e6aa7 | 2015-05-20 07:35:56 +0200 | [diff] [blame] | 504 | git pull --rebase |
| 505 | count=$((count + 1)) |
| 506 | done |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 507 | |
| 508 | # Results have been uploaded so it's pointless to keep the |
| 509 | # temporary files around. |
| 510 | rm -rf "${tmpdir}" |
Paul Menzel | 54e6aa7 | 2015-05-20 07:35:56 +0200 | [diff] [blame] | 511 | if test $count -eq 3; then |
| 512 | echo "Error uploading to board-status repo, aborting." |
| 513 | exit $EXIT_FAILURE |
| 514 | fi |
David Hendricks | 1b6e7a6 | 2013-11-11 18:44:05 -0800 | [diff] [blame] | 515 | fi |
| 516 | cd "$coreboot_dir" |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 517 | |
| 518 | if [ $CLOBBER_OUTPUT -eq 1 ]; then |
Martin Roth | 9f25da1 | 2015-12-17 12:49:15 -0700 | [diff] [blame] | 519 | rm -rf "${tmpdir}" |
Martin Roth | 13c7db8 | 2014-07-10 14:59:11 -0600 | [diff] [blame] | 520 | else |
David Hendricks | 588a722 | 2017-09-05 23:38:03 -0700 | [diff] [blame] | 521 | if [ $UPLOAD_RESULTS -eq 1 ]; then |
| 522 | echo |
| 523 | echo "output files are in $(dirname $0)/board-status/${mainboard_dir}/${tagged_version}/${timestamp}" |
| 524 | else |
| 525 | echo |
| 526 | echo "output files are in ${tmpdir}/${results}" |
| 527 | fi |
David Hendricks | 6583a81 | 2013-11-01 19:37:44 -0700 | [diff] [blame] | 528 | fi |
| 529 | |
| 530 | exit $EXIT_SUCCESS |