summaryrefslogtreecommitdiff
path: root/scripts/driver-select
blob: 862f43bff934ef71cbe9b8033446bca5ec3b273c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
#!/usr/bin/env bash
# Copyright 2009        Luis R. Rodriguez <mcgrof@gmail.com>
#
# This script allows you to select your compat-drivers driver and
# reduce compilation time.

COMPAT_CONFIG_CW="config.mk"
DRIVERS_MAKEFILE="drivers/net/wireless/Makefile"
ATH_MAKEFILE="drivers/net/wireless/ath/Makefile"
ATH9K_MAKEFILE="drivers/net/wireless/ath/ath9k/Makefile"
BRCM80211_MAKEFILE="drivers/net/wireless/brcm80211/Makefile"
RT2X00_MAKEFILE="drivers/net/wireless/rt2x00/Makefile"
TI_MAKEFILE="drivers/net/wireless/ti/Makefile"
NET_WIRELESS_MAKEFILE="net/wireless/Makefile"
EEPROM_MAKEFILE="drivers/misc/eeprom/Makefile"
DRIVERS_NET_ATHEROS="drivers/net/ethernet/atheros/Makefile"
DRIVERS_NET_BROADCOM="drivers/net/ethernet/broadcom/Makefile"
DRIVERS_NET_USB_MAKEFILE="drivers/net/usb/Makefile"
SSB_MAKEFILE="drivers/ssb/Makefile"
BCMA_MAKEFILE="drivers/bcma/Makefile"

# used to backup files from foo to foo.${BACKUP_EXT}
BACKUP_EXT="bk"

# Pretty colors
GREEN="\033[01;32m"
YELLOW="\033[01;33m"
NORMAL="\033[00m"
BLUE="\033[34m"
RED="\033[31m"
PURPLE="\033[35m"
CYAN="\033[36m"
UNDERLINE="\033[02m"

SUPPORTED_80211_DRIVERS="ath5k ath9k ath9k_ap ath9k_htc carl9170 ath6kl ar5523 wil6210 b43 zd1211rw rt2x00 wl1251 wl12xx brcmsmac brcmfmac mac80211_hwsim"

# b43 needs some more work for driver-select, the SSB stuff, plus
# what if you update b44 but not b43? It will bust.
SUPPORTED_ETH_DRIVERS="atl1 atl2 atl1e atl1c alx"

SUPPORTED_DRM_DRIVERS="i915"

function usage {
	echo -e "${GREEN}Usage${NORMAL}: ${BOLD}$0${NORMAL} [ ${PURPLE}<driver-name>${NORMAL} | ${CYAN}<driver-group-name>${NORMAL} | ${GREEN}restore${NORMAL} ]"

	# These should match the switch below.
	echo -e "Supported 802.11 drivers:"
	for i in $SUPPORTED_80211_DRIVERS; do
		echo -e "\t${PURPLE}${i}${NORMAL}"
	done

	echo
	echo -e "Supported Ethernet drivers:"
	for i in $SUPPORTED_ETH_DRIVERS; do
		echo -e "\t${PURPLE}${i}${NORMAL}"
	done

	echo -e "Supported DRM drivers:"
	for i in $SUPPORTED_DRM_DRIVERS; do
		echo -e "\t${PURPLE}${i}${NORMAL}"
	done

	# These should match the switch below.
	echo -e "\nSupported group drivers:"
	echo -e "\t${CYAN}atheros${NORMAL} < ${PURPLE} ath5k ath9k carl9170 zd1211rw ath6kl wil6210 ar5523${NORMAL}>"
	echo -e "\t${CYAN}ath${NORMAL} < ${PURPLE} ath5k ath9k carl9170 ath6kl wil6210 ar5523${NORMAL}>"
	echo -e "\t${CYAN}brcm80211${NORMAL} < ${PURPLE} brcmsmac brcmfmac ${NORMAL}>"
	echo -e "\t${CYAN}intel${NORMAL} < ${PURPLE} iwlwifi, iwlegacy ${NORMAL}>"
	echo -e "\t${CYAN}rtl818x${NORMAL} < ${PURPLE} rtl8180 rtl8187 ${NORMAL}>"
	echo -e "\t${CYAN}rtlwifi${NORMAL} < ${PURPLE} rtl8192ce ${NORMAL}>"
	echo -e "\t${CYAN}ti${NORMAL} < ${PURPLE} wl1251 wl12xx (SPI and SDIO)${NORMAL}>"
	
	echo -e "\nSupported group drivers: Bluetooth & Ethernet:"
	echo -e "\t${CYAN}atlxx${NORMAL} < ${PURPLE} atl1 atl2 atl1e alx${NORMAL}>"
	echo -e "\t${CYAN}bt${NORMAL} < ${PURPLE} Linux bluetooth drivers ${NORMAL}>"

	echo -e "\nSupported group drivers: DRM:"
	echo -e "\t${CYAN}drm${NORMAL} < ${PURPLE} i915${NORMAL}>"

	echo -e "Restoring compat-drivers:"
	echo -e "\t${GREEN}restore${NORMAL}: you can use this option to restore compat-drivers to the original state"
}

