diff options
Diffstat (limited to 'initramfs/initrd-stuff/bin/hwautocfg')
-rwxr-xr-x | initramfs/initrd-stuff/bin/hwautocfg | 461 |
1 files changed, 461 insertions, 0 deletions
diff --git a/initramfs/initrd-stuff/bin/hwautocfg b/initramfs/initrd-stuff/bin/hwautocfg new file mode 100755 index 00000000..edf77430 --- /dev/null +++ b/initramfs/initrd-stuff/bin/hwautocfg @@ -0,0 +1,461 @@ +#!/bin/sh +# +# universal (distro independent) hardware autoconfiguration script for +# OpenSLX linux diskless clients, using hwconfig from knoppix as base tool +# +# Dirk von Suchodoletz <dvs@OpenSLX.com>, 03-09-2006 +# +# (c) 2003 - 2006 - RZ Universitaet Freiburg +# (c) 2006 - OpenSLX.org + +# local functions used within hwautocfg +displaysetup () { +# (temporary) configuration file +local xfc=$1 +# define some defaults +local HSYNCRANGE="31.5-63.5" +local VSYNCRANGE="60-90" +local DEFAULTMODES='"1024x768" "800x600" "640x480"' +local DEFAULTCOLORDPT=24 +# set variables representing the xorg.conf sections (version 6.9.x) +local Module='\tLoad\t\t"dbe"\n +\tLoad\t\t"extmod"\n +\tLoad\t\t"type1"\n +\tLoad\t\t"speedo"\n +\tLoad\t\t"freetype"\n +\tLoad\t\t"v4l"' +local ServerFlags='\tOption\t\t"AllowMouseOpenFail"\n +\tOption\t\t"blank time"\t\t"5"\n +\tOption\t\t"standby time"\t\t"10"\n +\tOption\t\t"suspend time"\t\t"15"\n +\tOption\t\t"off time"\t\t"20"' +local Files='\tRgbPath\t\t"/usr/X11R6/lib/X11/rgb"\n +\tModulePath\t"/etc/X11/modules"\n +\tModulePath\t"/usr/X11R6/lib/modules"\n +\tFontPath\t"/usr/X11R6/lib/X11/fonts/misc/:unscaled"\n +\tFontPath\t"/usr/X11R6/lib/X11/fonts/75dpi/:unscaled"\n +\tFontPath\t"/usr/X11R6/lib/X11/fonts/100dpi/:unscaled"' +local InputDevice='\tIdentifier\t"Keyboard1"\n +\tDriver\t\t"keyboard"\n +\tOption\t\t"XkbRules"\t\t"xfree86"\n +\tOption\t\t"XkbLayout"\t\t"XKEYBOARD"\n +\tOption\t\t"XkbModel"\t\t"pc105"' +local InputMouseDef='\tIdentifier "Mouse1"\n +\tDriver\t\t"mouse"\n +\tOption\t\t"Protocol"\t\t"imps/2"\n +\tOption\t\t"Device"\t\t"/dev/input/mice"\n +\tOption\t\t"Emulate3Buttons"\n +\tOption\t\t"ZAxisMapping"\t\t"4 5"\n +\tOption\t\t"Buttons"\t\t"3"' +local InputMouseSyn='\tIdentifier "Mouse1"\n +\tDriver\t\t"synaptics"\n +\tOption\t\t"Protocol"\t\t"explorerps/2"\n +\tOption\t\t"Device"\t\t"/dev/input/mice"\n +\tOption\t\t"Emulate3Buttons"\t"on"\n +\tOption\t\t"Buttons"\t\t"5"\n +\tOption\t\t"InputFashion"\t\t"Mouse"\n +\tOption\t\t"SHMConfig"\t\t"on"\n +\tOption\t\t"ZAxisMapping"\t\t"4 5"' +local Monitor='\tIdentifier "Default"\n +\tModelName\t"MODEL"\n +\tOption\t\t"CalcAlgorithm"\t"CheckDesktopGeometry"\n +\tHorizSync\tHS\n +\tVertRefresh\tVS\n +\tOption\t"DPMS"\t\t"true"' +local Device='\tIdentifier\t"StdGraphics"\n +\tVendorName\t"XDESC"\n +\tDriver\t\t"XMODULE"' +local Screen='\tIdentifier\t"Screen 1"\n +\tDevice\t\t"StdGraphics"\n +\tMonitor\t\t"Default"\n +\tDefaultColorDepth CDP' +local ServerLayout='\tIdentifier\t"Simple Layout"\n +\tScreen\t\t"Screen 1"\n +\tInputDevice\t"Keyboard1"\t"CoreKeyboard"\n +\tInputDevice\t"Mouse1"\t"CorePointer"\n +\tOption\t\t"BlankTime"\t"5"\n +\tOption\t\t"StandbyTime"\t"10"\n +\tOption\t\t"SuspendTime"\t"20"\n +\tOption\t\t"OffTime"\t"30"' +local DRI='\tGroup\t\t"video"\n +\tMode\t\t0666' + +# displayvars may overwrite the above settings +displayvars + +if [ -n "$hw_graphic" ] ; then + DRV=${hw_graphic% *} + CDP=${hw_graphic##* } + if [ -z "$DRV" ] ; then error "$hcfg_gfxdrv" nonfatal + XMODULE=vesa + fi +fi +if [ -z "$CDP" ] ; then error "$hcfg_gfxcdp" nonfatal + CDP=${DEFAULTCOLORDPT} +fi + +if [ -n "$hw_monitor" ] ; then + # just cut all starting from k(Hz) ... + HS=${hw_monitor%k*} + VS=${hw_monitor%Hz*} + [ "${hw_monitor}" == "$VS" ] && VS=${hw_monitor%hz*} + VS=${VS##* } + SCR_MODES="\"${hw_monitor##* }\"" +else + # gather information about the monitor capabilities + screenres > /tmp/screenres + VERTSR=`cat /tmp/screenres | sed -n \ + '/Vertical Frequency Range/s/[^0-9]* \([0-9-]*\)/\1/p'` + HORISR=`cat /tmp/screenres | sed -n \ + '/Horizontal Frequency Range/s/[^0-9]* \([0-9-]*\)/\1/p'` + HS=$HORISR + VS=$VERTSR + # compute max resolution + SCR_MODES=`cat /tmp/screenres | sed -n \ + '/Recommended Screen Modes:/s/[^"]*\(.*\)/\1/p'` +fi + +if [ -z "$HS" ] ; then #error "$hcfg_hfrq" nonfatal + HS=${HSYNCRANGE} +fi +if [ -z "$VS" ] ; then #error "$hcfg_vfrq" nonfatal + VS=${VSYNCRANGE} +fi +if [ -z "$SCR_MODES" ] ; then #error "$hcfg_res" nonfatal + SCR_MODES=${DEFAULTMODES} +fi +monmanual=yes + +# check for special X driver (fglrx, nvidia, ...) +check_glx + +# finally write config file +echo -e "#\n# autogenerated X hardware configuration by $0\n# \ +Dirk von Suchodoletz <dirk@goe.net>, $date" >$xfc +echo -e "# DO NOT EDIT THIS FILE BUT '$0' INSTEAD!\n#" \ + >>$xfc +for section in Files ServerFlags Module InputDevice Monitor \ + Screen Device ServerLayout DRI ; do + echo "Section \"$section\"" >>$xfc + case "$section" in + Files) + echo -e ${Files} >>$xfc + # check for 64bit CPU/installation (fixme!!) + [ -n "$amd64" ] && \ + echo '"\tModulePath\t"/usr/X11R6/lib64/modules"\n' >>$xfc + for i in ${D_XFONTPATH} ; do + echo -e "\tFontPath\t\"$i/\"" >>$xfc ; done + ;; + ServerFlags) + echo -e ${ServerFlags} >>$xfc + ;; + Device) + echo -e ${Device} | \ + sed -e "s,XMODULE,${XMODULE}," -e "s%XDESC%${XDESC}%" >>$xfc + # write TV config - no problem, if no TV is connected + [ -n "$TVOUT" ] && echo -e $TVOUT >>$xfc + [ x$DRV = "xs3virge" ] && \ + echo -e "\tOption\t\t\"XVideo\" \"Off\"\n" >>$xfc + [ x$DRV = "xnvidia" ] && { + echo -e "\tOption\t\t\"NvAGP\" \"3\"" >>$xfc + echo -e "\tOption\t\t\"NoLogo\" \"1\"" >>$xfc ; } + ;; + Module) + echo -e ${Module} >>$xfc + #[ "x$DRM" = "xyes" ] && \ + echo -e "\tLoad\t\t\"dri\"" >>$xfc + [ x$GLX != "xno" ] && \ + echo -e "\tLoad\t\t\"glx\"" >>$xfc + ;; + Monitor) + echo -e ${Monitor} | \ + sed -e "s,HS,${HS},g" -e "s,VS,${VS},g" >>$xfc + ;; + InputDevice) + echo -e ${InputDevice} | sed -e "s,XKEYBOARD,${XKEYBOARD},g" \ + >>$xfc + [ "${XKEYBOARD}" = "de" ] && \ + echo -e '\tOption\t\t"XkbVariant"\t\t"nodeadkeys"' >>$xfc + echo -e "EndSection\n\nSection \"$section\"" >>$xfc + # if special synaptics touchpad was detected and specific driver + # is present + if strinfile "synaptics" /tmp/hwsetup.info && \ + test -e /mnt/usr/X11R6/lib/modules/input/synaptics_drv.o ; then + echo -e $InputMouseSyn >>$xfc + else + echo -e $InputMouseDef >>$xfc + fi + ;; + Screen) + echo -e ${Screen} | sed -e "s,CDP,${CDP}," >>$xfc + for BPP in 15 16 24 + do echo -e '\tSubSection "Display"\n\t\tDepth\t'\ + $BPP'\n\t\tModes\t'$SCR_MODES'\n\tEndSubSection' >>$xfc + [ $BPP = "$CDP" ] && break + done + ;; + ServerLayout) + echo -e ${ServerLayout} >>$xfc + ;; + DRI) + echo -e ${DRI} >>$xfc + ;; + esac + echo -e "EndSection\n" >>$xfc +done +} + +####################################################################### +# 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 ] && echo "** HW 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 + +# 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 + +# USB core is needed for presence of /proc/bus/usb +modprobe ${MODPRV} usbcore & + +# "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\ + ${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 + +# start the knoppix hardware autodetection tool +( hwsetup -v > /tmp/hwsetup.info && echo "hwsetup" > /tmp/hwrun1 ) & + +# ACPI configuration - at least not needed with SuSE 9.3/10.0 +# needed for other distros? + +# AGP configuration (agpgart and chipset specific driver) +modprobe ${MODPRV} agpgart || \ + modprobe ${MODPRV} agpgart agp_try_unsupported=1 + +# wait for /tmp/hwsetup.info to appear +waitfor /tmp/hwrun1 50000 || \ + error "$hcfg_hwsetup" +# load ide drivers first, takes a while to initialize +for DRIVER in cmd64x hpt366 piix slc90e66 cs5520 it821x rz1000 \ + triflex aec62xx cs5530 ns87415 sc1200 trm290 alim15x3 \ + cy82c693 opti621 serverworks via82cxxx amd74xx pdc202xx_new \ + siimage atiixp hpt34x pdc202xx_old sis5513; do + strinfile " ${DRIVER}" /tmp/hwsetup.info && { + IDE="yes" + modprobe ${MODPRV} ${DRIVER} & + DRIVERLIST="${DRIVERLIST} ${DRIVER}"; } +done +# check for IDE/SCSI (SATA) +for DRIVER in ata_piix sata_via sata_nv sata_sil sata_sis sata_svw \ + sata_sx4 sata_uli sata_vsc sata_qstor sata_promise sata_mv; do + strinfile " ${DRIVER}" /tmp/hwsetup.info && { + #SCSIIDE="yes" + modprobe ${MODPRV} ${DRIVER} & + DRIVERLIST="${DRIVERLIST} ${DRIVER}"; } +done +# check for USB, pcmcia and ieee1394 hardware drivers +for DRIVER in ohci-hcd uhci-hcd ehci-hcd ohci1394; do + strinfile " ${DRIVER}" /tmp/hwsetup.info && { + USB="yes" + modprobe ${MODPRV} ${DRIVER} + DRIVERLIST="${DRIVERLIST} ${DRIVER}"; } +done +# load usbhid (for USB keyboard/mouse) or remove usbcore module if USB +# not present +if [ -n "$USB" ] ; then + modprobe ${MODPRV} usbhid & +else rmmod usbcore +fi +# remove unneeded network card modules +for DRIVER in ${NWMODULES}; do + strinfile " ${DRIVER}" /tmp/hwsetup.info || { + rmmod ${DRIVER} & + DRIVERLIST="${DRIVERLIST} ${DRIVER}"; } +done +# 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? + +if [ -n "${PCMCIA}" ] ; then + modprobe ${MODPRV} ds +fi +# sound card setup (alsa and oss compatibility drivers) +if [ -f /etc/sysconfig/sound ] ; then + . /etc/sysconfig/sound +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 + +# 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 +test -f /proc/bus/usb/devices || mount -n -t usbfs usbfs /proc/bus/usb +[ -n "$IDE" ] && modprobe -q ide_generic 2>/dev/null +usleep 10 && hwsetup -v > /tmp/hwsetup.info +# 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 8; } + DRIVERLIST="${DRIVERLIST} ${DRIVER}" + fi + fi +done +# check if USB mouse and/or keyboard is connected and remove usbhid if +# not +strinfile "genericwheelusb" /tmp/hwsetup.info || \ + (strinfile "keybdev" /tmp/hwsetup.info || rmmod usbhid) + +# 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 +fi + +# not rather precise ... +if strinfile "SCSI" /tmp/hwsetup.info ; then + strinfile "CDROM" /tmp/hwsetup.info && { modprobe ${MODPRV} sr_mod; + modprobe ${MODPRV} sg; } + strinfile "HD" /tmp/hwsetup.info && modprobe ${MODPRV} sd_mod + strinfile "SCANNER" /tmp/hwsetup.info && \ + echo -e 'KERNEL=="sg*",\t\tNAME="%k", GROUP="disk", MODE="666"' \ + >> /mnt/etc/udev/rules.d/04-scanner.rules +fi +# fixme - psmouse entladen, falls nicht vorhanden + +# configure some variables from configuration file - wait for dhcp or ldap +# confiurator to complete +cfgcomplete +. /etc/machine-setup + +# run localizator and configure keyboard and console fonts +DEFKEYTABLE="de-latin1-nodeadkeys" +localization $country +if [ -z "${KEYTABLE}" ] ; then + error "$hcfg_keyb" nonfatal + KEYTABLE=${DEFKEYTABLE} +fi + +# run X11 / Xorg configurator if no xorg.conf file was provided by +# ConfigTGZ (check for /rootfs/${D_XF86CONFFILE#/mnt}) +if [ -f /rootfs${D_XF86CONFFILE#/mnt} ] ; then + echo "ready" > /tmp/xready +else + . /etc/sysconfig/xserver >/dev/null 2>&1 || error "$hcfg_hwsetup" nonfatal + ( displaysetup /etc/xorg.conf; echo "ready" > /tmp/xready ) & +fi + +# get idea of availabe harddisk partitions, put swap partitions into +# (/mnt)/etc/fstab and format and mount partitions of type 44 (unknown) +for hd in $(cat /tmp/hwsetup.info|sed -n -e '/HD$/,/device:/p'| \ + sed -n -e '/device:/p' | sed -e 's/device: //') ; do + 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 + # ext2fs_check_if_mount message supressed + ( mkfs.ext2 -Fq $hdpartnr 2>/dev/null + umount /mnt/tmp 2>/dev/null + # if mounting of temp partion fails fall back to tmpfs on /tmp + mount -n -o nocheck,noexec $hdpartnr /mnt/tmp 2>/dev/null || \ + mount -n -t tmpfs none /mnt/tmp + echo "$hdpartnr is mounted to /tmp" > /tmp/tmpready ) & + echo -e "$hdpartnr\t/tmp\t\text2\t\tdefaults\t 0 0" >> /tmp/fstab + 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" > /tmp/tmpready + +# wait for completion of clients root filesystem in /mnt +waitfor /tmp/fscmpl 40000 +[ -f /tmp/fstab ] && cat /tmp/fstab >> /mnt/etc/fstab + +# add entries to initialize keytable and consolefont to boot.ld +# postpone some commands into normal bootup environment +echo -e "\t# entries added by $0: $date" >> /mnt/etc/${D_INITDIR}/boot.ld +[ -n "${KEYTABLE}" ] && keytable +[ -n "${CONSOLE_FONT}" ] && consolefont + +# finalize X configuration +# only if X is link itself (normally to /var/X11R6/bin/X) check!! +link=`ls -l /mnt/usr/X11R6/bin/X 2>/dev/null` +if strinstr "/var/X11R6" "$link" ; then + testmkd /mnt/var/X11R6/bin + for i in /usr/X11R6/bin/Xorg /usr/X11R6/bin/XFree86 ; do + [ -e "/mnt/$i" ] && { ln -sf $i /mnt/var/X11R6/bin/X; break; } + done +fi +# wait for completion of Xorg configuration +waitfor /tmp/xready 10000 +cp /etc/xorg.conf ${D_XF86CONFFILE} + +# script run timer +[ $DEBUGLEVEL -eq 8 ] && echo "** HW setup finished at $(sysup)" + +echo "finished" > /tmp/hwcfg |