summaryrefslogtreecommitdiff
path: root/packages/usb-gadget-mode/files/usb-gadget
diff options
context:
space:
mode:
authorMatthias Hentges <oe@hentges.net>2007-06-06 02:27:38 +0000
committerMatthias Hentges <oe@hentges.net>2007-06-06 02:27:38 +0000
commit579875cdcbd028b73e09b077dc13138e867ba27d (patch)
treec8ed89a4e6d95b1cdd4349bdbb8ba564eccd76cf /packages/usb-gadget-mode/files/usb-gadget
parent97ed9a5df5501089de45ad25f98e86d0cac3d5d6 (diff)
usb-gadget-mode: Add usb-gadget mode: An initscript to load the configured USB gadget module on boot
Diffstat (limited to 'packages/usb-gadget-mode/files/usb-gadget')
-rwxr-xr-xpackages/usb-gadget-mode/files/usb-gadget59
1 files changed, 59 insertions, 0 deletions
diff --git a/packages/usb-gadget-mode/files/usb-gadget b/packages/usb-gadget-mode/files/usb-gadget
new file mode 100755
index 0000000000..611703f09d
--- /dev/null
+++ b/packages/usb-gadget-mode/files/usb-gadget
@@ -0,0 +1,59 @@
+#! /bin/sh
+#
+# Copyright Matthias Hentges <devel@hentges.net> (c) 2007
+# License: GPL (see http://www.gnu.org/licenses/gpl.txt for a copy of the license)
+#
+# Filename: usb-gadget
+# Date: 20070606 (YMD)
+#
+#################################################################################
+#
+# 20070606 - v0.0.1 - Initial release
+
+CONF_FILE="/etc/usb-gadget.conf"
+
+die() {
+ echo "ERROR: $1"
+ exit 1
+}
+
+go() {
+ test -e "$CONF_FILE" && . "$CONF_FILE"
+
+ case "$USB_MODE" in
+ networking) setup_usb g_ether "$MODULE_OPTIONS" ;;
+ storage) setup_usb g_file_storage "$MODULE_OPTIONS" ;;
+ none) unload_usb_gadgets ;;
+ esac
+
+}
+
+setup_usb() {
+
+ if ! ( lsmod | grep -q "$1" )
+ then
+ unload_usb_gadgets
+ echo "Loading [$1]"
+ modprobe "$1" "$MODULE_OPTIONS"
+ else
+ echo "Already loaded: [$1]"
+ fi
+}
+
+unload_usb_gadgets() {
+ KERNEL_VERSION="`uname -r`"
+ GADGET_MODULES="`find /lib/modules/$KERNEL_VERSION/kernel/drivers/usb/gadget -name "*g_*"`"
+
+ for module in $GADGET_MODULES
+ do
+ MODULE_NAME="`basename $module | sed "s/\.ko//"`"
+
+ if ( lsmod | grep -q "$MODULE_NAME" )
+ then
+ echo "Unloading [$MODULE_NAME]"
+ rmmod "$module"
+ fi
+ done
+}
+
+go