BMC: Block BMC reboot during code update
- Create functions inside obmc-flash-bmc script to enable
and disable reboots from command line.
- Create service files for enabling and disabling BMC reboots.
- The enable service will be called during the constructor of
ActivationBlockTransition and disable service will be run during
the destructor of ActivationBlockTransition.
Change-Id: Idcec12b2c1126e212ee861150c92aaacd23a1ace
Signed-off-by: Saqib Khan <khansa@us.ibm.com>
diff --git a/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager.bb b/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager.bb
index 3dae47e..619e784 100644
--- a/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager.bb
+++ b/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager.bb
@@ -75,6 +75,8 @@
usr-local.mount \
obmc-flash-bmc-ubiremount.service \
obmc-flash-bmc-updateubootvars@.service \
+ reboot-guard-enable.service \
+ reboot-guard-disable.service \
"
# Name of the mtd device where the ubi volumes should be created
diff --git a/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc b/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
index 6725eaa..d8eed57 100644
--- a/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
+++ b/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager/obmc-flash-bmc
@@ -271,6 +271,31 @@
ubi_setenv "root=${block}"
}
+#TODO: Replace the implementation with systemd-inhibitors lock
+# once systemd/systemd#949 is resolved
+rebootguardenable() {
+ dir="/run/systemd/system/"
+ file="reboot-guard.conf"
+ units=("reboot" "poweroff" "halt")
+
+ for unit in "${units[@]}"; do
+ mkdir -p ${dir}${unit}.target.d
+ echo -e "[Unit]\nRefuseManualStart=yes" >> ${dir}${unit}.target.d/${file}
+ done
+}
+
+#TODO: Replace the implementation with systemd-inhibitors lock
+# once systemd/systemd#949 is resolved
+rebootguarddisable() {
+ dir="/run/systemd/system/"
+ file="reboot-guard.conf"
+ units=("reboot" "poweroff" "halt")
+
+ for unit in "${units[@]}"; do
+ rm -rf ${dir}${unit}.target.d/${file}
+ done
+}
+
# Create a copy in the alt mtd
create_vol_in_alt() {
alt="alt-bmc"
@@ -334,6 +359,12 @@
version="$2"
update_env_vars
;;
+ rebootguardenable)
+ rebootguardenable
+ ;;
+ rebootguarddisable)
+ rebootguarddisable
+ ;;
*)
echo "Invalid argument"
exit 1
diff --git a/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager/reboot-guard-disable.service b/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager/reboot-guard-disable.service
new file mode 100644
index 0000000..b09df99
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager/reboot-guard-disable.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Removes the guard that blocks BMC reboot
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStart=/usr/bin/env obmc-flash-bmc rebootguarddisable
+SyslogIdentifier=obmc-flash-bmc
diff --git a/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager/reboot-guard-enable.service b/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager/reboot-guard-enable.service
new file mode 100644
index 0000000..4405e3d
--- /dev/null
+++ b/meta-phosphor/common/recipes-phosphor/flash/phosphor-software-manager/reboot-guard-enable.service
@@ -0,0 +1,8 @@
+[Unit]
+Description=Enable a guard that blocks BMC reboot
+
+[Service]
+Type=oneshot
+RemainAfterExit=no
+ExecStart=/usr/bin/env obmc-flash-bmc rebootguardenable
+SyslogIdentifier=obmc-flash-bmc