diff options
author | Mohaimen Alsamarai <mohaimen.alsamarai@fii-na.com> | 2021-06-25 00:59:29 +0300 |
---|---|---|
committer | Vivekanand Veeracholan <vveerach@google.com> | 2021-08-03 05:53:47 +0300 |
commit | 82a11d871bf57ecd614408f2aa7aa497c99cb802 (patch) | |
tree | 9c33e0980bed3ec9fa96ec28789080e81e36e3c6 /meta-fii/meta-kudo/recipes-kudo/host/files/ampere_power_util.sh | |
parent | 4d99a37d85f9acbc978ee638ca7ca44c3f4250f0 (diff) | |
download | openbmc-82a11d871bf57ecd614408f2aa7aa497c99cb802.tar.xz |
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
Diffstat (limited to 'meta-fii/meta-kudo/recipes-kudo/host/files/ampere_power_util.sh')
-rw-r--r-- | meta-fii/meta-kudo/recipes-kudo/host/files/ampere_power_util.sh | 117 |
1 files changed, 117 insertions, 0 deletions
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 000000000..420abfb8c --- /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; + |