-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautokernconf.sh
executable file
·502 lines (437 loc) · 12.4 KB
/
autokernconf.sh
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
#!/bin/bash
#
# autoikernconf.sh : Kernal Automagical Configuration.
#
# Copyright (C) 2000,2001,2007,2011 Giacomo Catenazzi <[email protected]>
# This is free software, see GNU General Public License v2 for details.
#
# Version: 3.2 (24.III.2011)
# Maintainer: Giacomo Catenazzi <[email protected]>
# Mirror: http://cateee.net/autokernconf/
# Mailing List: [email protected]
# Credits:
# Peter Samuelson [scan_PCI function]
# William Stearns and Andreas Schwab [bash v.1 support]
# Andreas Jellinghaus
# tuantuan [handling CONFIG__UNKNOW__]
#
# This script try to autoconfigure the Linux kernel, detecting the
# hardware (devices, ...) and software (protocols, filesystems, ...).
# It uses soft detections: no direct IO access to unknow devices, thus
# it is always safe to run this script and it never hangs, but it cannot
# detect all hardware (mainly some very old hardware).
#
# Report errors, bugs, additions, wishes and comments <[email protected]>.
#
# Usage:
# General Hints:
# you don't need super user privileges.
# you can run this script on a target machine without the need of
# the kernel sources.
#
# Extra information for the developers:
# There are a lots of redundance: because user maybe has not already
# installed the drivers (thus we use smart detection on PCI, USB,..)
# and not all file methods are usable ('lspci' not installed,
# '/proc' not mounted or 'dmesg' not usable).
# We want to check the drivers that system needs, not the drivers
# actually installed on actual system (in this case you should
# simply check the 'System.map').
#
# This is a simple bash shell script. It use only the following external
# program:
# Req: bash[if,echo,test], grep/egrep, sed, uname, which, cp,mv,rm
# Opt: dmesg
# and read this files:
# Opt: /proc/*; /var/log/dmesg; /etc/fstab; linux/drivers/pci/pci.ids
#--- Configuration of kernautoconf ---#
CONF_AUTO=config.auto
AUTO_KAC=kdetect.list
LKDDB_URL="https://cateee.net/sources/lkddb/lkddb.list"
IFSorig="$IFS"
LANG=C
Null=/dev/null
# check if kdetect.list file has been generated, yet
if ! [ -f "$AUTO_KAC" ] ; then
echo "$AUTO_KAC not found. please run ./kdetect.sh first."
exit 1
fi
# check if lkddb.list file is available
if ! [ -f lkddb.list ] ; then
echo "lkddb.list not found"
# try to download if not
if [ -n "$(which wget)" ] ; then
wget "$LKDDB_URL" || exit 1
elif [ -n "$(which curl)" ] ; then
curl -O "$LKDDB_URL" || exit 1
else
# we can't work without the database
echo "Please download $LKDDB_URL"
exit 1
fi
fi
# start a new config.auto
echo "#" > $CONF_AUTO
echo "# Automagically generated file. Do not edit!" >> $CONF_AUTO
echo "# (autoprobe v1.5)" >> $CONF_AUTO
echo "#" >> $CONF_AUTO
#--- (Configuration of Autoconfigure) ---#
#--- Definition of the Configuration Interface ---#
# 'comment' writes comments on output file
#
# comment 'some comment'
#
comment() {
if [ "$PROVIDE_DEBUG" = "y" ]; then
echo "# --- $@ ---" >> $CONF_AUTO
fi
echo "$@"
}
#
# 'define' sets configuration (general funcions)
# 'found' sets the value 'y/m' (driver detected)
# 'found_y' sets the value 'y' (driver detected, forces built-in)
# 'found_m' sets the value 'm' (driver detected, build as module)
# 'found_n' sets the value 'n' (driver not needed)
# 'provide' sets a PROVIDE_ variable (internal variable)
#
# The priority is: y > m > n > 'other'
#
# Rules:
# string and and numeric variables: 'define'
# important configuration (needed to boot): 'found_y'
# normal detection: 'found'
# ...: 'found_m'
# not needed configuration: 'found_n'
# not detected: '' (nothing)
# internal uses: 'provide'
#
# define CONF value
# found VAR
# found_y VAR_FOO
# found_m VAR_BAR
# found_n VAR_OTHER
# provide VAR_FOO_AND_BAR
#
define () {
echo "$1=$2" >> $CONF_AUTO
eval "$1=$2"
}
# "${!conf}" is available only on bash2. Too new for us!
raw_found () {
define "CONFIG_$1" y
}
# enable all CONFIG_ entries from matching database entry
found () {
for conf in $(echo "$@" | sed -ne 's/^.*[ \t]*:\(.*\)*[ \t]*:.*$/\1/p' - ) ; do
if [ "$conf" == "CONFIG__UNKNOW__" ]; then
echo "# $@" >> $CONF_AUTO
elif [ "$(eval echo \$$conf)" != "y" ]; then
define "$conf" y
fi
done
}
found_y () {
for conf in "$@" ; do
if [ "$(eval echo \$$conf)" != "y" ]; then
define "$conf" y
fi
done
}
found_m () {
for conf in "$@" ; do
if [ "$(eval echo \$$conf)" != "y" -a "$(eval echo \$$conf)" != "m" ]; then
define "$conf" m
fi
done
}
found_n () {
for conf in "$@" ; do
if [ -z "$(eval echo \$$conf)" ]; then
define "$conf" n
fi
done
}
provide () {
if [ "$(eval echo \$PROVIDE_$1)" != "y" ]; then
eval "PROVIDE_$1=y"
fi
}
#--- (Definition of Configuration Interface) ---#
is_mid () {
[ $( (echo "$1"; echo "$2"; echo "$3") | sort -n | head -2 | tail -1 ) = "$2" ]
}
# check whether argument consists only of "."
is_all_wildcard () {
[ "$(echo $@ | sed 's| ||g ; s|\.\.*|\.|g')" == "." ]
}
# check whether argument is empty an string
is_empty () {
[ -z "$1" ]
}
# enable PCI support if pci devices were detected
if grep -sqi '^pci [0-9]' $AUTO_KAC; then
provide CONFIG_PCI
found CONFIG_PCI
fi
# parse kdetect.list
parse_kdetect_list () {
for conf in $(grep "^config " $AUTO_KAC ) ; do
if [ "$conf" != "config" ] ; then
raw_found $conf
fi
done
}
# bus specific device matching
hid () {
is_all_wildcard "$1" "$2" "$3" && return
if grep -sqe "^hid $1 $2 $3" $AUTO_KAC ; then
found "$@"
fi
}
hda () {
is_all_wildcard "$1" "$2" && return
if grep -sqe "^hda $1 $2" $AUTO_KAC ; then
found "$@"
fi
}
i2c () {
is_empty "$1" && return
is_all_wildcard "$1" && return
if grep -sqe "^i2c $1" $AUTO_KAC ; then
found "$@"
fi
}
eisa () {
is_empty "$1" && return
is_all_wildcard "$1" && return
if grep -sqe "^eisa $1" $AUTO_KAC ; then
found "$@"
fi
}
bcma () {
is_all_wildcard "$1" "$2" "$3" "$4" && return
if grep -sqe "^bcma $1 $2 $3 $4" $AUTO_KAC ; then
found "$@"
fi
}
input () {
is_all_wildcard "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" "$10" "$11" "$12" "$13" && return
if grep -sqe "^input $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13" $AUTO_KAC ; then
found "$@"
fi
}
i2c-snd () {
is_empty "$1" && return
is_all_wildcard "$1" && return
if grep -sqe "^i2c-snd $1" $AUTO_KAC ; then
found "$@"
fi
}
parisc () {
is_all_wildcard "$1" "$2" "$3" "$4" && return
if grep -sqe "^parisc $1 $2 $3 $4" $AUTO_KAC ; then
found "$@"
fi
}
pcmcia () {
is_all_wildcard "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9" && return
if grep -sqe "^pcmcia $1 $2 $3 $4 $5 $6 $7 $8 $9" $AUTO_KAC ; then
found "$@"
fi
}
of () {
is_all_wildcard "$1" "$2" "$3" && return
if grep -sqe "^of $1 $2 $3" $AUTO_KAC ; then
found "$@"
fi
}
spi () {
is_empty "$1" && return
is_all_wildcard "$1" && return
if grep -sqe "^spi $1" $AUTO_KAC ; then
found "$@"
fi
}
vio () {
is_all_wildcard "$1" "$2" && return
if grep -sqe "^vio $1 $2" $AUTO_KAC ; then
found "$@"
fi
}
virtio () {
is_all_wildcard "$1" "$2"&& return
if grep -sqe "^virtio $1 $2" $AUTO_KAC ; then
found "$@"
fi
}
ssb () {
is_all_wildcard "$1" "$2" "$3" && return
if grep -sqe "^ssb $1 $2 $3" $AUTO_KAC ; then
found "$@"
fi
}
sdio () {
is_all_wildcard "$1" "$2" "$3" && return
if grep -sqe "^sdio $1 $2 $3" $AUTO_KAC ; then
found "$@"
fi
}
tc () {
is_all_wildcard "$1" "$2" && return
if grep -sqe "^tc $1 $2" $AUTO_KAC ; then
found "$@"
fi
}
zorro () {
is_all_wildcard "$1" "$2" && return
if grep -sqe "^zorro $1 $2" $AUTO_KAC ; then
found "$@"
fi
}
kver () {
# silently ignore
return
}
pci () {
is_all_wildcard "$1" "$2" "$3" "$4" "$5" && return
if grep -sqe "^pci $1 $2 $3 $4 $5" $AUTO_KAC ; then
found "$@"
fi
}
pci_epf () {
is_empty "$1" && return
is_all_wildcard "$1" && return
if grep -sqe "^pci_epf $1" $AUTO_KAC ; then
found "$@"
fi
}
rpmsg () {
is_empty "$1" && return
is_all_wildcard "$1" && return
if grep -sqe "^rpmsg $1" $AUTO_KAC ; then
found "$@"
fi
}
slim () {
is_all_wildcard "$1" "$2" "$3" "$4" && return
if grep -sqe "^slim $1 $2 $3 $4" $AUTO_KAC ; then
found "$@"
fi
}
usb () {
is_all_wildcard "$1" "$2" "$3" "$4" && return
line=$(grep -oe "^usb $1 $2 $3 $4" $AUTO_KAC )
if [ -n "$line" ] ; then
bcd=$(echo "$line" | grep -o '....$' )
if [ "$bcd" = "...." ] ; then
found "$@"
else
if is_mid "$bcd" "$5" "$6" ; then
found "$@"
fi
fi
fi
}
ieee1394 () {
is_all_wildcard "$1" "$2" "$3" "$4" && return
if grep -sqe "^ieee1394 $1 $2 $3 $4" $AUTO_KAC ; then
found "$@"
fi
}
ccw () {
is_all_wildcard "$1" "$2" "$3" "$4" && return
if grep -sqe "^ccw $1 $2 $3 $4" $AUTO_KAC ; then
found "$@"
fi
}
ap () {
is_empty "$1" && return
is_all_wildcard "$1" && return
if grep -sqe "^ap $1" $AUTO_KAC ; then
found "$@"
fi
}
acpi () {
is_empty "$1" && return
is_all_wildcard "$1" && return
if grep -sqe "^acpi $1" $AUTO_KAC ; then
found "$@"
fi
}
pnp () {
is_empty "$1" && return
is_all_wildcard "$1" && return
if grep -sqe "^pnp $1" $AUTO_KAC ; then
found "$@"
fi
}
serio () {
is_all_wildcard "$1" "$2" "$3" "$4" && return
if grep -sqe "^serio $1 $2 $3 $4" $AUTO_KAC ; then
found "$@"
fi
}
platform () {
is_empty "$1" && return
is_all_wildcard "$1" && return
if grep -sqe "^platform $1" $AUTO_KAC ; then
found "$@"
fi
}
fs () {
is_empty "$1" && return
is_all_wildcard "$1" && return
if grep -sqe "^fs $1" $AUTO_KAC ; then
found "$@"
fi
}
module () {
is_empty "$1" && return
is_all_wildcard "$1" && return
if grep -sqe "^module $1" $AUTO_KAC ; then
found "$@"
fi
}
#----------#
lkddb () {
[ "$1" = "pci" ] && ( shift; pci "$@" ; return )
[ "$1" = "pci_epf" ] && ( shift; pci_epf "$@" ; return )
[ "$1" = "usb" ] && ( shift; usb "$@" ; return )
[ "$1" = "ieee1394" ] && ( shift; ieee1394 "$@" ; return )
[ "$1" = "ccw" ] && ( shift; ccw "$@" ; return )
[ "$1" = "ap" ] && ( shift; ap "$@" ; return )
[ "$1" = "acpi" ] && ( shift; acpi "$@" ; return )
[ "$1" = "pnp" ] && ( shift; pnp "$@" ; return )
[ "$1" = "serio" ] && ( shift; serio "$@" ; return )
[ "$1" = "platform" ] && ( shift; platform "$@" ; return )
[ "$1" = "fs" ] && ( shift; fs "$@" ; return )
[ "$1" = "module" ] && ( shift; module "$@" ; return )
[ "$1" = "hid" ] && ( shift; hid "$@" ; return )
[ "$1" = "hda" ] && ( shift; hda "$@" ; return )
[ "$1" = "i2c" ] && ( shift; i2c "$@" ; return )
[ "$1" = "eisa" ] && ( shift; eisa "$@" ; return )
[ "$1" = "bcma" ] && ( shift; bcma "$@" ; return )
[ "$1" = "input" ] && ( shift; input "$@" ; return )
[ "$1" = "i2c-snd" ] && ( shift; i2c-snd "$@" ; return )
[ "$1" = "parisc" ] && ( shift; parisc "$@" ; return )
[ "$1" = "pcmcia" ] && ( shift; pcmcia "$@" ; return )
[ "$1" = "of" ] && ( shift; of "$@" ; return )
[ "$1" = "spi" ] && ( shift; spi "$@" ; return )
[ "$1" = "vio" ] && ( shift; vio "$@" ; return )
[ "$1" = "virtio" ] && ( shift; virtio "$@" ; return )
[ "$1" = "ssb" ] && ( shift; ssb "$@" ; return )
[ "$1" = "sdio" ] && ( shift; sdio "$@" ; return )
[ "$1" = "tc" ] && ( shift; tc "$@" ; return )
[ "$1" = "zorro" ] && ( shift; zorro "$@" ; return )
[ "$1" = "rpmsg" ] && ( shift; rpmsg "$@" ; return )
[ "$1" = "slim" ] && ( shift; slim "$@" ; return )
}
parse_kdetect_list
comment 'Parsing configuration database....'
comment '.... [please wait] ....'
. lkddb.list
comment 'Main detection finished'
#--- (Parse "autoconfig.rules") ---#
comment 'End of Autodetection'
exit 0