Metropoli BBS
VIEWER: init.son MODE: TEXT (ASCII)
:
#
#	Copyright (C) The Santa Cruz Operation, 1988.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, and Lachman Associates Inc. 
#	and should be treated as Confidential.
#
#
PATH=/bin:/usr/bin:/etc:/etc/conf/bin
LIB=/usr/lib/lli
CONF=/etc/conf
PATH=/bin:/usr/bin:/etc/:$CONF/bin:$LIB
#
# Set possible return codes for this script
#
OK=0;	FAIL=1;

# Prompt for yes or no answer with message passed as argument - 
# returns non-zero for no
getyn() {
	while	echo "$* (y/n/q) \c">&2
	do	read yn rest
		case $yn in
			[yY]) return 0				;;
			[nN]|[qQ]) return 1			;;
		*)	echo "Please answer y,n or q" >&2	;;
		esac
	done
}

#
# Fake up an mdevice and an sdevice for idcheck
#
makedevs() {
	dir=`pwd`
	rm -fr /tmp/dev$$
	mkdir /tmp/dev$$
	cd /etc/conf/cf.d
	cp mdevice /tmp/dev$$
	cd ../sdevice.d
	cat * > /tmp/dev$$/sdevice
	cd $dir
}

cleanup() {
	cd /
	rm -fr /tmp/dev$$
	[ -z "$base" ] || rm -fr /tmp/${base}
	exit $1
}

#
# determine release, and AT or MCA bus - set rel and type variables accordingly.
#
os_type() {
	rel=`sed -n 's/^#rel=\(.*\).$/\1/p' /etc/perms/rts`
	if [ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ]
	then
		type=`sed -n 's/^#typ=\(.*\)$/\1/p' /etc/perms/inst`
	else
		# 3.2.4 - one release supports AT, MCA, and EISA.
		uname -X | grep "BusType = MCA" >/dev/null 2>&1
		if [ $? -eq 0 ]
		then
			type=386MC
		else
			type=386GT
		fi
	fi
}

# Removes the given interrupt vector for the $clash device.
rmvector() {
	clash=$1
	vec=$2

	cd $confdir
	echo "\nRemoving interrupt vector $vec for the $clash device ..."

	[ "$vec" = "2" ] && vec=9
	major=`./configure -j $clash` && { 
		# remove device but leave it required
		if [ "$major" != "0" ] 
		then
			./configure -d -c -m $major -v $vec -Y >> conflog 2>&1 || { 
				cd $currdir
				cleanup $FAIL
			}
		else
			sed -e "s/Y/N/" ../sdevice.d/$clash > /tmp/bog$$
			mv /tmp/bog$$ ../sdevice.d/$clash 
		fi
		# remove required setting if no more left
		if grep "Y" ../sdevice.d/$clash > /dev/null 2>&1
		then
			true
		elif [ "$major" != "0" ]
		then
			./configure -d -c -m $major -v $vec -R -Y >> conflog 2>&1 || { 
				cd $currdir
				cleanup $FAIL
			}
		fi
    	}
	cd $currdir
	return $OK
}

