From d3b7fca9339c2a40cc5b02a5dcb171c084c4e84d Mon Sep 17 00:00:00 2001 From: Mike Engel Date: Thu, 10 Feb 2022 13:34:44 +0100 Subject: [PATCH] busybox: add power safe and reboot safe scripts for the MCA This commit adds power safe and reboot safe script for the MCA and substitute default reboot and poweroff busybox commands. Signed-off-by: Mike Engel https://onedigi.atlassian.net/browse/DEL-7828 --- .../busybox/busybox/poweroff_safe | 49 +++++++++++++++++++ .../recipes-core/busybox/busybox/reboot_safe | 49 +++++++++++++++++++ .../busybox/busybox_1.34.%.bbappend | 12 ++++- 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 meta-digi-dey/recipes-core/busybox/busybox/poweroff_safe create mode 100644 meta-digi-dey/recipes-core/busybox/busybox/reboot_safe diff --git a/meta-digi-dey/recipes-core/busybox/busybox/poweroff_safe b/meta-digi-dey/recipes-core/busybox/busybox/poweroff_safe new file mode 100644 index 000000000..8c10a7ff1 --- /dev/null +++ b/meta-digi-dey/recipes-core/busybox/busybox/poweroff_safe @@ -0,0 +1,49 @@ +#!/bin/sh +#=============================================================================== +# +# poweroff_safe +# +# Copyright (C) 2022 by Digi International Inc. +# All rights reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 as published by +# the Free Software Foundation. +# +# +# !Description: safe power-off script +# +#=============================================================================== + +scriptname="$(basename "$(readlink -f "${0}")")" +pwroff_safe="$(find /sys/devices/ -name pwroff_safe 2>/dev/null)" + +# Default timeout 30s +TOUT="30" +UNLOCK_STR="CTRU" + +usage() { + printf "\nInitiates a power-off on the system and programs the MCA" + printf "\nto force an immediate power-off after a configured timeout." + printf "\nThis assures the system will power off even if the" + printf "\nsystem hangs during regular shut down process." + printf "\nUsage: %s [OPTIONS]\n + -t timeout value in seconds (30 seconds by default) + -h Show this help + \n" "${scriptname}" +} + +while getopts "t:h" c; do + case "${c}" in + h) usage; exit;; + t) TOUT=${OPTARG};; + esac +done + +if [ -f "${pwroff_safe}" ]; then + # Configure the MCA to power off after ${TOUT} seconds + echo "${UNLOCK_STR}${TOUT}" > "${pwroff_safe}" +else + printf "\nSafe power-off operation not supported. Proceeding with a regular power-off\n\n" + exec poweroff +fi diff --git a/meta-digi-dey/recipes-core/busybox/busybox/reboot_safe b/meta-digi-dey/recipes-core/busybox/busybox/reboot_safe new file mode 100644 index 000000000..613bc49b4 --- /dev/null +++ b/meta-digi-dey/recipes-core/busybox/busybox/reboot_safe @@ -0,0 +1,49 @@ +#!/bin/sh +#=============================================================================== +# +# reboot_safe +# +# Copyright (C) 2022 by Digi International Inc. +# All rights reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 as published by +# the Free Software Foundation. +# +# +# !Description: safe reboot script +# +#=============================================================================== + +scriptname="$(basename "$(readlink -f "${0}")")" +reboot_safe="$(find /sys/devices/ -name reboot_safe 2>/dev/null)" + +# Default timeout 30s +TOUT="30" +UNLOCK_STR="CTRU" + +usage() { + printf "\nInitiates a reboot of the system and programs the MCA" + printf "\nto force an immediate reset after a configured timeout." + printf "\nThis assures the system will reset even if the" + printf "\nsystem hangs during regular reboot process." + printf "\nUsage: %s [OPTIONS]\n + -t timeout value in seconds (30 seconds by default) + -h Show this help + \n" "${scriptname}" +} + +while getopts "t:h" c; do + case "${c}" in + h) usage; exit;; + t) TOUT=${OPTARG};; + esac +done + +if [ -f "${reboot_safe}" ]; then + # Configure the MCA to reboot after ${TOUT} seconds + echo "${UNLOCK_STR}${TOUT}" > "${reboot_safe}" +else + printf "\nSafe reboot operation not supported. Proceeding with a regular reboot\n\n" + exec reboot +fi diff --git a/meta-digi-dey/recipes-core/busybox/busybox_1.34.%.bbappend b/meta-digi-dey/recipes-core/busybox/busybox_1.34.%.bbappend index 4d1640831..2a48c7282 100644 --- a/meta-digi-dey/recipes-core/busybox/busybox_1.34.%.bbappend +++ b/meta-digi-dey/recipes-core/busybox/busybox_1.34.%.bbappend @@ -1,4 +1,4 @@ -# Copyright (C) 2013-2019 Digi International. +# Copyright (C) 2013-2022 Digi International. FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:" @@ -13,6 +13,9 @@ SRC_URI += "file://standby \ file://pswitch-standby \ file://pswitch-poweroff \ file://bridgeifupdown \ + ${@bb.utils.contains("MACHINE_FEATURES", "mca", "file://poweroff_safe \ + file://reboot_safe \ + ", "", d)} \ " SRC_URI_append_ccimx6ul = " file://index.html \ @@ -20,6 +23,7 @@ SRC_URI_append_ccimx6ul = " file://index.html \ " HAS_SYSTEMD = "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}" +HAS_MCA = "${@bb.utils.contains('MACHINE_FEATURES', 'mca', 'true', 'false', d)}" # hwclock bootscript init parameters INITSCRIPT_PARAMS_${PN}-hwclock = "start 20 S . stop 20 0 6 ." @@ -91,6 +95,12 @@ do_install_append() { install -m 0755 ${WORKDIR}/bridgeifupdown ${D}${sysconfdir}/network/if-pre-up.d/ ln -s ../if-pre-up.d/bridgeifupdown ${D}${sysconfdir}/network/if-post-down.d/bridgeifupdown fi + + # install MCA power safe and reboot safe scripts + if ${HAS_MCA}; then + install -m 0755 ${WORKDIR}/poweroff_safe ${D}${base_bindir}/poweroff_safe + install -m 0755 ${WORKDIR}/reboot_safe ${D}${base_bindir}/reboot_safe + fi } do_install_append_ccimx6ul() {