aboutsummaryrefslogtreecommitdiff
path: root/hwdetect
blob: cb3bf1a5be0b97523336d954c49967276511ff23 (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
#! /bin/sh
# Autodetection script for scanning /sys for pci stuff
# for Archlinux by Tobias Powalowski <tpowa@archlinux.org>
usage () {
	echo "$0 [options]"
	echo ""
	echo " This is a tool that detects/lists modules that are exported by /sys"
	echo ""
	echo "  Options:"
	echo "    -load-modules         load all detected modules"
	echo "    -show-modules         show all detected modules"
	echo "    -show-agp             show AGP modules"	
	echo "    -show-ide             show IDE modules"
	echo "    -show-scsi            show SCSI modules"
	echo "    -show-sata            show SATA modules"
	echo "    -show-usb             show USB modules"
	echo "    -show-fw              show FIREWIRE modules"
	echo "    -show-net             show NETWORK modules"
	echo "    -show-isdn            show ISDN modules"
	echo "    -show-pcmcia          show PCMCIA modules"
	echo "    -show-sound           show SOUND modules"
	echo "    -show-video           show VIDEO modules"
	echo "    -show-other           show OTHER modules"
	echo ""
	echo "  For /etc/mkinitrd.conf use:"
	echo "    -ide                  show detected HOSTCONTROLLER_IDE"
	echo "    -scsi                 show detected HOSTCONTROLLER_SCSI"
	echo "    -sata                 show detected HOSTCONTROLLER_SATA"
	echo "    -usb                  show detected HOSTCONTROLER_USB"
	echo ""
	exit 1
}

[ "$1" == "" ] && usage

# find pci aliases
find /sys/devices/ -name "modalias" | grep pci > /tmp/modules

# delete pci devices that are blacklisted
for i in "${BLACKLIST[@]}"; do
	sed -i -e "/$i/d" /tmp/modules
done

# get the modaliases
for i in `cat /tmp/modules`; do
	cat $i >> /tmp/modprobe
done

# generate files for the different actions
for i in `cat /tmp/modprobe`; do
	modprobe --show-depends $i >> /tmp/modules-plain 2>/dev/null
done

# find PNP devices, like parports etc. workaround for rtc and pcspkr included
for i in `find /sys -name "id*" | grep pnp`; do
	devid=`cat $i`
	if [ "$devid" == "PNP0800" ]; then
		modprobe --show-depends pcspkr >> /tmp/modules-plain 2>/dev/null
	fi
	if [ "$devid" == "PNP0b00" ]; then
		modprobe --show-depends rtc >> /tmp/modules-plain 2>/dev/null
	fi
	modprobe --show-depends pnp:d${devid} >> /tmp/modules-plain 2>/dev/null
done

sort -u /tmp/modules-plain >> /tmp/modules-sorted
sed -ne "s#^insmod.*/\(.*\)\.ko.*#\1#p" /tmp/modules-sorted >> /tmp/moduleslist

listex() {
	ln=$1 ; shift
	if [ $# -gt 0 ]; then
		ex=$1 ; shift
		if [ "`echo $ln | grep -v $ex`" ]; then
			listex "$ln" $*
		fi
	else
		echo $ln | sed -ne "s#^/.*/\(.*\)\.ko.*#\1#p"
	fi
}
listmods() {
	key=$1 ; shift
	for ln in `grep "$key" /tmp/modules-sorted | sed 's|^insmod ||g' | sort -u`; do
		listex "$ln" $*
	done
}
showlist() {
	cat=$1 ; shift
	[ $# -gt 0 ] || return
	echo -n "$cat: "
	for i in $*; do echo -n "$i "; done
	echo ""
}

# starting different actions
while [ $# -gt 0 ]; do
	case $1 in
		-load-modules)
			# load all detected pci modules
			for i in `cat /tmp/moduleslist`; do
				modprobe $i > /dev/null 2>&1
			done
			;;

		-show-modules)
			showlist "AGP   " `listmods agp/`
			showlist "IDE   " `listmods ide/`
			showlist "SCSI  " `listmods scsi/ sata ata_piix libata`
			showlist "SATA  " `listmods ata eata`
			showlist "USB   " `listmods usb/`
			showlist "FW    " `listmods ieee1394/`
			showlist "NET   " `listmods net/`
			showlist "ISDN  " `listmods isdn/`
			showlist "PCMCIA" `listmods pcmcia/`
			showlist "SOUND " `listmods sound/`
			showlist "VIDEO " `listmods video/`
			showlist "OTHER " `listmods modules/ agp/ ide/ scsi/ sata usb/ ieee1394 net/ isdn/ pcmcia/ sound/ video/`
			;;

		-show-agp)    showlist "AGP   " `listmods agp/` ;;
		-show-ide)    showlist "IDE   " `listmods ide/` ;;
		-show-scsi)   showlist "SCSI  " `listmods scsi/ sata ata_piix libata` ;;
		-show-sata)   showlist "SATA  " `listmods ata eata` ;;
		-show-usb)    showlist "USB   " `listmods usb/` ;;
		-show-fw)     showlist "FW    " `listmods ieee1394/` ;;
		-show-net)    showlist "NET   " `listmods net/` ;;
		-show-isdn)   showlist "ISDN  " `listmods isdn/` ;;
		-show-pcmcia) showlist "PCMCIA" `listmods pcmcia/` ;;
		-show-sound)  showlist "SOUND " `listmods sound/` ;;
		-show-video)  showlist "VIDEO " `listmods video/` ;;
		-show-other)  showlist "OTHER " `listmods .ko agp/ ide/ scsi/ sata usb/ ieee1394 net/ isdn/ pcmcia/ sound/ video/` ;;

		-ide)  showlist "HOSTCONTROLLER_IDE"  `listmods ide/pci` ;;
		-scsi) showlist "HOSTCONTROLLER_SCSI" `listmods scsi/ sata ata_piix libata` ;;
		-sata) showlist "HOSTCONTROLLER_SATA" `listmods ata eata libata` ;;
		-usb)  showlist "HOSTCONTROLLER_USB"  `listmods usb/host` "" ;;
	esac
	shift
done

# cleanup
rm /tmp/{modules-plain,modules-sorted,moduleslist,modprobe,modules}

# vim: set ts=2 sw=2: