Rework the location where spantree sleeps so that it happens after link is up
[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         # work around Cisco portfast implementation not being fast
34         /bin/ip link set dev ${i} up
35
36         if [ "${spantree}" != "" ]
37         then
38                 msg "Sleeping for ${spantree} seconds for spanning tree"
39                 sleep ${spantree}
40         fi
41
42         msg -n "Trying DHCP on ${i} interface"
43
44         /sbin/udhcpc -i ${INTERFACE} -n -s /etc/ifup.udhcp.sh \
45                 -p /tmp/dhcp.${INTERFACE}.pid >> /tmp/stdout.log 2>> /tmp/stderr.log
46
47         if [ "$?" = 0 ]
48         then
49                 . /tmp/network.dhcp
50                 ok_msg
51                 return 0
52         else
53                 fail_msg
54                 return 1
55         fi
56 }
57
58
59
60 header "Loading network card modules"
61 for i in `find ${NET_MODULE_PATH} -name \*.ko`
62 do
63         load_module "${i}"
64 done
65
66 header "Finding ethernet devices"
67
68
69 NET_DEVICES=`/sbin/ifconfig -a | grep "^[a-z]" | cut -d" " -f1`
70 NET_DEVICE_COUNT=0
71 NET_DEVICE=""
72
73 for i in ${NET_DEVICES}
74 do
75
76         # we want to skip the loopback interfaces since they don't really count
77         if [ "${i}" = "lo" ]
78         then
79                 continue
80         fi
81
82         NET_DEVICE_COUNT=`expr ${NET_DEVICE_COUNT} + 1`
83
84         msg -n "Checking link status for ${i}"
85         /bin/mii-diag -s ${i} >> /tmp/stdout.log 2>> /tmp/stderr.log
86
87         if [ "$?" != "0" ];
88         then
89                 fail_msg
90         else
91                 ok_msg
92                 dhcp_on_interface ${i}
93                 if [ "$?" = "0" ]
94                 then
95                         NET_DEVICE="${i}"
96                 fi
97         fi
98 done
99
100 if [ "${NET_DEVICE}" = "" ];
101 then
102         msg ""
103         msg "Unable to find interface with link, manually trying each interface"
104         for i in ${NET_DEVICES}
105         do
106                 if [ "${i}" = "lo" ]
107                 then
108                         continue
109                 fi
110
111                 dhcp_on_interface ${i}
112                 if [ "$?" = "0" ]
113                 then
114                         NET_DEVICE="${i}"
115                         break
116                 fi
117         done
118 fi
119
120 #msg -n "Setting hostname to be HW address  "
121 #HOST=`echo ${NET_MACADDR} | sed 's/://g'`
122 #msg -n " ${NET_MACADDR}"
123 #hostname ${HOST} >> /tmp/stdout.log 2> /tmp/stderr.log
124 #if [ "$?" = 0 ]
125 #then
126         #ok_msg
127 #else
128         #fail_msg
129 #fi
130
131 for i in /lib/modules/`uname -r`/kernel/drivers/edac/*
132 do
133         MOD_NAME=`basename ${i} | cut -d"." -f1`
134         modprobe_module ${MOD_NAME}
135 done
136
137 for i in /lib/modules/`uname -r`/kernel/drivers/i2c/busses/*
138 do
139         MOD_NAME=`basename ${i} | cut -d"." -f1`
140         modprobe_module ${MOD_NAME}
141 done
142
143 if [ ${_startup} != "cloner" ]
144 then
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 fi
151
152 # XXX: this may cause lockups, if so we need a better way
153 header "Loading all SCSI/SATA disk modules"
154
155 for i in `find ${SCSI_MODULE_PATH} ${LIBATA_MODULE_PATH} ${FUSIONMPT_MODULE_PATH} ${MD_MODULE_PATH} -name \*.ko`
156 do
157         MOD_NAME=`basename ${i} | cut -d"." -f1`
158         modprobe_module ${MOD_NAME}
159 done
160
161 header "Loading other modules"
162 for i in `cat /etc/modules_other.conf`
163 do
164         modprobe_module ${i}    
165 done
166
167 msg "Waiting 10 seconds for block devices to settle."
168 sleep 10
169
170 # mount a logging device
171 . /etc/logdev.sh
172
173 . /etc/hardware_output.sh