Hieu Huynh | 325a811 | 2022-10-24 11:15:17 +0000 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # shellcheck disable=SC2046 |
| 4 | |
| 5 | if [ $# -lt 2 ]; then |
| 6 | exit 1 |
| 7 | fi |
| 8 | |
| 9 | case "$1" in |
| 10 | 1) GPIO_UARTx_MODE0="uart1-mode0" |
| 11 | GPIO_UARTx_MODE1="uart1-mode1" |
| 12 | # CPU0 UART0 connects to BMC UART1 |
| 13 | CONSOLE_PORT=0 |
| 14 | ;; |
| 15 | *) echo "Invalid UART port selection" |
| 16 | exit 1 |
| 17 | ;; |
| 18 | esac |
| 19 | |
| 20 | # Only switch the MUX when there is no active connection. This means we only |
| 21 | # switch the MUX before the first session starts and after the last session |
| 22 | # closes. We do this by querying number of connected sessions to the socket |
| 23 | # of requested console port. |
| 24 | # Example format: Accepted: 1; Connected: 1; |
| 25 | CONNECTED=$(systemctl --no-pager status obmc-console-ttyS${CONSOLE_PORT}-ssh.socket | grep -w Connected | cut -d ':' -f 3 | tr -d ' ;') |
| 26 | if [ ! "$CONNECTED" -le 1 ]; then |
| 27 | echo "Please close all connected session to ttyS${CONSOLE_PORT} !" |
| 28 | exit 0 |
| 29 | fi |
| 30 | |
| 31 | echo "Ampere UART MUX CTRL UART port $1 to mode $2" |
| 32 | |
| 33 | case "$2" in |
| 34 | # To HDR |
| 35 | 1) gpioset $(gpiofind "$GPIO_UARTx_MODE0")=1 |
| 36 | gpioset $(gpiofind "$GPIO_UARTx_MODE1")=0 |
| 37 | exit 0 |
| 38 | ;; |
| 39 | # To BMC |
| 40 | 2) gpioset $(gpiofind "$GPIO_UARTx_MODE0")=0 |
| 41 | gpioset $(gpiofind "$GPIO_UARTx_MODE1")=1 |
| 42 | exit 0 |
| 43 | ;; |
| 44 | *) echo "Invalid UART mode selection" |
| 45 | exit 1 |
| 46 | ;; |
| 47 | esac |