function backup_file {
	if [ -f $1.${BACKUP_EXT} ]; then
		echo -e "Backup exists: ${CYAN}${1}.${BACKUP_EXT}${NORMAL}"
		return
	fi
	echo -e "Backing up makefile: ${CYAN}${1}.${BACKUP_EXT}${NORMAL}"
	cp "${1}" "${1}.${BACKUP_EXT}"
}

function disable_makefile
{
	backup_file $1
	echo > $1
}

function select_drivers_from_makefile
{
	MAKEFILE="$1"
	shift
	backup_file $MAKEFILE
	CONFIGS=""
	COUNT=0
	for i in $@; do
		if [[ "$CONFIGS" = "" ]]; then
			CONFIGS="$i"
		else
			CONFIGS="${CONFIGS}|$i"
		fi
	done
	egrep "$CONFIGS" $MAKEFILE > ${MAKEFILE}.tmp
	mv ${MAKEFILE}.tmp ${MAKEFILE}
}

function select_drivers
{
	select_drivers_from_makefile $DRIVERS_MAKEFILE $@
}

function disable_lib80211
{
	backup_file $NET_WIRELESS_MAKEFILE
	perl -i -ne 'print if ! /LIB80211/ ' $NET_WIRELESS_MAKEFILE
}

function disable_b44 {
	backup_file $DRIVERS_NET_BROADCOM
	perl -i -ne 'print if ! /CONFIG_B44/ ' $DRIVERS_NET_BROADCOM
}

function disable_ssb
{
	disable_makefile ${SSB_MAKEFILE}
	perl -i -ne 'print if ! /drivers\/ssb\//' Makefile
}

function disable_bcma
{
	disable_makefile ${BCMA_MAKEFILE}
	perl -i -ne 'print if ! /drivers\/bcma\//' Makefile
}

function disable_rfkill
{
	backup_file Makefile
	perl -i -ne 'print if ! /CONFIG_COMPAT_RFKILL/' Makefile
}

function disable_eeprom
{
	disable_makefile ${EEPROM_MAKEFILE}
	perl -i -ne 'print if ! /drivers\/misc\/eeprom\//' Makefile
}

function disable_usbnet
{
	disable_makefile ${DRIVERS_NET_USB_MAKEFILE}
	perl -i -ne 'print if ! /drivers\/net\/usb\//' Makefile
}

function disable_usbnet {
	perl -i -ne 'print if ! /CONFIG_COMPAT_NET_USB_MODULES/' Makefile
} 

function disable_ethernet {
	perl -i -ne 'print if ! /CONFIG_COMPAT_NETWORK_MODULES/' Makefile
} 

function disable_var_03 {
	perl -i -ne 'print if ! /CONFIG_COMPAT_VAR_MODULES/' Makefile
} 

function disable_bt {
	perl -i -ne 'print if ! /CONFIG_COMPAT_BLUETOOTH/' Makefile
} 

function disable_80211 {
	perl -i -ne 'print if ! /CONFIG_COMPAT_WIRELESS/' Makefile
}

function disable_drm {
	perl -i -ne 'print if ! /CONFIG_COMPAT_VIDEO_MODULES/' Makefile
}

function disable_bt_usb_ethernet {
	backup_file Makefile
	disable_usbnet
	disable_ethernet
	disable_bt
	disable_update-initramfs
	disable_drm
}

function disable_bt_usb_ethernet_var {
	backup_file Makefile
	disable_bt_usb_ethernet
	disable_var_03
}

function enable_only_ethernet {
	backup_file Makefile
	backup_file $DRIVERS_NET_BROADCOM
	backup_file $DRIVERS_NET_ATHEROS
	disable_staging
	disable_usbnet
	disable_var_03
	disable_bt
	disable_drm
	# rfkill may be needed if you enable b44 as you may have b43
	disable_rfkill
	disable_80211
}

function disable_var {
	disable_ssb
	disable_bcma
	disable_usbnet
	disable_eeprom
	disable_update-initramfs
} 

function disable_var_01 {
	disable_lib80211
	disable_var
}

function disable_var_02 {
	#var_01 with eeprom not disabled
	disable_lib80211
	disable_ssb
	disable_bcma
	disable_usbnet
	disable_update-initramfs
}

function disable_staging {
	backup_file Makefile
	perl -i -ne 'print if ! /CONFIG_COMPAT_STAGING/ ' Makefile
}

