Delphine CC Chiu | 0528ecd | 2022-11-03 15:40:43 +0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Provide source directive to shellcheck. |
| 4 | # shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd |
| 5 | source /usr/libexec/power-cmd |
| 6 | |
| 7 | SLOT_ID=$(( $1-1 << 2 )) |
| 8 | |
| 9 | # Host Reboot |
| 10 | host-reboot() |
| 11 | { |
| 12 | for reset_cmd in "${reset_seq[@]}" |
| 13 | do |
| 14 | result="$(busctl call $SERVICE $OBJECT_PATH $INTERFACE sendRequest yyyyay $SLOT_ID $NETFN $LUN $CMD $DATA_LEN 0x01 0x42 0x01 0 "$reset_cmd")" |
| 15 | echo "$result" |
| 16 | if [ "$reset_cmd" == $POWER_BTN_LOW ] |
| 17 | then |
| 18 | sleep "$1" |
| 19 | fi |
| 20 | done |
| 21 | echo "Host Power Reset" |
| 22 | exit 0 |
| 23 | } |
| 24 | |
| 25 | # Check Host Response and Status |
| 26 | check-response() |
| 27 | { |
| 28 | response="$(busctl call $SERVICE $OBJECT_PATH $INTERFACE sendRequest yyyyay $SLOT_ID 0x38 $LUN 0x3 0x03 0x15 0xa0 0x00)" |
| 29 | |
| 30 | result=$(echo "$response" | cut -d" " -f $PWRGD_SYS_PWROK_INDEX) |
| 31 | res="$(( "$result" & 0x80 ))" |
| 32 | pgood="$(( "$res" >> 7 ))" |
| 33 | if [ "$pgood" == $STATE_ON ] |
| 34 | then |
| 35 | host-reboot 1 |
| 36 | exit 0; |
| 37 | else |
| 38 | echo "Host is Off" |
| 39 | exit 1; |
| 40 | fi |
| 41 | } |
| 42 | |
| 43 | check-response |