meta-facebook: yosemite4: Support host and chassis power control

Description:
- Support host and chassis power control by setting dbus property from phosphor-state-manager

Design:
- Add host/chassis power control services and scripts
 - chassis power control:
  - do 12V power on/off/cycle by setting virtual i/o exp output port.

Limitation:
- Implementation of host power control and sled cycle are not support for now.
- Host power control will be implemented after both BMC/BIC support PDLM commands.
- Sled cycle will be implemented after power control between CPLD and HSC was ready.

Test Case:
- host power on:
 - command:
  - busctl set-property xyz.openbmc_project.State.Host8 /xyz/openbmc_project/state/host8 xyz.openbmc_project.State.Host RequestedHostTransition s "xyz.openbmc_proct.State.Host.Transition.On"
 - show "Host power on is not support for now" in journal
- host power off:
 - command:
  - busctl set-property xyz.openbmc_project.State.Host8 /xyz/openbmc_project/state/host8 xyz.openbmc_project.State.Host RequestedHostTransition s "xyz.openbmc_project.State.Host.Transition.Off"
 - show "Host power off is not support for now" in journal
- host power cycle:
 - command:
  - busctl set-property xyz.openbmc_project.State.Host8 /xyz/openbmc_project/state/host8 xyz.openbmc_project.State.Host RequestedHostTransition s "xyz.openbmc_project.State.Host.Transition.Powercycle"
 - show "Host power cycle is not support for now" in journal
- host power reset:
 - command:
  - busctl set-property xyz.openbmc_project.State.Host8 /xyz/openbmc_project/state/host8 xyz.openbmc_project.State.Host RequestedHostTransition s "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"
 - show "Host power reset is not support for now" in journal
- chassis power on:
 - command:
  - busctl set-property xyz.openbmc_project.State.Chassis8 /xyz/openbmc_project/state/chassis8 xyz.openbmc_project.State.Chassis RequestedPowerTransition s "xyz.openbmc_project.State.Chassis.Transition.On"
- show chassis-poweron started in journal
- chassis power off:
 - command:
  - busctl set-property xyz.openbmc_project.State.Chassis8 /xyz/openbmc_project/state/chassis8 xyz.openbmc_project.State.Chassis RequestedPowerTransition s "xyz.openbmc_project.State.Chassis.Transition.Off"
- show chassis-poweroff started in journal
- chassis power cycle:
 - command:
  - busctl set-property xyz.openbmc_project.State.Chassis8 /xyz/openbmc_project/state/chassis8 xyz.openbmc_project.State.Chassis RequestedPowerTransition s "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"
- show chassis-powecycle started in journal
- sled cycle:
 - command:
  - busctl set-property xyz.openbmc_project.State.Chassis0 /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis RequestedPowerTransition s "xyz.openbmc_project.State.Chassis.Transition.PowerCycle
- show "SLED-cycle is not support for now" in journal

Change-Id: I021e2c438974765bebeff6c7ed7e7d5b56c586a3
Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
diff --git a/meta-facebook/meta-yosemite4/conf/machine/yosemite4.conf b/meta-facebook/meta-yosemite4/conf/machine/yosemite4.conf
index 28f6f82..17d12e6 100644
--- a/meta-facebook/meta-yosemite4/conf/machine/yosemite4.conf
+++ b/meta-facebook/meta-yosemite4/conf/machine/yosemite4.conf
@@ -20,3 +20,5 @@
 # Primary chassis as Sled plus secondary chassis in N slots.
 OBMC_CHASSIS_INSTANCES = "0 ${OBMC_HOST_INSTANCES}"
 
