summaryrefslogtreecommitdiff
path: root/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/host-powercycle
blob: 2e7d316e52f173dad43522ed2db8e6fbf2f164a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash

# shellcheck disable=SC2120

# Provide source directive to shellcheck.
# shellcheck source=meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/power-cmd
source /usr/libexec/phosphor-state-manager/power-cmd
CHASSIS_ID=$1

CHASSIS_BUS=$((CHASSIS_ID - 1))
IO_EXP_P0_PWRGD_R_OUT=18
GPIOCHIP_IO_EXP_HOST_POWER_STATUS=$(basename "/sys/bus/i2c/devices/$CHASSIS_BUS-0023/"*gpiochip*)

EID=$((CHASSIS_ID * 10))

get_host_status() {
    if ! host_status=$(gpio_get "$GPIOCHIP_IO_EXP_HOST_POWER_STATUS" "$IO_EXP_P0_PWRGD_R_OUT"); then
        echo "Failed to get host status"
        exit 1
    fi
}

# Get initial host status
get_host_status

# Current power is ON, cycle do OFF to ON. If current power is OFF then do ON
if [ "$host_status" == "$STATE_ON" ]; then
    # Set state effecter state: Entity ID 0x0000 for host power control, 0x2 for power off
    pldmtool raw -d 0x80 0x02 0x39 0x00 0x00 0x01 0x00 0x02 -m "$EID"
    # Wait for the host to power off
    sleep 10s

    # Get host status again after attempting to power off
    get_host_status

    if [ "$host_status" != "$STATE_OFF" ]; then
        msg="Do power cycle fail, fail to set host$CHASSIS_ID power off"
        echo "${msg}"
        add_sel "${msg}"
        exit 1
    fi
fi

if [ "$host_status" != "$STATE_ON" ]; then
    # Set state effecter state: Entity ID 0x0000 for host power control, 0x1 for power on
    pldmtool raw -d 0x80 0x02 0x39 0x00 0x00 0x01 0x00 0x01 -m "$EID"
    sleep 2s

    # Get host status again after attempting to power on
    get_host_status

    if [ "$host_status" != "$STATE_ON" ]; then
        msg="Do power cycle, failed to set host$CHASSIS_ID power on"
        echo "${msg}"
        add_sel "${msg}"
        exit 1
    fi
fi

msg="Host$1 power cycle success"
echo "${msg}"
add_sel "${msg}"
exit 0;