Initial commit
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage of this utility
|
||||
usage() {
|
||||
echo "Usage: $(basename "$0") [on|off|forceoff]";
|
||||
}
|
||||
|
||||
#Check CPU boot done pin drop in 30s
|
||||
timeout=30
|
||||
wait_graceful_off(){
|
||||
echo "Wait for host shutdown in ${timeout}s"
|
||||
while [ "${timeout}" -gt 0 ]; do
|
||||
host_state=$(gpioget --numeric host0-ready)
|
||||
timeout=$((timeout-1))
|
||||
if [ "${host_state}" -eq 0 ]; then
|
||||
echo "Host is graceful off"
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
echo "Host still on, but reach timeout"
|
||||
}
|
||||
|
||||
set_gpio_power_off() {
|
||||
echo "Set GPIO to power off chassis"
|
||||
gpioset --hold-period 50ms -t0 power-chassis-control0=1
|
||||
gpioset --hold-period 50ms -t0 power-chassis-control1=1
|
||||
}
|
||||
|
||||
set_gpio_power_on() {
|
||||
echo "Set GPIO to power on chassis"
|
||||
val=$(gpioget --numeric host0-ready)
|
||||
if [ "$val" == 1 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
gpioset --hold-period 50ms -t0 power-chassis-control0=0
|
||||
gpioset --hold-period 50ms -t0 power-chassis-control1=0
|
||||
|
||||
#Record IPMI power cycle SEL
|
||||
busctl call xyz.openbmc_project.Logging.IPMI \
|
||||
/xyz/openbmc_project/Logging/IPMI \
|
||||
xyz.openbmc_project.Logging.IPMI IpmiSelAdd ssaybq \
|
||||
"Power Cycle" "/xyz/openbmc_project/state/host0" \
|
||||
3 0x01 0xff 0xff true 0x0020
|
||||
}
|
||||
|
||||
if [ "$1" == "on" ]; then
|
||||
set_gpio_power_on
|
||||
elif [ "$1" == "off" ]; then
|
||||
wait_graceful_off
|
||||
set_gpio_power_off
|
||||
elif [ "$1" == "forceoff" ]; then
|
||||
set_gpio_power_off
|
||||
else
|
||||
echo "Invalid parameter"
|
||||
usage
|
||||
fi
|
||||
exit 0
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage of this utility
|
||||
usage() {
|
||||
echo "Usage: $(basename "$0") [reset|gracefuloff]"
|
||||
}
|
||||
|
||||
graceful_off() {
|
||||
echo "Set GPIO to graceful shutdown Host"
|
||||
gpioset --hold-period 50ms -t0 power-button=1
|
||||
sleep 0.1
|
||||
gpioset --hold-period 50ms -t0 power-button=0
|
||||
gpioget power-button >/dev/null 2>&1
|
||||
}
|
||||
|
||||
force_reset() {
|
||||
echo "Set GPIO to reset Host"
|
||||
gpioset --hold-period 50ms -t0 reset-button=0
|
||||
sleep 0.1
|
||||
gpioset --hold-period 50ms -t0 reset-button=1
|
||||
gpioget reset-button >/dev/null 2>&1
|
||||
}
|
||||
|
||||
if [ "$1" == "reset" ]; then
|
||||
force_reset
|
||||
elif [ "$1" == "gracefuloff" ]; then
|
||||
graceful_off
|
||||
else
|
||||
echo "Invalid parameter"
|
||||
usage
|
||||
fi
|
||||
exit 0
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description=NCPLite Chassis Power Off
|
||||
Before=phosphor-wait-power-off@%i.service
|
||||
Conflicts=ncplite-chassis-poweron@%i.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=@SBINDIR@/chassis-control off
|
||||
ExecStartPost=/bin/sh -c "busctl call xyz.openbmc_project.Logging.IPMI \
|
||||
/xyz/openbmc_project/Logging/IPMI \
|
||||
xyz.openbmc_project.Logging.IPMI IpmiSelAdd ssaybq \
|
||||
'Power Off' '/xyz/openbmc_project/state/host0' \
|
||||
3 0x00 0xff 0xff true 0x0020"
|
||||
ExecStartPost=/bin/sleep 10
|
||||
SyslogIdentifier=chassis-control
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=NCPLite Chassis Power on
|
||||
Before=phosphor-wait-power-on@%i.service
|
||||
After=obmc-power-start-pre@%i.target
|
||||
Conflicts=ncplite-chassis-poweroff@%i.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=@SBINDIR@/chassis-control on
|
||||
SyslogIdentifier=chassis-control
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
[Unit]
|
||||
Description=NCPLite Force Reset Host%i
|
||||
Wants=phosphor-reboot-host@%i.service
|
||||
Conflicts=obmc-chassis-poweroff@%i.target
|
||||
OnFailure=obmc-chassis-powerreset@%i.target
|
||||
|
||||
[Service]
|
||||
RemainAfterExit=no
|
||||
Type=oneshot
|
||||
ExecStart=@SBINDIR@/host-control reset
|
||||
ExecStartPost=/bin/sh -c "busctl call xyz.openbmc_project.Logging.IPMI /xyz/openbmc_project/Logging/IPMI xyz.openbmc_project.Logging.IPMI IpmiSelAdd ssaybq 'Reset Button Pressed' '/xyz/openbmc_project/state/chassis0' 3 0x02 0xff 0xff true 0x0020"
|
||||
SyslogIdentifier=host-control
|
||||
|
||||
[Install]
|
||||
WantedBy=obmc-host-force-warm-reboot@%i.target
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
[Unit]
|
||||
Description=NCPLite Host%i Off
|
||||
Before=obmc-chassis-hard-poweroff@%i.target
|
||||
Before=obmc-chassis-poweroff@%i.target
|
||||
Conflicts=obmc-host-startmin@%i.target
|
||||
OnFailure=obmc-chassis-poweroff@%i.target
|
||||
OnFailureJobMode=flush
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=@SBINDIR@/host-control gracefuloff
|
||||
ExecStartPost=/bin/sh -c "busctl call xyz.openbmc_project.Logging.IPMI \
|
||||
/xyz/openbmc_project/Logging/IPMI \
|
||||
xyz.openbmc_project.Logging.IPMI IpmiSelAdd ssaybq \
|
||||
'Power Button Pressed' '/xyz/openbmc_project/state/chassis0' \
|
||||
3 0x00 0xff 0xff true 0x0020"
|
||||
@@ -0,0 +1,81 @@
|
||||
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
|
||||
|
||||
DEPENDS += "gpioplus"
|
||||
DEPENDS += "systemd"
|
||||
|
||||
EXTRA_OEMESON:append = " -Dhost-gpios=enabled"
|
||||
|
||||
SRC_URI += " \
|
||||
file://host-control \
|
||||
file://chassis-control \
|
||||
file://ncplite-chassis-poweroff@.service \
|
||||
file://ncplite-chassis-poweron@.service \
|
||||
file://ncplite-host-off@.service \
|
||||
file://ncplite-host-force-reset@.service \
|
||||
"
|
||||
|
||||
RDEPENDS:${PN}:append = " bash"
|
||||
|
||||
DBUS_PACKAGES:append = "${PN}-ncplite"
|
||||
PACKAGE_BEFORE_PN += "${PN}-ncplite"
|
||||
SYSTEMD_PACKAGES += "${PN}-ncplite"
|
||||
|
||||
SYSTEMD_SERVICE:${PN}-ncplite += "ncplite-chassis-poweron@.service"
|
||||
SYSTEMD_SERVICE:${PN}-ncplite += "ncplite-chassis-poweroff@.service"
|
||||
SYSTEMD_SERVICE:${PN}-ncplite += "ncplite-host-off@.service"
|
||||
SYSTEMD_SERVICE:${PN}-ncplite += "ncplite-host-force-reset@.service"
|
||||
|
||||
# Chassis power on
|
||||
CHASSIS_POWERON_SVC = "ncplite-chassis-poweron@.service"
|
||||
CHASSIS_POWERON_INSTMPL = "ncplite-chassis-poweron@{0}.service"
|
||||
CHASSIS_POWERON_TGTFMT = "obmc-chassis-poweron@{0}.target"
|
||||
CHASSIS_POWERON_FMT = "../${CHASSIS_POWERON_SVC}:${CHASSIS_POWERON_TGTFMT}.requires/${CHASSIS_POWERON_INSTMPL}"
|
||||
SYSTEMD_LINK:${PN}-ncplite += "${@compose_list_zip(d, 'CHASSIS_POWERON_FMT', 'OBMC_CHASSIS_INSTANCES')}"
|
||||
|
||||
# Chassis power off
|
||||
CHASSIS_POWEROFF_SVC = "ncplite-chassis-poweroff@.service"
|
||||
CHASSIS_POWEROFF_INSTMPL = "ncplite-chassis-poweroff@{0}.service"
|
||||
CHASSIS_POWEROFF_TGTFMT = "obmc-chassis-poweroff@{0}.target"
|
||||
CHASSIS_POWEROFF_FMT = "../${CHASSIS_POWEROFF_SVC}:${CHASSIS_POWEROFF_TGTFMT}.requires/${CHASSIS_POWEROFF_INSTMPL}"
|
||||
SYSTEMD_LINK:${PN}-ncplite += "${@compose_list_zip(d, 'CHASSIS_POWEROFF_FMT', 'OBMC_CHASSIS_INSTANCES')}"
|
||||
|
||||
# Host off
|
||||
HOST_OFF_SVC = "ncplite-host-off@.service"
|
||||
HOST_OFF_INSTMPL = "ncplite-host-off@{0}.service"
|
||||
HOST_OFF_TGTFMT = "obmc-host-shutdown@{0}.target"
|
||||
HOST_OFF_FMT = "../${HOST_OFF_SVC}:${HOST_OFF_TGTFMT}.requires/${HOST_OFF_INSTMPL}"
|
||||
SYSTEMD_LINK:${PN}-ncplite += "${@compose_list_zip(d, 'HOST_OFF_FMT', 'OBMC_HOST_INSTANCES')}"
|
||||
|
||||
# Host force reboot
|
||||
HOST_FORCE_RESET_SVC = "ncplite-host-force-reset@.service"
|
||||
HOST_FORCE_RESET_INSTMPL = "ncplite-host-force-reset@{0}.service"
|
||||
HOST_FORCE_RESET_TGTFMT = "obmc-host-force-warm-reboot@{0}.target"
|
||||
HOST_FORCE_RESET_TARGET_FMT = "../${HOST_FORCE_RESET_SVC}:${HOST_FORCE_RESET_TGTFMT}.requires/${HOST_FORCE_RESET_INSTMPL}"
|
||||
SYSTEMD_LINK:${PN}-ncplite += "${@compose_list_zip(d, 'HOST_FORCE_RESET_TARGET_FMT', 'OBMC_HOST_INSTANCES')}"
|
||||
|
||||
# Chassis hard power off require host off in our machine
|
||||
CHASSIS_HARD_POWEROFF_TGTFMT = "obmc-chassis-hard-poweroff@{0}.target"
|
||||
CHASSIS_HOST_OFF_FMT = "../${HOST_OFF_SVC}:${CHASSIS_HARD_POWEROFF_TGTFMT}.requires/${HOST_OFF_INSTMPL}"
|
||||
SYSTEMD_LINK:${PN}-ncplite += "${@compose_list_zip(d, 'CHASSIS_HOST_OFF_FMT', 'OBMC_CHASSIS_INSTANCES')}"
|
||||
|
||||
do_install:append() {
|
||||
install -d ${D}${sbindir}
|
||||
install -m 0744 ${WORKDIR}/host-control ${D}${sbindir}/
|
||||
install -m 0744 ${WORKDIR}/chassis-control ${D}${sbindir}/
|
||||
}
|
||||
|
||||
FILES:${PN} += "${systemd_system_unitdir}/*"
|
||||
FILES:${PN}-host += "${bindir}/phosphor-host-condition-gpio"
|
||||
SYSTEMD_SERVICE:${PN}-host += "phosphor-host-condition-gpio@.service"
|
||||
|
||||
pkg_postinst:${PN}-obmc-targets:prepend() {
|
||||
mkdir -p $D$systemd_system_unitdir/multi-user.target.requires
|
||||
LINK="$D$systemd_system_unitdir/multi-user.target.requires/phosphor-host-condition-gpio@0.service"
|
||||
TARGET="../phosphor-host-condition-gpio@.service"
|
||||
ln -s $TARGET $LINK
|
||||
}
|
||||
|
||||
pkg_prerm:${PN}-obmc-targets:prepend() {
|
||||
LINK="$D$systemd_system_unitdir/multi-user.target.requires/phosphor-host-condition-gpio@0.service"
|
||||
rm $LINK
|
||||
}
|
||||
Reference in New Issue
Block a user