summaryrefslogtreecommitdiff
path: root/meta-ibs/meta-common/recipes-phosphor/initrdscripts
diff options
context:
space:
mode:
authorAndrey V.Kosteltsev <AKosteltsev@IBS.RU>2022-05-23 00:36:13 +0300
committerAndrey V.Kosteltsev <AKosteltsev@IBS.RU>2022-05-23 00:36:13 +0300
commit816146249ab44fb9e85f8dfd413e18e92a13842c (patch)
tree97df436faa8607f63dba853024879f467eea3054 /meta-ibs/meta-common/recipes-phosphor/initrdscripts
parent1bd1f086e0ecfc9017891b5b9a492446eda41095 (diff)
downloadopenbmc-816146249ab44fb9e85f8dfd413e18e92a13842c.tar.xz
Layers for SILA CP2-5422
Diffstat (limited to 'meta-ibs/meta-common/recipes-phosphor/initrdscripts')
-rw-r--r--meta-ibs/meta-common/recipes-phosphor/initrdscripts/obmc-phosphor-initfs.bbappend5
-rw-r--r--meta-ibs/meta-common/recipes-phosphor/initrdscripts/obmc-phosphor-initfs/obmc-shutdown.sh108
2 files changed, 113 insertions, 0 deletions
diff --git a/meta-ibs/meta-common/recipes-phosphor/initrdscripts/obmc-phosphor-initfs.bbappend b/meta-ibs/meta-common/recipes-phosphor/initrdscripts/obmc-phosphor-initfs.bbappend
new file mode 100644
index 0000000000..61fefda887
--- /dev/null
+++ b/meta-ibs/meta-common/recipes-phosphor/initrdscripts/obmc-phosphor-initfs.bbappend
@@ -0,0 +1,5 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
+
+DESCRIPTION = "Pinging system watchdog before BMC update"
+
+SRC_URI += "file://obmc-shutdown.sh"
diff --git a/meta-ibs/meta-common/recipes-phosphor/initrdscripts/obmc-phosphor-initfs/obmc-shutdown.sh b/meta-ibs/meta-common/recipes-phosphor/initrdscripts/obmc-phosphor-initfs/obmc-shutdown.sh
new file mode 100644
index 0000000000..204665de7e
--- /dev/null
+++ b/meta-ibs/meta-common/recipes-phosphor/initrdscripts/obmc-phosphor-initfs/obmc-shutdown.sh
@@ -0,0 +1,108 @@
+#!/bin/sh
+
+echo shutdown: "$@"
+
+export PS1=shutdown-sh#\
+# exec bin/sh
+
+cd /
+if [ ! -e /proc/mounts ]
+then
+ mkdir -p /proc
+ mount proc /proc -tproc
+ umount_proc=1
+else
+ umount_proc=
+fi
+
+# Remove an empty oldroot, that means we are not invoked from systemd-shutdown
+rmdir /oldroot 2>/dev/null
+
+# Move /oldroot/run to /mnt in case it has the underlying rofs loop mounted.
+# Ordered before /oldroot the overlay is unmounted before the loop mount
+mkdir -p /mnt
+mount --move /oldroot/run /mnt
+
+set -x
+for f in $( awk '/oldroot|mnt/ { print $2 }' < /proc/mounts | sort -r )
+do
+ umount $f
+done
+set +x
+
+update=/run/initramfs/update
+image=/run/initramfs/image-
+
+swdt="-t 10 -T 60"
+wdt="-t 1 -T 5"
+wdrst="-T 15"
+
+if ls $image* > /dev/null 2>&1
+then
+ if test -x $update
+ then
+ if test -c /dev/watchdog1
+ then
+ echo Pinging BMC Hardware watchdog ${swdt+with args $swdt}
+ watchdog $swdt -F /dev/watchdog1 &
+ fi
+ if test -c /dev/watchdog
+ then
+ echo Pinging watchdog ${wdt+with args $wdt}
+ watchdog $wdt -F /dev/watchdog &
+ wd=$!
+ else
+ wd=
+ fi
+ $update --clean-saved-files
+ remaining=$(ls $image*)
+ if test -n "$remaining"
+ then
+ echo 1>&2 "Flash update failed to flash these images:"
+ echo 1>&2 "$remaining"
+ else
+ echo "Flash update completed."
+ fi
+
+ if test -n "$wd"
+ then
+ kill -9 $wd
+ if test -n "$wdrst"
+ then
+ echo Resetting watchdog timeouts to $wdrst
+ watchdog $wdrst -F /dev/watchdog &
+ sleep 1
+ # Kill the watchdog daemon, setting a timeout
+ # for the remaining shutdown work
+ kill -9 $!
+ fi
+ fi
+ else
+ echo 1>&2 "Flash update requested but $update program missing!"
+ fi
+fi
+
+echo Remaining mounts:
+cat /proc/mounts
+
+test "$umount_proc" && umount /proc && rmdir /proc
+
+# tcsattr(tty, TIOCDRAIN, mode) to drain tty messages to console
+test -t 1 && stty cooked 0<&1
+
+# Execute the command systemd told us to ...
+if test -d /oldroot && test "$1"
+then
+ if test "$1" = kexec
+ then
+ $1 -f -e
+ else
+ $1 -f
+ fi
+fi
+
+
+echo "Execute ${1-reboot} -f if all unmounted ok, or exec /init"
+
+export PS1=shutdown-sh#\
+exec /bin/sh