home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Internet 2000 December / MICD_2000_12_NR1.iso / Dreamnet / drivery / SMC / 1211.exe / SCO / 3.X / RECONF < prev    next >
Text File  |  1997-10-26  |  18KB  |  648 lines

  1.  
  2. #
  3. #               (C) 1989-1990 The Santa Cruz Operation, Inc.  All Rights
  4. #               Reserved.  The user has unlimited right to use, modify
  5. #               and incorporate this code into other products provided
  6. #               it is used with SCO products and the user includes
  7. #               this notice and the associated copyright notices with
  8. #               any such application.
  9. #
  10. #
  11. #
  12. LIB=/usr/lib/lli
  13. CONF=/etc/conf
  14. PATH=/bin:/usr/bin:/etc/:$CONF/bin:$LIB
  15. #
  16. # Set possible return codes for this script
  17. #
  18. OK=0;   FAIL=1; RELINK=2;
  19.  
  20. BRAM="0"
  21. ERAM="0"
  22.  
  23. #
  24. # Prompt the user for a hex value, it must be within a given range
  25. # Usage:
  26. #       prompt_range "Message" default min max [step]
  27. #
  28. prompt_range() {
  29.         mesg=$1
  30.         default=$2
  31.         range_min=$3 range_max=$4
  32.         step="1"
  33.         if [ $# -eq 5 ]
  34.         then
  35.                 step=$5
  36.         fi
  37.  
  38.         while :
  39.         do
  40.                 echo "${mesg} (${range_min}..${range_max}) [${default}] or 'q' to quit: \c"
  41.                 read result
  42.                 case $result in
  43.                 Q|q)
  44.                         return $FAIL
  45.                         ;;
  46.                 "")
  47.                         result=$default
  48.                         ;;
  49.                 esac
  50.  
  51.                 hc $result $range_min $range_max $step
  52.                 case $? in
  53.                 0) return $OK;;
  54.                 1) cleanup $FAIL;;
  55.                 2) cleanup $FAIL;;
  56.                 esac
  57.         done
  58. }
  59.  
  60. #
  61. # Prompt the user to make a selection a list of values
  62. # Usage:
  63. #       prompt_select "Message" default "value_list"
  64. prompt_select() {
  65.         mesg=$1
  66.         default=$2
  67.         values=$3
  68.  
  69.         while :
  70.         do
  71.                 if [ "$default" = "" ]
  72.                 then
  73.                         echo "${mesg} (${values}) or 'q' to quit: \c"
  74.                 else
  75.                         echo "${mesg} (${values}) [${default}] or 'q' to quit: \c"
  76.                 fi
  77.                 read result
  78.                 case $result in
  79.                 Q|q)
  80.                         return $FAIL
  81.                         ;;
  82.                 "")
  83.                         result=$default
  84.                         ;;
  85.                 esac
  86.  
  87.                 for i in $values
  88.                 do
  89.                         if [ "$i" = "$result" ]
  90.                         then
  91.                                 return $OK
  92.                         fi
  93.                 done
  94.                 echo "Illegal value, must be one of (${values})"
  95.         done
  96. }
  97.  
  98. #
  99. # prompt the user to answer a yes no question or 'q' to quit
  100. # Usage:
  101. #       prompt_yn "Message" default
  102. prompt_yn() {
  103.         mesg=$1
  104.         default=$2
  105.  
  106.         while :
  107.         do
  108.                 echo "${mesg} (y/n) [${default}] or 'q' to quit: \c"
  109.                 read result
  110.  
  111.                 case $result in
  112.                 q|Q) return $FAIL;;
  113.                 y|Y) result="Y"; return $OK;;
  114.                 n|N) result="N"; return $OK;;
  115.                 "") result=`echo $default | tr "yn" "YN"`; return $OK;;
  116.                 esac
  117.  
  118.                 echo "Illegal value, please type 'y' 'n' or 'q'"
  119.         done
  120. }
  121.  
  122. #
  123. # Fake up an mdevice and an sdevice for idcheck
  124. # Do not remove $base if called with an argument...
  125. #
  126. makedevs() {
  127.         dir=`pwd`
  128.         rm -fr /tmp/dev$$
  129.         mkdir /tmp/dev$$
  130.         cd /etc/conf/cf.d
  131.         cp mdevice /tmp/dev$$
  132.         cd ../sdevice.d
  133.         cat * > /tmp/dev$$/sdevice
  134.         [ $1 ] && {
  135.                 # remove driver being reconfigured from sdevice & mdevice files.
  136.                 sed -e "/^$base/d" < /tmp/dev$$/sdevice > /tmp/bog$$
  137.                 mv /tmp/bog$$ /tmp/dev$$/sdevice
  138.                 sed -e "/^$base/d" < /tmp/dev$$/mdevice > /tmp/bog$$
  139.                 mv /tmp/bog$$ /tmp/dev$$/mdevice
  140.         }
  141.         cd $dir
  142. }
  143.  
  144. cleanup() {
  145.         cd /
  146.         rm -fr /tmp/dev$$
  147.         rm -fr /tmp/$base
  148.         exit $1
  149. }
  150.  
  151. # Removes the given interrupt vector for the $clash device.
  152. rmvector() {
  153.         clash=$1
  154.         vec=$2
  155.  
  156.         cd $confdir
  157.         echo "\nRemoving interrupt vector $vec for the $clash device ..."
  158.  
  159.         [ "$vec" = "2" ] && vec=9
  160.         major=`./configure -j $clash` && {
  161.                 # remove device but leave it required
  162.                 ./configure -d -c -m $major -v $vec -Y >> conflog 2>&1 || {
  163.                         cd $currdir
  164.                         cleanup $FAIL
  165.                 }
  166.                 # remove required setting if no more left
  167.                 if grep "Y" ../sdevice.d/$clash > /dev/null 2>&1
  168.                 then
  169.                         true
  170.                 else
  171.                         ./configure -d -c -m $major -v $vec -R -Y >> conflog 2>&1 || {
  172.                                 cd $currdir
  173.                                 cleanup $FAIL
  174.                         }
  175.                 fi
  176.         }
  177.         cd $currdir
  178.         return $OK
  179. }
  180.  
  181. # On unix, we must check the files in sdevice.d.
  182. # Sets the variable $clash to the driver code name if there is a driver that
  183. # has already been allocated the given vector. Uses awk.
  184. dointclash() {
  185.         driver=$1
  186.         vec=$2
  187.  
  188.         [ "$vec" = "2" ] && vec=9
  189.         cd $confdir/../sdevice.d
  190.         clash=`cat * | awk '{ if ( $6 == intr && $2 == "Y" ) exit } \
  191.                         END { print $1 }' intr=$vec`
  192.  
  193.         cd $currdir
  194.  
  195.         [ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
  196.         # found a clash
  197.         return $OK
  198. }
  199.  
  200. checkvec() {
  201.         driver=$1
  202.         vector=$2
  203.         clash=
  204.  
  205.         currdir=`pwd`
  206.         confdir=/etc/conf/cf.d
  207.  
  208.         while dointclash $driver $vector
  209.         do
  210.                 prompt_select "Interrupt vector $vector is already in use for the $clash device.\n\n\
  211. The alternatives available to you are:\n\n\
  212. \t1. Continue the installation and remove vector $vector for the $clash device.\n\
  213. \t2. Select a different interrupt vector.\n\n\
  214. Select an option" 1 "1 2" || {
  215.                         cleanup $FAIL
  216.                 }
  217.                 case $result in
  218.                 1)      rmvector $clash $vector || {
  219.                                 echo "Failed to remove vector $vector"
  220.                                 cleanup $FAIL
  221.                         }
  222.                         makedevs
  223.                         return $OK
  224.                         ;;
  225.                 2)      return $FAIL
  226.                         ;;
  227.                 esac
  228.         done
  229.         return $OK
  230. }
  231.  
  232. doaddrclash() {
  233.         driver=$1
  234.         addr1=$2
  235.         addr2=$3
  236.  
  237.         cd $confdir
  238.         clash=`../bin/idcheck -ar -l $addr1 -u $addr2 -i /tmp/dev$$`
  239.         cd $currdir
  240.  
  241.         [ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
  242.         # found a clash
  243.         return $OK
  244. }
  245.  
  246. # Removes the $clash device.
  247. rmaddr() {
  248.         clash=$1
  249.  
  250.         cd $confdir
  251.         echo "\nRemoving the $clash device ..."
  252.  
  253.         major=`./configure -j $clash` && {
  254.                 # remove device but leave it required
  255.                 if [ "$major" != "0" ]
  256.                 then
  257.                         ./configure -d -c -m $major -Y >> conflog 2>&1 || {
  258.                                 cd $currdir
  259.                                 cleanup $FAIL
  260.                         }
  261.                 else
  262.                         sed -e "s/Y/N/" ../sdevice.d/$clash > /tmp/bog$$
  263.                         mv /tmp/bog$$ ../sdevice.d/$clash
  264.                 fi
  265.                 # remove required setting if no more left
  266.                 if grep "Y" ../sdevice.d/$clash > /dev/null 2>&1
  267.                 then
  268.                         true
  269.                 elif [ "$major" != "0" ]
  270.                 then
  271.                         ./configure -d -c -m $major -R -Y >> conflog 2>&1 || {
  272.                                 cd $currdir
  273.                                 cleanup $FAIL
  274.                         }
  275.                 fi
  276.         }
  277.         cd $currdir
  278.         return $OK
  279. }
  280.  
  281. checkaddr() {
  282.         driver=$1
  283.         addr1=$2
  284.         addr2=$3
  285.         clash=
  286.  
  287.         currdir=`pwd`
  288.         confdir=/etc/conf/cf.d
  289.  
  290.         while doaddrclash $driver $addr1 $addr2
  291.         do
  292.                 if [ "$clash" = "ad" ]
  293.                 then
  294.                         echo "\n\nWARNING: Do not remove the $clash device \c"
  295.                         echo "if you are using an Adaptec disk controller"
  296.                 fi
  297.                 prompt_select "Addresses $addr1-$addr2 are already in use by the $clash device.\n\n\
  298. The alternatives available to you are:\n\n\
  299. \t1. Continue the installation and remove the $clash device.\n\
  300. \t2. Select a different address.\n\n\
  301. Select an option" 1 "1 2" || {
  302.                         cleanup $FAIL
  303.                 }
  304.                 case $result in
  305.                 1)      rmaddr $clash || {
  306.                                 echo "Failed to remove $clash device"
  307.                                 cleanup $FAIL
  308.                         }
  309.                         makedevs
  310.                         return $OK
  311.                         ;;
  312.                 2)      return $FAIL
  313.                         ;;
  314.                 esac
  315.         done
  316.         return $OK
  317. }
  318.  
  319. doramclash() {
  320.         driver=$1
  321.         addr1=$2
  322.         addr2=$3
  323.  
  324.         cd $confdir
  325.         clash=`../bin/idcheck -cr -l $addr1 -u $addr2 -i /tmp/dev$$`
  326.         cd $currdir
  327.  
  328.         [ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
  329.         # found a clash
  330.         return $OK
  331. }
  332.  
  333. checkram() {
  334.         driver=$1
  335.         addr1=$2
  336.         addr2=$3
  337.         clash=
  338.  
  339.         currdir=`pwd`
  340.         confdir=/etc/conf/cf.d
  341.  
  342.         while doramclash $driver $addr1 $addr2
  343.         do
  344.                 prompt_yn "
  345. Ram addresses $addr1-$addr2 is already in use for the $clash device.
  346. You must choose a unique address for this device to work.
  347. Do you wish to choose another address now?" y || cleanup $FAIL
  348.                 if [ "$result" = "Y" ]
  349.                 then
  350.                         return $FAIL
  351.                 else
  352.                         cleanup $FAIL
  353.                 fi
  354.         done
  355.         return $OK
  356. }
  357.  
  358. # On unix, we must check the lines in mdevice file.
  359. # Sets the variable $clash to the driver code name if there is a driver that
  360. # has already been allocated the given channel. Uses awk.
  361. dodmaclash() {
  362.         driver=$1
  363.         chan=$2
  364.         clash=
  365.  
  366.         # -1 is never a clash
  367.         [ "$chan" = "-1" ] && return $FAIL
  368.  
  369.         cd $confdir
  370.         clash=`awk '{ if ( $1 != driver && $9 == dma ) print $1 }' dma=$chan driver=$driver mdevice`
  371.  
  372.         [ "$clash" = "" ] && {
  373.                 cd $currdir
  374.                 return $FAIL
  375.         }
  376.  
  377.         cd ../sdevice.d
  378.         cat $clash | awk '{ if ( $2 == "Y" ) exit 1 }' || return $OK
  379.  
  380.         if [ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ]
  381.         then
  382.                 prompt_yn "
  383. DMA channel ${chan} is already in use by the $clash device.
  384. However, the $clash device is not currently configured into the kernel.
  385. Do you wish to remove DMA channel ${chan} from the $clash device?" y || cleanup $FAIL
  386.                 if [ "$result" = "Y" ]
  387.                 then
  388.                         sed -e "s/Y/N/" $clash > /tmp/bog$$
  389.                         mv /tmp/bog$$ $clash
  390.                         cd $currdir
  391.                         return $FAIL
  392.                 else
  393.                         cd $currdir
  394.                         return $FAIL
  395.                 fi
  396.         fi
  397.  
  398.         # Should be release >3.2.2, clash driver not installed if we get here.
  399.         cd $currdir
  400.         return $FAIL
  401. }
  402.  
  403. #
  404. # Check if there is a clash of DMA channels
  405. #
  406. checkdma() {
  407.         driver=$1
  408.         channel=$2
  409.         clash=
  410.  
  411.         currdir=`pwd`
  412.         confdir=/etc/conf/cf.d
  413.  
  414.         while dodmaclash $driver $channel
  415.         do
  416.                 prompt_yn "
  417. DMA channel ${channel} is already in use by the $clash device.
  418. You must choose a unique channel for this device to work.
  419. Do you wish to choose another channel now?" y || cleanup $FAIL
  420.                 if [ "$result" = "Y" ]
  421.                 then
  422.                         return $FAIL
  423.                 else
  424.                         cleanup $FAIL
  425.                 fi
  426.         done
  427.         return $OK
  428. }
  429.  
  430. check_args() {
  431.         name=$1
  432.         bd=$2
  433.  
  434.         case $name in
  435.         r7e) echo "Configuring PCI ethernet adapter board $bd";
  436.                 PREFIX="r7e";
  437.                 MAX_BD=3;
  438.                 ;;
  439.         *) echo "ERROR: Unknown LLI driver being configured ($name$bd)";
  440.                 cleanup $FAIL;
  441.                 ;;
  442.         esac
  443.  
  444.         if [ $bd -gt $MAX_BD ]
  445.         then
  446.                 echo "ERROR: Only boards 0..$MAX_BD are supported by this driver";
  447.                 cleanup $FAIL
  448.         fi
  449.         echo
  450. }
  451.  
  452. #
  453. # restorevector check for sio (vecs 3-4) and pa drivers (vec 7)
  454. # if these are being released by lli then let us restore them to sio or pa
  455. restorevector() {
  456.         currdir=`pwd`
  457.         cd /etc/conf/cf.d
  458.  
  459.         intvector=$1
  460.         test="0"
  461.         [ "$intvector" = "3" -o "$intvector" = "4" ] && {
  462.                 prompt_yn "Restore vector $intvector to sio driver" y
  463.                 [ "$result" = "Y" ] && {
  464.                         echo "Restoring vector $intvector to sio driver"
  465.                         siomajor=`./configure -j sio`
  466.                         ./configure -m $siomajor -c -v $intvector -a -Y
  467.                         return $OK
  468.                 }
  469.         }
  470.         [ "$intvector" = "7" ] && {
  471.                 prompt_yn "Restore vector $intvector to pa driver" y
  472.                 [ "$result" = "Y" ] && {
  473.                         echo "Restoring vector $intvector to pa driver"
  474.                         pamajor=`./configure -j pa`
  475.                         ./configure -m $pamajor -c -v $intvector -a -Y
  476.                         return $OK
  477.                 }
  478.         }
  479.         return $OK
  480. }
  481.  
  482. #
  483. # determine release, and AT or MCA bus - set rel and type variables accordingly.
  484. #
  485. os_type() {
  486.         rel=`sed -n 's/^#rel=\(.*\).$/\1/p' /etc/perms/rts`
  487.         if [ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ]
  488.         then
  489.                 type=`sed -n 's/^#typ=\(.*\)$/\1/p' /etc/perms/inst`
  490.         else
  491.                 # 3.2.4 - one release supports AT, MCA, and EISA.
  492.                 uname -X | grep "BusType = MCA" >/dev/null 2>&1
  493.                 if [ $? -eq 0 ]
  494.                 then
  495.                         type=386MC
  496.                 else
  497.                         type=386GT
  498.                 fi
  499.         fi
  500. }
  501.  
  502.  
  503.  
  504.  
  505. #
  506. # function to produce the info for the System file for the RTL
  507. # boards
  508. #
  509. system_r7e() {
  510. bd=$1
  511. IRQ=0;
  512. DMA=-1;
  513. FORCE="auto";
  514. BIO=0;
  515. EIO=0;
  516. BUS=0;
  517. DMACHAN=-1
  518. NMINORS="1"
  519.  
  520. ############################################
  521. ##########clt 11/15/1996####################
  522. ####change space.c file ####################
  523. #set -x
  524. #prompt_select "Enter auto, force 100 or 10bps:" $FORCE "auto 10 100" || cleanup $FAIL
  525. #FORCE=$result
  526. #[ "$result" = "auto" ] && FORCE="0"
  527. #[ "$result" = "10" ] && FORCE="10"
  528. #[ "$result" = "100" ] && FORCE="100"
  529.  
  530. prompt_select "Enter hardware_default_setting, or auto, force 10 or 10bps, half or full duplex:" $FORCE "hwset auto 10half 10full 100half 100full" || cleanup $FAIL
  531. FORCE=$result
  532. [ "$result" = "hwset" ] && FORCE="0"
  533. [ "$result" = "auto" ] && FORCE="2"
  534. [ "$result" = "10half" ] && FORCE="10"
  535. [ "$result" = "10full" ] && FORCE="11"
  536. [ "$result" = "100half" ] && FORCE="100"
  537. [ "$result" = "100full" ] && FORCE="101"
  538.  
  539. spacef=${CONF}/pack.d/${drv}0/space.c
  540. a=`grep  "^#define[ ]${drv}force_$bd" $spacef`
  541. c="#define ${drv}force_$bd $FORCE"
  542. sed "s/${a}/${c}/" $spacef > /tmp/bog$$
  543. cp /tmp/bog$$ $spacef
  544. rm /tmp/bog$$
  545.  
  546. echo "Detect PCI fast ethernet adapter hardware automatically."
  547. }
  548.  
  549.  
  550.  
  551. # main()
  552. #
  553.  
  554. #
  555. # get the name of the init script being run, since one script
  556. # is used for multiple drivers; get the number at the end of the
  557. # script's name
  558. #
  559. if [ $# -gt 1 ]
  560. then
  561.         name_below=$1; if_below=$2
  562.         name_above=$3; if_above=$4
  563.         configure=$5
  564. fi
  565.  
  566. base=`basename $0`
  567. drv=`echo $base | sed -e 's/[0-9]*$//`
  568. bd=`expr $base : '.*\(.\)'`
  569.  
  570. makedevs $OK
  571. check_args $drv $bd
  572.  
  573. #
  574. # verify the driver is in the kernel link-kit
  575. #
  576. idcheck -p $base -i /tmp/dev$$
  577. if [ $? -le 16 ]
  578. then
  579.         echo "Error: $base driver is not installed"
  580.         cleanup $FAIL
  581. fi
  582.  
  583. echo "Reconfiguring the $drv driver"
  584. cd /usr/lib/lli/$drv
  585. makedevs
  586.  
  587. #
  588. # create the temporary directory for installing the driver
  589. #
  590. cd /tmp; rm -rf $base
  591. mkdir $base; cd $base
  592.  
  593. DMACHAN="-1"
  594.  
  595. #
  596. # set rel, type variables.
  597. #
  598. os_type
  599.  
  600. # get the interrupt vector & Base I/O address for the board that we are removing
  601. currdir=`pwd`
  602. cd /etc/conf/sdevice.d
  603. ivec=`awk '{ if ( $1 != "*" ) print $6 }' < $base`
  604. OBIO=`awk '{ if ( $1 != "*" ) print $7 }' < $base`
  605. cd $currdir
  606.  
  607. #
  608. # Do special board dependent processing
  609. #
  610. system_$drv $bd
  611.  
  612. echo
  613. if [ "$IRQ" = "2" ]
  614. then
  615.         IRQ=9
  616. fi
  617.  
  618. echo "$base\tY\t$NMINORS\t5\t0\t$IRQ\t$BIO\t$EIO\t$BRAM\t$ERAM" >./System
  619.  
  620. #
  621. # All the drivers support more than one board.  In fact all the code to
  622. # support all the boards is in the Driver.o for the board for the 1st board
  623. # (eg the e3A0 driver acually contains enough code for the e3A1, e3A2 & e3A3
  624. # boards).  As we need a Driver.o to be associated with 2nd, 3rd or 4th board
  625. # we install a dummy Driver.o, and a Master and Node which will actually cause
  626. # calls into the base driver.
  627. #
  628. if [ $bd -gt 0 ]
  629. then
  630.         echo "$base     -       iScH    $PREFIX$bd      0       0       1       256     $DMACHAN" >./Master
  631.         echo "clone     $base   c       $base" >./Node
  632.  
  633.         idinstall -u -m -s -n -e -k $base
  634. else
  635.         echo "$base     I       iScH    $PREFIX 0       0       1       256     $DMACHAN" >./Master
  636.         idinstall -u -m -s -e -k $base
  637. fi
  638.  
  639. # delete any potential BASE I/O address conflicts with the sio driver
  640. [ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ] && sio_conflict
  641.  
  642. if [ "$ivec" = "3" -o "$ivec" = "4" -o "$ivec" = "7" ]
  643. then
  644.         [ ${ivec} != ${IRQ} ] && restorevector $ivec
  645. fi
  646.  
  647. cleanup $RELINK
  648.