meta-fii/meta-kudo: add sol connection

1. support the Ampere host and SCP

Signed-off-by: Lancelot Kao <lancelot.kao@fii-usa.com>
Change-Id: Ifb07bac01264c8d04741e6996f421ab457291d39
Signed-off-by: Mohaimen Alsamarai <mohaimen.alsamarai@fii-na.com>
diff --git a/meta-fii/meta-kudo/conf/machine/kudo.conf b/meta-fii/meta-kudo/conf/machine/kudo.conf
index c136987..ff3bbf9 100644
--- a/meta-fii/meta-kudo/conf/machine/kudo.conf
+++ b/meta-fii/meta-kudo/conf/machine/kudo.conf
@@ -20,6 +20,8 @@
 
 IMAGE_FSTYPES += " cpio.${INITRAMFS_CTYPE}.u-boot"
 
+SERIAL_CONSOLES = "115200;ttyS0"
+
 OBMC_MACHINE_FEATURES += " \
     obmc-host-ipmi \
     "
diff --git a/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console/kudo_uart_mux_ctrl.sh b/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console/kudo_uart_mux_ctrl.sh
new file mode 100644
index 0000000..2740778
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console/kudo_uart_mux_ctrl.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+#
+# Copyright (c) 2020 Ampere Computing LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#	http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Ampere Computing LLC mtjade: UART MUX/DEMUX for CPU0 UART0,1,4 and CPU1 UART1
+# Usage: ampere_uartmux_ctrl.sh <CPU UART port number> <UARTx_MODE>
+#        <UARTx_MODE> of 1 sets CPU To BSP
+#        <UARTx_MODE> of 2 sets SCP1 to SI2 
+function set_gpio_ctrl() {
+  echo $1 > /sys/class/gpio/export
+  echo $2 > /sys/class//gpio/gpio$1/direction
+  echo $3 > /sys/class/gpio/gpio$1/value
+  echo $1 > /sys/class/gpio/unexport
+}
+
+
+if [ $# -lt 1 ]; then
+  exit 1
+fi
+
+echo "Ampere UART MUX CTRL UART port $1 to mode" > /dev/ttyS0
+
+case "$1" in
+  ttyS1)
+    set_gpio_ctrl 167 out 1
+    ;;
+  ttyS3)
+    set_gpio_ctrl 161 out 1
+    set_gpio_ctrl 183 out 1 
+    set_gpio_ctrl 198 out 0
+    ;;
+  *)
+    echo "Invalid tty passed to $0. Exiting!" > /dev/ttyS0
+    ;;
+esac
+
diff --git a/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console/obmc-console@.service b/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console/obmc-console@.service
new file mode 100644
index 0000000..695eec3
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console/obmc-console@.service
@@ -0,0 +1,18 @@
+[Unit]
+Description=Phosphor Console Muxer listening on device /dev/%I
+BindsTo=dev-%i.device
+After=dev-%i.device
+StartLimitBurst=3
+StartLimitIntervalSec=300
+
+[Service]
+ExecStartPre=/usr/sbin/kudo_uart_mux_ctrl.sh %i
+ExecStart=/usr/sbin/obmc-console-server --config /etc/obmc-console/server.%i.conf %i
+SyslogIdentifier=obmc-console-server
+Restart=always
+RestartSec=10
+TimeoutStartSec=60
+TimeoutStopSec=60
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console/server.ttyS1.conf b/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console/server.ttyS1.conf
new file mode 100644
index 0000000..1751a05
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console/server.ttyS1.conf
@@ -0,0 +1,2 @@
+baud = 115200
+logfile = /var/log/obmc-console-cpu.log
diff --git a/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console/server.ttyS3.conf b/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console/server.ttyS3.conf
new file mode 100644
index 0000000..c8a9d97
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console/server.ttyS3.conf
@@ -0,0 +1,3 @@
+baud = 115200
+socket-id = ttyS3
+logfile = /var/log/obmc-console-scp.log
diff --git a/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console_%.bbappend b/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console_%.bbappend
new file mode 100644
index 0000000..9daae7c
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-phosphor/console/obmc-console_%.bbappend
@@ -0,0 +1,41 @@
+FILESEXTRAPATHS_prepend_kudo := "${THISDIR}/${PN}:"
+RDEPENDS_${PN}_append_kudo = " bash"
+
+# Remove what installed by common recipe
+OBMC_CONSOLE_HOST_TTY = ""
+SYSTEMD_SUBSTITUTIONS_remove_kudo = " OBMC_CONSOLE_HOST_TTY:${OBMC_CONSOLE_HOST_TTY}:${PN}-ssh@.service"
+SYSTEMD_SUBSTITUTIONS_remove_kudo = " OBMC_CONSOLE_HOST_TTY:${OBMC_CONSOLE_HOST_TTY}:${PN}-ssh.socket"
+
+# Declare port spcific conf and service files
+HOST_CONSOLE_TTY = "ttyS1 ttyS3"
+
+CONSOLE_CONF_FMT = "file://server.{0}.conf"
+SRC_URI_append_kudo = " ${@compose_list(d, 'CONSOLE_CONF_FMT', 'HOST_CONSOLE_TTY')}"
+SRC_URI_append_kudo = " file://${BPN}@.service"
+SRC_URI_append_kudo = " file://kudo_uart_mux_ctrl.sh"
+
+SYSTEMD_SERVICE_${PN}_append_kudo = " \
+        ${PN}@.service \
+        "
+
+do_install_append() {
+    for i in ${HOST_CONSOLE_TTY}
+    do
+        install -m 0644 ${WORKDIR}/server.${i}.conf ${D}${sysconfdir}/${BPN}/server.${i}.conf
+    done
+
+    # Deal with files installed by the base package's .bb install function
+    rm -f ${D}${sysconfdir}/${BPN}.conf
+    rm -f ${D}${sysconfdir}/${BPN}/server.ttyVUART0.conf
+
+    # Overwrite base package's obmc-console@.service with our own
+    install -m 0644 ${WORKDIR}/${BPN}@.service ${D}${systemd_unitdir}/system/${BPN}@.service
+    install -d ${D}/usr/sbin
+    install -m 0755 ${WORKDIR}/kudo_uart_mux_ctrl.sh ${D}/${sbindir}/kudo_uart_mux_ctrl.sh
+
+}
+
+pkg_postinst_${PN}_append () {
+    systemctl --root=$D enable obmc-console@ttyS1.service
+    systemctl --root=$D enable obmc-console@ttyS3.service
+}