From 17db0edc4b58bd7906e213c0b12293d82fc8f18f Mon Sep 17 00:00:00 2001 From: Stefan Saraev Date: Thu, 29 Aug 2013 21:45:09 +0300 Subject: [PATCH] busybox: implement suspend/resume SUSPEND_MODULES for systemd --- .../busybox/config/suspend-modules.conf | 1 + packages/sysutils/busybox/install | 1 + .../sleep.d.serial/99-suspend-modules.sh | 99 +++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 packages/sysutils/busybox/config/suspend-modules.conf create mode 100755 packages/sysutils/busybox/sleep.d.serial/99-suspend-modules.sh diff --git a/packages/sysutils/busybox/config/suspend-modules.conf b/packages/sysutils/busybox/config/suspend-modules.conf new file mode 100644 index 0000000000..1321ebc407 --- /dev/null +++ b/packages/sysutils/busybox/config/suspend-modules.conf @@ -0,0 +1 @@ +SUSPEND_MODULES="xhci-hcd jme asix anysee rtl8192se imon r8712u cx23885 cdc_acm" diff --git a/packages/sysutils/busybox/install b/packages/sysutils/busybox/install index 925fe49734..b0a88d6285 100755 --- a/packages/sysutils/busybox/install +++ b/packages/sysutils/busybox/install @@ -48,6 +48,7 @@ USER_PWD="`$ROOT/$TOOLCHAIN/bin/cryptpw -m sha512 $USER_PASSWORD`" cp $PKG_DIR/config/profile $INSTALL/etc cp $PKG_DIR/config/inputrc $INSTALL/etc cp $PKG_DIR/config/httpd.conf $INSTALL/etc + cp $PKG_DIR/config/suspend-modules.conf $INSTALL/etc echo "chmod 000 $INSTALL/etc/shadow" >> $FAKEROOT_SCRIPT mkdir -p $INSTALL/usr/config/sysctl.d diff --git a/packages/sysutils/busybox/sleep.d.serial/99-suspend-modules.sh b/packages/sysutils/busybox/sleep.d.serial/99-suspend-modules.sh new file mode 100755 index 0000000000..fc0b2f6f93 --- /dev/null +++ b/packages/sysutils/busybox/sleep.d.serial/99-suspend-modules.sh @@ -0,0 +1,99 @@ +#!/bin/sh +################################################################################ +# This file is part of OpenELEC - http://www.openelec.tv +# Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv) +# +# This Program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This Program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with OpenELEC.tv; see the file COPYING. If not, write to +# the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA. +# http://www.gnu.org/copyleft/gpl.html +################################################################################ + +. /etc/suspend-modules.conf + +modunload() +{ + local MOD D C USED MODS I + local UNL="$(echo $1 |tr - _)" RET=1 + + while read MOD D C USED D; do + [ "$MOD" = "$UNL" ] || continue + if [ "$USED" = "-" ]; then + # no dependent modules, just try to remove this one. + _rmmod "$MOD" $C + RET=$? + else + # modules depend on this one. try to remove them first. + MODS=",${USED%,}" + while [ -n "${MODS}" ]; do + # try to unload the last one first + MOD="${MODS##*,}" + modunload $MOD && RET=0 + # prune the last one from the list + MODS="${MODS%,*}" + done + # if we unloaded at least one module, then let's + # try again! + [ $RET -eq 0 ] && modunload $MOD + RET=$? + fi + return $RET + done < /proc/modules + # if we came this far, there was nothing to do, + # the module is no longer loaded. + return 0 +} + +_rmmod() +{ + if modprobe -r "$1"; then + touch "/run/openelec/suspend/module:$1" + return 0 + else + logger -t suspend-modules "# could not unload '$1', usage count was $2" + return 1 + fi +} + +resume_modules() +{ + for x in /run/openelec/suspend/module:* ; do + [ -O "${x}" ] || continue + modprobe "${x##*:}" &>/dev/null && \ + logger -t resume-modules "Reloaded module ${x##*:}." || \ + logger -t resume-modules "Could not reload module ${x##*:}." + done +} + +suspend_modules() +{ + [ -z "$SUSPEND_MODULES" ] && return 0 + # clean up + rm -rf /run/openelec/suspend + mkdir -p /run/openelec/suspend + for x in $SUSPEND_MODULES ; do + modunload $x && \ + logger -t suspend-modules "Unloading kernel module $x: Done" || \ + logger -t suspend-modules "Unloading kernel module $x: Failed" + done + return 0 +} + +case $1 in + pre) + suspend_modules + ;; + post) + resume_modules + ;; +esac