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 | ;; |
Chau Ly | 23148bd | 2023-01-13 04:18:51 +0000 | [diff] [blame^] | 15 | 2) GPIO_UARTx_MODE0="uart2-mode0" |
| 16 | GPIO_UARTx_MODE1="uart2-mode1" |
| 17 | # CPU0 UART1 connects to BMC UART2 |
| 18 | CONSOLE_PORT=1 |
| 19 | ;; |
| 20 | 3) GPIO_UARTx_MODE0="uart3-mode0" |
| 21 | GPIO_UARTx_MODE1="uart3-mode1" |
| 22 | # CPU0 UART4 connects to BMC UART3 |
| 23 | CONSOLE_PORT=2 |
| 24 | ;; |
| 25 | 4) GPIO_UARTx_MODE0="uart4-mode0" |
| 26 | GPIO_UARTx_MODE1="uart4-mode1" |
| 27 | # CPU1 UART1 connects to BMC UART4 |
| 28 | CONSOLE_PORT=3 |
| 29 | ;; |
Hieu Huynh | 325a811 | 2022-10-24 11:15:17 +0000 | [diff] [blame] | 30 | *) echo "Invalid UART port selection" |
| 31 | exit 1 |
| 32 | ;; |
| 33 | esac |
| 34 | |
| 35 | # Only switch the MUX when there is no active connection. This means we only |
| 36 | # switch the MUX before the first session starts and after the last session |
| 37 | # closes. We do this by querying number of connected sessions to the socket |
| 38 | # of requested console port. |
| 39 | # Example format: Accepted: 1; Connected: 1; |
| 40 | CONNECTED=$(systemctl --no-pager status obmc-console-ttyS${CONSOLE_PORT}-ssh.socket | grep -w Connected | cut -d ':' -f 3 | tr -d ' ;') |
| 41 | if [ ! "$CONNECTED" -le 1 ]; then |
| 42 | echo "Please close all connected session to ttyS${CONSOLE_PORT} !" |
| 43 | exit 0 |
| 44 | fi |
| 45 | |
| 46 | echo "Ampere UART MUX CTRL UART port $1 to mode $2" |
| 47 | |
| 48 | case "$2" in |
| 49 | # To HDR |
| 50 | 1) gpioset $(gpiofind "$GPIO_UARTx_MODE0")=1 |
| 51 | gpioset $(gpiofind "$GPIO_UARTx_MODE1")=0 |
| 52 | exit 0 |
| 53 | ;; |
| 54 | # To BMC |
| 55 | 2) gpioset $(gpiofind "$GPIO_UARTx_MODE0")=0 |
| 56 | gpioset $(gpiofind "$GPIO_UARTx_MODE1")=1 |
| 57 | exit 0 |
| 58 | ;; |
| 59 | *) echo "Invalid UART mode selection" |
| 60 | exit 1 |
| 61 | ;; |
| 62 | esac |