| #!/bin/bash |
| # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| # |
| # This opens various servo consoles using cu, from outside the chroot, |
| # automatically getting the correct console from dut-control. This |
| # also tees the output to a secondary logfile. |
| # |
| # The recommended way to use this is to setup an alias, e.g. add this in |
| # your .bashrc (outside the chroot): |
| # alias dut-console="~/chromiumos/src/platform/dev/contrib/dut-console" |
| # And then simply run: |
| # dut-console ec |
| # |
| # The script also allows to connect to different servod port, e.g. |
| # dut-control cpu 9999 |
| |
| # Script is stored in $CROS_SDK/src/platform/dev/contrib |
| CROS_SDK="$(readlink -f "$(dirname "$0")/../../../..")" |
| PYTHONPATH="${CROS_SDK}/chroot/usr/lib64/python2.7/site-packages" |
| |
| get_pty() { |
| local pty_name="$1" |
| local port="$2" |
| local args=() |
| |
| if [[ -n "${port}" ]]; then |
| args+=( --port "${port}" ) |
| fi |
| |
| PYTHONPATH="${PYTHONPATH}" \ |
| python "${PYTHONPATH}/servo/dut_control.py" "${pty_name}" "${args[@]}" | \ |
| cut -d : -f 2 |
| } |
| |
| find_cu() { |
| if ! hash cu; then |
| echo "Please install cu first:" >&2 |
| echo "sudo apt-get install cu" >&2 |
| exit 1 |
| fi |
| } |
| |
| usage() { |
| cat <<EOF |
| dut-control type [port] |
| |
| Opens CPU/EC servo console using "cu", outputs to both terminal, and an output |
| file named "log-\${type}[-\${port}]" in the current directory. |
| |
| type One of cpu, ec, cr50, fpmcu, servo, servo_v4 |
| [port] servod port (optional, uses default if not specified) |
| EOF |
| exit 2 |
| } |
| |
| main() { |
| local type="$1" |
| local port="$2" |
| local pty |
| local pty_name |
| local outlog |
| |
| find_cu |
| |
| case "${type}" in |
| cpu) |
| pty_name=cpu_uart_pty |
| ;; |
| ec) |
| pty_name=ec_uart_pty |
| ;; |
| cr50) |
| pty_name=cr50_uart_pty |
| ;; |
| fpmcu) |
| pty_name=fpmcu_uart_pty |
| ;; |
| servo) |
| pty_name=servo_console_pty |
| ;; |
| servo_v4) |
| pty_name=servo_v4_console_pty |
| ;; |
| *) |
| usage |
| ;; |
| esac |
| |
| pty="$(get_pty "${pty_name}" "${port}")" |
| |
| if [[ ! -e "${pty}" ]]; then |
| echo "Cannot find pty ${pty_name}." >&2 |
| exit 1 |
| fi |
| |
| outlog="log-${type}" |
| |
| if [[ -n "${port}" ]]; then |
| outlog="${outlog}-${port}" |
| fi |
| |
| echo "Opening ${pty_name}:${pty}..." |
| echo "Log in ${outlog}, type ~.<enter> to exit." |
| |
| cu --nostop -l "${pty}" | tee "${outlog}" |
| } |
| |
| main "$@" |