summaryrefslogtreecommitdiffstats
path: root/initramfs/initrd-stuff/bin/hwautocfg
blob: a9029575480ccbc52a47c423115b8a754fe0e766 (plain) (blame)
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
#!/bin/sh
# Copyright (c) 2003 - 2006 - RZ Uni Freiburg
# Copyright (c) 2006, 2007 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your feedback to feedback@openslx.org
#
# General information about OpenSLX can be found under http://openslx.org
#
# Universal (distro independent) hardware autoconfiguration script for 
# OpenSLX linux stateless clients, using hwconfig from knoppix as base tool 

#############################################################################
# pre part, load USB modules and start hardware detection pci and monitor
hwpre () {
echo "0 0 0 0" >/proc/sys/kernel/printk
# start the knoppix hardware autodetection tool
driverlist="parport parport_pc "
# hack for pseudo modules (not to load) hopefully "usbcore" is present
# as a module, might be exchanged with any other existing ...
for i in $driverlist ; do 
  echo -e "alias\t$i\tusbcore" >> /etc/modprobe.conf
done
( hwsetup -n -v > /tmp/hwsetup.info && echo "hwsetup" > /tmp/hwrun1 ) &
( usleep 8000; xconfig ) &
( for mod in usbcore uhci-hcd ohci-hcd usbhid; do
  modprobe -q $mod 2>/dev/null
  usleep 10000
done; ) &
return 0
}

#############################################################################
# network module part
nwmod () {
[ $DEBUGLEVEL -eq 20 ] && \
  echo "** loading all defined network adaptor modules at $(sysup)"
for mod in ${NWMODULES}; do
  modprobe ${MODPRV} $mod || error "$init_errnwad"
  usleep 50000 
done
return 0
}

