blob: b67db36ac7d98f5e2858b098745bd206cc2fcb3a [file] [log] [blame]
Supreeth Venkateshd1b931c2020-05-27 15:16:15 -05001#!/bin/bash
2
3GPIO_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)
5GPIO_PWR_BTN=$(($GPIO_BASE + 96 + 0))
6#MGMT_ASSERT_RST_BTN - Assert the system cold reset button, GPIO M1, Active High, (Default = Low)
7GPIO_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)
9GPIO_BMC_READY=$((${GPIO_BASE} + 96 + 7))
10
11# Usage of this utility
12function usage() {
13 echo "usage: power-util [on|off|cycle|status|reset]";
14}
15
16power_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
26power_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
36power_status() {
37 POWER_STATUS=$(cat /tmp/power_status)
38 echo ${POWER_STATUS}
39}
40
41power_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
48if [ $# -lt 1 ]; then
49 echo "Total number of parameter=$#"
50 echo "Insufficient parameter"
51 usage;
52 exit 0;
53fi
54
55if [ $1 = "on" ]; then
56 if [ $(power_status) == "off" ]; then
57 power_on
58 fi
59elif [ $1 = "off" ]; then
60 if [ $(power_status) == "on" ]; then
61 power_off
62 fi
63elif [ $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
70elif [ $1 == "reset" ]; then
71 if [ $(power_status) == "on" ]; then
72 power_reset
73 else
74 echo "ERROR: Server not powered on"
75 fi
76elif [ $1 == "status" ]; then
77 power_status
78else
79 echo "Invalid parameter=$1"
80 usage;
81fi
82
83exit 0;