meta-fii/meta-kudo: Use phosphor-state-manager

Added
1. phosphor-state-manager
2. ampere-hostctrl
3. Nuvoton chip and skeleton GPIO support in obmc-libobmc-intf
5. obmcutil support

Signed-off-by: Mohaimen Alsamarai <mohaimen.alsamarai@fii-na.com>
Change-Id: I2628a0cab35a9be5afd702cc6269932c0c901e6a
diff --git a/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl.bb b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl.bb
new file mode 100644
index 0000000..affbcf7
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl.bb
@@ -0,0 +1,81 @@
+SUMMARY = "Ampere Computing LLC Host Control Implementation"
+DESCRIPTION = "A host control implementation suitable for Ampere Computing LLC's systems"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+inherit systemd
+inherit obmc-phosphor-systemd
+
+S = "${WORKDIR}"
+
+SRC_URI = "file://ampere-host-shutdown.service \
+          file://ampere-host-reset.service \
+          file://ampere_power_util.sh \
+          file://ampere-chassis-poweroff.service \
+          file://ampere-chassis-poweron.service \
+          file://ampere-host-reset-ack.service \
+          file://ampere-host-force-reset.service \
+          file://ampere-host-power-cycle.service \
+          "
+
+DEPENDS = "systemd"
+RDEPENDS_${PN} = "bash"
+
+SYSTEMD_PACKAGES = "${PN}"
+SYSTEMD_SERVICE_${PN} = " \
+        ampere-host-shutdown.service \
+        ampere-host-reset.service \
+        ampere-chassis-poweroff.service \
+        ampere-chassis-poweron.service \
+        ampere-host-reset-ack.service \
+        ampere-host-force-reset.service \
+        ampere-host-power-cycle.service \
+        "
+# host power control
+# overwrite the host shutdown to graceful shutdown
+HOST_SHUTDOWN_TMPL = "ampere-host-shutdown.service"
+HOST_SHUTDOWN_TGTFMT = "obmc-host-shutdown@{0}.target"
+HOST_SHUTDOWN_FMT = "../${HOST_SHUTDOWN_TMPL}:${HOST_SHUTDOWN_TGTFMT}.requires/${HOST_SHUTDOWN_TMPL}"
+SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'HOST_SHUTDOWN_FMT', 'OBMC_HOST_INSTANCES')}"
+
+# Force the power cycle target to run the ampere power cycle
+HOST_REBOOT_SVC = "ampere-host-power-cycle.service"
+HOST_REBOOT_SVC_TGTFMT = "obmc-host-reboot@{0}.target"
+HOST_REBOOT_SVC_FMT = "../${HOST_REBOOT_SVC}:${HOST_REBOOT_SVC_TGTFMT}.requires/${HOST_REBOOT_SVC}"
+SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'HOST_REBOOT_SVC_FMT', 'OBMC_HOST_INSTANCES')}"
+
+# overwrite the host reset to graceful reset
+HOST_WARM_REBOOT_SOFT_SVC = "ampere-host-reset.service"
+HOST_WARM_REBOOT_TGTFMT = "obmc-host-warm-reboot@{0}.target"
+HOST_WARM_REBOOT_SOFT_SVC_FMT = "../${HOST_WARM_REBOOT_SOFT_SVC}:${HOST_WARM_REBOOT_TGTFMT}.requires/${HOST_WARM_REBOOT_SOFT_SVC}"
+SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'HOST_WARM_REBOOT_SOFT_SVC_FMT', 'OBMC_HOST_INSTANCES')}"
+
+# overwrite force reboot
+HOST_WARM_REBOOT_FORCE_TGT = "ampere-host-force-reset.service"
+HOST_WARM_REBOOT_FORCE_TGTFMT = "obmc-host-force-warm-reboot@{0}.target"
+HOST_WARM_REBOOT_FORCE_TARGET_FMT = "../${HOST_WARM_REBOOT_FORCE_TGT}:${HOST_WARM_REBOOT_FORCE_TGTFMT}.requires/${HOST_WARM_REBOOT_FORCE_TGT}"
+SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'HOST_WARM_REBOOT_FORCE_TARGET_FMT', 'OBMC_HOST_INSTANCES')}"
+
+# chassis power control
+CHASSIS_POWERON_SVC = "ampere-chassis-poweron.service"
+CHASSIS_POWERON_TGTFMT = "obmc-chassis-poweron@{0}.target"
+CHASSIS_POWERON_FMT = "../${CHASSIS_POWERON_SVC}:${CHASSIS_POWERON_TGTFMT}.requires/${CHASSIS_POWERON_SVC}"
+SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'CHASSIS_POWERON_FMT', 'OBMC_CHASSIS_INSTANCES')}"
+
+CHASSIS_POWEROFF_SVC = "ampere-chassis-poweroff.service"
+CHASSIS_POWEROFF_TGTFMT = "obmc-chassis-poweroff@{0}.target"
+CHASSIS_POWEROFF_FMT = "../${CHASSIS_POWEROFF_SVC}:${CHASSIS_POWEROFF_TGTFMT}.requires/${CHASSIS_POWEROFF_SVC}"
+SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'CHASSIS_POWEROFF_FMT', 'OBMC_CHASSIS_INSTANCES')}"
+
+TMPL = "phosphor-gpio-monitor@.service"
+INSTFMT = "phosphor-gpio-monitor@{0}.service"
+TGT = "multi-user.target"
+FMT = "../${TMPL}:${TGT}.requires/${INSTFMT}"
+SYSTEMD_LINK_${PN} += "${@compose_list(d, 'FMT', 'OBMC_HOST_MONITOR_INSTANCES')}"
+
+do_install() {
+    install -d ${D}/usr/sbin
+    install -m 0755 ${WORKDIR}/ampere_power_util.sh ${D}/${sbindir}/ampere_power_util.sh
+}
+
diff --git a/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-chassis-poweroff.service b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-chassis-poweroff.service
new file mode 100644
index 0000000..c3a4dce
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-chassis-poweroff.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Ampere Computing LLC Power OFF Chassis
+Requires=op-wait-power-off@%i.service
+Before=op-wait-power-off@%i.service
+Conflicts=obmc-chassis-poweron@0.target
+
+[Service]
+RemainAfterExit=no
+Type=oneshot
+ExecStart=/usr/bin/env ampere_power_util.sh mb off
+SyslogIdentifier=ampere_power_util.sh
+
diff --git a/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-chassis-poweron.service b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-chassis-poweron.service
new file mode 100644
index 0000000..1ab4922
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-chassis-poweron.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=Ampere Computing LLC Power ON Chassis
+Conflicts=obmc-chassis-poweroff@0.target
+
+[Service]
+RemainAfterExit=yes
+Type=oneshot
+ExecStart=/usr/bin/env ampere_power_util.sh mb on
+SyslogIdentifier=ampere_power_util.sh
+
diff --git a/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-force-reset.service b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-force-reset.service
new file mode 100644
index 0000000..8a40baf
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-force-reset.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Ampere Computing LLC force reset host
+Conflicts=obmc-chassis-poweroff@0.target
+OnFailure=obmc-chassis-powerreset@0.target
+
+[Service]
+RemainAfterExit=no
+Type=oneshot
+ExecStart=/usr/bin/env ampere_power_util.sh mb force_reset
+SyslogIdentifier=ampere_power_util.sh
+
diff --git a/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-power-cycle.service b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-power-cycle.service
new file mode 100644
index 0000000..0b32aa1
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-power-cycle.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Ampere Computing LLC power cycle service
+Conflicts=obmc-host-start@0.target
+OnFailure=obmc-chassis-powerreset@0.target
+
+[Service]
+RemainAfterExit=no
+Type=oneshot
+ExecStart=/usr/bin/env ampere_power_util.sh mb force_reset
+SyslogIdentifier=ampere_power_util.sh
+
diff --git a/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-reset-ack.service b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-reset-ack.service
new file mode 100644
index 0000000..a533879
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-reset-ack.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Ampere Computing LLC triggering reset ACK
+Conflicts=obmc-host-start@0.target
+OnFailure=obmc-chassis-powerreset@0.target
+
+[Service]
+RemainAfterExit=no
+Type=oneshot
+ExecStart=/usr/bin/env ampere_power_util.sh mb force_reset
+SyslogIdentifier=ampere_power_util.sh
+
diff --git a/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-reset.service b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-reset.service
new file mode 100644
index 0000000..2deb24d
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-reset.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=Ampere Computing LLC warm reset host
+Conflicts=obmc-chassis-poweroff@0.target
+
+[Service]
+RemainAfterExit=no
+Type=oneshot
+ExecStart=/usr/bin/env ampere_power_util.sh mb graceful_reset
+SyslogIdentifier=ampere_power_util.sh
+
diff --git a/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-shutdown.service b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-shutdown.service
new file mode 100644
index 0000000..b7a458e
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-kudo/host/ampere-hostctrl/ampere-host-shutdown.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Ampere Computing LLC graceful shutdown host
+Conflicts=obmc-host-start@0.target
+OnFailure=obmc-chassis-poweroff@0.target
+
+[Service]
+RemainAfterExit=no
+Type=oneshot
+ExecStart=/usr/bin/env ampere_power_util.sh mb graceful_shutdown
+SyslogIdentifier=ampere_power_util.sh
+
diff --git a/meta-fii/meta-kudo/recipes-kudo/host/files/ampere_power_util.sh b/meta-fii/meta-kudo/recipes-kudo/host/files/ampere_power_util.sh
new file mode 100644
index 0000000..420abfb
--- /dev/null
+++ b/meta-fii/meta-kudo/recipes-kudo/host/files/ampere_power_util.sh
@@ -0,0 +1,117 @@
+#!/bin/bash
+# Usage of this utility
+function usage() {
+  echo "usage: power-util mb [on|off|status|cycle|reset|graceful_shutdown|graceful_reset|force_reset]";
+}
+
+power_off() {
+  echo "Shutting down Server $2"
+  busctl set-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis RequestedPowerTransition s xyz.openbmc_project.State.Chassis.Transition.Off
+}
+
+power_on() {
+  echo "Powering on Server $2"
+  gpioset 6 11=1
+  sleep 1
+  gpioset 6 11=0
+  busctl set-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis RequestedPowerTransition s xyz.openbmc_project.State.Chassis.Transition.On
+}
+
+power_status() {
+  st=$(busctl get-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis CurrentPowerState | cut -d"." -f6)
+  if [ "$st" == "On\"" ]; then
+  echo "on"
+  else
+  echo "off"
+  fi
+}
+
+power_reset() {
+  echo "Reset on server $2"
+  busctl set-property xyz.openbmc_project.State.Host /xyz/openbmc_project/state/host0 xyz.openbmc_project.State.Host RequestedHostTransition s xyz.openbmc_project.State.Host.Transition.Reboot
+}
+
+graceful_shutdown() {
+  if [ -f "/run/openbmc/host@0-request" ]; then
+    echo "shutdown host immediately"
+    gpioset 6 11=1
+    sleep 6
+    gpioset 6 11=0
+    power_off
+  else
+    echo "Triggering graceful shutdown"
+    gpioset -l 2 6=0
+    sleep 3
+    gpioset -l 2 6=1
+    sleep 30s
+    power_off
+  fi
+}
+
+force_reset() {
+  echo "Triggering sysreset pin"
+  gpioset -l 2 1=0
+  sleep 1
+  gpioset -l 2 1=1
+}
+
+if [ $# -lt 2 ]; then
+  echo "Total number of parameter=$#"
+  echo "Insufficient parameter"
+  usage;
+  exit 0;
+fi
+
+if [ $1 != "mb" ]; then
+  echo "Invalid parameter1=$1"
+  usage;
+  exit 0;
+fi
+
+if [ $2 = "on" ]; then
+  if [ $(power_status) == "off" ]; then
+    power_on
+  fi
+elif [ $2 = "off" ]; then
+  if [ $(power_status) == "on" ]; then
+    power_off
+  fi
+  # If any request of graceful reset, need to power on
+  if [ -f "/run/openbmc/host@0-graceful-reset" ]; then
+    sleep 20s
+    power_on
+    rm -f "/run/openbmc/host@0-graceful-reset"
+  fi
+elif [ $2 == "cycle" ]; then
+  if [ $(power_status) == "on" ]; then
+    echo "Power cycling server"
+    power_off
+    sleep 20s
+    power_on
+  else
+    echo "Host is already off, do nothing"
+  fi
+elif [ $2 == "reset" ]; then
+  if [ $(power_status) == "on" ]; then
+    power_reset
+  else
+    echo "ERROR: Server not powered on"
+  fi
+elif [[ $2 == "graceful_shutdown" ]]; then
+  graceful_shutdown
+elif [ $2 == "graceful_reset" ]; then
+  mkdir -p "/run/openbmc/"
+  touch "/run/openbmc/host@0-graceful-reset"
+  graceful_shutdown
+  sleep 20s
+elif [ $2 == "status" ]; then
+  power_status
+elif [ $2 == "force_reset" ]; then
+  force_reset
+else
+  echo "Invalid parameter2=$2"
+  usage;
+fi
+
+exit 0;
+
diff --git a/meta-fii/meta-kudo/recipes-kudo/packagegroups/packagegroup-kudo-apps.bb b/meta-fii/meta-kudo/recipes-kudo/packagegroups/packagegroup-kudo-apps.bb
index 07d0380..cc32052 100644
--- a/meta-fii/meta-kudo/recipes-kudo/packagegroups/packagegroup-kudo-apps.bb
+++ b/meta-fii/meta-kudo/recipes-kudo/packagegroups/packagegroup-kudo-apps.bb
@@ -5,6 +5,7 @@
 
 PROVIDES = "${PACKAGES}"
 PACKAGES = " \
+    ${PN}-kudo-chassis \
     ${PN}-kudo-system \
     ${PN}-kudo-fw \
     ${PN}-fan-mgmt \
@@ -17,6 +18,14 @@
 RPROVIDES_${PN}-kudo-fw += "virtual-obmc-flash-mgmt"
 RPROVIDES_${PN}-fan-mgmt += "virtual-obmc-fan-mgmt"
 
+SUMMARY_${PN}-kudo-chassis = "kudo chassis"
+RDEPENDS_${PN}-kudo-chassis = " \
+    phosphor-hostlogger \
+    obmc-op-control-power \
+    obmc-phosphor-buttons-signals \
+    obmc-phosphor-buttons-handler \
+    "
+
 SUMMARY_${PN}-kudo-system = "kudo System"
 RDEPENDS_${PN}-kudo-system = " \
     ipmitool \
@@ -32,6 +41,7 @@
     gbmc-mac-config \
     kudo-boot \
     kudo-cmd \
+    phosphor-state-manager \
     "
 
 SUMMARY_${PN}-kudo-fw = "kudo Firmware"