Magellan Linux

Annotation of /trunk/busybox/usbdev.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1233 - (hide annotations) (download) (as text)
Fri Dec 10 22:49:20 2010 UTC (13 years, 5 months ago) by niro
File MIME type: application/x-sh
File size: 1648 byte(s)
-tuned mdev.conf and process uevents (need initscripts with trigger_uevent support)
-added mdev helpers
-added rc script for syslogd, needed by dropbear
1 niro 1233 #!/bin/sh
2    
3     # script is buggy; until patched just do exit 0
4     #exit 0
5    
6     # add zeros to device or bus
7     add_zeros () {
8     case "$(echo $1 | wc -L)" in
9     1) echo "00$1" ;;
10     2) echo "0$1" ;;
11     *) echo "$1"
12     esac
13     exit 0
14     }
15    
16    
17     # bus and device dirs in /sys
18     local USB_PATH=$(echo $MDEV | sed -e 's/usbdev\([0-9]\).[0-9]/usb\1/')
19     USB_PATH=$(find /sys/devices -type d -name "$USB_PATH")
20     local USB_DEV_DIR=$(echo $MDEV | sed -e 's/usbdev\([0-9]\).\([0-9]\)/\1-\2/')
21    
22     # dir names in /dev
23     local BUS=$(add_zeros $(echo $MDEV | sed -e 's/^usbdev\([0-9]\).[0-9]/\1/'))
24     local USB_DEV=$(add_zeros $(echo $MDEV | sed -e 's/^usbdev[0-9].\([0-9]\)/\1/'))
25    
26    
27     # try to load the proper driver for usb devices
28     case "$ACTION" in
29     add|"")
30     # load usb bus driver
31     for i in $USB_PATH/*/modalias ; do
32     modprobe `cat $i` 2>/dev/null
33     done
34     # load usb device driver if existent
35     if [ -d $USB_PATH/$USB_DEV_DIR ]; then
36     for i in $USB_PATH/$USB_DEV_DIR/*/modalias ; do
37     modprobe `cat $i` 2>/dev/null
38     done
39     fi
40     # move usb device file
41     mkdir -p bus/usb/$BUS
42     mv $MDEV bus/usb/$BUS/$USB_DEV
43     ;;
44     remove)
45     # unload device driver, if device dir is existent
46     if [ -d $USB_PATH/$USB_DEV_DIR ]; then
47     for i in $USB_PATH/$USB_DEV_DIR/*/modalias ; do
48     modprobe -r `cat $i` 2>/dev/null
49     done
50     fi
51     # unload usb bus driver. Does this make sense?
52     # what happens, if two usb devices are plugged in
53     # and one is removed?
54     for i in $USB_PATH/*/modalias ; do
55     modprobe -r `cat $i` 2>/dev/null
56     done
57     # remove device file and possible empty dirs
58     rm -f bus/usb/$BUS/$USB_DEV
59     rmdir bus/usb/$BUS/ 2>/dev/null
60     rmdir bus/usb/ 2>/dev/null
61     rmdir bus/ 2>/dev/null
62     esac