diff options
author | Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com> | 2023-02-22 08:17:37 +0300 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2023-03-03 18:46:13 +0300 |
commit | bed86692c269433864d801d77d14180fceb4a16a (patch) | |
tree | 7485c768241451b966ff1abc9a9e9d2b3bd1e4bf /meta-facebook/meta-greatlakes/recipes-greatlakes | |
parent | 0823bd2e6b84b30cd1ee537205df1edbe833cb46 (diff) | |
download | openbmc-bed86692c269433864d801d77d14180fceb4a16a.tar.xz |
meta-facebook: greatlakes: System state initialization
Description:
- System state initialization.
Design:
- Use script to determine 12V and host current state
12V: use BMC gpio
host: Use BIC gpio
- Set correct state on CurrentHostState property for host status
- Set correcr state on CurrentPowerState property for 12V status
Test Case:
1. 12V on and host off
2. 12V on and host on
3. 12V off and host off
Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
Change-Id: Ibff1f6e79290cfb39dc5442c240e324b38c18ecd
Diffstat (limited to 'meta-facebook/meta-greatlakes/recipes-greatlakes')
3 files changed, 100 insertions, 0 deletions
diff --git a/meta-facebook/meta-greatlakes/recipes-greatlakes/greatlakes-sysinit/files/greatlakes-system-state-init b/meta-facebook/meta-greatlakes/recipes-greatlakes/greatlakes-sysinit/files/greatlakes-system-state-init new file mode 100644 index 0000000000..153d3f9d0a --- /dev/null +++ b/meta-facebook/meta-greatlakes/recipes-greatlakes/greatlakes-sysinit/files/greatlakes-system-state-init @@ -0,0 +1,59 @@ +#!/bin/bash -e + +# Provide source directive to shellcheck. +# shellcheck source=meta-facebook/recipes-phosphor/state/phosphor-state-manager/greatlakes/power-cmd +source /usr/libexec/phosphor-state-manager/power-cmd + +SLOT_ID="$1" + +function get_power_status() +{ + POWER_OK_SLOT=$(( $1+9 )) + HOST_INSTANCE=$(( $1-1 << 2 )) + + chassis_status=$(gpioget 0 $POWER_OK_SLOT) + if [ "$chassis_status" == "$STATE_OFF" ]; then + echo "AC Off" + return 0 + fi + + response="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$HOST_INSTANCE" 0x38 "$LUN" 0x03 "$IANA_LEN" "$IANA")" + # Responses are BIC gpio states, the GPIO B7 represents host DC status + result=$(echo "$response" | cut -d" " -f "$PWRGD_SYS_PWROK_INDEX") + res="$(( "$result" & 0x80 ))" + host_status="$(( "$res" >> 7 ))" + if [ "$host_status" == "$STATE_OFF" ]; then + echo "Host Off" + return 0 + fi +} + +set_host_state() +{ + PROPERTY_VAL="xyz.openbmc_project.State.Host.HostState.$2" + busctl set-property "$HOST_BUS_NAME$1" "$HOST_OBJ_PATH$1" "$HOST_INTF_NAME" "$HOST_PROPERTY_NAME" s "$PROPERTY_VAL" +} + +set_chassis_state() +{ + PROPERTY_VAL="xyz.openbmc_project.State.Chassis.PowerState.$2" + busctl set-property "$CHASSIS_BUS_NAME$1" "$CHASSIS_OBJ_PATH$1" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$PROPERTY_VAL" +} + + +POWER_STATUS=$(get_power_status "$SLOT_ID") + +# Default power status +CHASSIS_STATE_VAL="Off" +HOST_STATE_VAL="Off" + +# Real power status +if [ "$POWER_STATUS" != "AC Off" ]; then + CHASSIS_STATE_VAL="On" + if [ "$POWER_STATUS" != "Host Off" ]; then + HOST_STATE_VAL="Running" + fi +fi + +set_chassis_state "$SLOT_ID" "$CHASSIS_STATE_VAL" +set_host_state "$SLOT_ID" "$HOST_STATE_VAL" diff --git a/meta-facebook/meta-greatlakes/recipes-greatlakes/greatlakes-sysinit/files/greatlakes-system-state-init@.service b/meta-facebook/meta-greatlakes/recipes-greatlakes/greatlakes-sysinit/files/greatlakes-system-state-init@.service new file mode 100644 index 0000000000..30e02799c7 --- /dev/null +++ b/meta-facebook/meta-greatlakes/recipes-greatlakes/greatlakes-sysinit/files/greatlakes-system-state-init@.service @@ -0,0 +1,15 @@ +[Unit] +Description=Greatlakes host state and chassis power state initialize for slot%i +Before=phosphor-multi-gpio-monitor.service +Wants=xyz.openbmc_project.State.Chassis@%i.service +After=xyz.openbmc_project.State.Chassis@%i.service +Wants=xyz.openbmc_project.State.Host@%i.service +After=xyz.openbmc_project.State.Host@%i.service + +[Service] +ExecStart=/usr/libexec/greatlakes-sysinit/greatlakes-system-state-init %i +SyslogIdentifier=greatlakes-system-state-init slot%i +Type=oneshot + +[Install] +WantedBy=sysinit.target diff --git a/meta-facebook/meta-greatlakes/recipes-greatlakes/greatlakes-sysinit/greatlakes-sysinit.bb b/meta-facebook/meta-greatlakes/recipes-greatlakes/greatlakes-sysinit/greatlakes-sysinit.bb new file mode 100644 index 0000000000..716251ed7d --- /dev/null +++ b/meta-facebook/meta-greatlakes/recipes-greatlakes/greatlakes-sysinit/greatlakes-sysinit.bb @@ -0,0 +1,26 @@ +SUMMARY = "Initialize system state" +DESCRIPTION = "Initialize system state" +LICENSE = "Apache-2.0" +LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10" + +inherit pkgconfig +inherit systemd +inherit obmc-phosphor-systemd + +RDEPENDS:${PN} += "bash" + +SRC_URI += " \ + file://greatlakes-system-state-init \ + file://greatlakes-system-state-init@.service \ + " + +do_install() { + install -d ${D}${libexecdir}/${PN} + install -m 0755 ${WORKDIR}/greatlakes-system-state-init ${D}${libexecdir}/${PN}/ +} + +TGT = "${SYSTEMD_DEFAULT_TARGET}" +GREATLAKES_SYS_ST_INIT_INSTFMT="../greatlakes-system-state-init@.service:${TGT}.wants/greatlakes-system-state-init@{0}.service" + +SYSTEMD_SERVICE:${PN} += "greatlakes-system-state-init@.service" +SYSTEMD_LINK:${PN} += "${@compose_list(d, 'GREATLAKES_SYS_ST_INIT_INSTFMT', 'OBMC_HOST_INSTANCES')}" |