meta-ampere: support ampere power/host already on targets
There are no targets to identity the already on of power state and the
already running of host state. This commit adds those targets.
The targets will be the check points to start ampere services such as
drivers binder, hang detection...
obmc-power-already-on@.target will be always activated when
chassis-power-control is asserted. It will be deactivated before
deasserting chassis-power-control.
obmc-host-already-on@.target will be activated when the host%i-ready
is triggered. The target will be deactivated before turning
off/reseting the host.
Tested:
1. The targets should be activated/deactivated as designing.
Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
Change-Id: I09a8b94d8043f31f7cee83b29765f7e2c7a5c35a
diff --git a/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl.bb b/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl.bb
index b0498f8..3f9babb 100644
--- a/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl.bb
+++ b/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl.bb
@@ -14,11 +14,17 @@
file://ampere-host-force-reset@.service \
file://ampere-host-on-host-check@.service \
file://ampere_host_check.sh \
+ file://obmc-power-already-on@.target \
+ file://obmc-host-already-on@.target \
+ file://ampere-bmc-reboot-host-check@.service \
"
SYSTEMD_PACKAGES = "${PN}"
SYSTEMD_SERVICE:${PN} = " \
ampere-host-force-reset@.service \
+ obmc-power-already-on@.target \
+ obmc-host-already-on@.target \
+ ampere-bmc-reboot-host-check@.service \
"
# append force reboot
@@ -36,6 +42,21 @@
SYSTEMD_LINK:${PN} += "${@compose_list_zip(d, 'HOST_ON_RESET_HOSTFMT', 'OBMC_HOST_INSTANCES')}"
SYSTEMD_SERVICE:${PN} += "${HOST_ON_RESET_HOSTTMPL}"
+# append on op-wait-power-on
+AMPERE_POWER_ON_TGT = "obmc-power-already-on@.target"
+AMPERE_POWER_ON_INSTMPL = "obmc-power-already-on@{0}.target"
+OP_WAIT_POWER_ON = "op-wait-power-on@{0}.service"
+AMPERE_POWER_ON_TARGET_FMT = "../${AMPERE_POWER_ON_TGT}:${OP_WAIT_POWER_ON}.wants/${AMPERE_POWER_ON_INSTMPL}"
+SYSTEMD_LINK:${PN} += "${@compose_list_zip(d, 'AMPERE_POWER_ON_TARGET_FMT', 'OBMC_HOST_INSTANCES')}"
+
+# append on obmc-chassis-poweron but will start after phosphor-state-manager init
+# host state as running
+HOST_CHECK_BMC_REBOOT_HOSTTMPL = "ampere-bmc-reboot-host-check@.service"
+HOST_CHECK_BMC_REBOOT_HOSTINSTMPL = "ampere-bmc-reboot-host-check@{0}.service"
+HOST_CHECK_BMC_REBOOT_HOSTTGTFMT = "obmc-chassis-poweron@{0}.target"
+HOST_CHECK_BMC_REBOOT_HOSTFMT = "../${HOST_CHECK_BMC_REBOOT_HOSTTMPL}:${HOST_CHECK_BMC_REBOOT_HOSTTGTFMT}.requires/${HOST_CHECK_BMC_REBOOT_HOSTINSTMPL}"
+SYSTEMD_LINK:${PN} += "${@compose_list_zip(d, 'HOST_CHECK_BMC_REBOOT_HOSTFMT', 'OBMC_HOST_INSTANCES')}"
+
do_install() {
install -d ${D}/usr/sbin
install -m 0755 ${WORKDIR}/ampere_host_check.sh ${D}/${sbindir}/
diff --git a/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/ampere-bmc-reboot-host-check@.service b/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/ampere-bmc-reboot-host-check@.service
new file mode 100644
index 0000000..feaa3d0
--- /dev/null
+++ b/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/ampere-bmc-reboot-host-check@.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=Check Host%i status after bmc reboot
+After=obmc-host-reset@%i.target
+After=obmc-host-reset-running@%i.target
+After=mapper-wait@-xyz-openbmc_project-state-host%i.service
+OnSuccess=obmc-host-already-on@%i.target
+ConditionPathExists=/run/openbmc/chassis@%i-on
+ConditionPathExists=/run/openbmc/host@%i-on
+Conflicts=obmc-chassis-poweroff@%i.target
+
+[Service]
+Type=oneshot
+ExecStart=/bin/sh -c "if [ $(busctl get-property `mapper get-service /xyz/openbmc_project/state/host0` /xyz/openbmc_project/state/host0 xyz.openbmc_project.State.Host CurrentHostState | grep -i '\.Running' | wc -l) != 0 ]; then exit 0; fi"
+
+
diff --git a/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/ampere-host-on-host-check@.service b/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/ampere-host-on-host-check@.service
index e3c8739..a68d043 100644
--- a/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/ampere-host-on-host-check@.service
+++ b/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/ampere-host-on-host-check@.service
@@ -5,6 +5,7 @@
Conflicts=obmc-host-stop@%i.target
Conflicts=phosphor-reset-host-check@%i.service
OnFailure=obmc-host-quiesce@%i.target
+OnSuccess=obmc-host-already-on@%i.target
OnFailureJobMode=flush
[Service]
diff --git a/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/obmc-host-already-on@.target b/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/obmc-host-already-on@.target
new file mode 100644
index 0000000..07f5039
--- /dev/null
+++ b/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/obmc-host-already-on@.target
@@ -0,0 +1,6 @@
+[Unit]
+Description=Ampere Host %i already on target
+Conflicts=obmc-chassis-poweroff@%i.target
+Conflicts=obmc-host-quiesce@%i.target
+Conflicts=ampere-host-force-reset@%i.service
+Conflicts=ampere-host-shutdown-ack@%i.service
diff --git a/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/obmc-power-already-on@.target b/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/obmc-power-already-on@.target
new file mode 100644
index 0000000..63699cf
--- /dev/null
+++ b/meta-ampere/meta-common/recipes-ampere/host/ampere-hostctrl/obmc-power-already-on@.target
@@ -0,0 +1,5 @@
+[Unit]
+Description=Ampere power %i already on target
+After=op-wait-power-on@%i.service
+Conflicts=obmc-chassis-poweroff@%i.target
+Conflicts=ampere-host-shutdown-ack@%i.service