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,56 @@
#!/bin/bash
# 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=$(( $1-1 ))
OFFSET=$(( 0x9 + SLOT ))
chassis-power-cycle()
{
CHASSIS_ID=$1
if [ "$CHASSIS_ID" -le 4 ]
then
chassis_status=$(chassis-power-status $SLOT)
if [ "$chassis_status" == "$STATE_ON" ]
then
i2cset -y "$CPLD_BUS_NUM" "$CPLD_PWR_CTRL_ADDR" "$OFFSET" "$POW_OFF_SLOT"
sleep 10
chassis_status=$(chassis-power-status $SLOT)
if [ "$chassis_status" -ne "$STATE_OFF" ]
then
echo "chassis$CHASSIS_ID power off fail"
exit 1
fi
fi
i2cset -y "$CPLD_BUS_NUM" "$CPLD_PWR_CTRL_ADDR" "$OFFSET" "$POW_ON_SLOT"
sleep 2
# Check chassis stattus after doing 12V cycle
chassis_status=$(chassis-power-status $SLOT)
if [ "$chassis_status" == "$STATE_ON" ]
then
busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_ON"
exit 0;
else
busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_OFF"
exit 0;
fi
fi
echo "Invalid slot id"
exit 1;
}
if [ "$1" == 0 ]
then
echo "Enter SLED-cycle"
result=$(i2cset -y "$CPLD_BUS_NUM" "$CPLD_PWR_CTRL_ADDR" 0x2b 0x1)
echo "$result"
else
echo "Enter slot$1 cycle"
chassis-power-cycle "$1"
fi
@@ -0,0 +1,10 @@
[Unit]
Description=Chassis Power Cycle: %i
[Service]
Type=oneshot
ExecStart=/usr/libexec/phosphor-state-manager/chassis-powercycle %i
ExecStartPost=/bin/systemctl restart phosphor-discover-system-state@%i.service
[Install]
WantedBy=obmc-chassis-powercycle@%i.target
@@ -0,0 +1,43 @@
#!/bin/bash
# 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
CHASSIS_ID=$1
SLOT=$(( $1-1 ))
OFFSET=$(( 0x9 + SLOT ))
# Server 12v power off
chassis-power-off()
{
result=$(i2cset -y "$CPLD_BUS_NUM" "$CPLD_PWR_CTRL_ADDR" "$OFFSET" "$POW_OFF_SLOT")
echo "$result"
sleep 1
# Check chassis status after doing 12V off
chassis_status=$(chassis-power-status $SLOT)
if [ "$chassis_status" == "$STATE_OFF" ]
then
busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_OFF"
echo "Chassis is power off"
else
busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_ON"
echo "Chassis is power on"
exit 0;
fi
}
chassis_status=$(chassis-power-status $SLOT)
if [ "$chassis_status" == "$STATE_UNKNOWN" ]
then
echo "Invalid slot id"
exit 1;
elif [ "$chassis_status" == "$STATE_ON" ]
then
chassis-power-off
exit 0;
else
echo "Chassis is already off"
exit 0;
fi
@@ -0,0 +1,9 @@
[Unit]
Description=power off chassis:%i
[Service]
Type=oneshot
ExecStart=/usr/libexec/phosphor-state-manager/chassis-poweroff %i
[Install]
WantedBy=obmc-chassis-hard-poweroff@%i.target
@@ -0,0 +1,43 @@
#!/bin/bash
# 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
CHASSIS_ID=$1
SLOT=$(( $1-1 ))
OFFSET=$(( 0x9 + SLOT ))
# Server 12v power on
chassis-power-on()
{
result=$(i2cset -y "$CPLD_BUS_NUM" "$CPLD_PWR_CTRL_ADDR" "$OFFSET" "$POW_ON_SLOT")
echo "$result"
sleep 1
# Check chassis stattus after doing 12V on
chassis_status=$(chassis-power-status $SLOT)
if [ "$chassis_status" == "$STATE_ON" ]
then
busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_ON"
echo "Chassis is power on"
else
busctl set-property "$CHASSIS_BUS_NAME""$CHASSIS_ID" "$CHASSIS_OBJ_PATH""$CHASSIS_ID" "$CHASSIS_INTF_NAME" "$CHASSIS_PROPERTY_NAME" s "$CHASSIS_OFF"
echo "Chassis is power off"
exit 0;
fi
}
chassis_status=$(chassis-power-status $SLOT)
if [ "$chassis_status" == "$STATE_UNKNOWN" ]
then
echo "Invalid slot id"
exit 1;
elif [ "$chassis_status" == "$STATE_OFF" ]
then
chassis-power-on
exit 0;
else
echo "Chassis is already on"
exit 0;
fi
@@ -0,0 +1,10 @@
[Unit]
Description=power on chassis:%i
[Service]
Type=oneshot
ExecStart=/usr/libexec/phosphor-state-manager/chassis-poweron %i
ExecStartPost=/bin/systemctl restart phosphor-discover-system-state@%i.service
[Install]
WantedBy=obmc-chassis-poweron@%i.target
@@ -0,0 +1,51 @@
#!/bin/bash
# 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
HOST_ID=$1
SLOT_ID=$(( $1-1 << 2 ))
# Host Reboot
host-reboot()
{
power_delay=$1
for pwr_cmd in "${power_seq[@]}"
do
response="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" "$NETFN" "$LUN" "$CMD" "$DATA_LEN" 0x01 0x42 0x01 0x00 "$pwr_cmd")"
echo "$response"
result=$(echo "$response" | cut -d" " -f "$IPMB_CMD_COMPLETE_CODE_INDEX")
if [ "$result" -ne 0 ]
then
echo "Failed to send ipmb command"
exit 1
fi
if [ "$pwr_cmd" == "$POWER_BTN_LOW" ]
then
sleep "$power_delay"
fi
done
}
# Check Host Response and Status
host_status=$(host-power-status $SLOT_ID)
if [ "$host_status" == "$STATE_ON" ]
then
host-reboot 6
sleep 15
host-reboot 2
host_status=$(host-power-status $SLOT_ID)
if [ "$host_status" == "$STATE_ON" ]
then
busctl set-property "$HOST_BUS_NAME""$HOST_ID" "$HOST_OBJ_PATH""$HOST_ID" "$HOST_INTF_NAME" "$HOST_PROPERTY_NAME" s "$HOST_ON"
exit 0;
else
busctl set-property "$HOST_BUS_NAME""$HOST_ID" "$HOST_OBJ_PATH""$HOST_ID" "$HOST_INTF_NAME" "$HOST_PROPERTY_NAME" s "$HOST_OFF"
exit 0;
fi
else
echo "Host is Off"
exit 1;
fi
@@ -0,0 +1,9 @@
[Unit]
Description=Host Power Cycle: %i
[Service]
Type=oneshot
ExecStart=/usr/libexec/phosphor-state-manager/host-powercycle %i
[Install]
WantedBy=obmc-host-reboot@%i.target
@@ -0,0 +1,51 @@
#!/bin/bash
# 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
HOST_ID=$1
SLOT_ID=$(( $1-1 << 2 ))
# Host Power Off
host-power-off()
{
for pwr_cmd in "${power_seq[@]}"
do
response="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" "$NETFN" "$LUN" "$CMD" "$DATA_LEN" 0x01 0x42 0x01 0x00 "$pwr_cmd")"
echo "$response"
result=$(echo "$response" | cut -d" " -f "$IPMB_CMD_COMPLETE_CODE_INDEX")
if [ "$result" -ne 0 ]
then
echo "Failed to send ipmb command"
exit 1
fi
if [ "$pwr_cmd" == "$POWER_BTN_LOW" ]
then
sleep 6
fi
done
# Check host stattus after doing host power off
host_status=$(host-power-status $SLOT_ID)
if [ "$host_status" == "$STATE_OFF" ]
then
busctl set-property "$HOST_BUS_NAME""$HOST_ID" "$HOST_OBJ_PATH""$HOST_ID" "$HOST_INTF_NAME" "$HOST_PROPERTY_NAME" s "$HOST_OFF"
echo "Host power off"
exit 0;
else
busctl set-property "$HOST_BUS_NAME""$HOST_ID" "$HOST_OBJ_PATH""$HOST_ID" "$HOST_INTF_NAME" "$HOST_PROPERTY_NAME" s "$HOST_ON"
echo "Host power on"
exit 0;
fi
}
# Check Host Response and Status
host_status=$(host-power-status $SLOT_ID)
if [ "$host_status" == "$STATE_ON" ]
then
host-power-off
else
echo "Power is already off"
exit 1;
fi
@@ -0,0 +1,9 @@
[Unit]
Description=power off host:%i
[Service]
Type=oneshot
ExecStart=/usr/libexec/phosphor-state-manager/host-poweroff %i
[Install]
WantedBy=obmc-host-shutdown@%i.target
@@ -0,0 +1,50 @@
#!/bin/bash
# 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
HOST_ID=$1
SLOT_ID=$(( $1-1 << 2 ))
# Host Power On
host-power-on()
{
for pwr_cmd in "${power_seq[@]}"
do
response="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" "$NETFN" "$LUN" "$CMD" "$DATA_LEN" 0x01 0x42 0x01 0x00 "$pwr_cmd")"
echo "$response"
result=$(echo "$response" | cut -d" " -f "$IPMB_CMD_COMPLETE_CODE_INDEX")
if [ "$result" -ne 0 ]
then
echo "Failed to send ipmb command"
exit 1
fi
if [ "$pwr_cmd" == "$POWER_BTN_LOW" ]
then
sleep 2
fi
done
# Check host status after doing host power on
host_status=$(host-power-status $SLOT_ID)
if [ "$host_status" == "$STATE_ON" ]
then
busctl set-property "$HOST_BUS_NAME""$HOST_ID" "$HOST_OBJ_PATH""$HOST_ID" "$HOST_INTF_NAME" "$HOST_PROPERTY_NAME" s "$HOST_ON"
echo "Host power on"
exit 0;
else
busctl set-property "$HOST_BUS_NAME""$HOST_ID" "$HOST_OBJ_PATH""$HOST_ID" "$HOST_INTF_NAME" "$HOST_PROPERTY_NAME" s "$HOST_OFF"
echo "Host power off"
exit 0;
fi
}
# Check Host Response and Status
host_status=$(host-power-status $SLOT_ID)
if [ "$host_status" == "$STATE_OFF" ]
then
host-power-on
else
echo "Power is already on"
exit 1;
fi
@@ -0,0 +1,9 @@
[Unit]
Description=power on host:%i
[Service]
Type=oneshot
ExecStart=/usr/libexec/phosphor-state-manager/host-poweron %i
[Install]
WantedBy=obmc-host-start@%i.target
@@ -0,0 +1,51 @@
#!/bin/bash
# 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
HOST_ID=$1
SLOT_ID=$(( $1-1 << 2 ))
# Host Reboot
host-reboot()
{
for reset_cmd in "${reset_seq[@]}"
do
response="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" "$NETFN" "$LUN" "$CMD" "$DATA_LEN" 0x01 0x42 0x01 0 "$reset_cmd")"
echo "$response"
result=$(echo "$response" | cut -d" " -f "$IPMB_CMD_COMPLETE_CODE_INDEX")
if [ "$result" -ne 0 ]
then
echo "Failed to send ipmb command"
exit 1
fi
if [ "$reset_cmd" == "$POWER_BTN_LOW" ]
then
sleep "$1"
fi
done
# Check host stattus after doing host power reset
host_status=$(host-power-status $SLOT_ID)
if [ "$host_status" == "$STATE_ON" ]
then
busctl set-property "$HOST_BUS_NAME""$HOST_ID" "$HOST_OBJ_PATH""$HOST_ID" "$HOST_INTF_NAME" "$HOST_PROPERTY_NAME" s "$HOST_ON"
echo "Host power Reset"
exit 0;
else
busctl set-property "$HOST_BUS_NAME""$HOST_ID" "$HOST_OBJ_PATH""$HOST_ID" "$HOST_INTF_NAME" "$HOST_PROPERTY_NAME" s "$HOST_OFF"
echo "Host power off"
exit 0;
fi
}
# Check Host Response and Status
host_status=$(host-power-status $SLOT_ID)
if [ "$host_status" == "$STATE_ON" ]
then
host-reboot 1
else
echo "Host is Off"
exit 1;
fi
@@ -0,0 +1,9 @@
[Unit]
Description=Host Power Reset: %i
[Service]
Type=oneshot
ExecStart=/usr/libexec/phosphor-state-manager/host-powerreset %i
[Install]
WantedBy=obmc-host-force-warm-reboot@%i.target
@@ -0,0 +1,67 @@
#!/bin/bash
export POWER_BTN_HIGH=0xFF
export POWER_BTN_LOW=0xFE
export RESET_BTN_HIGH=0xFF
export RESET_BTN_LOW=0xFD
export power_seq=( "$POWER_BTN_HIGH" "$POWER_BTN_LOW" "$POWER_BTN_HIGH" )
export reset_seq=( "$RESET_BTN_HIGH" "$RESET_BTN_LOW" "$RESET_BTN_HIGH")
export SERVICE="xyz.openbmc_project.Ipmi.Channel.Ipmb"
export OBJECT_PATH="/xyz/openbmc_project/Ipmi/Channel/Ipmb"
export INTERFACE="org.openbmc.Ipmb"
export DATA_LEN=0x05
export NETFN=0x06
export LUN=0x00
export CMD=0x52
export STATE_OFF=0
export STATE_ON=1
export STATE_UNKNOWN=-1
export CPLD_BUS_NUM=12
export CPLD_PWR_CTRL_ADDR=0xf
export POW_ON_SLOT=0x01
export POW_OFF_SLOT=0x00
export PWRGD_SYS_PWROK_INDEX=12
export IANA="0x15 0xA0 0x0"
export IANA_LEN=3
export CHASSIS_BUS_NAME="xyz.openbmc_project.State.Chassis"
export CHASSIS_OBJ_PATH="/xyz/openbmc_project/state/chassis"
export CHASSIS_INTF_NAME="xyz.openbmc_project.State.Chassis"
export CHASSIS_PROPERTY_NAME="CurrentPowerState"
export HOST_BUS_NAME="xyz.openbmc_project.State.Host"
export HOST_OBJ_PATH="/xyz/openbmc_project/state/host"
export HOST_INTF_NAME="xyz.openbmc_project.State.Host"
export HOST_PROPERTY_NAME="CurrentHostState"
export CHASSIS_ON="xyz.openbmc_project.State.Chassis.PowerState.On"
export CHASSIS_OFF="xyz.openbmc_project.State.Chassis.PowerState.Off"
export HOST_ON="xyz.openbmc_project.State.Host.HostState.Running"
export HOST_OFF="xyz.openbmc_project.State.Host.HostState.Off"
export IPMB_CMD_COMPLETE_CODE_INDEX=2
host-power-status()
{
SLOT_ID=$1
response="$(busctl call "$SERVICE" "$OBJECT_PATH" "$INTERFACE" sendRequest yyyyay "$SLOT_ID" 0x38 "$LUN" 0x03 0x03 0x15 0xa0 0x00)"
result=$(echo "$response" | cut -d" " -f "$PWRGD_SYS_PWROK_INDEX")
res="$(( "$result" & 0x80 ))"
status="$(( "$res" >> 7 ))"
echo "$status"
return 0
}
chassis-power-status()
{
slot=$1
status=-1
if [ "$slot" -le 4 ]
then
response="$(i2cget -y "$CPLD_BUS_NUM" "$CPLD_PWR_CTRL_ADDR" 0x25)"
res="$(( "$response" >> slot ))"
status="$(( "$res" & 0x01 ))"
fi
echo "$status"
return 0
}
@@ -0,0 +1,24 @@
#!/bin/bash
# Provide source directive to shellcheck.
gpioInitHighTable=(
"power-nic-bmc-enable"
"usb-bmc-enable"
"reset-cause-usb-hub"
"bmc-ready"
"fan0-bmc-cpld-enable"
"fan1-bmc-cpld-enable"
"fan2-bmc-cpld-enable"
"fan3-bmc-cpld-enable"
)
gpio-init()
{
for gpioInitHigh in "${gpioInitHighTable[@]}"
do
# need the word splitting for gpiofind command.
# shellcheck disable=SC2046
gpioset $(gpiofind "${gpioInitHigh}")=1
done
}
gpio-init
@@ -0,0 +1,11 @@
[Unit]
Description=Power Control Initialization
Before=mapper-wait@-xyz.openbmc_project.State.Chassis@0.service
Before=mapper-wait@-xyz-openbmc_project-state-bmc.service
[Service]
Type=oneshot
ExecStart=/usr/libexec/phosphor-state-manager/power-ctrl-init
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,9 @@
[Unit]
Description=Sled Cycle
[Service]
Type=oneshot
ExecStart=/usr/libexec/phosphor-state-manager/chassis-powercycle 0
[Install]
WantedBy=obmc-chassis-powercycle@0.target