blob: 387cfcf92cad07fdade7963499100666f9a28da2 [file] [log] [blame]
Hieu Huynh325a8112022-10-24 11:15:17 +00001#!/bin/bash
2#
3# shellcheck disable=SC2046
4
5if [ $# -lt 2 ]; then
6 exit 1
7fi
8
9case "$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 ;;
18esac
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;
25CONNECTED=$(systemctl --no-pager status obmc-console-ttyS${CONSOLE_PORT}-ssh.socket | grep -w Connected | cut -d ':' -f 3 | tr -d ' ;')
26if [ ! "$CONNECTED" -le 1 ]; then
27 echo "Please close all connected session to ttyS${CONSOLE_PORT} !"
28 exit 0
29fi
30
31echo "Ampere UART MUX CTRL UART port $1 to mode $2"
32
33case "$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 ;;
47esac