blob: 59f91ece73a265a4458c97b19c30b6dc21c1ddfd [file] [log] [blame]
Vijay Khemka45269ba2018-12-13 11:07:06 -08001#!/bin/bash
2# Usage of this utility
3function usage() {
4 echo "usage: power-util mb 1 [on|off]";
5}
6
7GPIO_BASE=$(cat /sys/class/gpio/gpio*/base)
8PWR_GPIO=$(($GPIO_BASE + 32 + 3))
9BMC_RDY_GPIO=$(($GPIO_BASE + 144 +1))
10
11if [ $# -lt 3 ]; then
12 echo "Total number of parameter=$#"
13 echo "Insufficient parameter"
14 usage;
15 exit 0;
16fi
17
18if [ $1 != "mb" ]; then
19 echo "Invalid parameter1=$1"
20 usage;
21 exit 0;
22fi
23
24if [ $2 -ne 1 ]; then
25 echo "Invalid parameter2=$2, Server $2 not supported"
26 usage;
27 exit 0;
28fi
29
30if [ $3 = "on" ]; then
31 echo "Powering on Server $2"
32 echo 0 > /sys/class/gpio/gpio${BMC_RDY_GPIO}/value
33 echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value
34 echo 0 > /sys/class/gpio/gpio${PWR_GPIO}/value
35 sleep 1
36 echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value
37elif [ $3 = "off" ]; then
38 echo "Shutting down Server $2"
39 echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value
40 sleep 1
41 echo 0 > /sys/class/gpio/gpio${PWR_GPIO}/value
42 sleep 6
43 echo 1 > /sys/class/gpio/gpio${PWR_GPIO}/value
44else
45 echo "Invalid parameter3=$3"
46 usage;
47fi
48
49exit 0;