# On unix, we must check the files in sdevice.d.
# Sets the variable $clash to the driver code name if there is a driver that
# has already been allocated the given vector. Uses awk.
dointclash() {
	driver=$1
	vec=$2

	[ "$vec" = "2" ] && vec=9
	cd $confdir/../sdevice.d
	clash=`cat * | awk '{ if ( $6 == intr && $2 == "Y" ) exit } \
			END { print $1 }' intr=$vec`

	cd $currdir

	[ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
	# found a clash
	return $OK
}

checkvec() {
	driver=$1
	vector=$2
	clash=

	currdir=`pwd`
	confdir=/etc/conf/cf.d

	while dointclash $driver $vector
	do
		rmvector $clash $vector
		makedevs
	done
	return $OK
}

doaddrclash() {
	driver=$1
	addr1=$2
	addr2=$3

	cd $confdir
	clash=`../bin/idcheck -ar -l $addr1 -u $addr2 -i /tmp/dev$$`
	cd $currdir

	[ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
	# found a clash
	return $OK
}

# Removes the $clash device.
rmaddr() {
	clash=$1

	cd $confdir
	echo "\nRemoving the $clash device ..."

	major=`./configure -j $clash` && { 
		# remove device but leave it required
		if [ "$major" != "0" ] 
		then
			./configure -d -c -m $major -Y >> conflog 2>&1 || { 
				cd $currdir
				cleanup $FAIL
			}
		else
			sed -e "s/Y/N/" ../sdevice.d/$clash > /tmp/bog$$
			mv /tmp/bog$$ ../sdevice.d/$clash 
		fi
		# remove required setting if no more left
		if grep "Y" ../sdevice.d/$clash > /dev/null 2>&1
		then
			true
		elif [ "$major" != "0" ]
		then
			./configure -d -c -m $major -R -Y >> conflog 2>&1 || { 
				cd $currdir
				cleanup $FAIL
			}
		fi
    	}
	cd $currdir
	return $OK
}

checkaddr() {
	driver=$1
	addr1=$2
	addr2=$3
	clash=

	currdir=`pwd`
	confdir=/etc/conf/cf.d

	while doaddrclash $driver $addr1 $addr2
	do
		rmaddr $clash
	done
	return $OK
}

doramclash() {
	driver=$1
	addr1=$2
	addr2=$3

	cd $confdir
	clash=`../bin/idcheck -cr -l $addr1 -u $addr2 -i /tmp/dev$$`
	cd $currdir

	[ "$clash" = "" -o "$clash" = "$driver" ] && return $FAIL
	# found a clash
	return $OK
}

dodmaclash() {
	driver=$1
	chan=$2
 	clash=

	# -1 is never a clash
	[ "$chan" -eq "-1" ] && return $FAIL

	cd $confdir
	files=`awk '{ if ( $9 == dma ) print $1 }' dma=$chan mdevice`

	cd $currdir
	[ "$files" = "" ] && return $FAIL

	# found a clash; see if driver is installed
	cd $confdir
	for clash in $files
 	do
		[ "$clash" = "$driver" ] && continue
 		awk '$1 !~ /^\*/ { if ( $2 == "Y" ) found=1 } END { exit found }' ../sdevice.d/$clash || return $OK
	done
	# None of the clashing devices are installed; no clash
	return $FAIL
}

check_args() {
	name=$1
	bd=$2

	case $name in
	son) echo "Configuring SONIC 32-bit board $bd";
		PREFIX="son";
		MAX_BD=3;
		;;
	*) echo "ERROR: Unknown LLI driver being configured ($name$bd)";
		cleanup $FAIL;
		;;
	esac

	if [ $bd -gt $MAX_BD ]
	then
		echo "ERROR: Only boards 0..$MAX_BD are supported by this driver";
		cleanup $FAIL

	elif [ $bd -ne $MAX_BD ]
	then
		currdir=`pwd`
		netconfigdir=/usr/lib/netconfig
		cd $netconfigdir/info
		newboard=`expr $bd + 1`
		newfile=${drv}${newboard}
		cp ${drv}0 $newfile
		sed -e '/^NAME=.*'"[^0]"'/s/0\"/'$newboard'\"/p' $newfile > /tmp/bog$$
		sed -e '/^DESCRIPTION=.*'"[^0]"'/s/0\"/'$newboard'\"/p' /tmp/bog$$ > $newfile
		rm -r /tmp/bog$$
		chown bin $newfile
		chgrp bin $newfile
		chmod 750 $newfile

		cd $netconfigdir/init
		ln $base ${drv}`expr $bd + 1` > /dev/null 2>&1

		cd $netconfigdir/remove
		ln $base ${drv}`expr $bd + 1` > /dev/null 2>&1
		cd $currdir
	fi
	echo
}

system_son() {
	bd=$1

	checkvec $name$bd $IRQ
	checkaddr $name$bd $BIO $EIO
	NMINORS="1"
	# up the 2k block buffers, this driver uses more than most drivers.
	awk '/^NBLK2048/ {
		NEW=$2+20
		printf "%s\t%s\n",$1,NEW
		next
	}
	{ print } ' < /etc/conf/cf.d/stune > /tmp/bog$$
	mv /tmp/bog$$ /etc/conf/cf.d/stune
}

#
# function to remove address conflicts in the sio driver
#
sio_conflict() {
	currdir=`pwd`
	cd /etc/conf/pack.d/sio
	if [ "$type" = "386GT" -a "$base" = "tok0" ]
	then
		# get rid of sio access to 0x2f0 (Global Interrupt enable) on AT
		grep "ibm COM3" space.c > /dev/null && {
			echo "Removing ibm COM3 from link kit..."
			[ ! -f space.c.rls ] && cp space.c space.c.rls
			sed -e /"ibm COM3/s/^{/\/* LLI {/p" space.c > /tmp/bog$$
			mv /tmp/bog$$ space.c > /dev/null 2>&1
		}
	fi
	grep "(sd)0x$BIO" space.c > /dev/null && {
		echo "Removing serial cards using base address 0x$BIO from link kit..."
		[ ! -f space.c.rls ] && cp space.c space.c.rls
		sed -e /"(sd)0x$BIO,/s/^{/\/* LLI {/p" space.c > /tmp/bog$$
		mv /tmp/bog$$ space.c > /dev/null 2>&1
	}
	cd $currdir
}

