1#!/bin/bash
2
3# shellcheck source=meta-facebook/recipes-fb/obmc_functions/files/fb-common-functions
4source /usr/libexec/fb-common-functions
5# shellcheck source=meta-facebook/meta-anacapa/recipes-phosphor/state/phosphor-state-manager/power-cmd
6source /usr/libexec/phosphor-state-manager/power-cmd
7
8# when host power on, bind pca9546 on bridge L/R board
9bind_i2c_device pca954x 0-0070 3
10bind_i2c_device pca954x 1-0070 3
11
12currentstate=$(busctl get-property \
13    xyz.openbmc_project.State.Host0 \
14    /xyz/openbmc_project/state/host0 \
15    xyz.openbmc_project.State.Host \
16    CurrentHostState | awk '{print $2}' | tr -d '"')
17
18if [ "$currentstate" == "xyz.openbmc_project.State.Host.HostState.TransitioningToRunning" ]; then
19    exit 0
20fi
21
22
23active=$(systemctl is-active host-poweron@0.service)
24if [ -z "$active" ] || [ "$active" != "inactive" ]; then
25    exit 0
26fi
27
28active=$(systemctl is-active host-powerreset@0.service)
29if [ -z "$active" ] || [ "$active" != "inactive" ]; then
30    exit 0
31fi
32
33# Sync power status to "On" for abnormal power-on scenarios.
34
35transition=$(busctl get-property \
36    xyz.openbmc_project.State.Host0 \
37    /xyz/openbmc_project/state/host0 \
38    xyz.openbmc_project.State.Host \
39    RequestedHostTransition | awk '{print $2}' | tr -d '"')
40
41if [ "$transition" != "xyz.openbmc_project.State.Host.Transition.On" ] && [ "$(power_status)" == "on" ]; then
42    busctl set-property xyz.openbmc_project.State.Host0 \
43        /xyz/openbmc_project/state/host0 \
44        xyz.openbmc_project.State.Host \
45        RequestedHostTransition s \
46        xyz.openbmc_project.State.Host.Transition.On
47fi
48
49
50exit 0
51