meta-facebook: minerva: add sol function
In the Minerva system, CMM needs to switch the UART to each MTIA blade BMC console of 16 blades on the ttyS0 by controlling the UART select pins to the CPLD.
Change-Id: I094074fd27fb24627038601c67569571acf427ee
Signed-off-by: Yang Chen <yang.chen@quantatw.com>
Signed-off-by: Yi-Shum <EasonChen1@quantatw.com>
diff --git a/meta-facebook/meta-minerva/recipes-phosphor/console/obmc-console/80-minerva-obmc-console-uart.rules b/meta-facebook/meta-minerva/recipes-phosphor/console/obmc-console/80-minerva-obmc-console-uart.rules
new file mode 100644
index 0000000..2b236f7
--- /dev/null
+++ b/meta-facebook/meta-minerva/recipes-phosphor/console/obmc-console/80-minerva-obmc-console-uart.rules
@@ -0,0 +1 @@
+SUBSYSTEM=="tty", ATTRS{iomem_base}=="0x1E790000", ENV{SYSTEMD_WANTS}="obmc-console@ttyS5", TAG+="systemd"
diff --git a/meta-facebook/meta-minerva/recipes-phosphor/console/obmc-console/select-uart-mux b/meta-facebook/meta-minerva/recipes-phosphor/console/obmc-console/select-uart-mux
new file mode 100644
index 0000000..f203836
--- /dev/null
+++ b/meta-facebook/meta-minerva/recipes-phosphor/console/obmc-console/select-uart-mux
@@ -0,0 +1,39 @@
+#!/bin/bash -e
+# shellcheck source=meta-facebook/meta-minerva/recipes-minerva/plat-tool/files/minerva-common-functions
+# Select UART Mux: UART Mux for switching between MTIA blade 0~15
+# Usage: select-uart-mux <0-15>
+source /usr/libexec/minerva-common-functions
+
+convert_decimal_to_binary() {
+ decimal=$1
+
+ binary=""
+ for ((i = 3; i >= 0; i--)); do
+ bit=$(( (decimal >> i) & 1 ))
+ binary="${binary}${bit}"
+ done
+
+ echo "$binary"
+}
+
+uart_mux_select()
+{
+ local BLADE_INDEX=$1
+
+ if ((BLADE_INDEX >= 0)) && ((BLADE_INDEX < 16)); then
+ BINARY_INDEX=$(convert_decimal_to_binary "$BLADE_INDEX")
+
+ set_gpio BLADE_UART_SEL0 "${BINARY_INDEX:3:1}"
+ set_gpio BLADE_UART_SEL1 "${BINARY_INDEX:2:1}"
+ set_gpio BLADE_UART_SEL2 "${BINARY_INDEX:1:1}"
+ set_gpio BLADE_UART_SEL3 "${BINARY_INDEX:0:1}"
+ else
+ logger -p user.info "uart_mux_select: unknow blade index ($BLADE_INDEX)"
+ return 1
+ fi
+
+ return 0
+}
+
+BLADE_INDEX=$1
+uart_mux_select "$BLADE_INDEX"
diff --git a/meta-facebook/meta-minerva/recipes-phosphor/console/obmc-console/server.ttyS5.conf b/meta-facebook/meta-minerva/recipes-phosphor/console/obmc-console/server.ttyS5.conf
new file mode 100644
index 0000000..d969f84
--- /dev/null
+++ b/meta-facebook/meta-minerva/recipes-phosphor/console/obmc-console/server.ttyS5.conf
@@ -0,0 +1,2 @@
+local-tty = ttyS5
+baud = 57600
diff --git a/meta-facebook/meta-minerva/recipes-phosphor/console/obmc-console_%.bbappend b/meta-facebook/meta-minerva/recipes-phosphor/console/obmc-console_%.bbappend
new file mode 100644
index 0000000..cbf40af
--- /dev/null
+++ b/meta-facebook/meta-minerva/recipes-phosphor/console/obmc-console_%.bbappend
@@ -0,0 +1,28 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
+
+inherit obmc-phosphor-systemd
+
+# Disable obmc-console ssh ports.
+PACKAGECONFIG:remove:minerva = "ssh"
+
+OBMC_CONSOLE_HOST_TTY = "ttyS5"
+OBMC_CONSOLE_TTYS = "ttyS5"
+
+SRC_URI:append:minerva = " \
+ file://server.ttyS5.conf \
+ file://80-minerva-obmc-console-uart.rules \
+ file://select-uart-mux \
+"
+
+RDEPENDS:${PN}:append:minerva = " bash"
+
+do_install:append:minerva() {
+
+ # Replace upstream-provided udev rules
+ install -d ${D}/${nonarch_base_libdir}/udev/rules.d
+ rm -f ${D}/${nonarch_base_libdir}/udev/rules.d/80-obmc-console-uart.rules
+ install -m 0644 ${WORKDIR}/80-minerva-obmc-console-uart.rules ${D}/${nonarch_base_libdir}/udev/rules.d
+
+ # Install script for selecting uart mux
+ install -m 0744 ${WORKDIR}/select-uart-mux ${D}${bindir}
+}
diff --git a/meta-facebook/meta-minerva/recipes-phosphor/images/fb-minerva-phosphor-image.inc b/meta-facebook/meta-minerva/recipes-phosphor/images/fb-minerva-phosphor-image.inc
index 6c9d5bc..986a99a 100644
--- a/meta-facebook/meta-minerva/recipes-phosphor/images/fb-minerva-phosphor-image.inc
+++ b/meta-facebook/meta-minerva/recipes-phosphor/images/fb-minerva-phosphor-image.inc
@@ -9,3 +9,8 @@
OBMC_IMAGE_EXTRA_INSTALL:append = " \
plat-svc \
"
+
+# For console to the MTIA blade
+OBMC_IMAGE_EXTRA_INSTALL:append = " \
+ obmc-console \
+"