allow resolution of symbol dependencies with modprobe for .ko loading
[bootimage-initfs.git] / etc / hardware.sh
1 #!/bin/ash
2
3 . /etc/library.sh
4
5 # -----------------------------------------------------------------------
6 # load the output file created by the breakin program
7 # -----------------------------------------------------------------------
8 if [ -e /var/run/breakin.dat ]
9 then
10         . /var/run/breakin.dat
11 fi
12
13 # FIXME:
14
15 NET_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/net"
16 SCSI_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/scsi"
17 LIBATA_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/ata"
18 MD_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/md"
19 FUSIONMPT_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/message/fusion"
20 MODULE_PREFIX="/lib/modules/`uname -r`/kernel/drivers"
21 SENSOR_ENABLE=0
22
23 dhcp_on_interface() {
24         INTERFACE=${1}
25
26
27         # this is a stop gap for my laptop
28         if [ "${INTERFACE}" = "ath0" ]
29         then
30                 return 1
31         fi
32
33         msg -n "Trying DHCP on ${i} interface"
34
35         # work around Cisco portfast implementation not being fast
36         /sbin/ifconfig ${i} up
37
38         sleep 1
39
40         /sbin/udhcpc -i ${INTERFACE} -n -s /etc/ifup.udhcp.sh \
41                 -p /tmp/dhcp.${INTERFACE}.pid >> /tmp/stdout.log 2>> /tmp/stderr.log
42
43         if [ "$?" = 0 ]
44         then
45                 . /tmp/network.dhcp
46                 ok_msg
47                 return 0
48         else
49                 fail_msg
50                 return 1
51         fi
52 }
53
54
55
56 header "Loading network card modules"
57 for i in `find ${NET_MODULE_PATH} -name \*.ko`
58 do
59         load_module "${i}"
60 done
61
62 header "Finding ethernet devices"
63
64 if [ "${spantree}" != "" ]
65 then
66         msg "Sleeping for ${spantree} seconds for spanning tree"
67         sleep ${spantree}
68 fi
69
70
71 NET_DEVICES=`/sbin/ifconfig -a | grep "^[a-z]" | cut -d" " -f1`
72 NET_DEVICE_COUNT=0
73 NET_DEVICE=""
74
75 for i in ${NET_DEVICES}
76 do
77
78         # we want to skip the loopback interfaces since they don't really count
79         if [ "${i}" = "lo" ]
80         then
81                 continue
82         fi
83
84         NET_DEVICE_COUNT=`expr ${NET_DEVICE_COUNT} + 1`
85
86         msg -n "Checking link status for ${i}"
87         /bin/mii-diag -s ${i} >> /tmp/stdout.log 2>> /tmp/stderr.log
88
89         if [ "$?" != "0" ];
90         then
91                 fail_msg
92         else
93                 ok_msg
94                 dhcp_on_interface ${i}
95                 if [ "$?" = "0" ]
96                 then
97                         NET_DEVICE="${i}"
98                 fi
99         fi
100 done
101
102 if [ "${NET_DEVICE}" = "" ];
103 then
104         msg ""
105         msg "Unable to find interface with link, manually trying each interface"
106         for i in ${NET_DEVICES}
107         do
108                 if [ "${i}" = "lo" ]
109                 then
110                         continue
111                 fi
112
113                 dhcp_on_interface ${i}
114                 if [ "$?" = "0" ]
115                 then
116                         NET_DEVICE="${i}"
117                         break
118                 fi
119         done
120 fi
121
122 #msg -n "Setting hostname to be HW address  "
123 #HOST=`echo ${NET_MACADDR} | sed 's/://g'`
124 #msg -n " ${NET_MACADDR}"
125 #hostname ${HOST} >> /tmp/stdout.log 2> /tmp/stderr.log
126 #if [ "$?" = 0 ]
127 #then
128         #ok_msg
129 #else
130         #fail_msg
131 #fi
132
133 for i in /lib/modules/`uname -r`/kernel/drivers/edac/*
134 do
135         MOD_NAME=`basename ${i} | cut -d"." -f1`
136         modprobe_module ${MOD_NAME}
137 done
138
139 for i in /lib/modules/`uname -r`/kernel/drivers/i2c/busses/*
140 do
141         MOD_NAME=`basename ${i} | cut -d"." -f1`
142         modprobe_module ${MOD_NAME}
143 done
144
145 for i in /lib/modules/`uname -r`/kernel/drivers/hwmon/*
146 do
147         MOD_NAME=`basename ${i} | cut -d"." -f1`
148         modprobe_module ${MOD_NAME}
149 done
150
151 # XXX: this may cause lockups, if so we need a better way
152 header "Loading all SCSI/SATA disk modules"
153
154 for i in `find ${SCSI_MODULE_PATH} ${LIBATA_MODULE_PATH} ${FUSIONMPT_MODULE_PATH} ${MD_MODULE_PATH} -name \*.ko`
155 do
156         MOD_NAME=`basename ${i} | cut -d"." -f1`
157         modprobe_module ${MOD_NAME}
158 done
159
160 header "Loading other modules"
161 for i in `cat /etc/modules_other.conf`
162 do
163         modprobe_module ${i}    
164 done
165
166 msg "Waiting 10 seconds for block devices to settle."
167 sleep 10
168
169 # mount a logging device
170 . /etc/logdev.sh
171
172 . /etc/hardware_output.sh