3 # This file is part of the coreboot project.
5 # Copyright (C) 2013 Google Inc.
6 # Copyright (C) 2014 Sage Electronic Engineering, LLC.
12 # Stuff from command-line switches
13 COREBOOT_IMAGE
="build/coreboot.rom"
18 SERIAL_PORT_SPEED
=115200
20 # Used to specify whether a command should always be run locally or
21 # if command should be run remoteley when a remote host is specified.
27 # Used if cbmem is not in default $PATH, e.g. not installed or when using `sudo`
32 # $1: 0 ($LOCAL) to run command locally,
33 # 1 ($REMOTE) to run remotely if remote host defined
35 # $3: 0 ($FATAL) Exit with an error if the command fails
36 # 1 ($NONFATAL) Don't exit on command test failure
45 if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
46 ssh $REMOTE_PORT_OPTION root@
${REMOTE_HOST} command -v "$2" > /dev
/null
49 command -v "$2" >/dev
/null
53 if [ $rc -eq 0 ]; then
57 if [ "$3" = "1" ]; then
74 pipe_location
="/dev/null"
77 if [ "$1" -eq "$REMOTE" ] && [ -n "$REMOTE_HOST" ]; then
78 ssh $REMOTE_PORT_OPTION "root@${REMOTE_HOST}" "$2" > "$pipe_location" 2>&1
80 $2 > "$pipe_location" 2>&1
88 # $1: 0 ($LOCAL) to run command locally,
89 # 1 ($REMOTE) to run remotely if remote host defined
91 # $3: filename to direct output of command into
100 echo "Failed to run \"$2\", aborting"
101 rm -f "$3" # don't leave an empty file
105 # run a command where failure is considered to be non-fatal
107 # $1: 0 ($LOCAL) to run command locally,
108 # 1 ($REMOTE) to run remotely if remote host defined
110 # $3: filename to direct output of command into
115 if [ $?
-eq 0 ]; then
119 echo "Failed to run \"$2\", ignoring"
120 rm -f "$3" # don't leave an empty file
123 # read from a serial port device
125 # $1: serial device to read from
126 # $2: serial port speed
127 # $3: filename to direct output of command into
128 get_serial_bootlog
() {
134 if [ ! -c "$TTY" ]; then
135 echo "$TTY is not a valid serial device"
139 # make the text more noticible
140 test_cmd
$LOCAL "tput" $NONFATAL
141 tput_not_available
=$?
142 if [ $tput_not_available -eq 0 ]; then
144 tput setaf
10 # set bright green
148 echo "Waiting to receive boot log from $TTY"
149 echo "Press [Enter] when the boot is complete."
152 if [ $tput_not_available -eq 0 ]; then
156 # set up the serial port
157 stty
-F $TTY $SPEED cs8
-cstopb -parenb clocal
159 # read from the serial port - user must press enter when complete
160 test_cmd
$LOCAL "tee"
162 echo "$LINE" |
tee -a "$FILENAME"
163 done < "$SERIAL_DEVICE" &
167 kill "$PID" 2>/dev
/null
169 echo "Finished reading boot log."
178 Path to cbmem on device under test (DUT).
180 Clobber temporary output when finished. Useful for debugging.
184 Path to coreboot image (Default is $COREBOOT_IMAGE).
185 -r, --remote-host <host>
186 Obtain machine information from remote host (using ssh).
187 -s, --serial-device </dev/xxx>
188 Obtain boot log via serial device.
189 -S, --serial-speed <speed>
190 Set the port speed for the serial device (Default is $SERIAL_PORT_SPEED).
192 Upload results to coreboot.org.
196 Use a specific SSH port.
201 if [ $?
-ne 4 ]; then
202 echo "GNU-compatible getopt(1) required."
206 LONGOPTS
="cbmem:,clobber,help,image:,remote-host:,upload-results"
207 LONGOPTS
="${LONGOPTS},serial-device:,serial-speed:"
208 LONGOPTS
="${LONGOPTS},ssh-port:"
210 ARGS
=$
(getopt
-o c
:Chi
:r
:s
:S
:u
-l "$LONGOPTS" -n "$0" -- "$@");
211 if [ $?
!= 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
239 # serial port options
246 SERIAL_PORT_SPEED
="$1"
252 REMOTE_PORT_OPTION
="-p $1"
259 echo "Non-option parameters detected: '$*'"
265 echo "error processing options at '$1'"
271 grep -rH 'coreboot.org' .git
/config
>/dev
/null
2>&1
272 if [ $?
-ne 0 ]; then
273 echo "Script must be run from root of coreboot directory"
277 if [ ! -e "$COREBOOT_IMAGE" ]; then
278 echo "board_status needs $COREBOOT_IMAGE, but it does not exist."
279 echo "Use \"-i IMAGE_FILE\" to select a different image, or \"--help\" for more options."
283 # Results will be placed in a temporary location until we're ready to upload.
284 # If the user does not wish to upload, results will remain in /tmp.
285 tmpdir
=$
(mktemp
-d --tmpdir coreboot_board_status.XXXXXXXX
)
287 # Obtain coreboot config by running cbfstool on the ROM image. cbfstool may
288 # already exist in build/ or util/cbfstool/, but if not then we'll build it
289 # now and clean it when we're done.
290 cbfstool_cmd
="build/cbfstool"
292 if [ ! -x $cbfstool_cmd ]; then
293 cbfstool_cmd
="util/cbfstool/cbfstool"
294 if [ -e $cbfstool_cmd ]; then
295 if test ! -x $cbfstool_cmd; then
296 echo "Cannot execute $cbfstool_cmd."
300 make -C util
/cbfstool
/
304 test_cmd
$LOCAL "$cbfstool_cmd"
306 tmpcfg
=$
(mktemp coreboot_config.XXXXXX
)
307 echo "Extracting config.txt from $COREBOOT_IMAGE"
308 $cbfstool_cmd "$COREBOOT_IMAGE" extract
-n config
-f "${tmpdir}/config.txt" >/dev
/null
2>&1
309 mv "${tmpdir}/config.txt" "${tmpdir}/config.short.txt"
310 cp "${tmpdir}/config.short.txt" "${tmpcfg}"
311 yes "" |
make "DOTCONFIG=${tmpcfg}" oldconfig
2>/dev
/null
>/dev
/null
312 mv "${tmpcfg}" "${tmpdir}/config.txt"
313 rm -f "${tmpcfg}.old"
314 $cbfstool_cmd "$COREBOOT_IMAGE" print
> "${tmpdir}/cbfs.txt"
315 rom_contents
=$
($cbfstool_cmd "$COREBOOT_IMAGE" print
2>&1)
316 if [ -n "$(echo $rom_contents | grep payload_config)" ]; then
317 echo "Extracting payload_config from $COREBOOT_IMAGE"
318 $cbfstool_cmd "$COREBOOT_IMAGE" extract
-n payload_config
-f "${tmpdir}/payload_config.txt" >/dev
/null
2>&1
320 if [ -n "$(echo $rom_contents | grep payload_version)" ]; then
321 echo "Extracting payload_version from $COREBOOT_IMAGE"
322 $cbfstool_cmd "$COREBOOT_IMAGE" extract
-n payload_version
-f "${tmpdir}/payload_version.txt" >/dev
/null
2>&1
324 md5sum -b "$COREBOOT_IMAGE" > "${tmpdir}/rom_checksum.txt"
326 if test $do_clean_cbfstool -eq 1; then
327 make -C util
/cbfstool clean
330 # Obtain board and revision info to form the directory structure:
331 # <vendor>/<board>/<revision>/<timestamp>
332 mainboard_dir
="$(grep CONFIG_MAINBOARD_DIR "${tmpdir}/config.txt
" | awk -F '"' '{ print
$2 }')"
333 vendor=$(echo "$mainboard_dir" | awk -F '/' '{ print
$1 }')
334 mainboard=$(echo "$mainboard_dir" | awk -F '/' '{ print
$2 }')
336 getrevision="util/board_status/getrevision.sh"
337 test_cmd $LOCAL $getrevision
338 tagged_version=$($getrevision -T)
339 timestamp=$($getrevision -t)
341 results="${vendor}/${mainboard}/${tagged_version}/${timestamp}"
343 if [ -n "$(echo $tagged_version | grep dirty)" ]; then
344 echo "The repository is in a dirty state. Please see the output of"
345 echo "'git status
' below."
350 echo "Temporarily placing output in ${tmpdir}/${results}"
351 mkdir -p "${tmpdir}/${results}"
353 mv "${tmpdir}/config.txt" "${tmpdir}/${results}"
354 test -f "${tmpdir}/payload_config.txt" && mv "${tmpdir}/payload_config.txt" "${tmpdir}/${results}"
355 test -f "${tmpdir}/payload_version.txt" && mv "${tmpdir}/payload_version.txt" "${tmpdir}/${results}"
356 mv "${tmpdir}/config.short.txt" "${tmpdir}/${results}"
357 mv "${tmpdir}/cbfs.txt" "${tmpdir}/${results}"
358 mv "${tmpdir}/rom_checksum.txt" "${tmpdir}/${results}"
360 touch "${tmpdir}/${results}/revision.txt"
361 printf "Local revision: %s\n" "$($getrevision -l)" >> "${tmpdir}/${results}/revision.txt"
362 printf "Tagged revision: %s\n" "${tagged_version}" >> "${tmpdir}/${results}/revision.txt"
363 printf "Upstream revision: %s\n" "$($getrevision -u)" >> "${tmpdir}/${results}/revision.txt"
364 printf "Upstream URL: %s\n" "$($getrevision -U)" >> "${tmpdir}/${results}/revision.txt"
365 printf "Timestamp: %s\n" "$timestamp" >> "${tmpdir}/${results}/revision.txt"
367 if [ -n "$CBMEM_PATH" ]; then
368 cbmem_cmd="$CBMEM_PATH"
373 if [ -n "$SERIAL_DEVICE" ]; then
374 get_serial_bootlog "$SERIAL_DEVICE" "$SERIAL_PORT_SPEED" "${tmpdir}/${results}/coreboot_console.txt"
375 elif [ -n "$REMOTE_HOST" ]; then
376 echo "Verifying that CBMEM is available on remote device"
377 test_cmd $REMOTE "$cbmem_cmd"
378 echo "Getting coreboot boot log"
379 cmd $REMOTE "$cbmem_cmd -1" "${tmpdir}/${results}/coreboot_console.txt"
380 echo "Getting timestamp data"
381 cmd_nonfatal $REMOTE "$cbmem_cmd -t" "${tmpdir}/${results}/coreboot_timestamps.txt"
383 echo "Getting remote dmesg"
384 cmd $REMOTE dmesg "${tmpdir}/${results}/kernel_log.txt"
386 echo "Verifying that CBMEM is available"
387 if [ $(id -u) -ne 0 ]; then
388 command -v "$cbmem_cmd" >/dev/null
389 if [ $? -ne 0 ]; then
390 echo "Failed to run $cbmem_cmd. Check \$PATH or" \
391 "use -c to specify path to cbmem binary."
394 cbmem_cmd="sudo $cbmem_cmd"
397 test_cmd $LOCAL "$cbmem_cmd"
400 echo "Getting coreboot boot log"
401 cmd $LOCAL "$cbmem_cmd -1" "${tmpdir}/${results}/coreboot_console.txt"
402 echo "Getting timestamp data"
403 cmd_nonfatal $LOCAL "$cbmem_cmd -t" "${tmpdir}/${results}/coreboot_timestamps.txt"
405 echo "Getting local dmesg"
406 cmd $LOCAL "sudo dmesg" "${tmpdir}/${results}/kernel_log.txt"
413 if [ $UPLOAD_RESULTS -eq 1 ]; then
414 # extract username from ssh://<username>@review.coreboot.org/blah
415 bsrepo=$(git config --get remote.origin.url | sed "s,\(.*\)/coreboot,\1/board-status,")
417 cd "util/board_status/"
418 if [ ! -e "board-status" ]; then
419 # FIXME: the board-status directory might get big over time.
420 # Is there a way we can push the results without fetching the
423 if [ $? -ne 0 ]; then
424 echo "Error cloning board-status repo, aborting."
431 echo "Checking for duplicate results"
432 # get any updates to board-status
435 echo "${tagged_version}" | grep dirty >/dev/null 2>&1
437 existing_results=$(git ls-files "${mainboard_dir}/${tagged_version}")
439 # reject duplicate results of non-dirty versions
440 if [ "${clean_version}" -eq 1 ] && [ -n "${existing_results}" ] ; then
441 echo "Result is a duplicate, aborting"
445 echo "Copying results to $(pwd)/${results}"
447 # Note: Result directory should be unique due to the timestamp.
448 cp -R "${tmpdir}/${vendor}" .
450 echo "Uploading results"
452 git commit -a -m "${mainboard_dir}/${tagged_version}/${timestamp}"
454 until git push origin master || test $count -eq 3; do
459 # Results have been uploaded so it's pointless to keep the
460 # temporary files around.
462 if test $count -eq 3; then
463 echo "Error uploading to board-status repo, aborting."
469 if [ $CLOBBER_OUTPUT -eq 1 ]; then
472 if [ $UPLOAD_RESULTS -eq 1 ]; then
474 echo "output files are in $(dirname $0)/board-status/${mainboard_dir}/${tagged_version}/${timestamp}"
477 echo "output files are in ${tmpdir}/${results}"