wl1251: register platform_device to pass board data
[pandora-wifi.git] / scripts / modlib.sh
1 #!/bin/bash
2 #
3 # Copyright 2007        Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
4 #
5 # You can use these to enable/disable modules without blacklisting them
6
7 # Make sure our imporant paths are included
8 PATH=$PATH:/usr/sbin:/sbin
9
10 # Appended to module file at the end when we want to ignore one
11 IGNORE_SUFFIX=".ignore"
12 VER=`uname -r`
13
14 # If 'module' is found, its renamed to 'module.ignore'
15 function module_disable {
16         # Basic check to see if this is a module available for loading
17         MODULE_CHECK=`modprobe -l $1`
18         if [ -z $MODULE_CHECK ]; then
19                 echo "Module $1 not detected -- this is fine"
20                 return
21         fi
22         MODULE=$1
23         MODULE_KO=${MODULE}.ko
24         # In case there are more than one of these modules. This can 
25         # happen, for example if your distribution provides one and you have
26         # compiled one in yourself later.
27         MODULE_COUNT=`find /lib/modules/$VER/ -name $MODULE_KO | wc -l`
28         ALL_MODULES=`find /lib/modules/$VER/ -name $MODULE_KO`
29         COUNT=1
30         CHECK=`modprobe -l $MODULE`
31         for i in $ALL_MODULES; do
32                 if [[ $MODULE_COUNT -gt 1 ]]; then
33                         if [[ $COUNT -eq 1 ]]; then
34                                 echo -en "$MODULE_COUNT $MODULE modules found "
35                                 echo -e "we'll disable all of them"
36                         fi
37                         echo -en "Disabling $MODULE ($COUNT) ..."
38                 else
39                         echo -en "Disabling $MODULE ..."
40                 fi
41                 mv -f $i ${i}${IGNORE_SUFFIX}
42                 depmod -ae
43                 CHECK_AGAIN=`modprobe -l $MODULE`
44                 if [ "$CHECK" != "$CHECK_AGAIN" ]; then
45                         echo -e "\t[OK]\tModule disabled:"
46                         echo "$CHECK"
47                 else
48                         echo -e "[ERROR]\tModule is still being detected:"
49                         echo "$CHECK"
50                 fi
51                 let COUNT=$COUNT+1
52         done
53 }
54
55 # If 'module.ignore' is found, rename it back to 'module'
56 function module_enable {
57         MODULE=$1
58         MODULE_KO=${MODULE}.ko
59         IGNORED_MODULE=${MODULE_KO}${IGNORE_SUFFIX}
60         # In case there are more than one of these modules. This can 
61         # happen, for example if your distribution provides one and you have
62         # compiled one in yourself later.
63         ALL_MODULES=`find /lib/modules/$VER/ -name $IGNORED_MODULE`
64         for i in $ALL_MODULES; do
65                 echo -en "Enabling $MODULE ..."
66                 DIR=`dirname $i`
67                 mv $i $DIR/$MODULE_KO
68                 depmod -ae
69                 CHECK=`modprobe -l $MODULE`
70                 if [ "$DIR/$MODULE_KO" != $CHECK ]; then
71                         if [ -z $CHECK ]; then
72                                 echo -e "\t[ERROR]\tModule could not be enabled"
73                         else
74                                 echo -en "\t[OK]\tModule renamed but another "
75                                 echo "module file is being preferred"
76                                 echo -e "Renamed module:\t\t$DIR/$MODULE_KO"
77                                 echo -e "Preferred module:\t$CHECK"
78                         fi
79                 else
80                         echo -e "\t[OK]\tModule enabled: "
81                         echo "$DIR/$MODULE_KO"
82                 fi
83                 # Lets only do this for the first module found
84                 break
85         done
86 }
87