Initial commit

This commit is contained in:
Your Name
2026-04-23 17:07:55 +08:00
commit b7e39e063b
16725 changed files with 1625565 additions and 0 deletions
@@ -0,0 +1,73 @@
SUMMARY = "Ampere Computing LLC Host Control Implementation"
DESCRIPTION = "A host control implementation suitable for Ampere Computing LLC's systems"
PR = "r1"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
inherit systemd
inherit obmc-phosphor-systemd
S = "${WORKDIR}"
SRC_URI = "file://ampere-host-shutdown.service \
file://ampere_power_util.sh \
file://ampere-chassis-poweroff.service \
file://ampere-chassis-poweron.service \
file://ampere-chassis-powercycle.service \
file://ampere-host-shutdown-ack.service \
file://ampere-host-power-cycle.service \
file://ampere-host-reset.service \
"
DEPENDS = "systemd"
RDEPENDS:${PN} = "bash"
SYSTEMD_PACKAGES = "${PN}"
SYSTEMD_SERVICE:${PN} = " \
ampere-host-shutdown.service \
ampere-chassis-poweroff.service \
ampere-chassis-poweron.service \
ampere-chassis-powercycle.service \
ampere-host-shutdown-ack.service \
ampere-host-power-cycle.service \
ampere-host-reset.service \
"
# host power control
# overwrite the host shutdown to graceful shutdown
HOST_SHUTDOWN_TMPL = "ampere-host-shutdown.service"
HOST_SHUTDOWN_TGTFMT = "obmc-host-shutdown@{0}.target"
HOST_SHUTDOWN_FMT = "../${HOST_SHUTDOWN_TMPL}:${HOST_SHUTDOWN_TGTFMT}.requires/${HOST_SHUTDOWN_TMPL}"
SYSTEMD_LINK:${PN} += "${@compose_list_zip(d, 'HOST_SHUTDOWN_FMT', 'OBMC_HOST_INSTANCES')}"
# Force the power cycle target to run the ampere power cycle
HOST_REBOOT_SVC = "ampere-host-power-cycle.service"
HOST_REBOOT_SVC_TGTFMT = "obmc-host-reboot@{0}.target"
HOST_REBOOT_SVC_FMT = "../${HOST_REBOOT_SVC}:${HOST_REBOOT_SVC_TGTFMT}.requires/${HOST_REBOOT_SVC}"
SYSTEMD_LINK:${PN} += "${@compose_list_zip(d, 'HOST_REBOOT_SVC_FMT', 'OBMC_HOST_INSTANCES')}"
# chassis power control
CHASSIS_POWERON_SVC = "ampere-chassis-poweron.service"
CHASSIS_POWERON_TGTFMT = "obmc-chassis-poweron@{0}.target"
CHASSIS_POWERON_FMT = "../${CHASSIS_POWERON_SVC}:${CHASSIS_POWERON_TGTFMT}.requires/${CHASSIS_POWERON_SVC}"
SYSTEMD_LINK:${PN} += "${@compose_list_zip(d, 'CHASSIS_POWERON_FMT', 'OBMC_CHASSIS_INSTANCES')}"
CHASSIS_POWEROFF_SVC = "ampere-chassis-poweroff.service"
CHASSIS_POWEROFF_TGTFMT = "obmc-chassis-poweroff@{0}.target"
CHASSIS_POWEROFF_FMT = "../${CHASSIS_POWEROFF_SVC}:${CHASSIS_POWEROFF_TGTFMT}.requires/${CHASSIS_POWEROFF_SVC}"
SYSTEMD_LINK:${PN} += "${@compose_list_zip(d, 'CHASSIS_POWEROFF_FMT', 'OBMC_CHASSIS_INSTANCES')}"
CHASSIS_POWERCYCLE_SVC = "ampere-chassis-powercycle.service"
CHASSIS_POWERCYCLE_TGTFMT = "obmc-chassis-powercycle@{0}.target"
CHASSIS_POWERCYCLE_FMT = "../${CHASSIS_POWERCYCLE_SVC}:${CHASSIS_POWERCYCLE_TGTFMT}.requires/${CHASSIS_POWERCYCLE_SVC}"
SYSTEMD_LINK:${PN} += "${@compose_list_zip(d, 'CHASSIS_POWERCYCLE_FMT', 'OBMC_CHASSIS_INSTANCES')}"
TMPL = "phosphor-gpio-monitor@.service"
INSTFMT = "phosphor-gpio-monitor@{0}.service"
TGT = "multi-user.target"
FMT = "../${TMPL}:${TGT}.requires/${INSTFMT}"
SYSTEMD_LINK:${PN} += "${@compose_list(d, 'FMT', 'OBMC_HOST_MONITOR_INSTANCES')}"
do_install() {
install -d ${D}${libexecdir}/${PN}
install -m 0755 ${WORKDIR}/ampere_power_util.sh ${D}${libexecdir}/${PN}/ampere_power_util.sh
}
@@ -0,0 +1,8 @@
[Unit]
Description=Ampere Computing LLC Power OFF Chassis
[Service]
RemainAfterExit=no
Type=oneshot
ExecStart=/usr/libexec/ampere-hostctrl/ampere_power_util.sh mb hotswap
SyslogIdentifier=ampere_power_util.sh
@@ -0,0 +1,11 @@
[Unit]
Description=Ampere Computing LLC Power OFF Chassis
Requires=phosphor-wait-power-off@%i.service
Before=phosphor-wait-power-off@%i.service
Conflicts=obmc-chassis-poweron@0.target
[Service]
RemainAfterExit=no
Type=oneshot
ExecStart=/usr/libexec/ampere-hostctrl/ampere_power_util.sh mb off
SyslogIdentifier=ampere_power_util.sh
@@ -0,0 +1,9 @@
[Unit]
Description=Ampere Computing LLC Power ON Chassis
Conflicts=obmc-chassis-poweroff@0.target
[Service]
RemainAfterExit=yes
Type=oneshot
ExecStart=/usr/libexec/ampere-hostctrl/ampere_power_util.sh mb on
SyslogIdentifier=ampere_power_util.sh
@@ -0,0 +1,12 @@
[Unit]
Description=Ampere Computing LLC power cycle service
Conflicts=obmc-host-start@0.target
OnFailure=obmc-chassis-powerreset@0.target
Wants=kudo-bios-verify.service
After=kudo-bios-verify.service
[Service]
RemainAfterExit=no
Type=oneshot
ExecStart=/usr/libexec/ampere-hostctrl/ampere_power_util.sh mb host_cycle
SyslogIdentifier=ampere_power_util.sh
@@ -0,0 +1,12 @@
[Unit]
Description=Ampere Computing LLC power cycle service
Conflicts=obmc-host-start@0.target
OnFailure=obmc-chassis-powerreset@0.target
Wants=kudo-bios-verify.service
After=kudo-bios-verify.service
[Service]
RemainAfterExit=no
Type=oneshot
ExecStart=/usr/libexec/ampere-hostctrl/ampere_power_util.sh mb host_reset
SyslogIdentifier=ampere_power_util.sh
@@ -0,0 +1,11 @@
[Unit]
Description=Ampere Computing LLC host shutdown ACK
Requires=phosphor-wait-power-off@%i.service
Before=phosphor-wait-power-off@%i.service
Conflicts=obmc-chassis-poweron@0.target
[Service]
RemainAfterExit=no
Type=oneshot
ExecStart=/usr/libexec/ampere-hostctrl/ampere_power_util.sh mb shutdown_ack
SyslogIdentifier=ampere_power_util.sh
@@ -0,0 +1,10 @@
[Unit]
Description=Ampere Computing LLC graceful shutdown host
Conflicts=obmc-host-start@0.target
OnFailure=obmc-chassis-poweroff@0.target
[Service]
RemainAfterExit=no
Type=oneshot
ExecStart=/usr/libexec/ampere-hostctrl/ampere_power_util.sh mb graceful_shutdown
SyslogIdentifier=ampere_power_util.sh
@@ -0,0 +1,140 @@
#!/bin/bash
# Provide source directive to shellcheck.
# shellcheck source=meta-fii/meta-kudo/recipes-kudo/kudo-fw-utility/kudo-fw/kudo-lib.sh
source /usr/libexec/kudo-fw/kudo-lib.sh
# Usage of this utility
function usage() {
echo "usage: power-util mb [on|off|graceful_shutdown|host_reset|host_cycle|shutdown_ack|hotswap]";
}
hotswap() {
kudo.sh rst hotswap
}
force_off() {
echo "Powering down Server"
set_gpio_ctrl POWER_OUT 1
sleep 6
set_gpio_ctrl POWER_OUT 0
}
power_off() {
busctl set-property xyz.openbmc_project.Watchdog /xyz/openbmc_project/watchdog/host0 xyz.openbmc_project.State.Watchdog ExpireAction s xyz.openbmc_project.State.Watchdog.Action.None
busctl set-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis RequestedPowerTransition s xyz.openbmc_project.State.Chassis.Transition.Off
}
power_on() {
echo "Powering on Server"
set_gpio_ctrl POWER_OUT 1
sleep 1
set_gpio_ctrl POWER_OUT 0
busctl set-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis RequestedPowerTransition s xyz.openbmc_project.State.Chassis.Transition.On
}
power_status() {
st=$(busctl get-property xyz.openbmc_project.State.Chassis /xyz/openbmc_project/state/chassis0 xyz.openbmc_project.State.Chassis CurrentPowerState | cut -d "." -f6)
if [ "${st}" == "On\"" ]; then
echo "on"
else
echo "off"
fi
}
host_status() {
BOOT_OK=$(get_gpio_ctrl S0_FW_BOOT_OK)
S5_N=$(get_gpio_ctrl S0_SLPS5_N)
if [ "$S5_N" == 1 ] || [ "$BOOT_OK" == 1 ]; then
echo "on"
else
echo "off"
fi
}
timestamp() {
date +"%s" # current time
}
graceful_shutdown() {
if [ -f "/run/openbmc/host@0-request" ]; then
echo "Shutdown host immediately"
power_off
else
echo "Triggering graceful shutdown"
mkdir /run/openbmc
timestamp > "/run/openbmc/host@0-shutdown-req-time"
set_gpio_ctrl S0_SHD_REQ 0
sleep 3
set_gpio_ctrl S0_SHD_REQ 1
fi
}
host_reset() {
echo "Triggering sysreset pin"
busctl set-property xyz.openbmc_project.Watchdog /xyz/openbmc_project/watchdog/host0 xyz.openbmc_project.State.Watchdog ExpireAction s xyz.openbmc_project.State.Watchdog.Action.None
set_gpio_ctrl S0_SYSRESET 0
sleep 1
set_gpio_ctrl S0_SYSRESET 1
}
host_cycle() {
echo "DC cycling host"
force_off
sleep 2
power_on
}
shutdown_ack() {
echo "Receive shutdown ACK triggered"
power_off
if [ -f "/run/openbmc/host@0-shutdown-req-time" ]; then
rm -rf "/run/openbmc/host@0-shutdown-req-time"
fi
}
if [ $# -lt 2 ]; then
echo "Total number of parameter=$#"
echo "Insufficient parameter"
usage;
exit 0;
fi
if [ "$1" != "mb" ]; then
echo "Invalid parameter1=$1"
usage;
exit 0;
fi
if [ "$2" = "on" ]; then
sleep 3
if [ "$(power_status)" == "off" ]; then
power_on
fi
elif [ "$2" = "off" ]; then
if [ "$(power_status)" == "on" ]; then
power_off
sleep 6
if [ "$(host_status)" == "on" ]; then
force_off
fi
fi
elif [ "$2" == "hotswap" ]; then
hotswap
elif [ "$2" == "graceful_shutdown" ]; then
graceful_shutdown
elif [ "$2" == "host_reset" ]; then
host_reset
elif [ "$2" == "host_cycle" ]; then
host_cycle
elif [ "$2" == "shutdown_ack" ]; then
shutdown_ack
else
echo "Invalid parameter2=$2"
usage;
fi
exit 0;