meta-ampere: mtmitchell: Refactor obmc-console setup
This commit refactors obmc-console setup for mtmitchell
Tested:
1. Successfully connects to host consoles via ssh sol
$ ssh root@${bmc} -p 220*
2. Successfully connects host consoles via ipmi sol
$ ipmitool -I lanplus -H ${bmc} -U root -P 0penBmc \
-C 17 sol activate
3. All the host console logs are in /var/log/
Signed-off-by: Chau Ly <chaul@amperecomputing.com>
Change-Id: Ia1e6faaa4757e8f478352fd03ed977beeac15200
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init.bb b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init.bb
index dd5f599..12a5c09 100644
--- a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init.bb
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init.bb
@@ -19,6 +19,8 @@
file://ampere_bmc_heartbeat.sh \
file://${MACHINE}_platform_gpios_init.sh \
file://gpio-lib.sh \
+ file://ampere_uart_console_setup.sh \
+ file://ampere_uartmux_ctrl.sh \
"
SYSTEMD_PACKAGES = "${PN}"
SYSTEMD_SERVICE:${PN} = "ampere-platform-init.service ampere-bmc-heartbeat.service"
@@ -29,6 +31,8 @@
install -m 0755 ${WORKDIR}/ampere_platform_init.sh ${D}${sbindir}/
install -m 0755 ${WORKDIR}/ampere_bmc_heartbeat.sh ${D}${sbindir}/
install -m 0755 ${WORKDIR}/${MACHINE}_platform_gpios_init.sh ${D}${sbindir}/platform_gpios_init.sh
+ install -m 0755 ${WORKDIR}/ampere_uart_console_setup.sh ${D}${sbindir}/
+ install -m 0755 ${WORKDIR}/ampere_uartmux_ctrl.sh ${D}/${sbindir}/
install -d ${D}${systemd_unitdir}/system/
install -m 0644 ${WORKDIR}/ampere-platform-init.service ${D}${systemd_unitdir}/system
}
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh
index 9d6ca0e..cae866e 100644
--- a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_platform_init.sh
@@ -4,6 +4,7 @@
source /usr/sbin/gpio-lib.sh
# shellcheck source=meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/mtmitchell_platform_gpios_init.sh
source /usr/sbin/platform_gpios_init.sh
+source /usr/sbin/ampere_uart_console_setup.sh
#pre platform init function. implemented in platform_gpios_init.sh
pre-platform-init
@@ -41,6 +42,10 @@
gpio_name_input "$gpioName"
done
+# =======================================================
+# Setting uart muxes to BMC as default
+uart_console_setup
+
#post platform init function. implemented in platform_gpios_init.sh
post-platform-init
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_uart_console_setup.sh b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_uart_console_setup.sh
new file mode 100644
index 0000000..10a1981
--- /dev/null
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_uart_console_setup.sh
@@ -0,0 +1,47 @@
+#!/bin/sh -e
+
+# shellcheck disable=SC2039
+# shellcheck disable=SC2112
+# shellcheck disable=SC3010
+# shellcheck disable=SC3030
+# shellcheck disable=SC3054
+
+export obmc_console_tty=("ttyS0" "ttyS1" "ttyS2" "ttyS3" "ttyS7" "ttyS8")
+
+function get_uart_port()
+{
+ tty=$1
+ case "${tty}" in
+ "ttyS0") uart=1
+ ;;
+ "ttyS1") uart=2
+ ;;
+ "ttyS2") uart=3
+ ;;
+ "ttyS3") uart=4
+ ;;
+ "ttyS7") uart=0
+ ;;
+ "ttyS8") uart=0
+ ;;
+ *) echo "Invalid tty passed to $0. Exiting!"
+ exit 1;
+ ;;
+ esac
+ echo $uart
+}
+
+function uart_console_setup()
+{
+ # Default the host routing through the mux to use the BMC (2)
+ # This allows the SoL console in webui, and the ssh port 2200, to work
+ # upon startup. If UART transcievers are installed on the header and required,
+ # this value should be set to 1
+ for tty in "${obmc_console_tty[@]}"; do
+ uart=$(get_uart_port "$tty")
+ if [ "${uart}" -ne 0 ]
+ then
+ /usr/sbin/ampere_uartmux_ctrl.sh "${uart}" 2
+ fi
+ done
+}
diff --git a/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_uartmux_ctrl.sh b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_uartmux_ctrl.sh
new file mode 100644
index 0000000..3148b61
--- /dev/null
+++ b/meta-ampere/meta-mitchell/recipes-ampere/platform/ampere-platform-init/ampere_uartmux_ctrl.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+#
+# shellcheck disable=SC2046
+# This can be called to set uart mux manually
+
+if [ $# -lt 2 ]; then
+ exit 1
+fi
+
+case "$1" in
+ 1) GPIO_UARTx_MODE0="uart1-mode0"
+ GPIO_UARTx_MODE1="uart1-mode1"
+ ;;
+ 2) GPIO_UARTx_MODE0="uart2-mode0"
+ GPIO_UARTx_MODE1="uart2-mode1"
+ ;;
+ 3) GPIO_UARTx_MODE0="uart3-mode0"
+ GPIO_UARTx_MODE1="uart3-mode1"
+ ;;
+ 4) GPIO_UARTx_MODE0="uart4-mode0"
+ GPIO_UARTx_MODE1="uart4-mode1"
+ ;;
+ *) echo "Invalid UART port selection"
+ exit 1
+ ;;
+esac
+
+echo "Ampere UART MUX CTRL UART port $1 to mode $2"
+
+case "$2" in
+ # To HDR
+ 1) gpioset $(gpiofind "$GPIO_UARTx_MODE0")=1
+ gpioset $(gpiofind "$GPIO_UARTx_MODE1")=0
+ exit 0
+ ;;
+ # To BMC
+ 2) gpioset $(gpiofind "$GPIO_UARTx_MODE0")=0
+ gpioset $(gpiofind "$GPIO_UARTx_MODE1")=1
+ exit 0
+ ;;
+ *) echo "Invalid UART mode selection"
+ exit 1
+ ;;
+esac