#############################################################################
# main part
hwmain () {
# "drivers" (pseudo, placeholder strings, ...) to exclude from loading
# depending on distro more hw modules have to be excluded too. use the
# D_HWMODTOIGNORE for that purpose
driverlist=" disabled unknown ignore pcspkr synaptics keybdev kanotix \
  slamr {D_HWMODTOIGNORE} "
# driver blacklist (real modules which fail to load)
driverlist=${driverlist}"hw_random genericwheelusb "
# hack for pseudo modules (not to load) hopefully "usbcore" is present
# as a module, might be exchanged with any other existing ...
for i in $driverlist ; do 
  echo -e "alias\t$i\tusbcore" >> /etc/modprobe.conf
done

# load kernel module for ps2 mice
[ -f /lib/modules/${KERNEL}/kernel/drivers/input/mouse/psmouse.ko ] && \
  modprobe ${MODPRV} psmouse

# and map the mousehandler to /dev/input/mice
[ -f /lib/modules/${KERNEL}/kernel/drivers/input/mousedev.ko ] && \
  modprobe ${MODPRV} mousedev

# wait for /tmp/hwsetup.info to appear
waitfor /tmp/hwrun1 50000 || \
  error "$hcfg_hwsetup"
# in some cases the time to wait for module load is to be increased
if [ -n "${SLOWHWSETUP}" ] ; then
  modwaittime=${SLOWHWSETUP}
  [ $DEBUGLEVEL -eq 21 ] && echo "** set modwaittime to ${SLOWHWSETUP}ms"
else
  modwaittime=5000
fi
[ $DEBUGLEVEL -eq 21 ] && echo "** 1st hwdetection finished at $(sysup)"
# load ide drivers first, takes a while to initialize
for driver in cmd64x hpt366 piix slc90e66 cs5520 it821x rz1000 \
    ahci triflex aec62xx cs5530 cs5535 ns87415 sc1200 trm290 alim15x3 \
    cy82c693 opti621 serverworks via82cxxx amd74xx pata_amd \
    pdc202xx_new siimage atiixp hpt34x pdc202xx_old sis5513; do
  strinfile " ${driver}" /tmp/hwsetup.info && {
    ide="yes"
    #modwaittime=$((10 + ${modwaittime}))
    modprobe ${MODPRV} ${driver} &
    driverlist="${driverlist} ${driver}"; usleep ${modwaittime}; }
done
# check for IDE/SCSI (SATA); changes in newer kernels prefix pata/sata
for driver in ata_piix sata_via sata_mv sata_nv sata_sil sata_sis sata_svw \
    sata_sx4 sata_uli sata_vsc sata_qstor sata_promise ahci; do
  strinfile " ${driver}" /tmp/hwsetup.info && {
    #SCSIIDE="yes"
    modprobe ${MODPRV} ${driver} &
    driverlist="${driverlist} ${driver}"; usleep ${modwaittime}; }
done
# check for USB2.0 and ieee1394 hardware drivers
for driver in ehci-hcd ohci1394; do
  strinfile " ${driver}" /tmp/hwsetup.info && {
    USB="yes"
    modprobe ${MODPRV} ${driver}
    driverlist="${driverlist} ${driver}"; }
done
[ -x /bin/mdev ] && mdev -s &
# check for pcmcia / cardbus stuff
for driver in yenta_socket i82365 pd6729 tcic; do
  strinfile " ${driver}" /tmp/hwsetup.info && {
    modprobe ${MODPRV} ${driver}
    driverlist="${driverlist} ${driver}"
    pcmcia="yes"; }
done
# should we check for card reader modules too?
# newer kernels support some of the major multicard readers which could
# be found in some barebone systems like Pundits or in many laptops
if [ -n "${pcmcia}" ] ; then
  modprobe ${MODPRV} ds
fi

[ $DEBUGLEVEL -eq 21 ] && echo "** module loading finished at $(sysup)"
# rerun the knoppix hardware autodetection tool for USB and ide devices
# like dvd or harddisk - wait a few seconds so hopefully the ide driver
# is initialized 
[ -x /bin/mdev ] && mdev -s
test -f /proc/bus/usb/devices || \
  mount -n -t usbfs usbfs /proc/bus/usb 2>/dev/null
[ $DEBUGLEVEL -eq 21 ] && echo "** started 2nd hwdetection at $(sysup)"
# remove unneeded network card and USB 1.1 modules
for driver in ${NWMODULES} ohci-hcd uhci-hcd ; do
  strinfile " ${driver}" /tmp/hwsetup.info || {
    rmmod ${driver}
    driverlist="${driverlist} ${driver}"; }
done
# wait depending on time of modules to load a little bit before the next
# round of hardware detection
usleep ${modwaittime} && hwsetup -v > /tmp/hwsetup.info
[ $DEBUGLEVEL -eq 21 ] && echo "** finished 2nd hwdetection at $(sysup)"

# load IDE high level drivers
if [ -n "$ide" ] ; then
  # you might want to check /etc/sysconfig/floppy for more info
  strinfile "ZIP" /tmp/hwsetup.info && modprobe ${MODPRV} ide-floppy
  strinfile "CDROM" /tmp/hwsetup.info && modprobe ${MODPRV} ide-cd
  strinfile "HD" /tmp/hwsetup.info && {
    modprobe ${MODPRV} ide-disk
    disk=yes; }
fi

# not rather precise ...
if strinfile "SCSI" /tmp/hwsetup.info ; then
  strinfile "CDROM" /tmp/hwsetup.info && { modprobe ${MODPRV} sr_mod;
    modprobe ${MODPRV} sg;
    # just for compatibility to hwsetup (which generates links to scd*)
    ( waitfor /dev/sr0 1000 && for i in /dev/sr* ; do 
      [ -e /dev/scd${i#/dev/sr} ] || cp -a -f $i /dev/scd${i#/dev/sr} ; done; ) &
    }
  strinfile "HD" /tmp/hwsetup.info && {
    modprobe ${MODPRV} sd_mod
    disk=yes; }
  # check if a (scsi) scanner was detected
  strinfile "SCANNER" /tmp/hwsetup.info && \
    echo -e 'KERNEL=="sg*",\t\tNAME="%k", GROUP="disk", MODE="666"' \
           >> /tmp/scanner-udev
fi
[ -x /bin/mdev ] && mdev -s
# sound card setup (alsa and oss compatibility drivers)
( if [ -f /etc/sysconfig/sound ] ; then
  . /etc/sysconfig/sound
  driver=${DRIVER}
else driver="snd-dummy"
fi
# problem with a specific module not disabled (via above trick) when
# busybox is used
#  rmmod snd_atiixp_modem snd_atiixp
modprobe ${MODPRV} ${driver}
driverlist="${driverlist} ${driver}"
modprobe ${MODPRV} snd-pcm-oss
modprobe ${MODPRV} snd-mixer-oss
# remaining drivers listed in /tmp/hwsetup.info
cat /tmp/hwsetup.info| while read line ; do
  if strinstr "driver:" "${line}"; then
    driver=${line##driver: }
    if ! strinstr " ${driver} " "${driverlist}"; then
      strinstr "Card:" "${driver}" || strinstr "ps/2" "${driver}" || {
        modprobe ${MODPRV} ${driver} &
        usleep 5000; }
      driverlist="${driverlist} ${driver}"
    fi
  fi
done ) &
[ $DEBUGLEVEL -eq 21 ] && echo "** finished most of module loading at $(sysup)"

# get idea of availabe harddisk partitions, put swap partitions into
# (/mnt)/etc/fstab and format and mount partitions of type 44 (unknown)
[ $DEBUGLEVEL -eq 21 ] && echo "** starting hdd stuff at $(sysup)"
if [ "${disk}" = "yes" ] ; then
for hd in $(cat /tmp/hwsetup.info|sed -n -e '/HD$/,/device:/p'| \
    sed -n -e '/device:/p'|sed -e 's/device: //') ; do
  /mnt/sbin/fdisk -l /dev/$hd|sed -n "/^\/dev\//p" > /tmp/hd_part
  for hdpartnr in $(cat /tmp/hd_part | \
      sed -n -e "/ 82 /p"|sed -e "s/[[:space:]].*//") ; do
    echo -e "$hdpartnr\tswap\t\tswap\t\tdefaults\t 0 0" >> /tmp/fstab
  done
  # we use special non assigned partition type (id44) for harddisk scratch 
  # space, thus no normal filesystem will be incidentally deleted or
  # corrupted
  for hdpartnr in $(cat /tmp/hd_part | \
        sed -n -e "/ 44 /p"|sed -e "s/[[:space:]].*//") ; do
    # check for supported filesystem and formatter
    ( if diskfm $hdpartnr ; then
        echo "$hdpartnr is mounted to /mnt/tmp at $(sysup)" > /tmp/tmpready
        echo -e "$hdpartnr\t/tmp\t\tauto\t\tdefaults\t 0 0" >> /tmp/fstab
      else
        echo "formatting failed for some reason ($(sysup))" > /tmp/tmpready
      fi ) &
    part44=yes
    break
  done
  # put detected linux partitions into /etc/fstab with "noauto"
  for hdpartnr in $(cat /tmp/hd_part | \
        sed -n -e "/ 83 /p"|sed -e "s/[[:space:]].*//") ; do
    mkdir -p /mnt/media/${hdpartnr#/dev/*} 2>/dev/null
    echo -e "$hdpartnr\t/media/${hdpartnr#/dev/*}\tauto\t\tnoauto,\
noexec\t 0 0" >> /tmp/fstab
  done 
done
# determine if tmp preparation should wait for format/mount or not
[ -z "$part44" ] && echo "finished at $(sysup)" > /tmp/tmpready
else
  echo "no disk found ( $(sysup) )" > /tmp/tmpready
fi
[ $DEBUGLEVEL -eq 21 ] && echo "** finished hdd stuff at $(sysup)"

# configure some variables from configuration file - wait for dhcp or ldap
# confiurator to complete
cfgcomplete
. /etc/machine-setup
[ $DEBUGLEVEL -eq 21 ] && echo "** finished waiting for config at $(sysup)"

# set X11 configuration file
if [ -n "${D_XF86CONFFILE}" ] ; then
  D_XF86CONFFILE="/mnt/${D_XF86CONFFILE}"
else
  D_XF86CONFFILE="/mnt/etc/X11/xorg.conf"
  error "$hcfg_xcfg" nonfatal
fi
# finish Xorg configuration if no xorg.conf file was provided by ConfigTGZ 
# (check for /rootfs/${D_XF86CONFFILE#/mnt})
if [ ! -f /rootfs${D_XF86CONFFILE#/mnt} ] ; then 
  xfc="/tmp/xorg.conf"
  . /etc/sysconfig/xserver >/dev/null 2>&1 || error "${hcfg_hwsetup}" nonfatal
  # replace OSS 3D server with proprietary one
  checkgraphix
  sed -e "s/\"vesa\"/\"${XMODULE}\"/" -i $xfc
  # check for 64bit CPU/installation (fixme!!)
  [ -d "/mnt/usr/X11R6/lib64/modules" ] && \
    sed -e "/Section \"Files\"/a\ \ ModulePath    \"/usr/X11R6/lib64/modules\"" \
     -i $xfc
  # run localizator and configure X11 keyboard
  localization "${country}"
  if [ -z "${XKEYBOARD}" ] ; then
    XKEYBOARD="us"
    error "${xcfg_keyb}" nonfatal
  fi
  sed "s/XKEYBOARD/${XKEYBOARD}/" -i $xfc
  # check for kind of xorg module used and patch the i8,9XX VGA BIOS if needed
  if strinfile '"i810"' $xfc && [ -f /tmp/res ] ; then
    highres=$(sort -run /tmp/res|grep -i x -m 1)
    915resolution -l|sed -n "s/Mode //;/32 bits/p" > /tmp/915res
    strinfile ${highres} /tmp/915res || {
      915resolution $(grep -i x -m 1 /tmp/915res|sed "s/\ :.*//") $(echo \
        $highres|sed "s/x/\ /") 2>&1 >/dev/null;
      # for some reason that does not work for a Dell laptop with i855 chipset
      915resolution 3c $(echo $highres|sed "s/x/\ /") 2>&1 >/dev/null; }
  fi
fi

# if any new device appeared up to now
if [ -x /bin/mdev ] ; then
  mdev -s &
  testmkd /dev/input 
  mknod /dev/input/mice c 13 63 2>/dev/null
fi
return 0
}

#############################################################################
# main script starts here

# functions common for all distros
. /etc/functions
# functions common for all distros, messages contains all error and
# info output
. /etc/messages
# load distro specific configuration variables and functions. distro
# specific functions may overwrite functions defined in /etc/functions
. /etc/sysconfig/config
. /etc/distro-functions

# script run timer
[ $DEBUGLEVEL -eq 8 -o $DEBUGLEVEL -eq 21 ] && \
  echo "** HW $1 setup started at $(sysup)"

# heavy debugging output in level 3 and above and specific for 11
[ $DEBUGLEVEL -gt 3 -a $DEBUGLEVEL -lt 8 -o $DEBUGLEVEL -eq 11 ] && \
  set -x

case $1 in
  # pre initializsation: loading USB base modules, starting hwsetup
  pre)
    hwpre
  ;;
  # loading network modules
  nwmod)
    nwmod
  ;;
  # main part of hardware setup including Xorg
  main)
    hwmain
    # main script run timer or debug information
    [ $DEBUGLEVEL -eq 8 -o $DEBUGLEVEL -eq 21 ] && \
      echo "** HW setup finished at $(sysup)"
    echo "hwsetup finished at $(sysup)" > /tmp/hwcfg
  ;;
esac