meta-fii: meta-mori: Set up phosphor-led-manager

Summary of changes:
    1. Create a yaml file to set up the action of SYSTEM BOOT STATUS LED
    2. Add bb file to install yaml to phosphor led manager package
    3. Add a script to control the SYSTEM BOOT STATUS LED corresponding
       to the OS status
    4. Set up phosphor led sysfs so the physical led can be controlled
    5. Set CHASSIS TARGET to none to remove unnecessary service call to
       obmc-led-group-start/stop@power_on/off.

Signed-off-by: Vincent Chou <vincent.chou@fii-na.com>
Change-Id: Ia7b136c52518a1e2af6662ffc42b4f72b3e15584
diff --git a/meta-fii/meta-mori/conf/machine/mori.conf b/meta-fii/meta-mori/conf/machine/mori.conf
index 25ce57c..4d99cb2 100644
--- a/meta-fii/meta-mori/conf/machine/mori.conf
+++ b/meta-fii/meta-mori/conf/machine/mori.conf
@@ -25,6 +25,7 @@
 PREFERRED_PROVIDER_virtual/bmc-update = "mori-bmc-update"
 PREFERRED_PROVIDER_virtual/bios-update = "mori-bios-update"
 PREFERRED_PROVIDER_virtual/cpld-update = "mori-cpld-update"
+PREFERRED_PROVIDER_virtual/phosphor-led-manager-config-native = "mori-led-manager-config-native"
 
 # Remove unneeded binaries from image
 IMAGE_FEATURES:remove = "obmc-bmcweb"
