5f7d422aed72a1b2afbcdc04979ae8f4e8d5754b
[wl12xx/compat-wireless.git] / scripts / driver-select
1 #!/bin/bash
2 # Copyright 2009        Luis R. Rodriguez <mcgrof@gmail.com>
3 #
4 # This this to select your compat-wireless driver and
5 # reduce compilation time.
7 DRIVERS_MAKEFILE="drivers/net/wireless/Makefile"
8 ATH_MAKEFILE="drivers/net/wireless/ath/Makefile"
9 ATH9K_MAKEFILE="drivers/net/wireless/ath/ath9k/Makefile"
10 RT2X00_MAKEFILE="drivers/net/wireless/rt2x00/Makefile"
11 NET_WIRELESS_MAKEFILE="net/wireless/Makefile"
12 EEPROM_MAKEFILE="drivers/misc/eeprom/Makefile"
13 DRIVERS_NET="drivers/net/Makefile"
14 DRIVERS_NET_USB_MAKEFILE="drivers/net/usb/Makefile"
15 SSB_MAKEFILE="drivers/ssb/Makefile"
17 # used to backup files from foo to foo.${BACKUP_EXT}
18 # If you change this also modify restore_compat() and
19 # restore_file() below I couldn't find a way to use
20 # the $BACKUP_EXT there.
21 BACKUP_EXT="bk"
23 # Pretty colors
24 GREEN="\033[01;32m"
25 YELLOW="\033[01;33m"
26 NORMAL="\033[00m"
27 BLUE="\033[34m"
28 RED="\033[31m"
29 PURPLE="\033[35m"
30 CYAN="\033[36m"
31 UNDERLINE="\033[02m"
33 SUPPORTED_80211_DRIVERS="ath5k ath9k ath9k_htc ar9170 b43 zd1211rw rt2x00"
35 if [ -d drivers/staging/ath6kl ]; then
36         SUPPORTED_80211_DRIVERS="$SUPPORTED_80211_DRIVERS ath6kl"
37 fi
39 # b43 needs some more work for driver-select, the SSB stuff, plus
40 # what if you update b44 but not b43? It will bust.
41 SUPPORTED_ETH_DRIVERS="atl1 atl2 atl1e atl1c"
43 function usage {
44         echo -e "${GREEN}Usage${NORMAL}: ${CYAN}$0${NORMAL} [ ${PURPLE}<driver-name>${NORMAL} | ${PURPLE}<driver-group-name>${NORMAL} | ${GREEN}restore${NORMAL} ]"
46         # These should match the switch below.
47         echo -e "Supported 802.11 drivers:"
48         for i in $SUPPORTED_80211_DRIVERS; do
49                 echo -e "\t${PURPLE}${i}${NORMAL}"
50         done
52         echo -e "\nSupported Ethernet drivers:"
53         for i in $SUPPORTED_ETH_DRIVERS; do
54                 echo -e "\t${PURPLE}${i}${NORMAL}"
55         done
57         # These should match the switch below.
58         echo -e "\nSupported group drivers:"
59         echo -e "\t${CYAN}atheros${NORMAL} < ${PURPLE} ath5k ath9k ar9170 zd1211rw ${NORMAL}>"
60         echo -e "\t${CYAN}ath${NORMAL} < ${PURPLE} ath5k ath9k ar9170 ${NORMAL}>"
61         echo -e "\t${CYAN}intel${NORMAL} < ${PURPLE} iwl3945 iwlagn ipw2100 ipw2200 ${NORMAL}>"
62         echo -e "\t${CYAN}iwlwifi${NORMAL} < ${PURPLE} iwl3945 iwlagn ${NORMAL}>"
63         echo -e "\t${CYAN}rtl818x${NORMAL} < ${PURPLE} rtl8180 rtl8187 ${NORMAL}>"
64         echo -e "\t${CYAN}wl12xx${NORMAL} < ${PURPLE} wl1251 (SPI and SDIO) wl1271 ${NORMAL}>"
66         echo -e "Restoring compat-wireless:"
67         echo -e "\t${GREEN}restore${NORMAL}: you can use this option to restore compat-wireless to the original state"
68 }
70 function backup_file {
71         if [ -f $1.${BACKUP_EXT} ]; then
72                 echo -e "Backup exists: ${CYAN}${1}.${BACKUP_EXT}${NORMAL}"
73                 return
74         fi
75         echo -e "Backing up makefile: ${CYAN}${1}.${BACKUP_EXT}${NORMAL}"
76         cp $1 $1.bk
77 }
79 function disable_makefile
80 {
81         backup_file $1
82         echo > $1
83 }
85 function select_driver 
86 {
87         backup_file $DRIVERS_MAKEFILE
88         perl -i -ne 'print if /'$1'/ ' $DRIVERS_MAKEFILE
89 }
91 function select_drivers
92 {
93         backup_file $DRIVERS_MAKEFILE
94         CONFIGS=""
95         COUNT=0
96         for i in $@; do
97                 if [[ "$CONFIGS" = "" ]]; then
98                         CONFIGS="$i"
99                 else
100                         CONFIGS="${CONFIGS}|$i"
101                 fi
102         done
103         egrep "$CONFIGS" $DRIVERS_MAKEFILE > ${DRIVERS_MAKEFILE}.tmp
104         mv ${DRIVERS_MAKEFILE}.tmp ${DRIVERS_MAKEFILE}
107 function disable_lib80211
109         backup_file $NET_WIRELESS_MAKEFILE
110         perl -i -ne 'print if ! /LIB80211/ ' $NET_WIRELESS_MAKEFILE
113 function disable_b44 {
114         backup_file $DRIVERS_NET
115         perl -i -ne 'print if ! /CONFIG_B44/ ' $DRIVERS_NET
118 function disable_ssb
120         disable_b44
121         disable_makefile ${SSB_MAKEFILE}
122         perl -i -ne 'print if ! /drivers\/ssb\/ \\/ ' Makefile
125 function disable_rfkill
127         backup_file Makefile
128         perl -i -ne 'print if ! /CONFIG_COMPAT_RFKILL/' Makefile
131 function disable_eeprom
133         disable_makefile ${EEPROM_MAKEFILE}
134         perl -i -ne 'print if ! /drivers\/misc\/eeprom\/ \\/' Makefile
137 function disable_usbnet
139         disable_makefile ${DRIVERS_NET_USB_MAKEFILE}
140         perl -i -ne 'print if ! /drivers\/net\/usb\/ \\/' Makefile
143 function disable_usbnet {
144         perl -i -ne 'print if ! /CONFIG_COMPAT_NET_USB_MODULES/' Makefile
145
147 function disable_ethernet {
148         perl -i -ne 'print if ! /CONFIG_COMPAT_NETWORK_MODULES/' Makefile
149
151 function disable_var_03 {
152         perl -i -ne 'print if ! /CONFIG_COMPAT_BLUETOOTH/' Makefile
153
155 function disable_bt {
156         perl -i -ne 'print if ! /CONFIG_COMPAT_VAR_MODULES/' Makefile
157
159 function disable_80211 {
160         perl -i -ne 'print if ! /CONFIG_COMPAT_WIRELESS/' Makefile
163 function disable_bt_usb_ethernet_var {
164         backup_file Makefile
165         disable_usbnet
166         disable_ethernet
167         disable_var_03
168         disable_bt
169
171 function enable_only_ethernet {
172         backup_file Makefile
173         backup_file $DRIVERS_NET
174         disable_usbnet
175         disable_var_03
176         disable_bt
177         # rfkill may be needed if you enable b44 as you may have b43
178         disable_rfkill
179         disable_80211
182 function disable_var {
183         disable_ssb
184         disable_usbnet
185         disable_eeprom
186
188 function disable_var_01 {
189         disable_lib80211
190         disable_var
193 function disable_var_02 {
194         #var_01 with eeprom not disabled
195         disable_lib80211
196         disable_ssb
197         disable_usbnet
200 function select_ath_driver 
202         backup_file $ATH_MAKEFILE
203         perl -i -ne 'print if /'$1'/ || /CONFIG_ATH_/ || /ath-objs/ || /regd.o/ || /hw.o/ ' $ATH_MAKEFILE
204         disable_var_01
207 function select_ath9k_driver
209         select_ath_driver CONFIG_ATH9K_HW
210         # In the future here we'll add stuff to disable ath9k_htc
213 # iwlwifi stuff needs more work
214 function select_iwl_driver 
216         perl -i -ne 'print if /'$1'/ || /CONFIG_BLEH/ ' drivers/net/wireless/iwlwifi/Makefile
217         disable_var_01
220 function restore_file {
221         #ORIG=$(shell ${1%%.${BACKUP_EXT}})
222         ORIG=${1%%.bk}
223         cp $1 $ORIG
224         rm -f $1
225         echo -e "Restored makefile: ${CYAN}${ORIG}${NORMAL} (and removed backup)"
228 function restore_compat {
229         #FILES=$(find ./ -type f -name *.$BACKUP_EXT)
230         FILES=$(find ./ -type f -name *.bk)
231         for i in $FILES; do
232                 restore_file $i
233         done
236 if [ $# -ne 1 ]; then
237         usage
238         exit
239 fi
241 if [ ! -f compat_version ]; then
242         echo "Must run $0 from the compat-wireless top level directory"
243         exit
244 fi
246 if [[ ! -f built-in.o ]]; then
247         if [[ "$1" != "restore" ]]; then
248                 echo -e "${YELLOW}Processing new driver-select request...${NORMAL}"
249         fi
250 fi
252 # Always backup the top level Makefile, unless restoring
253 if [[ "$1" != "restore" ]]; then
254         backup_file Makefile
255 fi
257 # If a user selects a new driver make sure we clean up for them
258 # first and also restore the backup makefiles then. Otherwise
259 # we'll be trying to leave drivers on Makefiles which are not
260 # already there from a previous run.
261 if [ -f built-in.o ]; then
262         echo -e "${YELLOW}Old build found, going to clean this up first...${NORMAL}"
263         make clean
264         echo -e "${YELLOW}Restoring Makefiles...${NORMAL}"
265         ./$0 restore
266 fi
268 case $1 in
269         restore)
270                 restore_compat
271                 ;;
272         atheros)
273                 select_drivers          CONFIG_ATH_COMMON \
274                                         CONFIG_ZD1211RW
275                 disable_var_01
276                 ;;
277         ath)
278                 disable_bt_usb_ethernet_var
279                 select_drivers          CONFIG_ATH_COMMON
280                 disable_var_01
281                 ;;
282         intel)
283                 select_drivers          CONFIG_IWLWIFI \
284                                         CONFIG_IPW
285                 disable_var
286                 ;;
287         iwlwifi)
288                 select_driver           CONFIG_IWLWIFI
289                 disable_var_01
290                 ;;
291         wl12xx)
292                 select_drivers          CONFIG_WL12XX
293                 disable_var_01
294                 ;;
295         ath5k)
296                 disable_bt_usb_ethernet_var
297                 select_driver           CONFIG_ATH_COMMON
298                 select_ath_driver       CONFIG_ATH5K
299                 #patch -p1 < enable-older-kernels/enable-2.6.23.patch
300                 ;;
301         ath9k)
302                 disable_bt_usb_ethernet_var
303                 select_driver           CONFIG_ATH_COMMON
304                 select_ath9k_driver
305                 patch -p1 < enable-older-kernels/enable-2.6.24.patch
306                 ;;
307         ar9170)
308                 disable_bt_usb_ethernet_var
309                 select_driver           CONFIG_ATH_COMMON
310                 select_ath_driver       CONFIG_AR9170_USB
311                 ;;
312         ath9k_htc)
313                 disable_bt_usb_ethernet_var
314                 select_driver           CONFIG_ATH_COMMON
315                 select_ath9k_driver
316                 ;;
317         ath6kl)
318                 disable_bt_usb_ethernet_var
319                 select_driver           CONFIG_NOTHING
320                 sed -e 's|net/mac80211/||' Makefile > Makefile.ath6kl
321                 mv Makefile.ath6kl Makefile
322                 ;;
323         rtl818x)
324                 select_drivers          CONFIG_RTL8180 CONFIG_RTL8187
325                 disable_var_02
326                 ;;
327         zd1211rw)
328                 select_driver           CONFIG_ZD1211RW
329                 disable_var_01
330                 ;;
331         b43)
332                 disable_usbnet
333                 disable_ethernet
334                 disable_var_03
335                 select_driver           CONFIG_B43
336                 ;;
337         rt2x00)
338                 select_driver           CONFIG_RT2X00
339                 disable_var_02
340                 ;;
341         atl1)
342                 enable_only_ethernet
343                 echo -e "obj-\$(CONFIG_ATL1) += atlx/" > $DRIVERS_NET
344                 ;;
345         atl2)
346                 enable_only_ethernet
347                 echo -e "obj-\$(CONFIG_ATL2) += atlx/" > $DRIVERS_NET
348                 ;;
349         atl1e)
350                 enable_only_ethernet
351                 echo -e "obj-\$(CONFIG_ATL1E) += atl1e/" > $DRIVERS_NET
352                 ;;
353         atl1c)
354                 enable_only_ethernet
355                 echo -e "obj-\$(CONFIG_ATL1C) += atl1c/" > $DRIVERS_NET
356                 ;;
357         *)
358                 echo "Unsupported driver"
359                 exit
360                 ;;
361 esac