From 803dde16b00027e4372affc69408b1159484cf1f Mon Sep 17 00:00:00 2001 From: Gabriel Valcazar Date: Fri, 8 Feb 2019 18:32:55 +0100 Subject: [PATCH] busybox: add suspend-actions script for the ccimx8x and ccimx6ul This script behaves the same way as our custom standby script, with a few modifications, for example: * instead of using initscripts to stop/start daemons, it uses systemctl calls * save variables that are needed when resuming in /tmp, because the script is executed twice instead of once (when suspending and when resuming) * remove the locking/unlocking of the critical section and the actual state change, since that is handled by systemd-suspend now Also, add a different standby script for when systemd is enabled. Said script acts as a wrapper for systemd's suspend mechanism. https://jira.digi.com/browse/DEL-6415 Signed-off-by: Gabriel Valcazar --- .../busybox-1.29.2/ccimx6ul/standby-actions | 63 +++++++++++++++++++ .../busybox-1.29.2/ccimx8x/standby-actions | 63 +++++++++++++++++++ .../busybox/busybox-1.29.2/standby-systemd | 19 ++++++ .../busybox/busybox_1.29.2.bbappend | 19 +++++- 4 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 meta-digi-dey/recipes-core/busybox/busybox-1.29.2/ccimx6ul/standby-actions create mode 100644 meta-digi-dey/recipes-core/busybox/busybox-1.29.2/ccimx8x/standby-actions create mode 100644 meta-digi-dey/recipes-core/busybox/busybox-1.29.2/standby-systemd diff --git a/meta-digi-dey/recipes-core/busybox/busybox-1.29.2/ccimx6ul/standby-actions b/meta-digi-dey/recipes-core/busybox/busybox-1.29.2/ccimx6ul/standby-actions new file mode 100644 index 000000000..639460c0a --- /dev/null +++ b/meta-digi-dey/recipes-core/busybox/busybox-1.29.2/ccimx6ul/standby-actions @@ -0,0 +1,63 @@ +#!/bin/sh +#=============================================================================== +# +# standby-actions +# +# Copyright (C) 2019 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: manage interfaces before suspending and after resuming from +# suspend +# +#=============================================================================== + +if [ "${1}" == "pre" ]; then + # Stop NetworkManager before suspend + systemctl stop NetworkManager + + # Suspend wireless interfaces + if [ -d "/proc/device-tree/wireless" ]; then + for i in $(sed -ne 's,^\(wlan[0-9]\)=.*,\1,g;T;p' /var/run/ifstate | sort -r); do + ifdown "${i}" && RESUME_IFACES="${RESUME_IFACES:+${RESUME_IFACES} }${i}" + done + + echo ${RESUME_IFACES} > /tmp/suspend_wlan_ifaces + grep -qs '^wlan' /proc/modules && rmmod wlan + fi + + # Suspend bluetooth interface + if [ -d "/proc/device-tree/bluetooth" ]; then + hciconfig hci0 2>&1 | grep -qs UP && touch /tmp/up_bt_on_resume + systemctl stop bluetooth + systemctl stop bluetooth-init + fi +elif [ "${1}" == "post" ]; then + # Resume wireless interfaces + if [ -d "/proc/device-tree/wireless" ]; then + # Trigger wireless module loading event, and wait until the interface exists + udevadm trigger --action=add --attr-match="modalias=sdio:c00v0271d050A" + timeout -t 5 sh -c "while [ ! -d /sys/class/net/wlan0 ]; do sleep .2; done" 2>/dev/null + + # Bring up the interfaces that were brought down on suspend + for i in $(cat /tmp/suspend_wlan_ifaces | tr ' ' '\n' | sort); do + grep -qs "^${i}" /var/run/ifstate || ifup "${i}" + done + rm -f /tmp/suspend_wlan_ifaces + fi + + # Resume NetworkManager after suspend + systemctl start NetworkManager + + # Resume bluetooth interface + if [ -d "/proc/device-tree/bluetooth" ]; then + if [ -e "/tmp/up_bt_on_resume" ]; then + systemctl start bluetooth + rm -f /tmp/up_bt_on_resume + fi + fi +fi diff --git a/meta-digi-dey/recipes-core/busybox/busybox-1.29.2/ccimx8x/standby-actions b/meta-digi-dey/recipes-core/busybox/busybox-1.29.2/ccimx8x/standby-actions new file mode 100644 index 000000000..a048e2e24 --- /dev/null +++ b/meta-digi-dey/recipes-core/busybox/busybox-1.29.2/ccimx8x/standby-actions @@ -0,0 +1,63 @@ +#!/bin/sh +#=============================================================================== +# +# standby-actions +# +# Copyright (C) 2019 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: manage interfaces before suspending and after resuming from +# suspend +# +#=============================================================================== + +if [ "${1}" == "pre" ]; then + # Stop NetworkManager before suspend + systemctl stop NetworkManager + + # Suspend wireless interfaces + if [ -d "/proc/device-tree/wireless" ]; then + for i in $(sed -ne 's,^\(wlan[0-9]\)=.*,\1,g;T;p' /var/run/ifstate | sort -r); do + ifdown "${i}" && RESUME_IFACES="${RESUME_IFACES:+${RESUME_IFACES} }${i}" + done + + echo ${RESUME_IFACES} > /tmp/suspend_wlan_ifaces + grep -qs '^wlan' /proc/modules && rmmod wlan + fi + + # Suspend bluetooth interface + if [ -d "/proc/device-tree/bluetooth" ]; then + hciconfig hci0 2>&1 | grep -qs UP && touch /tmp/up_bt_on_resume + systemctl stop bluetooth + systemctl stop bluetooth-init + fi +elif [ "${1}" == "post" ]; then + # Resume wireless interfaces + if [ -d "/proc/device-tree/wireless" ]; then + # Trigger wireless module loading event, and wait until the interface exists + udevadm trigger --action=add --attr-match="modalias=pci:v0000168Cd0000003Esv*sd*bc*sc*i*" + timeout -t 5 sh -c "while [ ! -d /sys/class/net/wlan0 ]; do sleep .2; done" 2>/dev/null + + # Bring up the interfaces that were brought down on suspend + for i in $(cat /tmp/suspend_wlan_ifaces | tr ' ' '\n' | sort); do + grep -qs "^${i}" /var/run/ifstate || ifup "${i}" + done + rm -f /tmp/suspend_wlan_ifaces + fi + + # Resume NetworkManager after suspend + systemctl start NetworkManager + + # Resume bluetooth interface + if [ -d "/proc/device-tree/bluetooth" ]; then + if [ -e "/tmp/up_bt_on_resume" ]; then + systemctl start bluetooth + rm -f /tmp/up_bt_on_resume + fi + fi +fi diff --git a/meta-digi-dey/recipes-core/busybox/busybox-1.29.2/standby-systemd b/meta-digi-dey/recipes-core/busybox/busybox-1.29.2/standby-systemd new file mode 100644 index 000000000..587dac56d --- /dev/null +++ b/meta-digi-dey/recipes-core/busybox/busybox-1.29.2/standby-systemd @@ -0,0 +1,19 @@ +#!/bin/sh +#=============================================================================== +# +# standby +# +# Copyright (C) 2019 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: suspend system to RAM +# +#=============================================================================== + +# Go to suspend using systemd's default suspend method +systemctl suspend diff --git a/meta-digi-dey/recipes-core/busybox/busybox_1.29.2.bbappend b/meta-digi-dey/recipes-core/busybox/busybox_1.29.2.bbappend index 343e5a8bb..b5d03c162 100644 --- a/meta-digi-dey/recipes-core/busybox/busybox_1.29.2.bbappend +++ b/meta-digi-dey/recipes-core/busybox/busybox_1.29.2.bbappend @@ -3,6 +3,8 @@ FILESEXTRAPATHS_prepend := "${THISDIR}/${BP}:" SRC_URI += "file://standby \ + file://standby-actions \ + file://standby-systemd \ file://busybox-ntpd \ file://index.html \ file://digi-logo.png \ @@ -13,9 +15,13 @@ SRC_URI += "file://standby \ file://bridgeifupdown \ " +HAS_SYSTEMD = "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}" + # hwclock bootscript init parameters INITSCRIPT_PARAMS_${PN}-hwclock = "start 20 S . stop 20 0 6 ." +FILES_${PN}_append = " ${systemd_unitdir}/system-sleep/" + # NTPD package PACKAGES =+ "${PN}-ntpd" FILES_${PN}-ntpd = "${sysconfdir}/init.d/busybox-ntpd" @@ -43,8 +49,17 @@ do_install_append() { install -m 0644 ${WORKDIR}/index.html ${D}/srv/www/ install -m 0644 ${WORKDIR}/digi-logo.png ${D}/srv/www/ fi - # Install 'standby' script - install -m 0755 ${WORKDIR}/standby ${D}${base_bindir} + # Install one standby script or another depending on having systemd or not + if ${HAS_SYSTEMD}; then + # Install systemd version of 'standby' script + install -m 0755 ${WORKDIR}/standby-systemd ${D}${base_bindir}/standby + # Install systemd 'standby-actions' hook + install -d ${D}${systemd_unitdir}/system-sleep/ + install -m 0755 ${WORKDIR}/standby-actions ${D}${systemd_unitdir}/system-sleep/ + else + # Install 'standby' script + install -m 0755 ${WORKDIR}/standby ${D}${base_bindir} + fi # Create a symlink called suspend to maintain backward compatibility ln -s standby ${D}${base_bindir}/suspend if grep "CONFIG_ACPID=y" ${WORKDIR}/defconfig; then