diff --git a/meta-fii/meta-mori/recipes-mori/boot-status-led/files/boot-status-led.service b/meta-fii/meta-mori/recipes-mori/boot-status-led/files/boot-status-led.service
new file mode 100644
index 0000000..dc41a1d
--- /dev/null
+++ b/meta-fii/meta-mori/recipes-mori/boot-status-led/files/boot-status-led.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Boot Status LED Manager
+After=xyz.openbmc_project.LED.GroupManager.service
+Wants=xyz.openbmc_project.LED.GroupManager.service
+
+[Service]
+ExecStart=/usr/bin/boot-status-led.sh
+Type=simple
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
diff --git a/meta-fii/meta-mori/recipes-mori/boot-status-led/files/boot-status-led.sh b/meta-fii/meta-mori/recipes-mori/boot-status-led/files/boot-status-led.sh
new file mode 100644
index 0000000..e08e178
--- /dev/null
+++ b/meta-fii/meta-mori/recipes-mori/boot-status-led/files/boot-status-led.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+BOOT_SERVICE_NAME="xyz.openbmc_project.State.Host"
+BOOT_STATUS_OBJPATH="/xyz/openbmc_project/state/host0"
+BOOT_INTERFACE_NAME="xyz.openbmc_project.State.OperatingSystem.Status"
+BOOT_Property="OperatingSystemState"
+
+LED_SERVICE_NAME="xyz.openbmc_project.LED.GroupManager"
+LED_INACTIVE_OBJPATH="/xyz/openbmc_project/led/groups/boot_status_inactive"
+LED_STANDBY_OBJPATH="/xyz/openbmc_project/led/groups/boot_status_standby"
+LED_INTERFACE_NAME="xyz.openbmc_project.Led.Group"
+LED_Property="Asserted"
+
+boot_status=""
+led_status=""
+
+while true; do
+    boot_status="$(busctl get-property $BOOT_SERVICE_NAME $BOOT_STATUS_OBJPATH $BOOT_INTERFACE_NAME $BOOT_Property | awk '{print $2}')"
+
+    if [[ $boot_status != "\"xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Standby\"" ]] && [[ $led_status != "BLINKING" ]];then
+        busctl set-property $LED_SERVICE_NAME $LED_INACTIVE_OBJPATH $LED_INTERFACE_NAME $LED_Property b true
+        busctl set-property $LED_SERVICE_NAME $LED_STANDBY_OBJPATH $LED_INTERFACE_NAME $LED_Property b false
+        led_status="BLINKING"
+    elif [[ $boot_status == "\"xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.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
+
+    sleep 10
+
+done
+
+exit 0
diff --git a/meta-fii/meta-mori/recipes-mori/boot-status-led/mori-boot-status-led.bb b/meta-fii/meta-mori/recipes-mori/boot-status-led/mori-boot-status-led.bb
new file mode 100644
index 0000000..c9b2e9d
--- /dev/null
+++ b/meta-fii/meta-mori/recipes-mori/boot-status-led/mori-boot-status-led.bb
@@ -0,0 +1,25 @@
+SUMMARY = "OpenBMC Mori Boot Status LED Service"
+DESCRIPTION = "OpenBMC Mori Boot Status LED Daemon."
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+inherit systemd
+
+DEPENDS += "systemd"
+RDEPENDS:${PN} += "bash"
+
+SRC_URI = " file://boot-status-led.sh \
+            file://boot-status-led.service \
+          "
+
+do_install() {
+    install -d ${D}${bindir}
+    install -m 0755 ${WORKDIR}/boot-status-led.sh ${D}${bindir}/
+
+    install -d ${D}${systemd_system_unitdir}
+    install -m 0644 ${WORKDIR}/boot-status-led.service ${D}${systemd_system_unitdir}
+}
+
+SYSTEMD_PACKAGES = "${PN}"
+SYSTEMD_SERVICE:${PN} = "boot-status-led.service"
diff --git a/meta-fii/meta-mori/recipes-phosphor/image/obmc-phosphor-image.bbappend b/meta-fii/meta-mori/recipes-phosphor/image/obmc-phosphor-image.bbappend
index 7fe06dc..0553468 100644
--- a/meta-fii/meta-mori/recipes-phosphor/image/obmc-phosphor-image.bbappend
+++ b/meta-fii/meta-mori/recipes-phosphor/image/obmc-phosphor-image.bbappend
@@ -56,3 +56,6 @@
 OBMC_IMAGE_EXTRA_INSTALL:append:mori = " phosphor-software-manager-version"
 OBMC_IMAGE_EXTRA_INSTALL:append:mori = " phosphor-software-manager-updater"
 OBMC_IMAGE_EXTRA_INSTALL:append:mori = " obmc-targets"
+OBMC_IMAGE_EXTRA_INSTALL:append:mori = " mori-boot-status-led"
+OBMC_IMAGE_EXTRA_INSTALL:append:mori = " phosphor-led-manager"
+OBMC_IMAGE_EXTRA_INSTALL:append:mori = " phosphor-led-sysfs"
diff --git a/meta-fii/meta-mori/recipes-phosphor/leds/mori-led-manager-config-native.bb b/meta-fii/meta-mori/recipes-phosphor/leds/mori-led-manager-config-native.bb
new file mode 100644
index 0000000..0a5282f
--- /dev/null
+++ b/meta-fii/meta-mori/recipes-phosphor/leds/mori-led-manager-config-native.bb
@@ -0,0 +1,19 @@
+SUMMARY = "Phosphor LED Group Management for mori"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+FILES:${PN} += "${datadir}/phosphor-led-manager/led.yaml"
+
+inherit native
+PROVIDES += "virtual/phosphor-led-manager-config-native"
+SRC_URI += "file://led.yaml"
+S = "${WORKDIR}"
+
+# Overwrite the example led layout yaml file prior
+# to building the phosphor-led-manager package
+do_install() {
+    SRC=${S}
+    DEST=${D}${datadir}/phosphor-led-manager
+    install -D ${SRC}/led.yaml ${DEST}/led.yaml
+}
diff --git a/meta-fii/meta-mori/recipes-phosphor/leds/mori-led-manager-config/led.yaml b/meta-fii/meta-mori/recipes-phosphor/leds/mori-led-manager-config/led.yaml
new file mode 100644
index 0000000..9d84f94
--- /dev/null
+++ b/meta-fii/meta-mori/recipes-phosphor/leds/mori-led-manager-config/led.yaml
@@ -0,0 +1,11 @@
+bmc_booted:
+
+boot_status_inactive:
+    boot_status_led:
+        Action: 'Blink'
+        DutyOn: 50
+        Period: 1000
+
+boot_status_standby:
+    boot_status_led:
+        Action: 'On'
diff --git a/meta-fii/meta-mori/recipes-phosphor/leds/phosphor-led-manager_%.bbappend b/meta-fii/meta-mori/recipes-phosphor/leds/phosphor-led-manager_%.bbappend
new file mode 100644
index 0000000..1231cae
--- /dev/null
+++ b/meta-fii/meta-mori/recipes-phosphor/leds/phosphor-led-manager_%.bbappend
@@ -0,0 +1 @@
+CHASSIS_TARGETS=""