Supreeth Venkatesh | d1b931c | 2020-05-27 15:16:15 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | GPIO_BASE=$(cat /sys/devices/platform/ahb/ahb:apb/1e780000.gpio/gpio/*/base) |
| 4 | #MGMT_ASSERT_PWR_BTN - Asserts the system power button, GPIO M0, Active High, (Default = Low) |
| 5 | GPIO_PWR_BTN=$(($GPIO_BASE + 96 + 0)) |
| 6 | #MGMT_ASSERT_RST_BTN - Assert the system cold reset button, GPIO M1, Active High, (Default = Low) |
| 7 | GPIO_RST_BTN=$(($GPIO_BASE + 96 + 1)) |
| 8 | # MGMT_ASSERT_BMC_READY - Hold low until BMC has completed initialization, then drive high, GPIO M7, (Default = Low) |
| 9 | GPIO_BMC_READY=$((${GPIO_BASE} + 96 + 7)) |
| 10 | |
| 11 | # Usage of this utility |
| 12 | function usage() { |
| 13 | echo "usage: power-util [on|off|cycle|status|reset]"; |
| 14 | } |
| 15 | |
| 16 | power_off() { |
| 17 | echo "Shutting down Server" |
| 18 | POWER_STATUS=off |
| 19 | printf %s "$POWER_STATUS" > /tmp/power_status |
| 20 | echo 1 > /sys/class/gpio/gpio${GPIO_PWR_BTN}/value |
| 21 | # Long Press |
| 22 | sleep 5 |
| 23 | echo 0 > /sys/class/gpio/gpio${GPIO_PWR_BTN}/value |
| 24 | } |
| 25 | |
| 26 | power_on() { |
| 27 | echo "Powering on Server" |
| 28 | echo 1 > /sys/class/gpio/gpio${GPIO_PWR_BTN}/value |
| 29 | # Short Press |
| 30 | sleep 1 |
| 31 | echo 0 > /sys/class/gpio/gpio${GPIO_PWR_BTN}/value |
| 32 | POWER_STATUS=on |
| 33 | printf %s "$POWER_STATUS" > /tmp/power_status |
| 34 | } |
| 35 | |
| 36 | power_status() { |
| 37 | POWER_STATUS=$(cat /tmp/power_status) |
| 38 | echo ${POWER_STATUS} |
| 39 | } |
| 40 | |
| 41 | power_reset() { |
| 42 | echo "Toggle Cold Reset" |
| 43 | echo 1 > /sys/class/gpio/gpio${GPIO_RST_BTN}/value |
| 44 | sleep 1 |
| 45 | echo 0 > /sys/class/gpio/gpio${GPIO_RST_BTN}/value |
| 46 | } |
| 47 | |
| 48 | if [ $# -lt 1 ]; then |
| 49 | echo "Total number of parameter=$#" |
| 50 | echo "Insufficient parameter" |
| 51 | usage; |
| 52 | exit 0; |
| 53 | fi |
| 54 | |
| 55 | if [ $1 = "on" ]; then |
| 56 | if [ $(power_status) == "off" ]; then |
| 57 | power_on |
| 58 | fi |
| 59 | elif [ $1 = "off" ]; then |
| 60 | if [ $(power_status) == "on" ]; then |
| 61 | power_off |
| 62 | fi |
| 63 | elif [ $1 == "cycle" ]; then |
| 64 | if [ $(power_status) == "on" ]; then |
| 65 | power_off |
| 66 | else |
| 67 | echo "WARNING: Powering on server" |
| 68 | power_on |
| 69 | fi |
| 70 | elif [ $1 == "reset" ]; then |
| 71 | if [ $(power_status) == "on" ]; then |
| 72 | power_reset |
| 73 | else |
| 74 | echo "ERROR: Server not powered on" |
| 75 | fi |
| 76 | elif [ $1 == "status" ]; then |
| 77 | power_status |
| 78 | else |
| 79 | echo "Invalid parameter=$1" |
| 80 | usage; |
| 81 | fi |
| 82 | |
| 83 | exit 0; |