+VIRTUAL-RUNTIME_obmc-host-state-manager = "phosphor-state-manager-host"
+VIRTUAL-RUNTIME_obmc-chassis-state-manager = "phosphor-state-manager-chassis"
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/images/fb-yosemite4-phosphor-image.inc b/meta-facebook/meta-yosemite4/recipes-phosphor/images/fb-yosemite4-phosphor-image.inc
new file mode 100644
index 0000000..0b220a9
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/images/fb-yosemite4-phosphor-image.inc
@@ -0,0 +1,9 @@
+# Currently, the led related services couldn't complete
+# causing that multi-user.target never complete.
+# If multi-user.target doesn't complete,
+# the obmc-host-startmin@.target couldn't start.
+# In that case, BMC couldn't set current host state to "Running".
+IMAGE_FEATURES:remove = " \
+    obmc-leds \
+"
+
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle
new file mode 100644
index 0000000..27e83a9
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+# shellcheck disable=SC2120
+
+# Provide source directive to shellcheck.
+# shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
+source /usr/libexec/phosphor-state-manager/power-cmd
+
+GPIOCHIP_IO_EXP_SLOT_PWR_CTRL=$(basename "/sys/bus/i2c/devices/$MEDUSA_IO_EXP_BUS_NUM-00$IO_EXP_SLOT_PWR_CTRL_ADDR/"*gpiochip*)
+
+#IO 0:7 input port for showing slot 1:8 power status
+#IO 8:16 output port for controlling slot 1:8 power status
+CHASSIS_ID=$1
+IO_EXP_SLOT_PWR_STATUS=$((CHASSIS_ID - 1))
+IO_EXP_SLOT_PWR_CTRL=$((IO_EXP_SLOT_PWR_STATUS + 8))
+
+chassis-power-cycle()
+{
+    CHASSIS_ID=$1
+
+    if [ "$CHASSIS_ID" -le 8  ]
+    then
+        chassis_status=$(gpioget "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_STATUS")
+        if [ "$chassis_status" == "$STATE_ON" ]
+        then
+            if ! gpioset "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_CTRL"=0
+            then
+                echo "Failed to set slot$1 power off"
+            fi
+            sleep 10
+        fi
+        if ! gpioset "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_CTRL"=1
+        then
+            echo "Failed to set slot$1 power on"
+        fi
+        sleep 2
+
+        # Check chassis status after doing 12V cycle
+        chassis_status=$(gpioget "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_STATUS")
+        if [ "$chassis_status" == "$STATE_ON" ]
+        then
+            busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_ON_PROPERTY"
+            exit 0;
+        else
+            busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_OFF_PROPERTY"
+            exit 0;
+        fi
+    fi
+
+    echo "Invalid slot id"
+    exit 1;
+}
+
+if [ "$1" == 0 ]
+then
+    # TODO: SLED cycle
+    echo "SLED-cycle is not support for now"
+else
+    echo "Starting slot$1 cycle"
+    chassis-power-cycle "$1"
+fi
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle@.service b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle@.service
new file mode 100644
index 0000000..a8a110e
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle@.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Chassis Power Cycle: %i
+
+[Service]
+Type=oneshot
+ExecStart=/usr/libexec/phosphor-state-manager/chassis-powercycle %i
+
+[Install]
+WantedBy=obmc-chassis-powercycle@%i.target
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweroff b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweroff
new file mode 100644
index 0000000..3e1dd3c
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweroff
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# shellcheck disable=SC2120
+
+# Provide source directive to shellcheck.
+# shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
+source /usr/libexec/phosphor-state-manager/power-cmd
+
+GPIOCHIP_IO_EXP_SLOT_PWR_CTRL=$(basename "/sys/bus/i2c/devices/$MEDUSA_IO_EXP_BUS_NUM-00$IO_EXP_SLOT_PWR_CTRL_ADDR/"*gpiochip*)
+
+#IO 0:7 input port for showing slot 1:8 power status
+#IO 8:16 output port for controlling slot 1:8 power status
+CHASSIS_ID=$1
+IO_EXP_SLOT_PWR_STATUS=$((CHASSIS_ID - 1))
+IO_EXP_SLOT_PWR_CTRL=$((IO_EXP_SLOT_PWR_STATUS + 8))
+
+# Server 12v power off
+chassis-power-off()
+{
+        if ! gpioset "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_CTRL"=0
+        then
+                echo "Failed to set slot$1 power off"
+        fi
+        sleep 1
+
+        # Check chassis status after doing 12V off
+        chassis_status=$(gpioget "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_STATUS")
+        if [ "$chassis_status" == "$STATE_OFF" ]
+        then
+                busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_OFF_PROPERTY"
+                echo "Chassis is power off"
+        else
+                busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_ON_PROPERTY"
+                echo "Chassis is power on"
+                exit 0;
+        fi
+}
+
+chassis_status=$(gpioget "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL $IO_EXP_SLOT_PWR_STATUS")
+if [ "$chassis_status" == "$STATE_ON" ]
+then
+        chassis-power-off
+        exit 0;
+else
+        echo "Chassis is already off"
+        exit 0;
+fi
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweroff@.service b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweroff@.service
new file mode 100644
index 0000000..09494c1
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweroff@.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=power off chassis:%i
+
+[Service]
+Type=oneshot
+ExecStart=/usr/libexec/phosphor-state-manager/chassis-poweroff %i
+
+[Install]
+WantedBy=obmc-chassis-hard-poweroff@%i.target
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweron b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweron
new file mode 100644
index 0000000..31d1520
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweron
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# shellcheck disable=SC2120
+
+# Provide source directive to shellcheck.
+# shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
+source /usr/libexec/phosphor-state-manager/power-cmd
+
+GPIOCHIP_IO_EXP_SLOT_PWR_CTRL=$(basename "/sys/bus/i2c/devices/$MEDUSA_IO_EXP_BUS_NUM-00$IO_EXP_SLOT_PWR_CTRL_ADDR/"*gpiochip*)
+
+#IO 0:7 input port for showing slot 1:8 power status
+#IO 8:16 output port for controlling slot 1:8 power status
+CHASSIS_ID=$1
+IO_EXP_SLOT_PWR_STATUS=$((CHASSIS_ID - 1))
+IO_EXP_SLOT_PWR_CTRL=$((IO_EXP_SLOT_PWR_STATUS + 8))
+
+# Server 12v power on
+chassis-power-on()
+{
+        if ! gpioset "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_CTRL"=1
+        then
+                echo "Failed to set slot$1 power on"
+        fi
+        sleep 1
+
+        # Check chassis status after doing 12V on
+        chassis_status=$(gpioget "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_STATUS")
+        if [ "$chassis_status" == "$STATE_ON" ]
+        then
+                busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_ON_PROPERTY"
+                echo "Chassis is power on"
+        else
+                busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_OFF_PROPERTY"
+                echo "Chassis is power off"
+                exit 0;
+        fi
+}
+
+chassis_status=$(gpioget "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_STATUS")
+if [ "$chassis_status" == "$STATE_OFF" ]
+then
+        chassis-power-on
+        exit 0;
+else
+        echo "Chassis is already on"
+        exit 0;
+fi
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweron@.service b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweron@.service
new file mode 100644
index 0000000..f706741
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweron@.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=power on chassis:%i
+
+[Service]
+Type=oneshot
+ExecStart=/usr/libexec/phosphor-state-manager/chassis-poweron %i
+
+[Install]
+WantedBy=obmc-chassis-poweron@%i.target
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powercycle b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powercycle
new file mode 100644
index 0000000..03b779c
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powercycle
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# Provide source directive to shellcheck.
+# shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
+source /usr/libexec/phosphor-state-manager/power-cmd
+
+# TODO: host power cycle
+echo "Host power cycle is not support for now"
\ No newline at end of file
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powercycle@.service b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powercycle@.service
new file mode 100644
index 0000000..f45e71f
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powercycle@.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Host Power Cycle: %i
+
+[Service]
+Type=oneshot
+ExecStart=/usr/libexec/phosphor-state-manager/host-powercycle %i
+
+[Install]
+WantedBy=obmc-host-reboot@%i.target
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweroff b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweroff
new file mode 100644
index 0000000..82ed6af
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweroff
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# Provide source directive to shellcheck.
+# shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
+source /usr/libexec/phosphor-state-manager/power-cmd
+
+# TODO: host power off
+echo "Host power off is not support for now"
\ No newline at end of file
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweroff@.service b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweroff@.service
new file mode 100644
index 0000000..3ead57e
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweroff@.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=power off host:%i
+
+[Service]
+Type=oneshot
+ExecStart=/usr/libexec/phosphor-state-manager/host-poweroff %i
+
+[Install]
+WantedBy=obmc-host-shutdown@%i.target
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweron b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweron
new file mode 100644
index 0000000..bc3d9df
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweron
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# Provide source directive to shellcheck.
+# shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
+source /usr/libexec/phosphor-state-manager/power-cmd
+
+# TODO: host power on
+echo "Host power on is not support for now"
\ No newline at end of file
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweron@.service b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweron@.service
new file mode 100644
index 0000000..6f59a6b
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-poweron@.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=power on host:%i
+
+[Service]
+Type=oneshot
+ExecStart=/usr/libexec/phosphor-state-manager/host-poweron %i
+
+[Install]
+WantedBy=obmc-host-start@%i.target
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powerreset b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powerreset
new file mode 100644
index 0000000..72536f9
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powerreset
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+# Provide source directive to shellcheck.
+# shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd
+source /usr/libexec/phosphor-state-manager/power-cmd
+
+# TODO: host power reset
+echo "Host power reset is not support for now"
\ No newline at end of file
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powerreset@.service b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powerreset@.service
new file mode 100644
index 0000000..0fd059c
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powerreset@.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Host Power Reset: %i
+
+[Service]
+Type=oneshot
+ExecStart=/usr/libexec/phosphor-state-manager/host-powerreset %i
+
+[Install]
+WantedBy=obmc-host-force-warm-reboot@%i.target
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/power-cmd b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/power-cmd
new file mode 100644
index 0000000..417dfdb
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/power-cmd
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+export STATE_OFF=0
+export STATE_ON=1
+export STATE_UNKNOWN=-1
+export MANAGEMENT_BOARD_IO_EXP_BUS_NUM="12"
+export MEDUSA_IO_EXP_BUS_NUM="11"
+export IO_EXP_SLOT_PWR_CTRL_ADDR="22"
+export IO_EXP_SLED_PWR_CTRL_ADDR="22"
+export CHASSIS_BUS_NAME="xyz.openbmc_project.State.Chassis"
+export CHASSIS_OBJ_PATH="/xyz/openbmc_project/state/chassis"
+export CHASSIS_INTF_NAME="xyz.openbmc_project.State.Chassis"
+export CHASSIS_PROPERTY_NAME="CurrentPowerState"
+export CHASSIS_ON_PROPERTY="xyz.openbmc_project.State.Chassis.PowerState.On"
+export CHASSIS_OFF_PROPERTY="xyz.openbmc_project.State.Chassis.PowerState.Off"
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/sled-cycle.service b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/sled-cycle.service
new file mode 100644
index 0000000..d6b2118
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/sled-cycle.service
@@ -0,0 +1,9 @@
+[Unit]
+Description=Sled Cycle
+
+[Service]
+Type=oneshot
+ExecStart=/usr/libexec/phosphor-state-manager/chassis-powercycle 0
+
+[Install]
+WantedBy=obmc-chassis-powercycle@0.target
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager_%.bbappend b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager_%.bbappend
new file mode 100644
index 0000000..4e6a1ba
--- /dev/null
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager_%.bbappend
@@ -0,0 +1,49 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
+
+EXTRA_OEMESON:append = " \
+                         -Dwarm-reboot=enabled \
+                       "
+
+CHASSIS_DEFAULT_TARGETS:remove:yosemite4 = " \
+    obmc-chassis-powerreset@{}.target.requires/phosphor-reset-chassis-on@{}.service \
+    obmc-chassis-powerreset@{}.target.requires/phosphor-reset-chassis-running@{}.service \
+    obmc-chassis-poweroff@{}.target.requires/obmc-power-stop@{}.service \
+    obmc-chassis-poweron@{}.target.requires/obmc-power-start@{}.service \
+    "
+
+SRC_URI:append:yosemite4 = " \
+    file://chassis-poweroff@.service \
+    file://chassis-poweron@.service \
+    file://chassis-powercycle@.service \
+    file://host-poweroff@.service \
+    file://host-poweron@.service \
+    file://host-powercycle@.service \
+    file://host-powerreset@.service \
+    file://chassis-poweroff \
+    file://chassis-poweron \
+    file://chassis-powercycle \
+    file://host-poweroff \
+    file://host-poweron \
+    file://host-powercycle \
+    file://host-powerreset \
+    file://power-cmd \
+    "
+
+RDEPENDS:${PN}:append:yosemite4 = " bash"
+
+do_install:append:yosemite4() {
+    install -d ${D}${systemd_system_unitdir}
+    install -m 0644 ${WORKDIR}/*.service ${D}${systemd_system_unitdir}/
+
+    install -d ${D}${libexecdir}/${PN}
+    install -m 0777 ${WORKDIR}/chassis-poweroff ${D}${libexecdir}/${PN}/
+    install -m 0777 ${WORKDIR}/chassis-poweron ${D}${libexecdir}/${PN}/
+    install -m 0777 ${WORKDIR}/chassis-powercycle ${D}${libexecdir}/${PN}/
+    install -m 0777 ${WORKDIR}/host-poweroff ${D}${libexecdir}/${PN}/
+    install -m 0777 ${WORKDIR}/host-poweron ${D}${libexecdir}/${PN}/
+    install -m 0777 ${WORKDIR}/host-powercycle ${D}${libexecdir}/${PN}/
+    install -m 0777 ${WORKDIR}/host-powerreset ${D}${libexecdir}/${PN}/
+    install -m 0777 ${WORKDIR}/power-cmd ${D}${libexecdir}/${PN}/
+}
+
+FILES:${PN} += " ${systemd_system_unitdir}/*.service"