Initial commit
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Ensure host is off on clean AC cycle
|
||||
Before=host-poweron.service
|
||||
Before=firmware-updates-pre.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/host_ensure_off.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Powercycle host
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
Environment=DONT_STOP_WATCHDOG=1
|
||||
ExecStart=/usr/bin/host_powercycle.sh
|
||||
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=Powercycle host
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/host_powercycle.sh
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Power off host
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
Environment=DONT_STOP_WATCHDOG=1
|
||||
ExecStart=/usr/bin/host_poweroff.sh
|
||||
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=Power off host
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/host_poweroff.sh
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Power on host
|
||||
After=firmware-updates.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/host_poweron.sh
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Cold Reset Host
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
Environment=DONT_STOP_WATCHDOG=1
|
||||
ExecStart=/usr/bin/host_reset.sh cold
|
||||
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=Cold Reset Host
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/host_reset.sh cold
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
[Unit]
|
||||
Description=Warm Reset Host
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
Environment=DONT_STOP_WATCHDOG=1
|
||||
ExecStart=/usr/bin/host_reset.sh warm
|
||||
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=Warm Reset Host
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/host_reset.sh warm
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2021 Google 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.
|
||||
|
||||
if ! was_ac_reset.sh; then
|
||||
echo "Not a tray reset, ignoring" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Powering off the host" >&2
|
||||
host_poweroff.sh
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2021 Google 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.
|
||||
|
||||
# shellcheck source=meta-google/recipes-google/gpio/gpio-ctrl/lib.sh
|
||||
source /usr/share/gpio-host-pwr/lib.sh || exit
|
||||
|
||||
gpio_build_cache 10 "$HOST_GPIO_PGOOD" || exit 255
|
||||
pgood="$(gpio_get_value "$HOST_GPIO_PGOOD")" || exit 255
|
||||
echo "HOST_PGOOD=$pgood" >&2
|
||||
(( pgood == 0 ))
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2021 Google 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.
|
||||
|
||||
# shellcheck source=meta-google/recipes-google/gpio/gpio-ctrl/lib.sh
|
||||
source /usr/share/gpio-host-pwr/lib.sh || exit
|
||||
gpio_build_cache 10 "$HOST_GPIO_PGOOD" "$HOST_GPIO_PWR_BTN" || exit
|
||||
|
||||
rc=0
|
||||
host_poweroff.sh || rc=$?
|
||||
# We want to ensure we aren't too quickly bouncing the power button
|
||||
sleep 0.5
|
||||
host_poweron.sh || rc=$?
|
||||
exit $rc
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2021 Google 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.
|
||||
|
||||
# shellcheck source=meta-google/recipes-google/gpio/gpio-ctrl/lib.sh
|
||||
source /usr/share/gpio-host-pwr/lib.sh || exit
|
||||
|
||||
gpio_build_cache 10 "$HOST_GPIO_PGOOD" "$HOST_GPIO_PWR_BTN" || exit
|
||||
gpio_init "$HOST_GPIO_PGOOD" || exit
|
||||
|
||||
# Set the power status LED
|
||||
if [ -n "$HOST_LED_PWR" ]; then
|
||||
echo 'none' > /sys/class/leds/"$HOST_LED_PWR"/trigger || true
|
||||
echo '0' > /sys/class/leds/"$HOST_LED_PWR"/brightness || true
|
||||
fi
|
||||
|
||||
# Ensure the watchdog is no longer going to run
|
||||
host_pwr_stop_watchdog || true
|
||||
|
||||
# We don't want to do anything if the machine is already off
|
||||
pgood="$(gpio_get_value "$HOST_GPIO_PGOOD")" || exit
|
||||
if (( pgood == 0 )); then
|
||||
echo 'Host is already off, doing nothing' >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Do a long push of the button if PGOOD
|
||||
echo 'Stopping host power' >&2
|
||||
rc=0
|
||||
gpio_set_value "$HOST_GPIO_PWR_BTN" 1 || rc=$?
|
||||
|
||||
# Loop until we realize that host power is off
|
||||
# Limit the loop count to 10 seconds as we should never
|
||||
# have to wait this long for poweroff
|
||||
s=$SECONDS
|
||||
while true; do
|
||||
if ! pgood="$(gpio_get_value "$HOST_GPIO_PGOOD")"; then
|
||||
rc=1
|
||||
break
|
||||
fi
|
||||
if (( pgood == 0 )); then
|
||||
echo 'Host is now off' >&2
|
||||
break
|
||||
fi
|
||||
if (( SECONDS - s > 10 )); then
|
||||
echo 'Poweroff timed out, terminating' >&2
|
||||
rc=2
|
||||
break
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
|
||||
gpio_set_value "$HOST_GPIO_PWR_BTN" 0 || rc=$?
|
||||
|
||||
exit $rc
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2021 Google 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.
|
||||
|
||||
# shellcheck source=meta-google/recipes-google/gpio/gpio-ctrl/lib.sh
|
||||
source /usr/share/gpio-host-pwr/lib.sh || exit
|
||||
|
||||
gpio_build_cache 10 "$HOST_GPIO_PGOOD" "$HOST_GPIO_PWR_BTN" || exit
|
||||
gpio_init "$HOST_GPIO_PGOOD" || exit
|
||||
|
||||
# Set the power status LED
|
||||
if [ -n "$HOST_LED_PWR" ]; then
|
||||
echo 'none' > /sys/class/leds/"$HOST_LED_PWR"/trigger || true
|
||||
echo '255' > /sys/class/leds/"$HOST_LED_PWR"/brightness || true
|
||||
fi
|
||||
|
||||
# Ensure the watchdog is available before the host starts
|
||||
host_pwr_start_watchdog || true
|
||||
|
||||
# We don't want to do anything if the machine is already on
|
||||
pgood="$(gpio_get_value "$HOST_GPIO_PGOOD")" || exit
|
||||
if (( pgood == 1 )); then
|
||||
echo 'Host is already running, doing nothing' >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Do a quick push of the button if PGOOD
|
||||
echo "Starting host power" >&2
|
||||
rc=0
|
||||
gpio_set_value "$HOST_GPIO_PWR_BTN" 1 || rc=$?
|
||||
sleep 0.1
|
||||
gpio_set_value "$HOST_GPIO_PWR_BTN" 0 || rc=$?
|
||||
|
||||
# Loop until we realize that host power is on
|
||||
# Limit the loop count to 10 seconds as we should never
|
||||
# have to wait this long for poweroff
|
||||
s=$SECONDS
|
||||
while true; do
|
||||
if ! pgood="$(gpio_get_value "$HOST_GPIO_PGOOD")"; then
|
||||
rc=1
|
||||
break
|
||||
fi
|
||||
if (( pgood == 1 )); then
|
||||
echo 'Host is now on' >&2
|
||||
break
|
||||
fi
|
||||
if (( SECONDS - s > 10 )); then
|
||||
echo 'Poweron timed out, terminating' >&2
|
||||
rc=2
|
||||
break
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
|
||||
exit $rc
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2021 Google 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.
|
||||
|
||||
# shellcheck source=meta-google/recipes-google/gpio/gpio-ctrl/lib.sh
|
||||
source /usr/share/gpio-host-pwr/lib.sh || exit
|
||||
|
||||
if [[ "${1-}" == "warm" ]]; then
|
||||
rst_txt='WARM' >&2
|
||||
rst_gpio="$HOST_GPIO_WARM_RESET"
|
||||
else
|
||||
rst_txt='COLD' >&2
|
||||
rst_gpio="$HOST_GPIO_COLD_RESET"
|
||||
fi
|
||||
|
||||
gpio_build_cache 10 "$rst_gpio" || exit
|
||||
|
||||
# Do a quick push of the button if PGOOD
|
||||
echo "Issuing $rst_txt reset" >&2
|
||||
rc=0
|
||||
gpio_set_value "$rst_gpio" 1 || rc=$?
|
||||
sleep 0.1
|
||||
gpio_set_value "$rst_gpio" 0 || rc=$?
|
||||
|
||||
# Make sure the watchdog is stopped while the host is in reset
|
||||
# and can't possibly restart it.
|
||||
host_pwr_stop_watchdog || true
|
||||
|
||||
exit $rc
|
||||
@@ -0,0 +1,73 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2021 Google 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.
|
||||
|
||||
# This is intended to be used as a library for managing gpio line values.
|
||||
# Executing this directly will do nothing.
|
||||
[ -n "${host_pwr_init-}" ] && return
|
||||
|
||||
# shellcheck source=meta-google/recipes-google/gpio/gpio-ctrl/lib.sh
|
||||
source /usr/share/gpio-ctrl/lib.sh || exit
|
||||
|
||||
# Read by the tooling to determine if the machine is powered on or off
|
||||
# shellcheck disable=SC2034
|
||||
HOST_GPIO_PGOOD='unset'
|
||||
# Set according to whether the host is powered on or off
|
||||
# shellcheck disable=SC2034
|
||||
HOST_LED_PWR=''
|
||||
# Written by the tooling to assert the power button
|
||||
# shellcheck disable=SC2034
|
||||
HOST_GPIO_PWR_BTN='unset'
|
||||
# Written by the tooling to assert a cold reset
|
||||
# shellcheck disable=SC2034
|
||||
HOST_GPIO_COLD_RESET='unset'
|
||||
# Written by the tooling to assert a warm reset
|
||||
# shellcheck disable=SC2034
|
||||
HOST_GPIO_WARM_RESET='unset'
|
||||
|
||||
# Load configurations from a known location in the filesystem to populate
|
||||
# named GPIOs
|
||||
shopt -s nullglob
|
||||
for conf in /usr/share/gpio-host-pwr/conf.d/*.sh; do
|
||||
# shellcheck source=/dev/null
|
||||
source "$conf"
|
||||
done
|
||||
|
||||
##################################################
|
||||
# Stop the host watchdog
|
||||
# Return:
|
||||
# 0 if success, non-zero if error
|
||||
##################################################
|
||||
host_pwr_stop_watchdog() {
|
||||
# Check to see if we can stop the watchdog safely
|
||||
# We don't want to stop if we are called from the watchdog itself
|
||||
if [ -n "${DONT_STOP_WATCHDOG-}" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo 'Stopping the host watchdog' >&2
|
||||
systemctl stop phosphor-watchdog@host0
|
||||
}
|
||||
|
||||
##################################################
|
||||
# Start the host watchdog
|
||||
# Return:
|
||||
# 0 if success, non-zero if error
|
||||
##################################################
|
||||
host_pwr_start_watchdog() {
|
||||
echo 'Starting the host watchdog' >&2
|
||||
systemctl start phosphor-watchdog@host0
|
||||
}
|
||||
|
||||
host_pwr_init=1
|
||||
@@ -0,0 +1,57 @@
|
||||
SUMMARY = "GPIO based powercontrol for a host system"
|
||||
DESCRIPTION = "GPIO based powercontrol for a host system."
|
||||
PR = "r1"
|
||||
LICENSE = "Apache-2.0"
|
||||
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
|
||||
|
||||
inherit systemd
|
||||
|
||||
RDEPENDS:${PN} += " \
|
||||
bash \
|
||||
gpio-ctrl \
|
||||
"
|
||||
|
||||
SRC_URI += " \
|
||||
file://host-ensure-off.service \
|
||||
file://host-powercycle-watchdog.service \
|
||||
file://host-powercycle.service \
|
||||
file://host-poweroff-watchdog.service \
|
||||
file://host-poweroff.service \
|
||||
file://host-poweron.service \
|
||||
file://host-reset-cold-watchdog.service \
|
||||
file://host-reset-cold.service \
|
||||
file://host-reset-warm-watchdog.service \
|
||||
file://host-reset-warm.service \
|
||||
file://host_ensure_off.sh \
|
||||
file://host_isoff.sh \
|
||||
file://host_powercycle.sh \
|
||||
file://host_poweroff.sh \
|
||||
file://host_poweron.sh \
|
||||
file://host_reset.sh \
|
||||
file://lib.sh \
|
||||
"
|
||||
|
||||
SYSTEMD_PACKAGES = "${PN}"
|
||||
SYSTEMD_SERVICE:${PN} += " \
|
||||
host-reset-cold.service \
|
||||
host-reset-cold-watchdog.service \
|
||||
host-reset-warm.service \
|
||||
host-reset-warm-watchdog.service \
|
||||
host-ensure-off.service \
|
||||
host-powercycle.service \
|
||||
host-powercycle-watchdog.service \
|
||||
host-poweroff.service \
|
||||
host-poweroff-watchdog.service \
|
||||
host-poweron.service \
|
||||
"
|
||||
|
||||
do_install() {
|
||||
install -d ${D}${bindir}
|
||||
install -m 0755 ${WORKDIR}/host_*.sh ${D}${bindir}/
|
||||
|
||||
install -d ${D}${datadir}/gpio-host-pwr
|
||||
install -m 0755 ${WORKDIR}/lib.sh ${D}${datadir}/gpio-host-pwr/
|
||||
|
||||
install -d ${D}${systemd_system_unitdir}
|
||||
install -m 0644 ${WORKDIR}/*.service ${D}${systemd_system_unitdir}/
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2021 Google 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.
|
||||
|
||||
##################################################
|
||||
# Stop the host watchdog
|
||||
# Return:
|
||||
# 0 if success, non-zero if error
|
||||
##################################################
|
||||
stop_host_watchdog() {
|
||||
if (( $# != 0 )); then
|
||||
echo 'Usage: stop_host_watchdog' >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local srv='xyz.openbmc_project.Watchdog'
|
||||
local obj='/xyz/openbmc_project/watchdog/host0'
|
||||
local intf='xyz.openbmc_project.State.Watchdog'
|
||||
local method='Enabled'
|
||||
local args=('b' 'false')
|
||||
busctl set-property "${srv}" "${obj}" "${intf}" "${method}" "${args[@]}"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
SUMMARY = "Watchdog Shell Library"
|
||||
DESCRIPTION = "Watchdog Shell Library"
|
||||
PR = "r1"
|
||||
LICENSE = "Apache-2.0"
|
||||
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
|
||||
|
||||
SRC_URI += " \
|
||||
file://libwatchdog.sh \
|
||||
"
|
||||
|
||||
RDEPENDS:${PN} = "bash"
|
||||
|
||||
do_install() {
|
||||
install -d ${D}${libexecdir}
|
||||
install -m 0755 ${WORKDIR}/libwatchdog.sh ${D}${libexecdir}/
|
||||
}
|
||||
Reference in New Issue
Block a user