meta-quanta: gbs: fix only detect POST done state once

Fix the boot status LED behavior:

1. turn off boot status LED when system power off
2. keep monitoring POST done state GPIO to blink or turn
   on LED

Signed-off-by: George Hung <george.hung@quantatw.com>
Change-Id: Ibd4f639c1e0a9b879f59380b84da00ab92694e48
diff --git a/meta-gbs/recipes-gbs/boot-status-led/files/boot-status-led.service b/meta-gbs/recipes-gbs/boot-status-led/files/boot-status-led.service
index 0627a94..ea44dda 100644
--- a/meta-gbs/recipes-gbs/boot-status-led/files/boot-status-led.service
+++ b/meta-gbs/recipes-gbs/boot-status-led/files/boot-status-led.service
@@ -1,14 +1,13 @@
 [Unit]
 Description=Boot Status LED Manager
 After=xyz.openbmc_project.LED.GroupManager.service
-Requires=xyz.openbmc_project.LED.GroupManager.service
+Wants=xyz.openbmc_project.LED.GroupManager.service
 
 [Service]
 ExecStart=/usr/bin/boot-status-led.sh
 StandardOutput=syslog
 Type=simple
-RemainAfterExit=yes
-Restart=no
+Restart=yes
 
 [Install]
 WantedBy=multi-user.target
diff --git a/meta-gbs/recipes-gbs/boot-status-led/files/boot-status-led.sh b/meta-gbs/recipes-gbs/boot-status-led/files/boot-status-led.sh
index 65fc0bc..a80082a 100644
--- a/meta-gbs/recipes-gbs/boot-status-led/files/boot-status-led.sh
+++ b/meta-gbs/recipes-gbs/boot-status-led/files/boot-status-led.sh
@@ -11,22 +11,38 @@
 LED_INTERFACE_NAME="xyz.openbmc_project.Led.Group"
 LED_Property="Asserted"
 
-dbus_state=0
+PWR_STATE_SERVICE="xyz.openbmc_project.State.Chassis"
+PWR_STATE_OBJPATH="/xyz/openbmc_project/state/chassis0"
+PWR_STATE_INTERFACE_NAME="xyz.openbmc_project.State.Chassis"
+PWR_STATE_Property="CurrentPowerState"
+
 boot_status=""
-check_flag=0
+power_state=""
+led_status=""
 
 mapper wait $LED_INACTIVE_OBJPATH
 mapper wait $LED_STANDBY_OBJPATH
 while true; do
-    boot_status=$(busctl get-property $BOOT_SERVICE_NAME $BOOT_STATUS_OBJPATH $BOOT_INTERFACE_NAME $BOOT_Property | awk '{print $2}')
+    power_state="$(busctl get-property $PWR_STATE_SERVICE $PWR_STATE_OBJPATH $PWR_STATE_INTERFACE_NAME $PWR_STATE_Property | awk '{print $2}')"
 
-    if [ $boot_status != "\"Standby\"" ] && [ $check_flag -eq 0 ];then
-        busctl set-property $LED_SERVICE_NAME $LED_INACTIVE_OBJPATH $LED_INTERFACE_NAME $LED_Property b true
-        check_flag=1
-    elif [ $boot_status == "\"Standby\"" ];then
-        busctl set-property $LED_SERVICE_NAME $LED_INACTIVE_OBJPATH $LED_INTERFACE_NAME $LED_Property b false
-        busctl set-property $LED_SERVICE_NAME $LED_STANDBY_OBJPATH $LED_INTERFACE_NAME $LED_Property b true
-        break
+    boot_status="$(busctl get-property $BOOT_SERVICE_NAME $BOOT_STATUS_OBJPATH $BOOT_INTERFACE_NAME $BOOT_Property | awk '{print $2}')"
+
+    if [[ $power_state != "\"xyz.openbmc_project.State.Chassis.PowerState.On\"" ]];then
+        if [[ $led_status != "OFF" ]];then
+            busctl set-property $LED_SERVICE_NAME $LED_INACTIVE_OBJPATH $LED_INTERFACE_NAME $LED_Property b false
+            busctl set-property $LED_SERVICE_NAME $LED_STANDBY_OBJPATH $LED_INTERFACE_NAME $LED_Property b false
+            led_status="OFF"
+        fi
+        continue
+    else
+        if [[ $boot_status != "\"Standby\"" ]] && [[ $led_status != "BLINKING" ]];then
+            busctl set-property $LED_SERVICE_NAME $LED_INACTIVE_OBJPATH $LED_INTERFACE_NAME $LED_Property b true
+            led_status="BLINKING"
+        elif [[ $boot_status == "\"Standby\"" ]] && [[ $led_status != "ON" ]];then
+            busctl set-property $LED_SERVICE_NAME $LED_INACTIVE_OBJPATH $LED_INTERFACE_NAME $LED_Property b false
+            busctl set-property $LED_SERVICE_NAME $LED_STANDBY_OBJPATH $LED_INTERFACE_NAME $LED_Property b true
+            led_status="ON"
+        fi
     fi
     sleep 1
 done