aboutsummaryrefslogtreecommitdiffstats
path: root/main/busybox-initscripts/usbdev
diff options
context:
space:
mode:
Diffstat (limited to 'main/busybox-initscripts/usbdev')
-rwxr-xr-x[-rw-r--r--]main/busybox-initscripts/usbdev75
1 files changed, 19 insertions, 56 deletions
diff --git a/main/busybox-initscripts/usbdev b/main/busybox-initscripts/usbdev
index ea5b915573..c811736dda 100644..100755
--- a/main/busybox-initscripts/usbdev
+++ b/main/busybox-initscripts/usbdev
@@ -1,62 +1,25 @@
#!/bin/sh
-# script is buggy; until patched just do exit 0
-#exit 0
+# mdev -s will not set SUBSYSTEM or DEVNAME so we trigger a hotplug event
+if [ "$SUBSYSTEM" != "usb" ] || [ "$DEVTYPE" != "usb_device" ]; then
+ uev=/sys/bus/usb/devices/$MDEV/uevent
+ [ -e "$uev" ] && echo "add" > "$uev"
+ exit
+fi
-# add zeros to device or bus
-add_zeros () {
- case "$(echo $1 | wc -L)" in
- 1) echo "00$1" ;;
- 2) echo "0$1" ;;
- *) echo "$1"
- esac
- exit 0
-}
+[ -n "$DEVNAME" ] || exit
-
-# bus and device dirs in /sys
-USB_PATH=$(echo $MDEV | sed -e 's/usbdev\([0-9]\).[0-9]/usb\1/')
-USB_PATH=$(find /sys/devices -type d -name "$USB_PATH")
-USB_DEV_DIR=$(echo $MDEV | sed -e 's/usbdev\([0-9]\).\([0-9]\)/\1-\2/')
-
-# dir names in /dev
-BUS=$(add_zeros $(echo $MDEV | sed -e 's/^usbdev\([0-9]\).[0-9]/\1/'))
-USB_DEV=$(add_zeros $(echo $MDEV | sed -e 's/^usbdev[0-9].\([0-9]\)/\1/'))
-
-
-# try to load the proper driver for usb devices
case "$ACTION" in
- add|"")
- # load usb bus driver
- for i in $USB_PATH/*/modalias ; do
- modprobe `cat $i` 2>/dev/null
- done
- # load usb device driver if existent
- if [ -d $USB_PATH/$USB_DEV_DIR ]; then
- for i in $USB_PATH/$USB_DEV_DIR/*/modalias ; do
- modprobe `cat $i` 2>/dev/null
- done
- fi
- # move usb device file
- mkdir -p bus/usb/$BUS
- mv $MDEV bus/usb/$BUS/$USB_DEV
- ;;
- remove)
- # unload device driver, if device dir is existent
- if [ -d $USB_PATH/$USB_DEV_DIR ]; then
- for i in $USB_PATH/$USB_DEV_DIR/*/modalias ; do
- modprobe -r `cat $i` 2>/dev/null
- done
- fi
- # unload usb bus driver. Does this make sense?
- # what happens, if two usb devices are plugged in
- # and one is removed?
- for i in $USB_PATH/*/modalias ; do
- modprobe -r `cat $i` 2>/dev/null
- done
- # remove device file and possible empty dirs
- rm -f bus/usb/$BUS/$USB_DEV
- rmdir bus/usb/$BUS/ 2>/dev/null
- rmdir bus/usb/ 2>/dev/null
- rmdir bus/ 2>/dev/null
+add)
+ mkdir -p "${DEVNAME%/*}"
+ mv $MDEV $DEVNAME
+ # autoload driver
+ for i in /sys/$DEVPATH/*/modalias; do
+ [ -e "$i" ] && echo $i
+ done | xargs sort -u | xargs modprobe -a 2>/dev/null
+ ;;
+remove)
+ rm $DEVNAME
+ ;;
esac
+