Reset boot progress and OS status sensors after reboot

Reset boot progress and OS status sensors if host is not
running

Resolves openbmc/openbmc#2804

Change-Id: I1fee2bf7776ae957e87452d9cfa7a4fca647b46f
Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
diff --git a/common/recipes-phosphor/state/files/phosphor-reset-sensor-states@.service b/common/recipes-phosphor/state/files/phosphor-reset-sensor-states@.service
new file mode 100644
index 0000000..689372f
--- /dev/null
+++ b/common/recipes-phosphor/state/files/phosphor-reset-sensor-states@.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=Reset host sensors
+After=phosphor-reset-host-check@%i.service
+Wants=mapper-wait@-xyz-openbmc_project-state-host%i.service
+After=mapper-wait@-xyz-openbmc_project-state-host%i.service
+ConditionPathExists=!/run/openbmc/host@%i-on
+
+[Service]
+Restart=no
+Type=oneshot
+ExecStart=/bin/sh -c "busctl set-property `mapper get-service /xyz/openbmc_project/state/host0` /xyz/openbmc_project/state/host0 xyz.openbmc_project.State.Boot.Progress  BootProgress s xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified"
+ExecStart=/bin/sh -c "busctl set-property `mapper get-service /xyz/openbmc_project/state/host0` /xyz/openbmc_project/state/host0 xyz.openbmc_project.State.OperatingSystem.Status OperatingSystemState s xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive"
+
+[Install]
+WantedBy=obmc-host-reset@%i.target
diff --git a/common/recipes-phosphor/state/phosphor-state-manager.bb b/common/recipes-phosphor/state/phosphor-state-manager.bb
index c04d21b..672090e 100644
--- a/common/recipes-phosphor/state/phosphor-state-manager.bb
+++ b/common/recipes-phosphor/state/phosphor-state-manager.bb
@@ -13,6 +13,7 @@
     ${PN}-bmc \
     ${PN}-discover \
     ${PN}-host-check \
+    ${PN}-reset-sensor-states \
 "
 PACKAGES =+ "${STATE_MGR_PACKAGES}"
 PACKAGES_remove = "${PN}"
@@ -21,7 +22,13 @@
 
 DBUS_PACKAGES = "${STATE_MGR_PACKAGES}"
 
-SYSTEMD_PACKAGES = "${PN}-discover"
+SYSTEMD_PACKAGES = "${PN}-discover \
+                    ${PN}-reset-sensor-states \
+"
+# The reset-sensor-states function will reset the host
+# sensors on a BMC reset or system power loss so it is
+# recommended when bringing in the host state function
+RRECOMMENDS_${PN}-host = "${PN}-reset-sensor-states"
 
 inherit autotools pkgconfig
 inherit obmc-phosphor-dbus-service
@@ -38,6 +45,7 @@
 RDEPENDS_${PN}-bmc += "libsystemd phosphor-dbus-interfaces"
 RDEPENDS_${PN}-discover += "libsystemd phosphor-dbus-interfaces"
 RDEPENDS_${PN}-host-check += "libsystemd phosphor-dbus-interfaces"
+RDEPENDS_${PN}-reset-sensor-states += "libsystemd phosphor-dbus-interfaces"
 
 FILES_${PN}-host = "${sbindir}/phosphor-host-state-manager"
 DBUS_SERVICE_${PN}-host += "xyz.openbmc_project.State.Host.service"
@@ -56,11 +64,18 @@
 SYSTEMD_SERVICE_${PN}-host-check += "phosphor-reset-host-check@.service"
 SYSTEMD_SERVICE_${PN}-host-check += "phosphor-reset-host-running@.service"
 
+SYSTEMD_SERVICE_${PN}-reset-sensor-states += "phosphor-reset-sensor-states@.service"
+
 RESET_CHECK_TMPL = "phosphor-reset-host-check@.service"
 RESET_CHECK_TGTFMT = "obmc-host-reset@{1}.target"
 RESET_CHECK_INSTFMT = "phosphor-reset-host-check@{0}.service"
 RESET_CHECK_FMT = "../${RESET_CHECK_TMPL}:${RESET_CHECK_TGTFMT}.requires/${RESET_CHECK_INSTFMT}"
 
+SENSOR_RESET_TMPL = "phosphor-reset-sensor-states@.service"
+SENSOR_RESET_TGTFMT = "obmc-host-reset@{1}.target"
+SENSOR_RESET_INSTFMT = "phosphor-reset-sensor-states@{0}.service"
+SENSOR_RESET_FMT = "../${SENSOR_RESET_TMPL}:${SENSOR_RESET_TGTFMT}.requires/${SENSOR_RESET_INSTFMT}"
+
 RESET_RUNNING_TMPL = "phosphor-reset-host-running@.service"
 RESET_RUNNING_TGTFMT = "obmc-host-reset@{1}.target"
 RESET_RUNNING_INSTFMT = "phosphor-reset-host-running@{0}.service"
@@ -69,6 +84,8 @@
 SYSTEMD_LINK_${PN}-host-check += "${@compose_list_zip(d, 'RESET_CHECK_FMT', 'OBMC_HOST_INSTANCES', 'OBMC_HOST_INSTANCES')}"
 SYSTEMD_LINK_${PN}-host-check += "${@compose_list_zip(d, 'RESET_RUNNING_FMT', 'OBMC_HOST_INSTANCES', 'OBMC_HOST_INSTANCES')}"
 
+SYSTEMD_LINK_${PN}-reset-sensor-states += "${@compose_list_zip(d, 'SENSOR_RESET_FMT', 'OBMC_HOST_INSTANCES', 'OBMC_HOST_INSTANCES')}"
+
 # Force the standby target to run the host reset check target
 RESET_TMPL_CTRL = "obmc-host-reset@.target"
 SYSD_TGT = "${SYSTEMD_DEFAULT_TARGET}"