meta-facebook: yosemite4: refactor common function for stability

Refactor `check_nuvoton_board` function to avoid some scritps define
`set -e` in the beginning of `#!/bin/bash` that will think failed when
return value is non-zero and related services might got failed also.

Tested:
Run related services successfully.
root@bmc:/# systemctl status yosemite4-sys-init.service
bmc systemd[1]: Starting Yosemite4 Early System Init...
bmc systemd[1]: yosemite4-sys-init.service: Deactivated successfully.
bmc systemd[1]: Finished Yosemite4 Early System Init.

root@bmc:/# systemctl status mctpd.service
* mctpd.service - MCTP control protocol daemon
    Drop-In: /usr/lib/systemd/system/mctpd.service.d
             `-setup-local-eid.conf, setup-static-endpoints.conf

Signed-off-by: Tim Lee <timlee660101@gmail.com>
Change-Id: I6045d6ae6349cf84f0e920e4d219def602515809
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/gpio/phosphor-gpio-monitor/probe-slot-device b/meta-facebook/meta-yosemite4/recipes-phosphor/gpio/phosphor-gpio-monitor/probe-slot-device
index 9640271..f99c7ee 100644
--- a/meta-facebook/meta-yosemite4/recipes-phosphor/gpio/phosphor-gpio-monitor/probe-slot-device
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/gpio/phosphor-gpio-monitor/probe-slot-device
@@ -2,8 +2,7 @@
 # shellcheck source=meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
 source /usr/libexec/yosemite4-common-functions
 
-check_nuvoton_board
-is_nuvoton_board=$?
+is_nuvoton_board="$(check_nuvoton_board)"
 
 HOST_BUS=$(($1 - 1))
 HOST_VIRTUAL_BUS=$(($1 + 15))
@@ -18,7 +17,7 @@
 echo $HOST_VIRTUAL_BUS-0051 > /sys/bus/i2c/drivers/at24/bind
 echo $HOST_VIRTUAL_BUS-0054 > /sys/bus/i2c/drivers/at24/bind
 
-if [ "$is_nuvoton_board" -eq "1" ]
+if [ -n "$is_nuvoton_board" ]
 then
     # Set interface of SD BIC to I3C
     GPIOCHIP=$(basename /sys/bus/i2c/devices/$HOST_BUS-0023/*gpiochip*)
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle
index 5566ba5..448b7be 100644
--- a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-powercycle
@@ -21,8 +21,7 @@
 GPIOCHIP_IO_EXP_SLED_PWR_CTRL=$(basename "/sys/bus/i2c/devices/$MANAGEMENT_BOARD_IO_EXP_BUS_NUM-00$IO_EXP_SLED_PWR_CTRL_ADDR/"*gpiochip*)
 #GPIOCHIP_IO_EXP_BIC_PWR_CTRL=$(basename "/sys/bus/i2c/devices/$IO_EXP_SLOT_PWR_STATUS-00$IO_EXP_BIC_PWR_CTRL_ADDR/"*gpiochip*)
 
-check_nuvoton_board
-is_nuvoton_board=$?
+is_nuvoton_board="$(check_nuvoton_board)"
 
 chassis-power-cycle()
 {
@@ -33,7 +32,7 @@
         chassis_status=$(gpio_get "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_STATUS")
         if [ "$chassis_status" == "$STATE_ON" ]
         then
-            if [ "$is_nuvoton_board" -eq "1" ]
+            if [ -n "$is_nuvoton_board" ]
             then
                 # inform management CPLD that the slot is 12V off
                 if ! gpio_set "$GPIOCHIP_IO_EXP_SLED_PWR_CTRL" "$IO_EXP_SLOT_12V_STATUS"=0
@@ -58,7 +57,7 @@
         chassis_status=$(gpio_get "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_STATUS")
         if [ "$chassis_status" == "$STATE_ON" ]
         then
-            if [ "$is_nuvoton_board" -eq "1" ]
+            if [ -n "$is_nuvoton_board" ]
             then
                 # inform management CPLD that the slot is 12V on
                 if ! gpio_set "$GPIOCHIP_IO_EXP_SLED_PWR_CTRL" "$IO_EXP_SLOT_12V_STATUS"=1
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweroff b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweroff
index 3bfb5ec..b717554 100644
--- a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweroff
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweroff
@@ -20,8 +20,7 @@
 #GPIOCHIP_IO_EXP_BIC_PWR_CTRL=$(basename "/sys/bus/i2c/devices/$IO_EXP_SLOT_PWR_STATUS-00$IO_EXP_BIC_PWR_CTRL_ADDR/"*gpiochip*)
 GPIOCHIP_IO_EXP_SLOT_12V_STATUS_CTRL=$(basename "/sys/bus/i2c/devices/$MANAGEMENT_BOARD_IO_EXP_BUS_NUM-00$IO_EXP_SLED_PWR_CTRL_ADDR/"*gpiochip*)
 
-check_nuvoton_board
-is_nuvoton_board=$?
+is_nuvoton_board="$(check_nuvoton_board)"
 
 # Server 12v power off
 chassis-power-off()
@@ -55,7 +54,7 @@
 
 if [ "$chassis_status" == "$STATE_ON" ]
 then
-        if [ "$is_nuvoton_board" -eq "1" ]
+        if [ -n "$is_nuvoton_board" ]
         then
                 # inform management CPLD that the slot is 12V off
                 if ! gpio_set "$GPIOCHIP_IO_EXP_SLOT_12V_STATUS_CTRL" "$IO_EXP_SLOT_12V_STATUS"=0
diff --git a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweron b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweron
index 14b9bab..386cfc2 100644
--- a/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweron
+++ b/meta-facebook/meta-yosemite4/recipes-phosphor/state/phosphor-state-manager/chassis-poweron
@@ -18,8 +18,7 @@
 IO_EXP_SLOT_PWR_CTRL=$((IO_EXP_SLOT_PWR_STATUS + 8))
 IO_EXP_SLOT_12V_STATUS=$((CHASSIS_ID + 23))
 
-check_nuvoton_board
-is_nuvoton_board=$?
+is_nuvoton_board="$(check_nuvoton_board)"
 
 # Server 12v power on
 chassis-power-on()
@@ -34,7 +33,7 @@
     chassis_status=$(gpio_get "$GPIOCHIP_IO_EXP_SLOT_PWR_CTRL" "$IO_EXP_SLOT_PWR_STATUS")
     if [ "$chassis_status" == "$STATE_ON" ]
     then
-        if [ "$is_nuvoton_board" -eq "1" ]
+        if [ -n "$is_nuvoton_board" ]
         then
             # inform management CPLD that the slot is 12V off
             if ! gpio_set "$GPIOCHIP_IO_EXP_SLOT_12V_STATUS_CTRL" "$IO_EXP_SLOT_12V_STATUS"=1
diff --git a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-early-sys-init b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-early-sys-init
index 0ee8a8d..9d10248 100644
--- a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-early-sys-init
+++ b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-svc/files/yosemite4-early-sys-init
@@ -2,8 +2,7 @@
 # shellcheck source=meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
 source /usr/libexec/yosemite4-common-functions
 
-check_nuvoton_board
-is_nuvoton_board=$?
+is_nuvoton_board="$(check_nuvoton_board)"
 
 enable_all_fan_input()
 {
@@ -58,7 +57,7 @@
 set_gpio NIC2_MAIN_PWR_EN 1
 set_gpio NIC3_MAIN_PWR_EN 1
 
-if [ "$is_nuvoton_board" -ne "1" ]
+if [ -z "$is_nuvoton_board" ]
 then
     # short-term set gpio v0~v3 to input pin for slot5~8 reset button
     mknod -m 660 /dev/mem c 1 1
@@ -69,7 +68,7 @@
 # Enable all fan input as early as possible
 enable_all_fan_input
 
-if [ "$is_nuvoton_board" -eq "1" ]
+if [ -n "$is_nuvoton_board" ]
 then
     # Set interface to SD BIC to I3C for Nuvoton BMC
     set_sd_bic_interface_to_i3c
diff --git a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
index 4e948e6..5c69011 100644
--- a/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
+++ b/meta-facebook/meta-yosemite4/recipes-yosemite4/plat-tool/files/yosemite4-common-functions
@@ -22,9 +22,7 @@
 
 check_nuvoton_board()
 {
-    check_nuvoton=$(grep nuvoton /sys/firmware/devicetree/base/compatible)
-    if [ "$check_nuvoton" != "" ]; then
-        return 1
-    fi
+    set +e
+    grep nuvoton /sys/firmware/devicetree/base/compatible
     return 0
 }