function disable_update-initramfs
{
	backup_file Makefile
	perl -i -ne 'print if ! /update-initramfs/' Makefile
}

function enable_only_drm {
	backup_file Makefile
	disable_ethernet
	disable_staging
	disable_usbnet
	disable_var_03
	disable_bt
	# rfkill may be needed if you enable b44 as you may have b43
	disable_rfkill
	disable_80211
}

function select_ath_driver 
{
	backup_file $ATH_MAKEFILE
	perl -i -ne 'print if /'$1'/ || /CONFIG_ATH_/ || /ath-objs/ || /regd.o/ || /hw.o/ || /key.o/' $ATH_MAKEFILE
	disable_var_01
}

function select_ath_no_common
{
	backup_file $ATH_MAKEFILE
	perl -i -ne 'print if /'$1'/' $ATH_MAKEFILE
	disable_var_01
}

function select_ath9k_driver
{
	select_ath_driver CONFIG_ATH9K_HW
	# In the future here we'll add stuff to disable ath9k_htc
}

function select_ath9k_driver_ap
{
	select_ath9k_driver
	backup_file $COMPAT_CONFIG_CW
	perl -i -ne 'print if ! /CONFIG_COMPAT_ATH9K_RATE_CONTROL/ ' $COMPAT_CONFIG_CW
}

function select_ti_drivers
{
	select_drivers CONFIG_WL_TI
	select_drivers_from_makefile $TI_MAKEFILE $@
}

function select_brcm80211_driver 
{
	backup_file $BRCM80211_MAKEFILE
	perl -i -ne 'print if /'$1'/ || /CONFIG_BRCMUTIL/ ' $BRCM80211_MAKEFILE
}

function restore_file {
	local ORIG="${1%%.${BACKUP_EXT}}"
	cp $1 $ORIG
	rm -f $1
	echo -e "Restored makefile: ${CYAN}${ORIG}${NORMAL} (and removed backup)"
}

function restore_compat {
	local FILES=$(find ./ -type f -name *\."${BACKUP_EXT}")
	for i in $FILES; do
		restore_file $i
	done
}

if [ $# -ne 1 ]; then
	usage
	exit
fi

if [ ! -f .compat_version ]; then
	echo "Must run $0 from the compat-drivers top level directory"
	exit
fi

if [[ ! -f built-in.o ]]; then
	if [[ "$1" != "restore" ]]; then
		echo -e "${PURPLE}Processing new driver-select request...${NORMAL}"
	fi
fi

# Always backup the top level Makefile, unless restoring
if [[ "$1" != "restore" ]]; then
	backup_file Makefile
fi

# If a user selects a new driver make sure we clean up for them
# first and also restore the backup makefiles then. Otherwise
# we'll be trying to leave drivers on Makefiles which are not
# already there from a previous run.
if [ -f built-in.o ]; then
	echo -e "${PURPLE}Old build found, going to clean this up first...${NORMAL}"
	make clean
	echo -e "${PURPLE}Restoring Makefiles...${NORMAL}"
	./$0 restore
fi

case $1 in
	restore)
		restore_compat
		;;
# Group drivers
	atheros)
		select_drivers		CONFIG_ATH_CARDS \
					CONFIG_COMPAT_ZD1211RW
		disable_staging
		disable_bt_usb_ethernet_var
		disable_var_01
		;;
	ath)
		disable_bt_usb_ethernet_var
		select_drivers		CONFIG_ATH_CARDS
		disable_var_01
		;;
	intel)
		select_drivers		CONFIG_IWLWIFI \
					CONFIG_IWLEGACY \
					CONFIG_IPW
		disable_staging
		disable_var
		disable_bt
		disable_ethernet
		disable_usbnet
		;;
	iwlwifi)
		select_drivers		CONFIG_IWLWIFI
		disable_staging
		disable_var_01
		disable_bt
		disable_ethernet
		disable_usbnet
		;;
	iwlegacy)
		select_drivers		CONFIG_IWLEGACY
		disable_staging
		disable_var_01
		disable_bt
		disable_ethernet
		disable_usbnet
		;;
	rtl818x)
		select_drivers		CONFIG_RTL8180 CONFIG_RTL8187
		disable_staging
		disable_bt_usb_ethernet
		disable_ssb
		disable_bcma
		disable_lib80211
		;;
	rtlwifi)
		select_drivers		CONFIG_RTL8192CE CONFIG_RTLWIFI
		disable_staging
		disable_bt_usb_ethernet_var
		disable_lib80211
		;;
	ti)
		select_drivers		CONFIG_WL_TI
		disable_bt_usb_ethernet_var
		disable_staging
		disable_var_01
		;;
	brcm80211)
		disable_staging
		disable_bt_usb_ethernet_var
		select_drivers		CONFIG_BRCMUTIL \
					CONFIG_BRCMFMAC \
					CONFIG_BRCMSMAC
		;;
