#ident	"@(#)c37x	35.3"

#
# Find out what CE boards exist in the system and download them.
# When the DYNAMIC flag is set to "y", the board configuration will
# be determined each time the system is booted (with ce_bds). If
# DYNAMIC is not set to "y" the static file /usr/etc/ce.conf will be
# read (if it does not exist in this case, it will be created
# with ce_bds).
#
# The combination of command line options "start force" ignores
# the previous run level. This is done so this shell script may be
# called from another shell file (sysadm menues).
#

OSID=/usr/etc/downloads/osi			export OSID
CECFG=/usr/etc/ce.conf
STARTFLAG=$2
DYNAMIC=y

case $1 in
'start')
	set `who -r`
	if [ "$STARTFLAG" = force -o $9 = "S" ]
	then
		# comming from single-user mode (or forced to run)
		if cd $OSID
		then :
		else
			echo "OSI directory \"$OSID\" does not exist"
			exit 1
		fi

		# Determin what boards are in the system
		if [ "$DYNAMIC" = y ]
		then
			out=`ce_bds -sh 2>/dev/null`
		else
			if [ ! -f $CECFG ]
			then
				ce_bds -sh >$CECFG 2>/dev/null
			fi
			out=`cat $CECFG`
		fi

		echo "$out" | while read cpu type board
		do
			case $type in
			    147 )
				# no download for the MVME147
				continue
				;;
			    372 )
				DLF=$OSID/uMAP${type}
				SMF=$OSID/uMAP${type}.sym
				;;
			    374 )
				DLF=$OSID/uTOP${type}
				SMF=$OSID/uTOP${type}.sym
				;;
			    * )
				continue
				;;
			esac

			if ce_reset $cpu
			then
				dl $DLF $cpu >/dev/null
				sleep 8
				dl -a `grep set_mask $SMF | 
					cut -d\| -f2`,0x0 $cpu
				echo "${type}_${cpu} downloaded."
			fi
		done
	fi
	;;
'stop')
	;;
*)
	echo "usage: /etc/init.d/c37x {start|stop}"
	;;
esac
exit 0

