Corrected custom sleep at boot code; set to 1 sec
[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 if [ "x${_sleeptime}" = "x" ]
14 then
15         _sleeptime=1
16 fi
17
18 # FIXME:
19
20 NET_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/net"
21 SCSI_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/scsi"
22 LIBATA_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/ata"
23 MD_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/md"
24 FUSIONMPT_MODULE_PATH="/lib/modules/`uname -r`/kernel/drivers/message/fusion"
25 MODULE_PREFIX="/lib/modules/`uname -r`/kernel/drivers"
26 SENSOR_ENABLE=0
27
28 dhcp_on_interface() {
29         INTERFACE=${1}
30
31
32         # this is a stop gap for my laptop
33         if [ "${INTERFACE}" = "ath0" ]
34         then
35                 return 1
36         fi
37
38
39         # work around Cisco portfast implementation not being fast
40
41         if [ "${spantree}" != "" ]
42         then
43                 msg "Sleeping for ${spantree} seconds for spanning tree"
44                 sleep ${spantree}
45         fi
46
47         msg -n "Trying DHCP on ${i} interface"
48
49         /sbin/udhcpc -i ${INTERFACE} -T 5 -n -s /etc/ifup.udhcp.sh \
50                 -p /tmp/dhcp.${INTERFACE}.pid >> /tmp/stdout.log 2>> /tmp/stderr.log
51
52         if [ "$?" = 0 ]
53         then
54                 . /tmp/network.dhcp
55                 ok_msg
56                 return 0
57         else
58                 fail_msg
59                 return 1
60         fi
61 }
62
63 header "Loading other modules"
64 for i in `cat /etc/modules_other_early.conf`
65 do
66         modprobe_module ${i}    
67 done
68
69
70 header "Loading network card modules"
71 for i in `find ${NET_MODULE_PATH} -name \*.ko`
72 do
73         load_module "${i}"
74 done
75
76 header "Switching mlx4 devices to ethernet"
77
78 for i in `find /sys/ -name mlx4_port* 2> /dev/null`
79 do
80
81         msg "Setting ${i} to eth"
82         echo "eth" > $i
83 done
84
85 header "Finding ethernet devices"
86
87 NET_DEVICES=`/sbin/ifconfig -a | grep "^[a-z]" | cut -d" " -f1`
88 NET_DEVICE_COUNT=0
89 NET_DEVICE=""
90
91 for i in ${NET_DEVICES}
92 do
93
94         # we want to skip the loopback interfaces since they don't really count
95         if [ "${i}" = "lo" ]
96         then
97                 continue
98         fi
99
100         NET_DEVICE_COUNT=`expr ${NET_DEVICE_COUNT} + 1`
101
102         /bin/ip link set dev ${i} up
103         /sbin/ifconfig ${i} up
104
105         if [ "${_mtu}" != "" ]
106         then
107                 msg "Setting MTU to ${_mtu} for ${i}"
108                 /bin/ip link set dev ${i} mtu ${_mtu} up
109         fi
110
111         msg "Sleeping for ${_sleeptime} seconds for link to come up on ${i}"
112         sleep ${_sleeptime}
113
114         msg -n "Checking link status for ${i}"
115         LINK=`/usr/bin/ethtool ${i} | grep Link | awk '{print $3}' 2> /dev/null`
116
117         if [ "${LINK}" != "yes" ];
118         then
119                 fail_msg
120         else
121                 ok_msg
122                 dhcp_on_interface ${i}
123                 if [ "$?" = "0" ]
124                 then
125                         NET_DEVICE="${i}"
126                 fi
127         fi
128 done
129
130 if [ "${NET_DEVICE}" = "" ];
131 then
132         msg ""
133         msg "Unable to find interface with link, manually trying each interface"
134         for i in ${NET_DEVICES}
135         do
136                 if [ "${i}" = "lo" ]
137                 then
138                         continue
139                 fi
140
141                 dhcp_on_interface ${i}
142                 if [ "$?" = "0" ]
143                 then
144                         NET_DEVICE="${i}"
145                         break
146                 fi
147         done
148 fi
149
150 #msg -n "Setting hostname to be HW address  "
151 #HOST=`echo ${NET_MACADDR} | sed 's/://g'`
152 #msg -n " ${NET_MACADDR}"
153 #hostname ${HOST} >> /tmp/stdout.log 2> /tmp/stderr.log
154 #if [ "$?" = 0 ]
155 #then
156         #ok_msg
157 #else
158         #fail_msg
159 #fi
160
161 for i in /lib/modules/`uname -r`/kernel/drivers/edac/*
162 do
163         MOD_NAME=`basename ${i} | cut -d"." -f1`
164         modprobe_module ${MOD_NAME}
165 done
166
167 for i in /lib/modules/`uname -r`/kernel/drivers/i2c/busses/*
168 do
169         MOD_NAME=`basename ${i} | cut -d"." -f1`
170         modprobe_module ${MOD_NAME}
171 done
172
173 # XXX: this may cause lockups, if so we need a better way
174 header "Loading all SCSI/SATA disk modules"
175
176 for i in `find ${LIBATA_MODULE_PATH} ${SCSI_MODULE_PATH} ${FUSIONMPT_MODULE_PATH} ${MD_MODULE_PATH} -name \*.ko`
177 do
178         MOD_NAME=`basename ${i} | cut -d"." -f1`
179         modprobe_module ${MOD_NAME}
180 done
181
182 header "Loading other modules"
183 for i in `cat /etc/modules_other.conf`
184 do
185         modprobe_module ${i}    
186 done
187
188 msg "Waiting ${_sleeptime} seconds for block devices to settle."
189 sleep ${_sleeptime}
190
191 # mount a logging device
192 . /etc/logdev.sh
193
194 . /etc/hardware_output.sh