add()
{
	name_above=mkdev
	drv=`echo $base | sed -e 's/[0-9]*$//`
	bd=`expr $base : '.*\(.\)'`
	chains=/usr/lib/lli/chains
	chain=$base:$name_above

	makedevs
	check_args $drv $bd

	#
	# Check and manage our internal chains file.
	# This file allows coexistent mkdev and netconfig calls.
	#

	#
	# check to see if the driver is already in the kernel link-kit so we can
	# either add it or update it later on
	#
	idcheck -p $base -i /tmp/dev$$
	if [ $? -gt 16 ]
	then
		installed="TRUE"
	else
		installed="FALSE"
	fi

	if [ "$bd" = "0" ]
	then
		echo "Installing the $drv driver into the link kit"
		cd /usr/lib/lli/$drv
		if [ "$installed" = "TRUE" ]
		then
			idinstall -u -e -k $base
		else
			idinstall -a -e -k $base
		fi
		makedevs
	else
		idcheck -p ${drv}0 -i /tmp/dev$$
		if [ $? -le 16 ]
		then
			echo "${drv}0 must be configured before attempting to configure $drv"
			cleanup $FAIL
		fi
	fi

	#
	# create the temporary directory for installing the driver
	#
	cd /tmp; rm -rf $base
	mkdir $base; cd $base

	DMA="-1"

	#
	# Do special board dependent processing
	#
	system_$drv $bd

	echo
	if [ "$IRQ" = "2" ]
	then
		IRQ=9
	fi

	echo "$base\tY\t$NMINORS\t5\t1\t$IRQ\t$BIO\t$EIO\t$BRAM\t$ERAM" >./System

	#
	# All the drivers support more than one board.  In fact all the code to
	# support all the boards is in the Driver.o for the board for the 1st board
	# (eg the e3A0 driver acually contains enough code for the e3A1, e3A2 & e3A3
	# boards).  As we need a Driver.o to be associated with 2nd, 3rd or 4th board
	# we install a dummy Driver.o, and a Master and Node which will actually cause
	# calls into the base driver.
	#
	if [ $bd -gt 0 ]
	then
		echo "$base	-	iScH	$PREFIX$bd	0	0	1	256	$DMA" >./Master
		echo "clone	$base	c	$base" >./Node
	
		if [ "$installed" = "TRUE" ]
		then
			idinstall -u -m -s -n -e -k $base
		else
			cp $LIB/Driver.o .
			idinstall -a -e -k $base
		fi
	else
		echo "$base	I	iScH	$PREFIX	0	0	1	256	$DMA" >./Master
		idinstall -u -m -s -e -k $base
	fi
	# we successfully installed this driver, add it to the chains file
	echo $chain >> $chains

	echo "NODE=/etc/conf/node.d/$base" >/tmp/$base.src
	chmod 777 /tmp/$base.src
}

#
# if tcp is installed we remove the board from /etc/tcp and /etc/strcf
#
cleantcp() {
	driver=$1

	[ -f /etc/tcp ] && {
		sed "/$driver/d" /etc/tcp > /tmp/bog$$
		cp /tmp/bog$$ /etc/tcp
	}
	[ -f /etc/strcf ] && {
		sed "/$driver/d" /etc/strcf > /tmp/bog$$
		cp /tmp/bog$$ /etc/strcf
	}
	rm -f /tmp/bog$$
}

# main()
drv=`basename $0`
drv=`expr $drv : "init\.\([^%]*\).*"`

#
# set rel, type variables.
#
os_type

if [ "$type" = "386GT" ]
then
	if [ "$drv" = "e3C" ]
	then
		exit $OK
	fi
elif [ "$type" = "386MC" ]
then
	if [ "$drv" = "e3A" -o "$drv" = "e3B" -o "$drv" = "e3D" -o "$drv" = "exos" -o "$drv" = "hpe" -o "$drv" = "hpi" -o "$drv" = "i3B" -o "$drv" = "i6E" ]
	then
		exit $OK
	fi
fi

echo "Installing the $drv driver"

case "$drv" in 
	"i6E")	bds=""		;;
	"tok")	bds="1"		;;
	*)	bds="1 2 3"	;;
esac