# Singular modules
	ath5k)
		disable_staging
		disable_bt_usb_ethernet_var
		select_drivers		CONFIG_ATH_CARDS
		select_ath_driver	CONFIG_ATH5K
		#patch -p1 < enable-older-kernels/enable-2.6.23.patch
		;;
	ath9k)
		disable_staging
		disable_bt_usb_ethernet_var
		select_drivers		CONFIG_ATH_CARDS
		select_ath9k_driver
		;;
	ath9k_ap)
		disable_staging
		disable_bt_usb_ethernet_var
		select_drivers		CONFIG_ATH_CARDS
		select_ath9k_driver_ap
		;;
	carl9170)
		disable_staging
		disable_bt_usb_ethernet_var
		select_drivers		CONFIG_ATH_CARDS
		select_ath_driver	CONFIG_CARL9170
		;;
	ath9k_htc)
		disable_staging
		disable_bt_usb_ethernet_var
		select_drivers		CONFIG_ATH_CARDS
		select_ath9k_driver
		;;
	ath6kl)
		disable_staging
		disable_bt_usb_ethernet_var
		select_drivers		CONFIG_ATH_CARDS
		select_ath_driver	CONFIG_ATH6KL
		;;
	wil6210)
		disable_staging
		disable_bt_usb_ethernet_var
		select_drivers		CONFIG_ATH_CARDS
		select_ath_no_common	CONFIG_WIL6210
		;;
	ar5523)
		disable_staging
		disable_bt_usb_ethernet_var
		select_drivers		CONFIG_ATH_CARDS
		select_ath_no_common	CONFIG_AR5523
		;;
	brcmsmac)
		disable_staging
		disable_bt_usb_ethernet_var
		select_drivers		CONFIG_BRCMSMAC
		select_brcm80211_driver	CONFIG_BRCMSMAC CONFIG_BRCMUTIL
		;;
	brcmfmac)
		disable_staging
		disable_bt_usb_ethernet_var
		select_drivers		CONFIG_BRCMFMAC
		select_brcm80211_driver	CONFIG_BRCMFMAC CONFIG_BRCMUTIL
		;;
	zd1211rw)
		select_drivers		CONFIG_COMPAT_ZD1211RW
		disable_staging
		disable_var_01
		;;
	b43)
		disable_staging
		disable_bt_usb_ethernet
		disable_eeprom
		disable_lib80211
		select_drivers		CONFIG_B43
		;;
	rt2x00)
		select_drivers		CONFIG_RT2X00
		disable_staging
		disable_bt_usb_ethernet
		disable_var_02
		;;
	wl1251)
		select_ti_drivers	CONFIG_WL1251
		disable_staging
		disable_var_01
		;;
	wl12xx)
		select_ti_drivers	CONFIG_WL12XX
		disable_staging
		disable_var_01
		;;
	wl18xx)
		select_ti_drivers	CONFIG_WL18XX
		disable_staging
		disable_var_01
		;;
	mac80211_hwsim)
		select_drivers		CONFIG_COMPAT_MAC80211_HWSIM
		disable_staging
		disable_bt_usb_ethernet_var
		;;
# Ethernet and Bluetooth drivers
	atl1)
		enable_only_ethernet
		disable_b44
		echo -e "obj-\$(CONFIG_ATL1) += atlx/" > $DRIVERS_NET_ATHEROS
		;;
	atl2)
		enable_only_ethernet
		disable_b44
		echo -e "obj-\$(CONFIG_ATL2) += atlx/" > $DRIVERS_NET_ATHEROS
		;;
	atl1e)
		enable_only_ethernet
		disable_b44
		echo -e "obj-\$(CONFIG_ATL1E) += atl1e/" > $DRIVERS_NET_ATHEROS
		;;
	atl1c)
		enable_only_ethernet
		disable_b44
		echo -e "obj-\$(CONFIG_ATL1C) += atl1c/" > $DRIVERS_NET_ATHEROS
		;;
	alx)
		enable_only_ethernet
		disable_b44
		echo -e "obj-\$(CONFIG_ALX) += alx/" > $DRIVERS_NET_ATHEROS
		;;
	atlxx)
		select_drivers		CONFIG_ATL1 CONFIG_ATL2 CONFIG_ATL1E CONFIG_ALX
		enable_only_ethernet
		disable_b44
		disable_update-initramfs
		;;
	bt)
		select_drivers 		CONFIG_BT
		disable_var
		disable_ethernet
		disable_staging
		disable_80211
		;;
	i915)
		enable_only_drm
		;;
	drm)
		enable_only_drm
		;;
	*)
		echo "Unsupported driver"
		exit
		;;
esac