diff options
author | ThuBaNguyen <thu@os.amperecomputing.com> | 2021-07-05 09:32:26 +0300 |
---|---|---|
committer | Thang Q. Nguyen <thang@os.amperecomputing.com> | 2021-08-04 10:59:04 +0300 |
commit | 2f952142e9ed8b436a0e702a0f46ac88842dd51e (patch) | |
tree | e4f58ad3c728bd6361d31c738e91b0cf257c079b /meta-ampere/meta-common/recipes-ac01/host | |
parent | 509991d6a5f34772788ca6d8401c19109e6280a6 (diff) | |
download | openbmc-2f952142e9ed8b436a0e702a0f46ac88842dd51e.tar.xz |
meta-ampere: power control: refactor host power control
Refactor the Mt.Jade Host power control operations to support Altra
CPU following the Altra SoC BMC Interface specification which still
satisfying the OpenBMC power control framework.
Tested: check the below cases and ensure Host state report correctly:
1. Run "reboot" from Host Linux. Check the Host is graceful
shutdown, then SYS_RESET is asserted and the Host is booted.
2. Run "shutdown" from Host Linux. Check the Host is graceful
shutdown then the chassis power is turned OFF.
3. Run "ipmitool chassis power soft". Check the Host is graceful
shutdown
4. Execute Redfish GracefulShutdown. Check the Host is graceful
shutdown then the chassis power is turned OFF.
5. Execute Redfish GracefulRestart. Check the Host is graceful
shutdown then turned ON.
6. Check other IPMI chassis power and Redfish Reset actions work.
Signed-off-by: ThuBaNguyen <thu@os.amperecomputing.com>
Change-Id: I3a9716f37d7e80bdc1a1d0422e561c8fc51ad040
Diffstat (limited to 'meta-ampere/meta-common/recipes-ac01/host')
11 files changed, 69 insertions, 120 deletions
diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb index f8e295401..4a44d1b2f 100644 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb +++ b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl.bb @@ -14,12 +14,9 @@ SYSTEMD_ENVIRONMENT_FILE_${PN} +="obmc/gpio/shutdown_ack obmc/gpio/reboot_ack" S = "${WORKDIR}" SRC_URI = " \ - file://ampere-host-reset.service \ file://ampere_power_util.sh \ - file://ampere-chassis-poweron.service \ - file://ampere-host-reset-ack.service \ - file://ampere-host-force-reset.service \ - file://ampere-host-power-cycle.service \ + file://ampere-host-force-reset@.service \ + file://ampere-host-shutdown-ack@.service \ " DEPENDS = "systemd virtual/obmc-gpio-monitor" @@ -27,37 +24,16 @@ RDEPENDS_${PN} = "bash virtual/obmc-gpio-monitor" SYSTEMD_PACKAGES = "${PN}" SYSTEMD_SERVICE_${PN} = " \ - ampere-host-reset.service \ - ampere-chassis-poweron.service \ - ampere-host-reset-ack.service \ - ampere-host-force-reset.service \ - ampere-host-power-cycle.service \ + ampere-host-force-reset@.service \ + ampere-host-shutdown-ack@.service \ " -# host power control -# 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_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')}" - TMPL = "phosphor-gpio-monitor@.service" INSTFMT = "phosphor-gpio-monitor@{0}.service" TGT = "multi-user.target" diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-chassis-poweron.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-chassis-poweron.service deleted file mode 100644 index 76ceb8856..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-chassis-poweron.service +++ /dev/null @@ -1,9 +0,0 @@ -[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-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset.service deleted file mode 100644 index 8a40baf7b..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset.service +++ /dev/null @@ -1,11 +0,0 @@ -[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-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset@.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset@.service new file mode 100644 index 000000000..6e03c8b81 --- /dev/null +++ b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-force-reset@.service @@ -0,0 +1,14 @@ +[Unit] +Description=Ampere Computing LLC force reset host%i +Wants=phosphor-reboot-host@%i.service +Conflicts=obmc-chassis-poweroff@%i.target +OnFailure=obmc-chassis-powerreset@%i.target + +[Service] +RemainAfterExit=no +Type=oneshot +ExecStart=/bin/sh -c "sleep 3 && /usr/bin/env ampere_power_util.sh mb force_reset" +SyslogIdentifier=ampere_power_util.sh + +[Install] +WantedBy=obmc-host-force-warm-reboot@%i.target
\ No newline at end of file diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-power-cycle.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-power-cycle.service deleted file mode 100644 index 2fb03effb..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-power-cycle.service +++ /dev/null @@ -1,10 +0,0 @@ -[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 cycle -SyslogIdentifier=ampere_power_util.sh diff --git a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset-ack.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset-ack.service deleted file mode 100644 index 504186ec6..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset-ack.service +++ /dev/null @@ -1,10 +0,0 @@ -[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-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset.service deleted file mode 100644 index ac7618ad0..000000000 --- a/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-reset.service +++ /dev/null @@ -1,9 +0,0 @@ -[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-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown-ack@.service b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown-ack@.service new file mode 100644 index 000000000..6588191aa --- /dev/null +++ b/meta-ampere/meta-common/recipes-ac01/host/ampere-hostctrl/ampere-host-shutdown-ack@.service @@ -0,0 +1,8 @@ +[Unit] +Description=Ampere Computing LLC host shutdown ACK +Conflicts=obmc-chassis-poweron@0.target + +[Service] +Type=oneshot +ExecStart=/usr/bin/env ampere_power_util.sh mb shutdown_ack +SyslogIdentifier=ampere_host_shutdown_ack diff --git a/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh b/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh index 9a8b06c6b..aa742104f 100644 --- a/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh +++ b/meta-ampere/meta-common/recipes-ac01/host/files/ampere_power_util.sh @@ -4,15 +4,6 @@ function usage() { echo "usage: power-util mb [on|status|cycle|reset|graceful_reset|force_reset|soft_off]"; } -power_off() { - echo "power_off" -} - -power_on() { - echo "Powering on 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.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 @@ -22,21 +13,13 @@ power_status() { 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 -} - -timestamp() { - date +"%s" # current time -} - shutdown_ack() { if [ -f "/run/openbmc/host@0-softpoweroff" ]; then echo "Receive shutdown ACK triggered after softportoff the host." touch /run/openbmc/host@0-softpoweroff-shutdown-ack else echo "Receive shutdown ACK triggered" +<<<<<<< HEAD fi } @@ -50,6 +33,10 @@ graceful_shutdown() { sleep 1 gpioset -l 0 49=0 sleep 30s +======= + sleep 3 + systemctl start obmc-chassis-poweroff@0.target +>>>>>>> 397e033ef... meta-ampere: power control: refactor host power control fi } @@ -81,6 +68,26 @@ soft_off() { } force_reset() { + if [ -f "/run/openbmc/host@0-softpoweroff" ]; then + # In graceful host reset, after trigger os shutdown, + # the phosphor-state-manager will call force-warm-reset + # in this case the force_reset should wait for shutdown_ack from host + cnt=30 + while [ $cnt -gt 0 ]; + do + if [ -f "/run/openbmc/host@0-softpoweroff-shutdown-ack" ]; then + break + fi + echo "Waiting for shutdown-ack count down $cnt" + sleep 1 + cnt=$((cnt - 1)) + done + # The host OS is failed to shutdown + if [ $cnt == 0 ]; then + echo "Shutdown-ack time out after 30s." + exit 0 + fi + fi echo "Triggering sysreset pin" gpioset -l 0 91=1 sleep 1 @@ -100,30 +107,23 @@ if [ $1 != "mb" ]; then exit 0; fi -if [ $2 = "on" ]; then - if [ $(power_status) == "off" ]; then - power_on +# check if power guard enabled +dir="/run/systemd/system/" +file="reboot-guard.conf" +units=("reboot" "poweroff" "halt") +for unit in "${units[@]}"; do + if [ -f ${dir}${unit}.target.d/${file} ]; then + echo "PowerGuard enabled, cannot do power control, exit!!!" + exit -1 fi -elif [ $2 == "cycle" ]; then - if [ $(power_status) == "on" ]; then - echo "Powering off 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_reset" ]; then +done + +if [ ! -d "/run/openbmc/" ]; then mkdir -p "/run/openbmc/" - touch "/run/openbmc/host@0-graceful-reset" - graceful_shutdown - sleep 20s +fi + +if [ $2 == "shutdown_ack" ]; then + shutdown_ack elif [ $2 == "status" ]; then power_status elif [ $2 == "force_reset" ]; then diff --git a/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/reboot_ack b/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/reboot_ack index 0436d32da..a8ad98ee7 100644 --- a/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/reboot_ack +++ b/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/reboot_ack @@ -1,4 +1,4 @@ DEVPATH=/dev/input/event0 KEY=75 POLARITY=1 -TARGET=ampere-host-reset-ack.service +TARGET=obmc-host-force-warm-reboot@0.target diff --git a/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/shutdown_ack b/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/shutdown_ack index a0e857fac..18cc87246 100644 --- a/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/shutdown_ack +++ b/meta-ampere/meta-common/recipes-ac01/host/files/obmc/gpio/shutdown_ack @@ -1,4 +1,4 @@ DEVPATH=/dev/input/event0 KEY=50 POLARITY=1 -TARGET=ampere-chassis-poweroff.service +TARGET=ampere-host-shutdown-ack@0.service |