if [ -f /etc/perms/tcprt ]
then
	grep rel=1.1 /etc/perms/tcprt >/dev/null 2>&1
	[ $? -eq 0 ] && {
		cp /usr/lib/lli/mkdev-tcp /usr/lib/mkdev/tcp
		chmod 750 /usr/lib/mkdev/tcp
		chgrp bin /usr/lib/mkdev/tcp
		chown bin /usr/lib/mkdev/tcp
	}
fi
[ -d /usr/lib/netconfig/info ] || mkdir -p /usr/lib/netconfig/info
[ -d /usr/lib/netconfig/init ] || mkdir -p /usr/lib/netconfig/init
[ -d /usr/lib/netconfig/remove ] || mkdir -p /usr/lib/netconfig/remove
[ -d /usr/lib/netconfig/reconf ] || mkdir -p /usr/lib/netconfig/reconf
cp /usr/lib/lli/mkdev /usr/lib/mkdev/${drv}
cp /usr/lib/lli/info/${drv}* /usr/lib/netconfig/info

cd /usr/lib/netconfig

for i in 0 $bds
do
	rm -f init/${drv}${i} init/${drv}${i}.def remove/${drv}${i}
	ln /usr/lib/lli/reconf/${drv}0 reconf/${drv}${i}
done
if [ "$bds" != "" ]
then
	for i in $bds
	do
		rm -f info/${drv}{$i}
	done
fi
ln /usr/lib/lli/init/${drv}0 init/${drv}0
ln /usr/lib/lli/remove/${drv}0 remove/${drv}0

# remove drivers first
cd /etc/conf/cf.d
boards="${drv}0"
for i in $bds
do
	boards="$boards ${drv}${i}"
done

# print warning message if any previously configured drivers are removed.
for i in $boards
do
	major=`./configure -j $i` && {
		[ -f ../sdevice.d/$i ] && {
			cfg=`awk '{\
				if ( substr($1, 1, 1) != "*" )\
					print $2\
			}' ../sdevice.d/$i`
			[ $cfg = "Y" ] && {
				echo "Removing old $i driver, you must reconfigure it to work."
				cleantcp $i
			}
		}
		./configure -d -c -m $major
	}
	rm -fr ../*/$i
done

# now add in the zero one.
cd /usr/lib/lli/$drv
idcheck -p ${drv}0
if [ $? -gt 16 ]
then
# Update all DSP components except the Sdevice file
	idinstall -u -m -n -o -p -e -k ${drv}0
else
# Add the Driver
	idinstall -a -e -k ${drv}0
fi

#
# Create the chains file.
#
[ -f /usr/lib/lli/chains ] || touch /usr/lib/lli/chains

#
# In place upgrade script for LLI Phoenix
#

[ -f /tmp/system_upgrade ] || {
	. /usr/lib/lli/dlist
	COUNT=0
	for d in $DRVS
	do
		ls /tmp/init.$d* >/dev/null 2>&1 && COUNT=`expr $COUNT + 1`
	done
	if [ $COUNT -eq 1 ]
	then
		echo "\n\tAfter installing the 32-bit LLI Driver Disk, please use"
		echo "\tnetconfig or mkdev <driver> to add drivers into your"
		echo "\tsystem.  Press <RETURN> to continue... \c"
		read foo
	fi
	exit $OK
}

BRAM="0"
ERAM="0"

cd $LINKSAV
grep "^${drv}[0-9][ 	]" < sdevice > /tmp/cards$$
CARDS=`awk '{ print $1 }' < /tmp/cards$$`

cd /etc/conf/cf.d

makedevs

for i in $CARDS
do
	grep $i /tmp/cards$$ > /tmp/card$$
	check=`awk '{ print $2 }' < /tmp/card$$`
	[ "$check" = "Y" ] || continue
	awk '{
		printf "base=%s\n",$1
		printf "NMINORS=%s\n",$3
		printf "IRQ=%s\n",$6
		printf "BIO=%s\n",$7
		printf "EIO=%s\n",$8
		printf "BRAM=%s\n",$9
		printf "ERAM=%s\n",$10
	}' < /tmp/card$$ > /tmp/bog$$
	. /tmp/bog$$
	rm -f /tmp/bog$$
	if [ "$rel" = "3.2.0" -o "$rel" = "3.2.1" -o "$rel" = "3.2.2" ]
	then
		# delete potential base I/O address conflicts with sio driver
		[ -f /tmp/system_upgrade ] || sio_conflict
	fi
	add
done
rm -f /tmp/card$$ /tmp/cards$$
cleanup $OK
[ RETURN TO DIRECTORY ]