meta-ampere: Support Fault LED
Monitor the Socket 0 and Socket 1's CPU_FAULT GPIO and turn on the Fault
LED when any GPIO turns ON.
Tested:
1. Flash special SCP image to stimulate CPU Fault LED
2. Check if the Fault LED is ON.
Signed-off-by: Tung Nguyen <tung.nguyen@amperecomputing.com>
Signed-off-by: Chanh Nguyen <chanh@os.amperecomputing.com>
Change-Id: I73bf34b4361528c9c8825942ddc7f24d51589189
diff --git a/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor.bb b/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor.bb
new file mode 100644
index 0000000..e068b4d
--- /dev/null
+++ b/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor.bb
@@ -0,0 +1,33 @@
+SUMMARY = "MTJade fault-led application"
+PR = "r1"
+LICENSE = "Apache-2.0"
+LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
+
+inherit obmc-phosphor-systemd
+
+DEPENDS += "virtual/obmc-gpio-monitor"
+RDEPENDS_${PN} += "virtual/obmc-gpio-monitor"
+
+S = "${WORKDIR}"
+SRC_URI += "file://toggle_fault_led.sh"
+
+do_install() {
+ install -d ${D}${bindir}
+ install -m 0755 ${WORKDIR}/toggle_fault_led.sh \
+ ${D}${bindir}/toggle_fault_led.sh
+}
+
+OBMC_FAULT_MONITOR_INSTANCES = "s0_fault_alert s1_fault_alert"
+
+SYSTEMD_ENVIRONMENT_FILE_${PN} += "obmc/gpio/s0_fault_alert \
+ obmc/gpio/s1_fault_alert \
+ "
+
+TMPL = "phosphor-gpio-monitor@.service"
+INSTFMT = "phosphor-gpio-monitor@{0}.service"
+TGT = "multi-user.target"
+FMT = "../${TMPL}:${TGT}.requires/${INSTFMT}"
+
+SYSTEMD_SERVICE_${PN} += "ampere_fault_led.service"
+SYSTEMD_LINK_${PN} += "${@compose_list(d, 'FMT', 'OBMC_FAULT_MONITOR_INSTANCES')}"
+
diff --git a/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/ampere_fault_led.service b/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/ampere_fault_led.service
new file mode 100644
index 0000000..05c63d0
--- /dev/null
+++ b/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/ampere_fault_led.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=Ampere Computing LLC fault event condition service
+Wants=mapper-wait@-xyz-openbmc_project-led-groups.service
+After=mapper-wait@-xyz-openbmc_project-led-groups.service
+StartLimitIntervalSec=0
+
+[Service]
+Type=oneshot
+ExecStart=/usr/bin/env toggle_fault_led.sh
+SyslogIdentifier=fault-led
diff --git a/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/obmc/gpio/s0_fault_alert b/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/obmc/gpio/s0_fault_alert
new file mode 100644
index 0000000..dd048ef
--- /dev/null
+++ b/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/obmc/gpio/s0_fault_alert
@@ -0,0 +1,5 @@
+DEVPATH=/dev/input/by-path/platform-gpio-keys-event
+KEY=73
+POLARITY=1
+TARGET=ampere_fault_led.service
+EXTRA_ARGS=--continue
diff --git a/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/obmc/gpio/s1_fault_alert b/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/obmc/gpio/s1_fault_alert
new file mode 100644
index 0000000..1963ce0
--- /dev/null
+++ b/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/obmc/gpio/s1_fault_alert
@@ -0,0 +1,5 @@
+DEVPATH=/dev/input/by-path/platform-gpio-keys-event
+KEY=201
+POLARITY=1
+TARGET=ampere_fault_led.service
+EXTRA_ARGS=--continue
diff --git a/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/toggle_fault_led.sh b/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/toggle_fault_led.sh
new file mode 100644
index 0000000..8d3d543
--- /dev/null
+++ b/meta-ampere/meta-jade/recipes-phosphor/gpio/fault-monitor/toggle_fault_led.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+#
+# Copyright (c) 2021 Ampere Computing LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Toggle the state of identify LED Group
+
+SERVICE="xyz.openbmc_project.LED.GroupManager"
+INTERFACE="xyz.openbmc_project.Led.Group"
+PROPERTY="Asserted"
+
+# Get current state
+object=$(busctl tree $SERVICE --list | grep system_fault)
+state=$(busctl get-property $SERVICE $object $INTERFACE $PROPERTY \
+ | awk '{print $NF;}')
+
+if [ "$state" == "false" ]; then
+ target='true'
+else
+ target='false'
+fi
+
+# Set target state
+busctl set-property $SERVICE $object $INTERFACE $PROPERTY b $target
diff --git a/meta-ampere/meta-jade/recipes-phosphor/leds/mtjade-led-manager-config/led.yaml b/meta-ampere/meta-jade/recipes-phosphor/leds/mtjade-led-manager-config/led.yaml
index 07e35ca..ba21c58 100644
--- a/meta-ampere/meta-jade/recipes-phosphor/leds/mtjade-led-manager-config/led.yaml
+++ b/meta-ampere/meta-jade/recipes-phosphor/leds/mtjade-led-manager-config/led.yaml
@@ -11,3 +11,10 @@
DutyOn: 50
Period: 0
Priority: 'On'
+
+systemFault:
+ fault:
+ Action: 'On'
+ DutyOn: 50
+ Period: 0
+ Priority: 'Blink'
diff --git a/meta-ampere/meta-jade/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bbappend b/meta-ampere/meta-jade/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bbappend
index 07bff93..c9538de 100644
--- a/meta-ampere/meta-jade/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bbappend
+++ b/meta-ampere/meta-jade/recipes-phosphor/packagegroups/packagegroup-obmc-apps.bbappend
@@ -1 +1,2 @@
RDEPENDS_${PN}-extras_append_mtjade = " phosphor-webui phosphor-image-signing"
+RDEPENDS_${PN}-inventory_append_mtjade = " fault-monitor"