From ddab60c17bdd6aed41878fe8a09cd72f6dae80a8 Mon Sep 17 00:00:00 2001 From: Mike Choi Date: Thu, 29 Aug 2019 23:51:45 -0700 Subject: [PATCH] wedge400: Add presence_util.sh to get scm/fan/psu(pem)/debug card present status (#95) Summary: presence_util.sh to get scm/fan/psu(pem)/debug card present status Pull Request resolved: https://github.com/facebookexternal/openbmc.celestica/pull/95 Test Plan: root@bmc-oob:~# presence_util.sh CARDS scm : 1 FANS fan1 : 1 fan2 : 1 fan3 : 1 fan4 : 1 POWER SUPPLIES psu1 : 1 psu2 : 0 DEBUG CARD debug_card : 1 root@bmc-oob:~# Pass Reviewed By: joancaneus fbshipit-source-id: 4b957efd4d --- .../openbmc-utils/files/presence_util.sh | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/meta-facebook/meta-wedge400/recipes-utils/openbmc-utils/files/presence_util.sh b/meta-facebook/meta-wedge400/recipes-utils/openbmc-utils/files/presence_util.sh index 289c266bfb4e..16ef6f5990db 100755 --- a/meta-facebook/meta-wedge400/recipes-utils/openbmc-utils/files/presence_util.sh +++ b/meta-facebook/meta-wedge400/recipes-utils/openbmc-utils/files/presence_util.sh @@ -23,13 +23,14 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin . /usr/local/bin/openbmc-utils.sh SMB_DIR=$SMBCPLD_SYSFS_DIR -SCM_CMD=$SMB_DIR'/scm_present_int_status' +SCM_CMD=$SMB_DIR"/scm_present_int_status" FAN_CMD=$FCMCPLD_SYSFS_DIR +DEBUG_CARD_PRSNT_GPIO="/tmp/gpionames/DEBUG_PRESENT_N/value" function usage { - program=`basename "$0"` + program=$(basename "$0") echo "Usage:" echo " $program " echo " $program " @@ -41,20 +42,20 @@ function usage function get_presence { local file=$1 key=$2 - val=$(head -n1 $file | awk '{print substr($0,0,3) }' | sed 's/.x//') - if [ $val -eq 0 ]; then + val=$(head -n1 "$file" | awk '{print substr($0,0,3) }' | sed "s/.x//") + if [ "$val" = "0" ]; then val=1 else val=0 fi - echo $key ":" $val + echo "$key : $val" } # SCM function get_scm_presence { - key='scm' - get_presence $SCM_CMD $key + key="scm" + get_presence "$SCM_CMD" "$key" } # FANs @@ -62,9 +63,9 @@ function get_fan_presence { local num=1 while [ $num -le 4 ]; do - key='fan'$num - file=$FAN_CMD'/fan'$num'_present' - get_presence $file $key + key="fan${num}" + file="$FAN_CMD/fan${num}_present" + get_presence "$file" "$key" (( num++ )) done } @@ -73,12 +74,25 @@ function get_fan_presence function get_psu_presence { for i in {1..2}; do - key='psu'${i} - file=$SMB_DIR'/psu_present_'${i}'_N_int_status' - get_presence $file $key + key="psu${i}" + file="$SMB_DIR/psu_present_${i}_N_int_status" + get_presence "$file" "$key" done } +# Debug card +function get_debug_card_presence +{ + key="debug_card" + val=$(head -n1 $DEBUG_CARD_PRSNT_GPIO | awk '{print substr($0,0,3) }' | sed "s/.x//") + if [ "$val" = "0" ]; then + val=0 + else + val=1 + fi + echo $key ":" $val +} + # get all info if [[ $1 = "" ]]; then echo "CARDS" @@ -90,6 +104,10 @@ if [[ $1 = "" ]]; then echo "POWER SUPPLIES" get_psu_presence + echo "DEBUG CARD" + get_debug_card_presence + + exit 0 else if [[ $1 = "scm" ]]; then get_scm_presence @@ -97,8 +115,10 @@ else get_fan_presence elif [[ $1 = "psu" ]]; then get_psu_presence + elif [[ $1 = "debug_card" ]]; then + get_debug_card_presence else usage - exit -1 fi + exit 0 fi