summaryrefslogblamecommitdiffstats
path: root/initramfs/initrd-stuff/bin/hwautocfg
blob: 37ce39808aa4b2dceb7a274d527708660cf17bd9 (plain) (tree)
1
2
3
4
5
6
7
8
9
         

                                             
 




                                                                         
 
                                                                         
 
                                                                       
                                                                            
 
                                                                             
                                                                         









                                                                       
                          

                                                 
              


         
 






                                                                             
               


        
 


                                                                             
                                                                      

                                                                      

                                                                       
                                                    
                                                    

                                                                      
                          


                                                    
                                 

                                                                        
 



                                                                   
                                      
                              
                       




                                                                         
                  
  
                                                                        
                                                     
                                                                
                                                                       

                                                               

                                               
                                         
                                  
                                                                  
    


                                                                            
                                               
                  
                                  
                                                                  
    
                                                
                                   
                                               
             

                                           
    
                             





                                                 
    
                                              

                                                                       
                            

                       
 
                                                                       


                                                                       
                           

                                                   
                                                                       





                                                  


                                                                        
                                                                        
 
                             
                       
                                                               

                                                                    


                                       
  
 

                                            
                                                                     

                                                                       
                                                      
                                                                                 
     


                                       
                                          

                                                                     
                               
  
                           



















                                                                      
                      





                                                                               
                                                                    

                                                                       
                               
                                                                 

                                                                 

                                                          
                                                                     
      


                                                                           

                                                            



                                                                           


                                                                           
              
         





                                                                   
                           
       
    

                                                                  


                                                   
                                                                  
 





                                                                           






                                         
                                                                           
                                            

                                                 
                                                                              

                                              
                                             



                                                                                 






                                              






                                                                              

                                                                             

                                                                        
  
 





                                           

        
 

                                                                             
 










                                                                      
                                                
                                           





                                                                     
                                                                   


         
                           


         
                                              


                                                
                                                    
                                             
                                                    

    
#!/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 the above does not work for a Dell laptop with Intel 
      # 855 chipset, so add another mode too
      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