# !/bin/bash
#
#    Copyright (c) 1996-2017 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    Description:
#      Initialization script to start/stop Fabric OS services and interfaces
#      on different platform.
#

#
# Set a signal handler for the script.
#
trap sig_handler SIGBUS
#
# fabos script debug log
#
fabos_log=/var/log/fabos.log
insmod_log=/tmp/insmod.log
enable_fabos_log=0
#
# mark fabos complete
#
fabos_complete()
{
	tt=`date "+%D %T"`
	echo ${tt},fabos exit code $1 >> $fabos_log
	echo ${tt},fabos_state,0 >> $fabos_log
	sync
}
#
# panic test
#
fabos_test()
{
	if [ "`bootenv insmod`" = "1" ]; then
		echo === insmod $@
		echo `date "+%D %T"`,$file,loading  >> $fabos_log && sync
		insmod $@ > $insmod_log 2>&1
		[ $? -eq 0 ] && echo "`date '+%D %T'`,loaded" >> $insmod_log
		cat $insmod_log >> $fabos_log && sync
	else
		fabos_complete 0
	fi
}

#
# Signal handler for this script.
#
sig_handler()
{
	fabos_complete 1
	echo "**********************************************************"
	echo "RECEIVED UNEXPECTED SIGNAL. PROCESS INFORMATION:"
	echo "**********************************************************"
	ps auxw
	exit 1
}

#
# unsupported <platform> <exit status>
#
# Throw an error message indicating that this platform is not
# supported and exit the script with the specified status code.
#
unsupported()
{
	fabos_complete 2
    echo "Platform code ${1} isn't supported" >&2
    exit ${2}
}

#install crontab
install_crontab()
{
	if [ -f /fabos/rbin/mail_handler ]; then
		/usr/bin/crontab /fabos/rbin/mail_handler
	else
		/usr/bin/crontab /fabos/sbin/mail_handler
	fi
	# Some cases SanNav pushes the certficate before firmware commit happens
	if [ -d /etc/fabos/certs/kafka ]; then
		if ! [ -d /mnt/etc/fabos/certs/kafka ]; then
			mkdir /mnt/etc/fabos/certs/kafka
		fi
	fi

}

# Source common library
. /etc/init.d/functions

PATH=${PATH}":/fabos/sbin:/fabos/bin:/fabos/libexec"


FABOSHOME=/fabos
export FABOSHOME

export 	ROLE_ID=root
export  CURRENT_AD=0
export	HOME_VF=128
export  CURRENT_VF=128
export  CHASSIS_ROLEID=0
export  VFROLEMAP=-1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0

export OPENSSL_CONF="/etc/fabos/openssl.cnf"

# Determine the system platform identifier.
SWBD=`sin | swbd 2> ${NULL}`
CPID=`sin | cpid 2> ${NULL}`
MODE="d`bootenv startup 2> ${NULL}`"
FABOS_START=`bootenv fabos 2> ${NULL}`
SYSLOCK_DEBUG=`bootenv syslock_debug 2> ${NULL}`
if [ "$SYSLOCK_DEBUG" != "1" ] ; then
   SYSLOCK_DEBUG="0"
fi
XPRT_VERBOSE=`bootenv xprt_verbose 2> ${NULL}`
if [ "$XPRT_VERBOSE" != "1" ] ; then
   XPRT_VERBOSE="0"
fi

# Determine the linux version
LINUXVERSION=`uname -r`

if [[ "$LINUXVERSION" > "3.12.37rt50" ]] ; then
FOS_LINUX_BRINGUP="1"
echo "******************FOS Linux Bringup**** $SWBD "
else
FOS_LINUX_BRINGUP_WORKAROUND="1"
fi

#
# Link platform-specific HIL lib for Zentron in Neptune
#
mkSWBD62_lib()
{
	libs=`ls ${FABOSHOME}/lib/libhil-neptune*` 
	for i in $libs; do
		 ln -sif $i `echo $i | sed -e 's/\(libhil\).\+\(\.[a\|so].*\)/\1\2/g'`
	done
	return 0
}
#
# Link platform-specific HIL lib for Zentron in Pluto
#
mkSWBD77_lib()
{
	libs=`ls ${FABOSHOME}/lib/libhil-pluto*` 
	for i in $libs; do
		 ln -sif $i `echo $i | sed -e 's/\(libhil\).\+\(\.[a\|so].*\)/\1\2/g'`
	done
	return 0
}
#
# Link platform-specific HIL lib for Yoda in XXX
#
mkSWBD141_lib()
{
	libs=`ls ${FABOSHOME}/lib/libhil-neptune*` 
	for i in $libs; do
		 ln -sif $i `echo $i | sed -e 's/\(libhil\).\+\(\.[a\|so].*\)/\1\2/g'`
	done
	return 0
}
#
# Link platform-specific HIL lib for Yoda in XXX
#
mkSWBD142_lib()
{
	libs=`ls ${FABOSHOME}/lib/libhil-pluto*` 
	for i in $libs; do
		 ln -sif $i `echo $i | sed -e 's/\(libhil\).\+\(\.[a\|so].*\)/\1\2/g'`
	done
	return 0
}
mkSWBD171_lib()
{
	libs=`ls ${FABOSHOME}/lib/libhil-amp*` 
	for i in $libs; do
		 ln -sif $i `echo $i | sed -e 's/\(libhil\).\+\(\.[a\|so].*\)/\1\2/g'`
	done
	return 0
}

# 148 (skybolt) pizza box is a special case.. 
# do not replicate the below 148 changes for any pizza box
mkSWBD148_lib()
{
        libs=`ls /fabos/lib/libhil-sky*`
        for i in $libs; do
                 ln -sif $i `echo $i | sed -e 's/\(libhil\).\+\(\.[a\|so].*\)/\1\2/g'`
        done
        return 0
}
#
# Link platform-specific HIL lib for Lando in XXX
#
mkSWBD165_lib()
{
	libs=`ls ${FABOSHOME}/lib/libhil-venator*` 
	for i in $libs; do
		 ln -sif $i `echo $i | sed -e 's/\(libhil\).\+\(\.[a\|so].*\)/\1\2/g'`
	done
	return 0
}
#
# Link platform-specific HIL lib for Lando in XXX
#
mkSWBD166_lib()
{
	libs=`ls ${FABOSHOME}/lib/libhil-allegiance*` 
	for i in $libs; do
		 ln -sif $i `echo $i | sed -e 's/\(libhil\).\+\(\.[a\|so].*\)/\1\2/g'`
	done
	return 0
}

#
# Link platform-specific HIL lib for wedge+
#
mkSWBD172_lib()
{
	libs=`ls ${FABOSHOME}/lib/libhil-wedge_plus*` 
	for i in $libs; do
		 ln -sif $i `echo $i | sed -e 's/\(libhil\).\+\(\.[a\|so].*\)/\1\2/g'`
	done
	return 0
}
#
# Zentron CP can be used in more than one type of chassis. The
# HIL library must match the chassis. Create symbolic link
# to the appropriate library based on the SWBD value.
#
mk_hil() {
    case ${SWBD##SWBD} in
	'62' | '77' | '141' | '142' | '165' | '166' | '172')
	    $ECHO "Installing ${SWBD} libhil"
	    mk${SWBD}_lib
	    if [ $? -ne 0 ]; then
		echo "Cannot create link for ${SWBD} HIL lib" >&2
		fabos_complete 3
		exit 1
	    fi
	    ;;
    esac
}

# Determine the state-sync transport based on the platform identifier.
case ${SWBD##SWBD} in
    '10' | '21' | '42' | '62' | '63' | '77' | '141' | '142' | '148' | '171')
	XPT="XCP"
	;;

    *)
	XPT="XLO"
	;;
esac

#
# stop_daemons <switch_number>
# Stop daemons related to a particular switch.
#
stop_daemons()
{
    pid=`cat /var/run/*.pid 2> ${NULL}`

    if [ "$pid" != "" ] ; then
	kill -TERM $pid > ${NULL} 2>&1
	sleep 2
	pid=`ps -eaf | grep "\-s $1" |  /usr/bin/tr -s " " : | /usr/bin/cut -d: -f2`
	kill -KILL $pid > ${NULL} 2>&1
    fi

    sleep 1
    # remove pid file if any.
    rm -f /var/run/*$1.pid
}

#
# killproc <switch no>
# Kill the switch specific daemons
#
killproc()
{
    # kill switch specific daemons
    pid=`cat /var/run/*$1.pid 2> ${NULL}`
    if [ "$pid" != "" ] ; then
	kill -TERM $pid > ${NULL} 2>&1
	sleep 1
	kill -KILL $pid > ${NULL} 2>&1
    fi

    # remove pid file if any.
    rm -f /var/run/*$1.pid
}

#
# kill httpd
#
killhttp()
{
    # kill webtools for this switch
    if [ -f '/tmp/webtools/logs/httpd.pid.$1' ] ; then
        pid=`cat /tmp/webtools/logs/httpd.pid.$1 2> ${NULL}`
        if [ "$pid" != "" ] ; then
	    kill -TERM $pid > ${NULL} 2>&1
        fi
    fi
}

#
# setDbg block
#
doSetDbg()
{
	#
	# In order to turn on setdbg for the following, you need
	# to do chkconfig fabosSetDbg on, which will be preserved
	# across firmwaredownloads and reboots.
	#
	# Please don't add any setdbg outside of this check even as
	# a temporary measure, which lead to chaos in some customer
	# sites. It's easy to forget to remove this kind of stuff.
	#
	if $CHECK fabosSetDbg; then
		/fabos/cliexec/setdbg TRUNK 4
		/fabos/cliexec/setdbg FLTR 4
		/fabos/cliexec/setdbg INTR 4
		/fabos/cliexec/setdbg PHAN 4
		/fabos/cliexec/setdbg LOOP 4
		/fabos/cliexec/setdbg SPEED 4
		/fabos/cliexec/setdbg BLADE 1
		/fabos/cliexec/setdbg FSSK 4
		/fabos/cliexec/setdbg SYNC_SWC 4
		/fabos/cliexec/setdbg RCVY_SWC 4

	fi
		# setDbg FLTR	4
		# setDbg INTR	4
		# setDbg RCVY_SWC	4
}

#
# modutil <load | unload> <module name>
#
# Load a kernel module, which may be compressed
#
modutil()
{
    cmd=$1
    file=$2
    shift 2
    case $cmd in
	("load")
	[ $enable_fabos_log -eq 1 ] && echo `date "+%D %T"`,$file,loading >> $fabos_log && sync
	if [ -r /fabos/modules/$file.ko ]
	    then if insmod /fabos/modules/$file.ko "$@" > $insmod_log 2>&1
		then
			[ $enable_fabos_log -eq 1 ] && echo "`date '+%D %T'`,loaded" >> $fabos_log
			return
		else
			RETURN_VALUE=$?;
			echo insmod return error code $RETURN_VALUE >> $insmod_log
	    fi
	elif [ -r /fabos/modules/$file.ko.gz ]
	    then if zcat /fabos/modules/$file.ko.gz | insmod - "$@" > $insmod_log 2>&1
		then 
			[ $enable_fabos_log -eq 1 ] && echo "`date '+%D %T'`,loaded" >> $fabos_log
			return
		else
			RETURN_VALUE=$?;
			echo insmod return error code $RETURN_VALUE >> $insmod_log
	    fi
	else
		RETURN_VALUE=1
		echo "modutil: load $file does not exist"
		echo "modutil: load $file does not exist" > $insmod_log
	fi
	echo "Error $RETURN_VALUE returned by insmod while loading $file" >&2
	[ $enable_fabos_log -eq 1 ] && cat $insmod_log >> $fabos_log && sync
	return $RETURN_VALUE
	;;
	(*) ;;
    esac
}

#
# linuxmodutil <load | unload> <module name>
#
# Load a linux kernel module
#
LINUXINSMOD_SUCESS=0
linuxmodutil()
{
    case $1 in
    load)
	[ $enable_fabos_log -eq 1 ] && echo `date "+%D %T"`,$2,loading >> $fabos_log && sync
	insmod $2 $3 $4 $5 $6 > $insmod_log 2>&1
	RETURN_VALUE=$?
	if [ $RETURN_VALUE -ne $LINUXINSMOD_SUCESS ]; then
	  echo insmod return error code $RETURN_VALUE >> $insmod_log
	  echo "Error " $RETURN_VALUE " returned by insmod while loading " $2
	else
	  echo "`date '+%D %T'`,$2,loaded" >> $insmod_log
	fi
	[ $enable_fabos_log -eq 1 ] && cat $insmod_log >> $fabos_log && sync
	;;

    *)
	;;
    esac
    return 0
}

load_switch_module()
{
if [ "$FOS_LINUX_BRINGUP" != "1" ] ; then
	CPULOAD=$(/fabos/cliexec/config get system.cpuLoad 2)
	CPULOAD=${CPULOAD:-121}
	CPULOAD=$(($CPULOAD*2048/100))
	modutil load switch-module sw_cpu_load=$CPULOAD
else
	modutil load switch-module
fi

}

load_dgpio_module()
{
	modutil load dgpio-module
        major=`cat /proc/devices | /bin/grep dfsgpio | cut -f 1 -d" "`
        rm -f /dev/dgpio-module.mod
        mknod /dev/dgpio-module.mod c $major 0
}

#
# Start module for Meteor platform.
#
swbd21_module()
{
	modutil load db-module
	modutil load meteor-module
	modutil load portlog-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load pen-module
	modutil load condor-module
	modutil load fc-module
	modutil load mtracer-module
	modutil load diag-module

	return 0
}

#
# Start module for neptune platform.
#
swbd62_module()
{
        modutil load enetswch-module
        modutil load db-module
        modutil load neptune-zentron-module
	modutil load portlog-module
	modutil load ki-module
        modutil load fss-module
        modutil load fabsys-module 
        modutil load iu-module
	load_switch_module
	modutil load chassis-module
        modutil load pen-module
#        modutil load marathon-module
#	modutil load scimitar-module
	modutil load striker-blade-module
	modutil load condor2-module
	modutil load condor3-module
#	modutil load egret-module
#	modutil load pinball-module
	modutil load fcip-module
	modutil load blaster-module
	modutil load fc-module
	modutil load routing-module
	modutil load uartmux-module
	modutil load mtracer-module
	modutil load diag-module
	modutil load dpcichassis-module
	mk_device flowcap flowcap 0
	return 0
}

#
# Start module for pluto platform.
#
swbd77_module()
{
	modutil load enetswch-module
	modutil load db-module
	modutil load pluto-zentron-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module ethsw_ha_enabled=$ETHSW_HA_ENABLE
	modutil load iu-module
#	modutil load hsl-module
	load_switch_module
	modutil load chassis-module
#	modutil load dce-blade-module
	modutil load pen-module
#	modutil load marathon-module
#	modutil load ironman-module
#	modutil load lance-module
#	modutil load scimitar-module
	modutil load striker-blade-module
#	modutil load condor-module
	modutil load condor2-module
	modutil load condor3-module
#	modutil load anvil-module
#	modutil load zeus-module
#	modutil load egret-module
#	modutil load pinball-module
	modutil load fcip-module
	modutil load blaster-module
	modutil load fc-module
#	modutil load fcoe-module
	modutil load routing-module
	modutil load uartmux-module
	modutil load mtracer-module
	modutil load diag-module
	modutil load dpcichassis-module
	mk_device flowcap flowcap 0

        return 0
}

#
# Start module for neptune platform.
#
swbd141_module()
{
#	modutil load enetswch-module
	modutil load db-module
	modutil load neptune-yoda-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module ethsw_ha_enabled=$ETHSW_HA_ENABLE
	modutil load iu-module
#	modutil load hsl-module
	load_switch_module
	modutil load chassis-module
#	modutil load dce-blade-module
	modutil load pen-module
#        modutil load marathon-module
#	modutil load ironman-module
#	modutil load lance-module
#	modutil load scimitar-module
	modutil load striker-blade-module
#	modutil load condor2-module
	modutil load condor3-module
	#modutil load anvil-module
	#modutil load zeus-module
#	modutil load egret-module
#	modutil load pinball-module
	modutil load fcip-module
	modutil load blaster-module
	modutil load fc-module
	modutil load fcoe-module
	modutil load routing-module
	modutil load uartmux-module
#	modutil load mtracer-module
	modutil load diag-module
	modutil load dpcichassis-module
	mk_device flowcap flowcap 0
#	mk_device c3regdump c3regdump 0
#	In v8.0 c3regdump is now fcasic3
	mk_device fcasic3 fcasic3 0
	return 0
}

#
# Start module for pluto platform.
#
swbd142_module()
{
#	modutil load enetswch-module
	modutil load db-module
	modutil load pluto-yoda-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module ethsw_ha_enabled=$ETHSW_HA_ENABLE
	modutil load iu-module
#	modutil load hsl-module
	load_switch_module
	modutil load chassis-module
#	modutil load dce-blade-module
	modutil load pen-module
#	modutil load marathon-module
#	modutil load ironman-module
#	modutil load lance-module
#	modutil load scimitar-module
	modutil load striker-blade-module
	modutil load condor2-module
	modutil load condor3-module
#	modutil load anvil-module
#	modutil load zeus-module
#	modutil load egret-module
#	modutil load pinball-module
	modutil load fcip-module
	modutil load blaster-module
	modutil load fc-module
	modutil load fcoe-module
	modutil load routing-module
	modutil load uartmux-module
#	modutil load mtracer-module
	modutil load diag-module
	modutil load dpcichassis-module
	mk_device flowcap flowcap 0
#	mk_device c3regdump c3regdump 0
#	In v8.0 c3regdump is now fcasic3
	mk_device fcasic3 fcasic3 0
	return 0
#	modutil load condor2-module
}

#
# Start module for Skybolt platform.
#
swbd148_module()
{

	#modutil load enetswch-module
	#modutil load db-module
	modutil load skybolt-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module ethsw_ha_enabled=$ETHSW_HA_ENABLE
	modutil load iu-module
	load_switch_module
    modutil load kap-module
	modutil load chassis-module
	modutil load skyb-blade-module
	modutil load condor3-module
	#modutil load linux-kernel-bde dmasize=8M himem=1
	modutil load linux-kernel-bde dmasize=8M maxpayload=128
	modutil load linux-bcm-core
	modutil load linux-uk-proxy
	modutil load linux-bcm-diag
	modutil load bcm-switch-module
	modutil load blzr-module
	modutil load fc-module
	modutil load routing-module
	#modutil load uartmux-module
	#modutil load mtracer-module
	modutil load diag-module
    modutil load fdpci-module
    modutil load dpci_switch-module
	mk_device flowcap flowcap 0

    return 0
}

swbd171_module()
{

	#modutil load enetswch-module
	#modutil load db-module
	modutil load amp-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module ethsw_ha_enabled=$ETHSW_HA_ENABLE
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load skyb-blade-module
	modutil load condor3-module
	#modutil load linux-kernel-bde dmasize=8M himem=1
	modutil load linux-kernel-bde dmasize=8M maxpayload=128
	modutil load linux-bcm-core
	modutil load linux-uk-proxy
	modutil load linux-bcm-diag
	modutil load bcm-switch-module
	modutil load blzr-module
	modutil load fc-module
	modutil load routing-module
	#modutil load uartmux-module
	#modutil load mtracer-module
	modutil load diag-module
    modutil load fdpci-module
    modutil load dpci_switch-module
	mk_device flowcap flowcap 0

    return 0
}
#
# Redbird
#
swbd156_module()
{
        modutil load redbird-module serdes_set_enable=1
        modutil load portlog-module
        modutil load ki-module
        modutil load fss-module
        modutil load fabsys-module
        modutil load iu-module
        load_switch_module
        modutil load chassis-module
        modutil load pulsar-blade-module
        modutil load condor3-module
        modutil load fc-module
        modutil load routing-module
        #modutil load mtracer-module	// as 148
        modutil load diag-module
        modutil load fdpci-module
	modutil load dpci_switch-module
        mk_device flowcap flowcap 0

        return 0
}

#
# Shenlong
#
swbd167_module()
{
        modutil load shenlong-module serdes_set_enable=1
        modutil load portlog-module
        modutil load ki-module
        modutil load fss-module
        modutil load fabsys-module
        modutil load iu-module
        load_switch_module
        modutil load chassis-module
        modutil load pulsar-blade-module
        modutil load condor3-module
        modutil load fc-module
        modutil load routing-module
        #modutil load mtracer-module	// as 148
        modutil load diag-module
        modutil load fdpci-module
        modutil load dpci_switch-module
        modutil load dfpga-module
        mk_device flowcap flowcap 0

        return 0
}

#
# Start module for allegiance platform.
#
swbd166_module()
{
#	modutil load enetswch-module
#	modutil load db-module
	modutil load allegiance-lando-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module ethsw_ha_enabled=$ETHSW_HA_ENABLE
	modutil load iu-module
#	modutil load hsl-module
	load_switch_module
	modutil load kap-module
	modutil load chassis-module
#	modutil load dce-blade-module
	modutil load pen-module
#   modutil load marathon-module
#	modutil load ironman-module
#	modutil load lance-module
#	modutil load scimitar-module
#	modutil load striker-blade-module
#	modutil load condor2-module
#	modutil load condor3-module
	#modutil load anvil-module
	#modutil load zeus-module
#	modutil load egret-module
#	modutil load pinball-module
#	modutil load fcip-module
#	modutil load blaster-module
	modutil load fc-module
    modutil load condor4-module
    modutil load condor4p-module
	modutil load fcoe-module
	modutil load routing-module
	modutil load diag-module
	modutil load dpci_pciehp
	modutil load skyb-blade-module
	modutil load linux-kernel-bde dmasize=16M maxpayload=128 usemsi=1 brcd_chassis_type=0
	modutil load linux-bcm-core
	modutil load linux-uk-proxy
	modutil load linux-bcm-diag
	modutil load bcm-switch-module
	modutil load blzr-module

	modutil load spi-fpga-module
	return 0
}

#
# Start module for venator platform.
#
swbd165_module()
{
#	modutil load enetswch-module
#	modutil load db-module
	modutil load venator-lando-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module ethsw_ha_enabled=$ETHSW_HA_ENABLE
	modutil load iu-module
#	modutil load hsl-module
	load_switch_module
	modutil load kap-module
	modutil load chassis-module
#	modutil load dce-blade-module
	modutil load pen-module
#	modutil load marathon-module
#	modutil load ironman-module
#	modutil load lance-module
#	modutil load scimitar-module
#	modutil load striker-blade-module
#	modutil load condor-module
#	modutil load condor2-module
#	modutil load condor3-module
#	modutil load anvil-module
#	modutil load zeus-module
#	modutil load egret-module
#	modutil load pinball-module
#	modutil load fcip-module
#	modutil load blaster-module
	modutil load fc-module
	modutil load condor4-module
	modutil load condor4p-module
	modutil load fcoe-module
	modutil load routing-module
	modutil load diag-module
	modutil load dpci_pciehp
	modutil load skyb-blade-module
	modutil load linux-kernel-bde dmasize=16M maxpayload=128 usemsi=1 brcd_chassis_type=1
	modutil load linux-bcm-core
	modutil load linux-uk-proxy
	modutil load linux-bcm-diag
	modutil load bcm-switch-module
	modutil load blzr-module

	modutil load spi-fpga-module

        return 0
}

#
# Start module for neptune co-cpu platform.
#
swbd63_module()
{

	modutil load fss-module
	modutil load ki-module
        return 0
}

load_ip_crypto()
{
	IPSV4MODDIR=/lib/modules/$LINUXVERSION/kernel/net/ipv4
	IPSV6MODDIR=/lib/modules/$LINUXVERSION/kernel/net/ipv6
	CRYPTOMODDIR=/lib/modules/$LINUXVERSION/kernel/crypto
	KEYMODDIR=/lib/modules/$LINUXVERSION/kernel/net/key
	XFRMMODDIR=/lib/modules/$LINUXVERSION/kernel/net/xfrm

	linuxmodutil load $KEYMODDIR/af_key.ko
	linuxmodutil load $XFRMMODDIR/xfrm_user.ko

	# Make sure we only look at .ko files
	for i in ${IPSV4MODDIR}/*.ko ${IPSV6MODDIR}/*.ko ${CRYPTOMODDIR}/*.ko
	do
		linuxmodutil load $i
	done
}

#
# Start module for Saturn platform.
#
swbd42_module()
{
	modutil load db-module
	modutil load saturn-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module

	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pen-module
#	modutil load marathon-module
#	modutil load scimitar-module
#	modutil load ironman-module
	modutil	load lance-module
	modutil load condor-module
	modutil load condor2-module
	modutil load egret-module
	modutil load pinball-module
	modutil load fcip-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	load_ip_crypto

	return 0
}

#
# Load module for Icecube platform.
#
swbd29_module()
{
	modutil load icecube-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	load_ip_crypto

	return 0
}

# Pulsar support
#
swbd23_module()
{
	modutil load pulsar24-module
	modutil load portlog-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load pulsar-blade-module
	modutil load spectrum-pic-module
	modutil load xena-pic-module
	modutil load condor-module
	modutil load egret-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	load_ip_crypto

	return 0
}

#
# Pulsar32 support
#
swbd32_module()
{
	modutil load pulsar32-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load condor-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	load_ip_crypto

	return 0
}

#
# Pulsar2 support
#
swbd58_module()
{
	modutil load pulsar2-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load condor-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	load_ip_crypto

	return 0
}

#
# Stealth support
#
swbd34_module()
{
	modutil load stealth-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	load_ip_crypto

	return 0
}

#
# Start module for mini_chassis/Sprint platform.
#
swbd46_module()
{
	modutil load sprint-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
#	modutil load marathon-module
#	modutil load scimitar-module
	modutil load condor-module
	modutil load pinball-module
	modutil load fcip-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	NFMODDIR=/lib/modules/$LINUXVERSION/kernel/net/ipv4/netfilter
	linuxmodutil load $NFMODDIR/ip_conntrack.ko
	linuxmodutil load $NFMODDIR/ip_conntrack_ftp.ko
	linuxmodutil load $NFMODDIR/ip_nat.ko
	linuxmodutil load $NFMODDIR/ip_nat_ftp.ko
	linuxmodutil load $NFMODDIR/ip_nat_snmp_basic.ko
	linuxmodutil load $NFMODDIR/iptable_nat.ko

	load_ip_crypto

	return 0
}

#
# Start module for mini_chassis/Mace platform.
#
swbd67_module()
{
	modutil load mace-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load lance-module
	modutil load condor2-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	return 0
}

#
# Blazer2 support
#
swbd37_module()
{
	modutil load blazer2-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	load_ip_crypto

	return 0
}

#
# Viking support
#
swbd44_module()
{
	modutil load viking-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load condor-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	load_ip_crypto

	return 0
}

#
# Create a gpio node which uses the misc device driver
# with a minor number of 185.
#
mk_gpio_device()
{

	# Create gpio driver node if the misc driver
	# is available, needed for lbist

	node="misc"
	# note that the usual (cut -d ' ' -f 1) doesn't work for
	# misc since it has leading blanks
	major=`grep $node\$ /proc/devices | cut -c 1-3`

	if [  $major ]; then
		# found it now create the gpio node (minor = 185)
		node="gpio"
		rm -f /dev/$node 
    	mknod --mode=644 /dev/$node c $major 185
	fi  

	return 0
}

#
# Icecube2 support
#
swbd43_module()
{
	modutil load icecube2-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	load_ip_crypto

	return 0
}

#
# Glacier2 support
#
swbd45_module()
{
	modutil load glacier2-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	load_ip_crypto

	return 0
}

#
# Dragon support
#
swbd51_module()
{
	modutil load dragon-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	return 0
}

#
# Superhawk support
#
swbd61_module()
{
	modutil load superhawk-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	return 0
}

#
# Thor support
#
swbd64_module()
{
	modutil load thor-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye2-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	return 0
}

#
# Spirit support
#
swbd66_module()
{
	modutil load spirit-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load condor2-module
	modutil load fc-module
 	modutil load routing-module
 	modutil load mtracer-module
 	modutil load diag-module

	return 0
}

#
# Little Bear 8G support
#
swbd70_module()
{
	modutil load lb_8g-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye2-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	return 0
}

#
# Tomahawk support
#
swbd71_module()
{
	modutil load tomahawk-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye2-module
	modutil load fc-module
 	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	return 0
}

#
# Bulova support
#
swbd72_module()
{
	modutil load bulova-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye2-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module
	

	return 0
}

#
# Blazer3 support
#
swbd73_module()
{
	modutil load blazer3-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye2-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module
	
	return 0
}

#
# Superhawk2 support
#
swbd75_module()
{
	modutil load superhawk2-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye2-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module
	
	return 0
}

#
# Gladius support
#
swbd92_module()
{
	modutil load gladius-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load condor2-module
	modutil load fc-module
 	modutil load routing-module
 	modutil load mtracer-module
 	modutil load diag-module

	return 0
}
#
# Falcon2 support
#
swbd86_module()
{
    modutil load falcon2-module
    modutil load portlog-module
    modutil load ki-module
    modutil load fss-module
    modutil load fabsys-module
    modutil load iu-module
    load_switch_module
    modutil load chassis-module
    modutil load pulsar-blade-module
    modutil load geye2-module
    modutil load fc-module
    modutil load routing-module
    modutil load mtracer-module
    modutil load diag-module

    return 0
}

#
# Kestrel2 support
#
swbd87_module()
{
    modutil load kestrel2-module
    modutil load portlog-module
    modutil load ki-module
    modutil load fss-module
    modutil load fabsys-module
    modutil load iu-module
    load_switch_module
    modutil load chassis-module
    modutil load pulsar-blade-module
    modutil load geye2-module
    modutil load fc-module
    modutil load routing-module
    modutil load mtracer-module
    modutil load diag-module

    return 0
}


#
# Elara support
#
swbd76_module()
{
	modutil load elara-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
        modutil load fabsys-module ethsw_ha_enabled=$ETHSW_HA_ENABLE
	modutil load iu-module
#	modutil load hsl-module
	load_switch_module
	modutil load chassis-module
	modutil load condor2-module
#
# Load the anvil revision module to determine whether this platform has
# pass 1 or 2 chips loaded and load the corresponding anvil module.
#
	modutil load anvil_rev-module

	if [ -r /proc/driver/anvil_rev ]; then 
		anvil_rev=`cat /proc/driver/anvil_rev`
	else
		anvil_rev=0
	fi

	case $anvil_rev in
		1*) modutil load anvil_pass1-module
		    ;;

		2*) modutil load anvil-module
		    ;;

	 	*) echo "Unsupported Anvil version $anvil_rev, defaulting to 1.x";
		   modutil load anvil_pass1-module
		   ;;
	esac

	rev=`echo $anvil_rev | gawk ' { print $1} '`
	major=`echo $rev | cut -d"." -f1`
	minor=`echo $rev | cut -d"." -f2`
	if [[( $major -eq  2  && $minor -ge 2 ) || ( $major -gt 2 )]]; then
		echo "Anvil version 2.2 or higher found";
		anvil_allports=1
	else
		echo "Anvil version 2.1 or less found";
		anvil_allports=0
	fi
	modutil load dce-blade-module dce_anvil_allports=$anvil_allports

	modutil load zeus-module
	modutil load fc-module
	modutil load fcoe-module
	modutil load routing-module
	modutil load altera-module
	modutil load mtracer-module
	modutil load diag-module
	modutil load fdpci-module
	return 0
}

#
# Spear support (cdr2/blaster/slicers+nunchuk)
#
swbd79_module()
{
        modutil load enetswch-module
	modutil load spear-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load sssc-blade-module
	modutil load condor2-module
 	modutil load linux-kernel-bde dmasize=8M himem=1
 	modutil load linux-bcm-core
 	modutil load bcm-switch-module
	modutil load blaster-module
	modutil load cpcdc-module
	modutil load fc-module
 	modutil load routing-module
	modutil load diag-module

	return 0
}

#
# Spearlite support (cdr2/blaster)
#
swbd80_module()
{
        modutil load enetswch-module
	modutil load spear-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load sssc-blade-module
	modutil load condor2-module
	modutil load blaster-module
	modutil load fc-module
 	modutil load routing-module

	return 0
}

#
# Spike support (ge2/blaster)
#
swbd83_module()
{
	modutil load spike-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load striker-blade-module
	modutil load geye2-module
	modutil load blaster-module
	modutil load fc-module
 	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	NFMODDIR=/lib/modules/$LINUXVERSION/kernel/net/ipv4/netfilter
	linuxmodutil load $NFMODDIR/ip_conntrack.ko
	linuxmodutil load $NFMODDIR/ip_conntrack_ftp.ko
	linuxmodutil load $NFMODDIR/ip_nat.ko
	linuxmodutil load $NFMODDIR/ip_nat_ftp.ko
	linuxmodutil load $NFMODDIR/ip_nat_snmp_basic.ko
	linuxmodutil load $NFMODDIR/iptable_nat.ko
	linuxmodutil load $NFMODDIR/ipt_MASQUERADE.ko

	return 0
}

#
# Utah support
#
swbd82_module()
{
    modutil load utah-module
    modutil load portlog-module
    modutil load tp-module
    modutil load fss-module
    modutil load fabsys-module
    modutil load iu-module
    load_switch_module
    modutil load pulsar-blade-module
    modutil load geye2-module
    modutil load fc-module
    modutil load ham-module
    modutil load swd-module
    modutil load routing-module
	modutil load mtracer-module

    return 0
}

#
# A_wing Support
#
swbd178_module()
{
	modutil load awing-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load kap-module
	modutil load chassis-module
	modutil load awing-blade-module
	modutil load geye4-module
	modutil load linux-kernel-bde dmasize=8M maxpayload=128
	modutil load linux-uk-proxy
	modutil load linux-bcm-core
	modutil load linux-bcm-diag
	modutil load bcmgh-switch-module
	modutil load blzr-module
	modutil load fc-module
	modutil load routing-module
	modutil load diag-module
	modutil load fdpci-module
	modutil load dpci_switch-module

	return 0
}

#
# wedge support
#
swbd161_module()
{
    modutil load wedge64-module
    modutil load portlog-module
    modutil load ki-module
    modutil load fss-module
    modutil load fabsys-module
    modutil load iu-module
    load_switch_module
    modutil load chassis-module
    modutil load pulsar-blade-module
    modutil load condor4-module
    modutil load fc-module
    modutil load routing-module
    modutil load diag-module
    modutil load dpci_switch-module
    #modutil load mtracer-module
if [ "$FOS_LINUX_BRINGUP" != "1" ] ; then
    modutil load fdpci-module
fi

    return 0
}

swbd162_module()
{
    modutil load wedge64-module
    modutil load portlog-module
    modutil load ki-module
    modutil load fss-module
    modutil load fabsys-module
    modutil load iu-module
    load_switch_module
    modutil load chassis-module
    modutil load pulsar-blade-module
    modutil load condor4-module
    modutil load fc-module
    modutil load routing-module
    modutil load diag-module
    modutil load dpci_switch-module
    #modutil load mtracer-module
if [ "$FOS_LINUX_BRINGUP" != "1" ] ; then
    modutil load fdpci-module
fi

    return 0
}

#
# chewbacca support
#
swbd169_module()
{
    modutil load chewbacca40-module
    modutil load portlog-module
    modutil load ki-module
    modutil load fss-module
    modutil load fabsys-module
    modutil load iu-module
    load_switch_module
    modutil load chassis-module
    modutil load pulsar-blade-module
    modutil load geye4-module
#    modutil load condor4-module
    modutil load fc-module
    modutil load routing-module
    #modutil load mtracer-module
    modutil load diag-module
    modutil load fdpci-module
    modutil load dpci_switch-module

    return 0
}
swbd170_module()
{
    modutil load chewbacca24-module
    modutil load portlog-module
    modutil load ki-module
    modutil load fss-module
    modutil load fabsys-module
    modutil load iu-module
    load_switch_module
    modutil load chassis-module
    modutil load pulsar-blade-module
    modutil load geye4-module
#    modutil load condor4-module
    modutil load fc-module
    modutil load routing-module
    #modutil load mtracer-module
    modutil load diag-module
    modutil load fdpci-module
    modutil load dpci_switch-module

    return 0
}

#
# Wedge+ support
#
swbd172_module()
{
    modutil load wedge_plus-module 
    modutil load portlog-module
    modutil load ki-module
    modutil load fss-module
    modutil load fabsys-module
    modutil load iu-module
    load_switch_module
    modutil load chassis-module
    modutil load pulsar-blade-module
    modutil load condor4p-module
    modutil load fc-module
    modutil load routing-module
    #modutil load mtracer-module
    modutil load diag-module
    modutil load fdpci-module
    modutil load dpci_switch-module

    return 0
}

#
# Tyr support
#
swbd173_module()
{
    modutil load tyr-module
    modutil load portlog-module
    modutil load ki-module
    modutil load fss-module
    modutil load fabsys-module
    modutil load iu-module
    load_switch_module
    modutil load kap-module
    modutil load chassis-module
    modutil load pulsar-blade-module
    modutil load condor4p-module
    modutil load fc-module
    modutil load fcoe-module
    modutil load routing-module
    #modutil load mtracer-module
    modutil load diag-module
    modutil load fdpci-module
    modutil load dpci_switch-module

    return 0
}


#
# Stinger support
#
swbd109_module()
{
    modutil load stinger-module
    modutil load portlog-module
    modutil load ki-module
    modutil load fss-module
    modutil load fabsys-module
    modutil load iu-module
    load_switch_module
    modutil load chassis-module
    modutil load pulsar-blade-module
    #modutil load condor4-module
    modutil load condor3-module
    modutil load fc-module
    modutil load routing-module
    modutil load mtracer-module
    modutil load diag-module
    modutil load fdpci-module
	mk_device flowcap flowcap 0

    return 0
}

#
# Pharos support
#
swbd117_module()
{
    if $CHECK iom_security
    then
        IOM_SECURITY="iom_security_is_on=1"
    fi
    if $CHECK serdes_set
    then
        SERDES_SET="serdes_set_enable=1"
    fi
    modutil load pharos-module $SERDES_SET $IOM_SECURITY
    modutil load portlog-module
    modutil load ki-module
    modutil load fss-module
    modutil load fabsys-module
    modutil load iu-module
    load_switch_module
    modutil load chassis-module
    modutil load pulsar-blade-module
    modutil load condor3-module
    modutil load fc-module
    modutil load routing-module
    modutil load mtracer-module
    modutil load diag-module
    modutil load fdpci-module
	mk_device flowcap flowcap 0
	
    return 0
}

#
# Tomtoo support
#
swbd118_module()
{
	modutil load tomtoo-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load condor3-module
	modutil load fc-module
 	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module
	modutil load fdpci-module
	mk_device flowcap flowcap 0

	return 0
}

#
# Odin support
#
swbd133_module()
{
    modutil load odin-module
    modutil load portlog-module
    modutil load ki-module
    modutil load fss-module
    modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load condor3-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module
	modutil load fdpci-module
	mk_device flowcap flowcap 0
	load_dgpio_module

    return 0
}


#
# Dragon2 support
#
swbd124_module()
{
	modutil load dragon2-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye2-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module

	return 0
}

#
# Dragon2T support
#
swbd125_module()
{
	modutil load dragon2t-module
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load geye2-module
	modutil load fc-module
	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module
	
	return 0
}

#
# Bulova2 module
#
swbd129_module()
{
	if [ -f /var/HP_gen ]
	then
		DEJA_VU="platform_option_deja_vu=1"
		HP_GEN="platform_option_remembered=$(cat /var/HP_gen)"
	fi
	modutil load bulova2-module $DEJA_VU $HP_GEN
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load condor3-module
	modutil load fc-module
 	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module
	modutil load fdpci-module
	mk_device flowcap flowcap 0
	
	return 0
}

#
# Superhawk3
#
swbd130_module()
{
	modutil load superhawk3-module serdes_set_enable=1 link_tune_is_on=1
	modutil load portlog-module
	modutil load ki-module
	modutil load fss-module
	modutil load fabsys-module
	modutil load iu-module
	load_switch_module
	modutil load chassis-module
	modutil load pulsar-blade-module
	modutil load condor3-module
	modutil load fc-module
 	modutil load routing-module
	modutil load mtracer-module
	modutil load diag-module
	modutil load fdpci-module
	mk_device flowcap flowcap 0

	return 0
}

#
# Qilin support
#
swbd134_module()
{
    modutil load qilin-module
    modutil load portlog-module
    modutil load ki-module
    modutil load fss-module
    modutil load fabsys-module
    modutil load iu-module
    load_switch_module
    modutil load chassis-module
    modutil load pulsar-blade-module
    modutil load geye2-module
    modutil load fc-module
    modutil load routing-module
    modutil load mtracer-module
    modutil load diag-module

    return 0
}
# Kestrel3
#
swbd149_module()
{
        modutil load kestrel3-module serdes_set_enable=1
        modutil load portlog-module
        modutil load ki-module
        modutil load fss-module
        modutil load fabsys-module
        modutil load iu-module
        load_switch_module
        modutil load chassis-module
        modutil load pulsar-blade-module
        modutil load condor3-module
        modutil load fc-module
        modutil load routing-module
        modutil load mtracer-module
        modutil load diag-module
        modutil load fdpci-module
        mk_device flowcap flowcap 0

        return 0
}

#
# Falcon3 module
#
swbd150_module()
{
    modutil load falcon3-module
    modutil load portlog-module
    modutil load ki-module
    modutil load fss-module
    modutil load fabsys-module
    modutil load iu-module
    load_switch_module
    modutil load chassis-module
    modutil load pulsar-blade-module
    modutil load condor3-module
    modutil load fc-module
    modutil load routing-module
    modutil load mtracer-module
    modutil load diag-module
    modutil load fdpci-module
    mk_device flowcap flowcap 0

    return 0
}

#
# Graphite
#
swbd157_module()
{
        modutil load graphite-module
        modutil load portlog-module
        modutil load ki-module
        modutil load fss-module
        modutil load fabsys-module
        modutil load iu-module
        load_switch_module
        modutil load chassis-module
        modutil load pulsar-blade-module
        modutil load condor3-module
        modutil load fc-module
        modutil load routing-module
#       modutil load mtracer-module
        modutil load diag-module
        modutil load fdpci-module
	modutil load dpci_switch-module
        mk_device flowcap flowcap 0

        return 0
}

#
# Carbon
#
swbd158_module()
{
        modutil load carbon-module
        modutil load portlog-module
        modutil load ki-module
        modutil load fss-module
        modutil load fabsys-module
        modutil load iu-module
        load_switch_module
        modutil load chassis-module
        modutil load pulsar-blade-module
        modutil load condor3-module
        modutil load fc-module
        modutil load routing-module
#        modutil load mtracer-module
        modutil load diag-module
        modutil load fdpci-module
	modutil load dpci_switch-module
        mk_device flowcap flowcap 0

        return 0
}


# Create node for each device driver.
# mk_device <module name> {<device name> <minor-dev-num>}
#
mk_device()
{
	set $@
	node=$1
	shift 1
	major=`/bin/grep -w  $node\$ /proc/devices | cut -d ' ' -f 1`
	while [ $# -gt 0 ]; do
		if [ ! $major ]; then
			fabos_complete 4
			exit 1;
		fi
		rm -f /dev/$1
		mknod --mode=666 /dev/$1 c $major $2

		shift 2
	done
     return 0
}

#
# Create node for each block device driver.
# mk_block_device <module name> {<device name> <minor-dev-num>}
#
mk_block_device()
{
	set $@
	node=$1
	shift 1
	major=`grep $node\$ /proc/devices | cut -d ' ' -f 1`
	if [ ! $major ]; then
		fabos_complete 5
		exit 1;
	fi
	rm -f /dev/$1
	mknod --mode=666 /dev/$1 b $major $2

	return 0
}

make_fcasic4_devices()
{
	echo "GEN6 platform";
	mk_device fcasic4 fcasic4 0
#	slots=`slotshow | awk '{print $1}' | grep [0-9]`
#	for (( i = 0; i <= 12; i++ ))
#	do 
#		for (( j = 0; j < 4; j++ ))
#		do
#			tempstr=${i}_${j}
#			val=$(((i*10) + j))
#			mk_device fcasic4 fcasic4_${tempstr} $val
#		done 
#	done
	return 0
}

make_fcasic4P_devices()
{
	mk_device fcasic4P fcasic4P 0
#	slots=`slotshow | awk '{print $1}' | grep [0-9]`
#	for (( i = 0; i <= 12; i++ ))
#	do 
#		for (( j = 0; j < 4; j++ ))
#		do
#			tempstr=${i}_${j}
#			val=$(((i*10) + j))
#			mk_device fcasic4P fcasic4P_${tempstr} $val
#		done 
#	done
	return 0
}

make_devices()
{
	mk_device ki ki 0
	case ${SWBD##SWBD} in
	'63')
		mk_device ham ham 0
		mk_device swd swd 0
		mk_device ata_dumper ata_dumper 0
		mk_device fss_mgmt fssm 0
		mk_device fss_data fssd 0
		;;
	'165' | '166')
		mk_device fabsys fabsys 0
		mk_device portlog portlog 0 portlog0 0 portlog1 1
		mk_device chassis chassis 0
		mk_device fc fc 0 fc0 0 fc1 1 fc2 2 fc3 3 fc4 4 fc5 5 fc6 6 fc7 7 
		mk_device fc fc8 8 fc9 9 fc10 10 fc11 11 fc12 12 fc13 13 fc14 14 fc15 15 
		mk_device switch switch 0 switch0 0 switch1 1 switch2 2 switch3 3 switch4 4 switch5 5 switch6 6 switch7 7
		mk_device switch switch8 8 switch9 9 switch10 10 switch11 11 switch12 12 switch13 13 switch14 14 switch15 15
		mk_device ham ham 0
		mk_device swd swd 0
		mk_device fss_mgmt fssm 0
		mk_device fss_data fssd 0
		echo "done fssd"
        mk_device dpci_pciehp dpci_pciehp.mod 0
		mk_device dioc dioc 0
		mk_device spi-fpga spi-fpga 0
		mk_device fm1 fm1 0
		mk_device fm1 fm1-pcd 1
		mk_device fm1 fm1-port-rx2 11
		mk_device fm1 fm1-port-rx3 12
		mk_device fm1 fm1-port-tx2 17
		mk_device fm1 fm1-port-tx3 18
		;;
	'141' | '142')
		mk_device fabsys fabsys 0
		mk_device portlog portlog 0 portlog0 0 portlog1 1
		mk_device chassis chassis 0
		mk_device fc fc 0 fc0 0 fc1 1 fc2 2 fc3 3 fc4 4 fc5 5 fc6 6 fc7 7 
		mk_device switch switch 0 switch0 0 switch1 1 switch2 2 switch3 3 switch4 4 switch5 5 switch6 6 switch7 7
		mk_device ham ham 0
		mk_device swd swd 0
		mk_device fss_mgmt fssm 0
		mk_device fss_data fssd 0
		mk_device dpci_pciehp dpci_pciehp.mod 0
		mk_device dioc dioc 0
		mk_device spi-fpga spi-fpga 0
		;;
	'148' | '171')
		mk_device fabsys fabsys 0
		mk_device chassis chassis 0
		mk_device portlog portlog 0 portlog0 0 portlog1 1
		mk_device fc fc 0 fc0 0 fc1 1 fc2 2 fc3 3 fc4 4 fc5 5 fc6 6 fc7 7
		mk_device switch switch 0 switch0 0 switch1 1 switch2 2 switch3 3 switch4 4 switch5 5 switch6 6 switch7 7
		mk_device ham ham 0
		mk_device swd swd 0
		#mk_device ata_dumper ata_dumper 0
		mk_device fss_mgmt fssm 0
		mk_device fss_data fssd 0
		if [ ! -c /dev/linux-uk-proxy ]; then
			mknod /dev/linux-uk-proxy c 125 0
		fi
		mknod /dev/dpci_switch-module.mod c 113 0
		mk_device dioc dioc 0
		;;
	'156')
		mk_device fabsys fabsys 0
		mk_device chassis chassis 0
		mk_device portlog portlog 0 portlog0 0 portlog1 1
		mk_device fc fc 0 fc0 0 fc1 1 fc2 2 fc3 3 fc4 4 fc5 5 fc6 6 fc7 7
		mk_device switch switch 0 switch0 0 switch1 1 switch2 2 switch3 3 switch4 4 switch5 5 switch6 6 switch7 7
		mk_device ham ham 0
		mk_device swd swd 0
		#mk_device ata_dumper ata_dumper 0		# Jeff, key
		mk_device fss_mgmt fssm 0
		mk_device fss_data fssd 0
		rm -f /dev/dpci_switch-module.mod
		mknod /dev/dpci_switch-module.mod c 113 0
		mk_device dioc dioc 0
		#mk_device c3regdump c3regdump 0
		mk_device fcasic3 fcasic3 0
		;;
	'167')
		mk_device fabsys fabsys 0
		mk_device portlog portlog 0 portlog0 0 portlog1 1
		mk_device chassis chassis 0
		mk_device fc fc 0 fc0 0 fc1 1 fc2 2 fc3 3 fc4 4 fc5 5 fc6 6 fc7 7
		mk_device switch switch 0 switch0 0 switch1 1 switch2 2 switch3 3 switch4 4 switch5 5 switch6 6 switch7 7
		mk_device ham ham 0
		mk_device swd swd 0
		#mk_device ata_dumper ata_dumper 0		# Jeff, key
		mk_device fss_mgmt fssm 0
		mk_device fss_data fssd 0
		rm -f /dev/dpci_switch-module.mod
		mknod /dev/dpci_switch-module.mod c 113 0
		#we cannot use mk_device() because module name is different to device name
		major=`cat /proc/devices | /bin/grep dfpga | cut -f 1 -d" "`
		rm -f /dev/dfpga-module.mod
		mknod /dev/dfpga-module.mod c $major 0
		mk_device dioc dioc 0
		#mk_device c3regdump c3regdump 0
		# In v8.0 c3regdump is now fcasic3
		mk_device fcasic3 fcasic3 0
		;;
	'161' | '162' | '169' | '170' | '172' | '178')
		mk_device fabsys fabsys 0
		mk_device portlog portlog 0 portlog0 0 portlog1 1
		mk_device chassis chassis 0
		mk_device fc fc 0 fc0 0 fc1 1 fc2 2 fc3 3 fc4 4 fc5 5 fc6 6 fc7 7
		mk_device switch switch 0 switch0 0 switch1 1 switch2 2 switch3 3 switch4 4 switch5 5 switch6 6 switch7 7
		mk_device ham ham 0
		mk_device swd swd 0
		#mk_device ata_dumper ata_dumper 0
		mk_device fss_mgmt fssm 0
		mk_device fss_data fssd 0
#if [ "$FOS_LINUX_BRINGUP" != "1" ] ; then
	rm -f /dev/dpci_switch-module.mod
        mknod /dev/dpci_switch-module.mod c 113 0
		mk_device dioc dioc 0
#fi
		;;
		# Merge the following 173 with above, once TYR bring up done
	'173')
		mk_device fabsys fabsys 0
		mk_device portlog portlog 0 portlog0 0 portlog1 1
		mk_device chassis chassis 0
		mk_device fc fc 0 fc0 0 fc1 1 fc2 2 fc3 3 fc4 4 fc5 5 fc6 6 fc7 7
		mk_device switch switch 0 switch0 0 switch1 1 switch2 2 switch3 3 switch4 4 switch5 5 switch6 6 switch7 7
		mk_device ham ham 0
		mk_device swd swd 0
		#mk_device ata_dumper ata_dumper 0
		mk_device fss_mgmt fssm 0
		mk_device fss_data fssd 0
		mknod /dev/dpci_switch-module.mod c 113 0
		mk_device dioc dioc 0
		;;
	157 | 158)
		mk_device fabsys fabsys 0
		mk_device portlog portlog 0 portlog0 0 portlog1 1
		mk_device chassis chassis 0
		mk_device fc fc 0 fc0 0 fc1 1 fc2 2 fc3 3 fc4 4 fc5 5 fc6 6 fc7 7
		mk_device switch switch 0 switch0 0 switch1 1 switch2 2 switch3 3 switch4 4 switch5 5 switch6 6 switch7 7
		mk_device ham ham 0
		mk_device swd swd 0
		# mk_device ata_dumper ata_dumper 0
		mk_device fss_mgmt fssm 0
		mk_device fss_data fssd 0
		rm -f /dev/dpci_switch-module.mod
		mknod /dev/dpci_switch-module.mod c 113 0
		mk_device dioc dioc 0
		mk_device fcasic3 fcasic3 0
		;;
	*)
		mk_device fabsys fabsys 0
		mk_device portlog portlog 0 portlog0 0 portlog1 1
		mk_device chassis chassis 0
		mk_device fc fc 0 fc0 0 fc1 1 fc2 2 fc3 3 fc4 4 fc5 5 fc6 6 fc7 7
		mk_device switch switch 0 switch0 0 switch1 1 switch2 2 switch3 3 switch4 4 switch5 5 switch6 6 switch7 7
		mk_device ham ham 0
		mk_device swd swd 0
		mk_device ata_dumper ata_dumper 0
		mk_device fss_mgmt fssm 0
		mk_device fss_data fssd 0
		mk_device dioc dioc 0
		;;
	esac

	case ${SWBD##SWBD} in
	# Blazer2, Icecube2, Viking, Glacier2, Dragon, Superhawk, Thor, Little Bear 8G
	# Bulova, Blazer3, Superhawk2, utah, Kestrel3, Redbird, Shenlong
	# create the gpio node (minor = 185)
	'37' | '43' | '44' | '45' | '51' | '61' | '64' | '70' | '72' | '73' | '75' | '82' | '86' | '87' | '117' | '124' | '125' | '129' | '130' | '134' | '149' | '150' | '156' | '157' | '158' | '167')
		# mk_device misc gpio 185
		mk_gpio_device
		;;
	esac

	# Zentron has ethernet switch driver
	# shared memory driver is needed for Zentron
	case ${SWBD##SWBD} in
	'63')
		mk_device smd smd 0
		mk_device smdplat smdplat 0
		;;
	'62' | '77')
		mk_device enetswch enetswitch 0
		mk_device uartmux uartmux 0
		mk_device smd smd 0
		mk_device smdplat smdplat 0
        mk_device dpcichassis-module dpcichassis-module  0
		;;
	'141' | '142')
		#mk_device enetswch enetswitch 0
		mk_device uartmux uartmux 0
		#mk_device smd smd 0
		#mk_device smdplat smdplat 0
		mk_device fcoe fcoe 0
		mk_device esw_hsl esw_hsl 0
		mk_device dpcichassis-module dpcichassis-module  0
		;;
	'165' | '166')
if [ "$FOS_LINUX_BRINGUP" != "1" ] ; then
		if [ "$FOS_LINUX_BRINGUP_WORKAROUND" != "1" ] ; then
			mk_device uartmux uartmux 0
		fi
fi
		if [ ! -c /dev/linux-uk-proxy ]; then
			mknod /dev/linux-uk-proxy c 125 0
		fi
	#	mk_device fcoe fcoe 0
	#	mk_device esw_hsl esw_hsl 0
#		mk_device dpcichassis-module dpcichassis-module  0
		;;
	esac

	# Elara has Altera configuration device to program Zeus
	# Add diag node
	case ${SWBD##SWBD} in
	'76')
		mk_device altera altera 0
		mk_device fcoe fcoe 0
		mk_device fdpci fdpci 0
		mk_device esw_hsl esw_hsl 0
		;;
	# Spear/Spearlite/Spike
	'79' | '80')
		mk_device enetswch enetswitch 0
		;;

	#SKYBOLT - revisit for enetswch module
	#'148')
	#	mk_device enetswch enetswitch 0	
	#	;;
	esac
	
	# Platform that use Condor3
	case ${SWBD##SWBD} in
	'109' | '117' | '118' | '129' | '130' | '133' | '148' | '171' | '149' | '150' | '156' | '157' | '158' | '167')
		mk_device fcasic3 fcasic3 0
if [ "$FOS_LINUX_BRINGUP" != "1" ] ; then
        mk_device fdpci fdpci 0
fi
		;;
	esac

	case ${SWBD##SWBD} in
	'161' | '162')
		make_fcasic4_devices 
		;;
	esac

	case ${SWBD##SWBD} in
	 '165' | '166')
		make_fcasic4_devices 
		#make_fcasic4P_devices
		;;
	esac

	case ${SWBD##SWBD} in
	'165' | '166')
		make_fcasic4_devices 
		make_fcasic4P_devices 
		;;
	esac

	# Platform that uses GE4
	case ${SWBD##SWBD} in
	'169' | '170')
		make_fcasic4_devices 
	#	mk_device fcoe fcoe 0
		;;
	esac

	# Platform that uses C4+
	case ${SWBD##SWBD} in
	'172' | '173')
		make_fcasic4P_devices 
		#mk_device fcoe fcoe 0
		;;
	esac

	# A_WING platform that uses geye4
	case ${SWBD##SWBD} in 
	'178')
		make_fcasic4_devices 
		if [ ! -c /dev/linux-uk-proxy ]; then
			mknod /dev/linux-uk-proxy c 125 0
		fi
		;;
	esac
}
			
#
# this function will load the "panic dump" related modules
# These modules need to be loaded first and we have to call
# "pdcheck.sh" to check for a panic dump from a previous reboot
# if found we will save them in CF (it is all done in pdcheck.sh)
#
load_common() {
	modutil load smd-module
	# SKYBOLT - check smdp installation later
    if [[("$SWBD" == "SWBD62") || ("$SWBD" == "SWBD63") || ("$SWBD" == "SWBD77") || ("$SWBD" == "SWBD141") || ("$SWBD" == "SWBD142") || ("$SWBD" == "SWBD165") || ("$SWBD" == "SWBD166")]]; then
		modutil load smdp-module
	fi
	modutil load raslog-module
	modutil	load basic-module
	max_dump_sz_val=`/sbin/tracecfg -i ${SWBD##SWBD}`
	modutil load trace-module platform=${SWBD##SWBD} max_dump_sz=$max_dump_sz_val
	mk_device raslog raslog 0
	mk_device trace trace 0 trace1 1
	/sbin/tracecfg -w ${SWBD##SWBD} > /var/log/tracecfg.log

	if [[("$SWBD" == "SWBD141") || ("$SWBD" == "SWBD142") || ("$SWBD" == "SWBD161") || ("$SWBD" == "SWBD162") || ("$SWBD" == "SWBD148") || ("$SWBD" == "SWBD156") || ("$SWBD" == "SWBD157") || ("$SWBD" == "SWBD158") || ("$SWBD" == "SWBD165") || ("$SWBD" == "SWBD166") || ("$SWBD" == "SWBD167") || ("$SWBD" == "SWBD169") || ("$SWBD" == "SWBD170") || ("$SWBD" == "SWBD171") || ("$SWBD" == "SWBD172") || ("$SWBD" == "SWBD173") || ("$SWBD" == "SWBD178")]]; then
		modutil load syslock-module syslock_debug=$SYSLOCK_DEBUG
		modutil load smplocks-module
	fi
	if [ "`bootenv bootargs 2> ${NULL} |grep fablog`" != "" ]; then
		str=`bootenv bootargs`
		for i in $str; do
			if echo $i | grep fablog &> ${NULL}; then
				MTRACER_ENABLE=`echo $i |grep fablog | awk '{print $1}' | cut -d "=" -f 2 2> ${NULL}`
			fi
		done
	fi
	modutil load fablog-module mtracer_enable=$MTRACER_ENABLE $TRACKER
	modutil load xprt-module xprt_verbose=$XPRT_VERBOSE
	modutil load isc-module
	modutil load tp-module
	modutil load hasm-module
	case ${SWBD##SWBD} in
        '141' | '142' | '148' | '156' | '157' | '158' | '161' | '162' | '165' | '167' | '166' | '169' | '170' | '171' | '172' | '173' | '178')
		;;
        *)
			if [ "$FOS_LINUX_BRINGUP" != "1" ] ; then
				modutil load rscmon-module
			fi
        ;;
    esac


	# common devices need to be make before pdcheck
	mk_device isc_mgmt iscm 0
	mk_device isc_data iscd 0

	mk_device tp tp 0

	case ${SWBD##SWBD} in
        '141' | '142' | '148' | '156' | '157' | '158' | '161' | '162' | '165' | '166'| '167'  | '169' | '170' | '171' | '172' | '173' | '178')
        ;;
        *)
			if [ "$FOS_LINUX_BRINGUP" != "1" ] ; then
				mk_device rscmon rscmon 0
			fi
		;;
	esac
}

#
# load Brocade ECC module on platforms for which we have a module for that processor.
# for now just freescale 8548 based platforms.
#
load_brcdeccmod() {
	case ${SWBD##SWBD} in
	'62' | '63' | '64' | '67' | '76' | '77' | '141' | '142' | '148' | '156' | '157' | '158' | '165' | '166' | '167' | '171')
		file=/lib/modules/default/kernel/drivers/brcdecc/brcdeccmod.ko
		[ $enable_fabos_log -eq 1 ] && echo `date "+%D %T"`,$file,loading >> $fabos_log && sync
		insmod $file > $insmod_log 2>&1
		if [ $? -eq 0 ]; then
			echo "`date '+%D %T'`,$file,loaded" >> $insmod_log
		else
			echo insmod return error code $? >> $insmod_log
		fi
		[ $enable_fabos_log -eq 1 ] && cat $insmod_log >> $fabos_log && sync
		;;
	esac
}

#
# check all the daemons off so that they don't show in chkconfig cli as on.
#
chkconfigoff_63() {
	daemons=`ls /etc/config`
	for i in $daemons; do
		$CHECK $i off > ${NULL} 2>&1
	done

	#we might want a few on
	$CHECK fabos on
	$CHECK raslogd on
	$CHECK syslog on
	$CHECK panicdump on
	$CHECK sshd on

}

#
# main-cpu in Neptune
#
main_cpu_ip_neptune() {
	echo "main-cpu in Neptune..."
    # Configure eth1
    ifconfig eth1 127.1.1.$((CPID % 2 + 7)) \
		netmask 255.255.255.0 > ${NULL} 2>&1

    route add -host 127.1.1.$((8 - CPID % 2)) dev eth1 > ${NULL} 2>&1

	# configure eth2 for neptune, 127.1.16.16, 127.1.17.17
	ifconfig eth2 127.1.$((CPID % 2 + 16)).$((CPID % 2 + 16)) \
		netmask 255.255.255.0 > ${NULL} 2>&1
}


#
# main-cpu in Pluto
#
main_cpu_ip_pluto() {
	echo "main-cpu in Pluto..."
    ifconfig eth1 127.1.1.$((CPID % 2 + 5)) \
		netmask 255.255.255.0 > ${NULL} 2>&1

    route add -host 127.1.1.$((6 - CPID % 2)) dev eth1 > ${NULL} 2>&1

	# configure eth2 for Pluto, 127.1.14.14, 127.1.15.15
    ifconfig eth2 127.1.$((CPID % 2 + 14)).$((CPID % 2 + 14)) \
		netmask 255.255.255.0 > ${NULL} 2>&1
}

#
# co-cpu in Neptune
#
co_cpu_ip_neptune() {
	echo "Co-CPU running in Neptune..."
    ifconfig eth1 127.1.2.$((CPID % 2 + 16)) \
	netmask 255.255.255.0 > ${NULL} 2>&1
    route add -host 127.1.2.$((17 - CPID % 2)) dev eth1 > ${NULL} 2>&1

    ifconfig eth2 127.1.$((CPID % 2 + 16)).$(((CPID % 2 + 6) * 10)) \
	netmask 255.255.255.0 > ${NULL} 2>&1
}

#
# co-cpu in Pluto
#
co_cpu_ip_pluto() {
	echo "Co-CPU running in Pluto..."
    ifconfig eth1 127.1.2.$((CPID % 2 + 14)) \
	netmask 255.255.255.0 > ${NULL} 2>&1
    route add -host 127.1.2.$((15 - CPID % 2)) dev eth1 > ${NULL} 2>&1

    ifconfig eth2 127.1.$((CPID % 2 + 14)).$(((CPID % 2 + 4) * 10)) \
	netmask 255.255.255.0 > ${NULL} 2>&1
}

#
# main-cpu in DCX 8510XT-8
#
main_cpu_ip_neptune_yoda() {
	echo "main-cpu in DCX 8510XT-8..."

	# configure eth2 for neptune yoda, 127.1.16.16, 127.1.17.17
	ifconfig eth2 127.1.$((CPID % 2 + 16)).$((CPID % 2 + 16)) \
		netmask 255.255.0.0 > ${NULL} 2>&1
}

#
# main-cpu in DCX 8510XT-4
#
main_cpu_ip_pluto_yoda() {
	echo "main-cpu in 8510XT-4..."

	# configure eth2 for Pluto yoda, 127.1.14.14, 127.1.15.15
	ifconfig eth2 127.1.$((CPID % 2 + 14)).$((CPID % 2 + 14)) \
		netmask 255.255.0.0 > ${NULL} 2>&1
}

zentron_ip() {
    case ${SWBD##SWBD} in
    '62')
		main_cpu_ip_neptune
    	;;
    '77')
		main_cpu_ip_pluto
    	;;
    '141')
		main_cpu_ip_neptune_yoda
    	;;
    '142')
		main_cpu_ip_pluto_yoda
    	;;
	'63')
	    case ${CHASS##CHASS} in
		'62' | '141')
			co_cpu_ip_neptune
			;;
		'77' | '142')
			co_cpu_ip_pluto
			;;
		*)
			;;
		esac

	   ;;
	*)
    esac
}

save_ethernet_ip() {

    case ${SWBD##SWBD} in
    '62' | '77' | '141' | '142' | '165' | '166')
        INTERFACE="bond0"
        ;;
    *)
        INTERFACE="eth0"
        ;;
    esac

	# read ip, mask and gw with ifconfig
	timeout=120 # 2 minute
	for ((i=0;i<$timeout;i++)); do
		sleep 1
		ip=`ifconfig $INTERFACE | grep inet | awk '{print $2}' | cut -d ":" -f 2 2> ${NULL}`
		[ "$ip" = "" ] && continue
		mask=`ifconfig $INTERFACE | grep inet | awk '{print $4}' | cut -d ":" -f 2 2>${NULL}`
		[ "$mask" = "" ] && continue
		gw=`route | grep default | awk '{print $2}' 2>${NULL}`
		[ "$gw" != "" ] && break
	done
	if [ $i -ge $timeout ]; then
		echo interface = $INTERFACE
		[ -n "$ip" ] && echo "ip = $ip" || echo "ip is empty !"
		[ -n "$mask" ] && echo "netmask = $mask" ||  echo "netmask is empty !"
		[ -n "$gw" ] && echo "gateway = $gw" || echo "gateway is empty !"
		return
	fi

    case ${SWBD##SWBD} in
    '62' | '64' | '67' | '76' | '77' | '141' | '142' | '165' | '166')
        MASK_NAME="netmask"
        ;;
    *)
        MASK_NAME="submask"
        ;;
    esac

    IPADDR=`bootenv ipaddr 2> ${NULL}`
    GATEWAY=`bootenv gatewayip 2> ${NULL}`
    NETMASK=`bootenv $MASK_NAME 2> ${NULL}`

    if test "$ip" != "$IPADDR"; then
        bootenv ipaddr "$ip"
    fi

    if test "$mask" != "$NETMASK"; then
        bootenv $MASK_NAME "$mask"
    fi

    if test "$gw" != "$GATEWAY"; then
        bootenv gatewayip "$gw"
    fi

}

#
# bconoff
#
# Retrieve the flag from bootcount.file
#
bconoff() {
    sed -n -e 's/Check Off Fabos:\([[:digit:]]\{1,\}\).*$/\1/gp'
}

#
# bcsecs
#
# Retrieve the secs from bootcount.file
#
bcsecs() {
    sed -n -e 's/Seconds:\([[:digit:]]\{1,\}\).*$/\1/gp'
}

#
# bcboots
#
# Retrieve the secs from bootcount.file
#
bcboots() {
    sed -n -e 's/^Boo.\+unts:\([[:digit:]]\{1,\}\).*$/\1/gp'
}

#
# fips_status
#
# Check if FIPS is on or off
#
fips_status() {
    
    # File name of FIPS
    # Read the file /etc/fabos/pwron_fips_status to check if FIPS is on or off.
    # Absence of the file or a zero written to it means FIPS is off and we can
    # chkconfig fabos off, otherwise FIPS is enabled.

    FIPS_FILE=/etc/fabos/pwron_fips_status

    if [ -a $FIPS_FILE ]; then
        FIPS_FLAG=`cat $FIPS_FILE|sed -n -e 's/^\([[:digit:]]\{1,\}\).*$/\1/gp'`
        if [ $FIPS_FLAG -eq 0 ]; then
            FIPS=0
        else
            FIPS=1
        fi
    else
        FIPS=0
    fi
    return $FIPS
}

fwinstall_set_ip() {

	echo  "In fwinstall_set_ip.."
	case ${SWBD##SWBD} in
	'62' | '64' | '67' | '76' | '77' | '141' | '142' | '165' | '166' | '172')
		MASK_NAME="netmask"
		;;
	*)
		MASK_NAME="submask"
		;;
	esac

	IPADDR=`bootenv ipaddr 2> ${NULL}`
	GATEWAY=`bootenv gatewayip 2> ${NULL}`
	NETMASK=`bootenv $MASK_NAME 2> ${NULL}`

	if [[("$SWBD" == "SWBD62") || ("$SWBD" == "SWBD77") || ("$SWBD" == "SWBD141") || ("$SWBD" == "SWBD142") || ("$SWBD" == "SWBD165") || ("$SWBD" == "SWBD166") || ("$SWBD" == "SWBD172")]]; then
		/sbin/ifconfig bond0 $IPADDR netmask $NETMASK
		/sbin/route add default gw $GATEWAY
		if [ "$SWBD" != "SWBD166" ] || [ "$FOS_LINUX_BRINGUP_WORKAROUND" != "1" ]; then
			modutil load enetswch-module
		fi
		modutil load smd-module
		modutil load smdp-module

		mk_device smd smd 0
		mk_device smdplat smdplat 0

		CHASS=`sin -c| chassbd 2> ${NULL}`

		zentron_ip
	else
		/sbin/ifconfig eth0 $IPADDR netmask $NETMASK
		/sbin/route add default gw $GATEWAY
	fi

}

#
# print_sw_disable_msg
# Print switch disabled message
#
print_sw_disable_msg() {
cat > new_file << EOF
**************************************************************
* Fabric OS has detected frequent switch reboot condition.   *
* The switch has been disabled as a preventive action. If    *
* the switch reboots again Rolling Reboot Detection will     *
* halt the switch from loading Fabric OS.                    *
*                                                            *
* Please use 'switchcfgpersistentenable' to enable the       *
* switch, once the problem is resolved.                      *
**************************************************************
EOF
cat new_file
}

#
# bootcount
#
# bootcount control
#
boot_count() {
		#
		# bootcount utility only runs if FIPS if off
		#
		fips_status
		if [ $? -eq 0 ]; then
        echo "FIPS off, RRD..."
        if $CHECK rrd; then
            bootcount -p ${SWBD##SWBD} -f 1
        else
            bootcount -p ${SWBD##SWBD} -f 0
       	fi
		result=$?
        # special handling if RRD is detected
        if [ $result -eq 2 ]; then
			/fabos/cliexec/config set switch.persistentDisable 2 1
			print_sw_disable_msg
        elif [ $result -eq 1 ]; then
			/bin/rm /dev/raslog 2>/dev/null
			/bin/rm /dev/trace 2>/dev/null
			if test "$SWBD" != "SWBD63"; then
				fwinstall_set_ip
			fi
			if test "$SWBD" == "SWBD117"; then
				# Pharos: light Fault LED, set Fault bit in Status Register
				/fabos/factory/fpga_reg a0 40
				/fabos/factory/fpga_reg c1 08
			fi
			fabos_complete 6
            exit
        fi
	fi
}

do_install() {
    echo ""
    echo "Firmware is being installed, please wait ..."
    echo ""

    if test "$SWBD" != "SWBD63"; then

        case ${SWBD##SWBD} in
        '62' | '64' | '67' | '76' | '77' | '141' | '142' | '165' | '166')
            MASK_NAME="netmask"
            ;;
        *)
            MASK_NAME="submask"
            ;;
        esac
 
        IPADDR=`bootenv ipaddr 2> ${NULL}`
        SERVERIP=`bootenv serverip 2> ${NULL}`
        GATEWAY=`bootenv gatewayip 2> ${NULL}`
        NETMASK=`bootenv $MASK_NAME 2> ${NULL}`
		IPV6ADDR=`bootenv ipv6addr 2> ${NULL}`
        bootenv ethact ENET0
#
#		Bonding modulde is not working in Yoda CP currently. Use eth0 interface for installation.
#
#
#        if [[("$SWBD" == "SWBD62") || ("$SWBD" == "SWBD77") || ("$SWBD" == "SWBD141") || ("$SWBD" == "SWBD142")]]; then
#
        if [[("$SWBD" == "SWBD62") || ("$SWBD" == "SWBD77") || ("$SWBD" == "SWBD165") || ("$SWBD" == "SWBD166")]]; then
            /sbin/ifconfig bond0 $IPADDR netmask $NETMASK
            /sbin/route add default gw $GATEWAY
			if [ -n "$IPV6ADDR" ]; then
				/sbin/ip -6 addr add $IPV6ADDR dev bond0
			fi
	        if [ "$SWBD" != "SWBD166" ]  || [ "$FOS_LINUX_BRINGUP_WORKAROUND" != "1" ]; then  
			   modutil load enetswch-module
			fi
        else
            /sbin/ifconfig eth0 $IPADDR netmask $NETMASK
            /sbin/route add default gw $GATEWAY
			if [ -n "$IPV6ADDR" ]; then
				/sbin/ip -6 addr add $IPV6ADDR dev eth0
			fi
        fi
    else
		fabos_complete 7
        exit 3
    fi

	P_TYPE=`grep -c "/usr/bin/scp" /var/tmp/tmp_clean.0`
	if [ $P_TYPE -eq 1 ]; then
		PROTOCOL="scp"
	elif [ `grep -c "sftp" /var/tmp/tmp_clean.0` -eq 1 ]; then
		PROTOCOL="sftp"
	else
		PROTOCOL="ftp"
	fi

	# Small delay introduced before invoking install script as the
	# ethernet module on some platforms takes time to come up.
	sleep 10

    # run install script
    /var/tmp/install -t clean -p $PROTOCOL -f /var/tmp/tmp_clean.0 release
    if [ $? -ne 0 ]; then
		bootenv -u Upgrade
		echo ""
		echo "FirmwareCleaninstall failed, you can reboot to retry."
		echo ""
		fabos_complete 8
		exit 3
    fi

    bootenv Upgrade cleancommit
	echo ""
	echo "FirmwareCleaninstall finished loading the 1st Partition, rebooting the switch..."
	echo ""
	fabos_complete 9
	/bin/rm /var/tmp/install
	/usr/bin/reboot -f
	exit 3

}

do_cleancommit() {
	echo ""
	echo "Doing firmwarecleanInstall commit on second partition."
	echo ""

	FS='ext3'
	FSOPTS='-f'
	case "$SWBD" in
		"SWBD12" | "SWBD21" | "SWBD22" ) FS=xfs ;;
	*) ;;
	esac

	#format the second partition
	MNT=`mount | grep mnt | awk '{printf("%s", $1);} '`
	umount /mnt
	case "$FS" in
	   "ext3")
		/sbin/mke2fs -g32768 -b4096 -j $MNT
		/sbin/tune2fs -c 0 -i 0 $MNT
	   ;;
	   * )
		/sbin/mkfs -t $FS $FSOPTS $MNT
	   ;;
	esac

	mount -o noatime $MNT /mnt

    echo ""
    echo "Commit started on the second partition, please wait..."
    echo ""
    /fabos/cliexec/firmwarecommit -c 2> ${NULL}
    COMMIT_STATUS=$?
    /bin/mkdir -p /mnt/tmp
    /bin/mkdir -p /mnt/proc
    /bin/mkdir -p /mnt/mnt
    chown root:root /dev/null /dev/zero
    bootenv -u Upgrade
    if [ $COMMIT_STATUS -eq 0 ]; then
        echo ""
        echo "FirmwareCleaninstall commit completed successfully."
		echo ""
        echo "FirmwareCleaninstall will complete after the reboot."
		echo "Rebooting the switch ..."
        echo ""
		fabos_complete 10
        /usr/bin/reboot -f
        exit 3
    else
        echo "FirmwareCleaninstall commit failed. Please do \"firmwarecommit -c\" after doing a reboot or retry firmwareCleanInstall."
    fi

}

handle_clean_install() {
	UPGRADE=`bootenv Upgrade 2> ${NULL}`

	if test "$UPGRADE" = "clean"; then
		do_install
	fi

	if test "$UPGRADE" = "cleancommit"; then
		do_cleancommit
	fi

	if test "$UPGRADE" = "cocleancommit"; then
		do_cleancommit
	fi
}

TRC_FILE_COUNT=5
#
# Rotate specified trace files
#
rotate_trc_file() {

        if [ "$2" == "trc" ];then
                ext=.gz
        else
                ext=.od
        fi
        COUNT=$TRC_FILE_COUNT
        rm -rf /var/trace/trace$1*.trc$TRC_FILE_COUNT$ext 2> /dev/null
        rm -rf /var/trace/trace$1*.trc$TRC_FILE_COUNT 2> /dev/null

        while [ $COUNT -gt 0 ]
        do
                (( COUNT1 = $COUNT - 1 ))
                FILE=`/bin/ls /var/trace/trace$1*trc$COUNT1$ext* 2> /dev/null`
                DATE=`echo $FILE | cut -d '.' -f 2`
                /bin/mv $FILE /var/trace/trace$1.$DATE.trc${COUNT}$ext 2> /dev/null
                (( COUNT = $COUNT - 1 ))
        done
}
#
# Rotate all trace files
#
trace_file_rotation() {

        if [ -f /var/trace/tracepd.*.trc0.od ]; then
                rotate_trc_file pd
        fi
        if [ -f /var/trace/traceboot.*.trc0.od ]; then
                rotate_trc_file boot
        fi

}

#
# Power off external USB
#
usb_power_off() {
    usb_drv=$1
    if [ -e /sys/bus/usb/drivers/hub/${usb_drv} ]; then
        echo ${usb_drv} > /sys/bus/usb/drivers/hub/unbind
	fi
}

prepare_netboot () {
	case ${SWBD##SWBD} in
	'63')
	    if test "`bootenv bootcmd 2> ${NULL} | grep dhcp`" != ""; then
		rm -f /etc/raslog.int /etc/raslog.ext
		echo RASLOG > /etc/raslog.int
		echo RASLOG > /etc/raslog.ext
		mkdir /mnt/etc 2> /dev/null
		cp -f /etc/raslog.* /mnt/etc
	    fi
	    ;;
	'62' | '77' | '141' | '142')
	    # setup for cocpu netboot
	    /bin/touch /tmp/dhcpd.leases
	    /sbin/dhcpd -4 -cf \
		/etc/dhcpd.conf.swbd${SWBD##SWBD}.stby.cp${CPID} \
		-lf /tmp/dhcpd.leases -pf /tmp/dhcpd.pid eth2
	    ln -s /boot/zImage.tree.initrd /tftpboot/ 2> /dev/null
	    /fabos/cliexec/hareset -c
	    mkdir /etc/cocpu /etc/cocpu/config 2> /dev/null
	    cp -af /etc/config/* /etc/cocpu/config
	    ;;

	*)
	    ;;
	esac

}
# Code to set the limit on the size of the corefile
# 
setulimit(){
        set -- $(/bin/df -k ${1:-/core_files})
        typeset -i size=${11}
        if ((size > 4000000))
        then    ulimit -c unlimited
        elif ((size < 0))
        then    ulimit -c 0
        else    ulimit -c $((size*7/10))
        fi
}

swap_eth_ports()
{
	PHARO_ETH_LOG=/tmp/pha_eth_log
	eth0_a=eth0
	eth0_b=eth1
	eth0_temp=eth_pahros0
	ETHA_CHECK=`/sbin/ifconfig $eth0_a 2>/dev/null`
	ETHB_CHECK=`/sbin/ifconfig $eth0_b 2>/dev/null`
	touch $PHARO_ETH_LOG
	if [ -r /proc/system/fpga ]
	then 
		test_fix_det=0x`/bin/cat /proc/system/fpga | /fabos/link_bin/grep "0x11f80000b0" | /bin/awk '{print $8}'`
		echo "TEST_FIXTURE_DET=$test_fix_det" >> $PHARO_ETH_LOG
		let "test_fix_det&=1"
		if [ $test_fix_det -eq 0 ]
		then
			if [ "$ETHA_CHECK" != "" ] && [ "$ETHB_CHECK" != "" ]
			then
				echo "In chassis: connected to backplane Ethernet port." >> $PHARO_ETH_LOG
				# change the backplane Ethernet port to eth0
				ip link set dev $eth0_a down >/dev/null 2>&1
				ip link set dev $eth0_b down >/dev/null 2>&1
				ip link set dev $eth0_a name $eth0_temp >/dev/null 2>&1
				ip link set dev $eth0_b name $eth0_a >/dev/null 2>&1
				ip link set dev $eth0_temp name $eth0_b >/dev/null 2>&1
				ip link set dev $eth0_a up >/dev/null 2>&1
				ip link set dev $eth0_b up >/dev/null 2>&1
			else
				echo "$eth0_a or $eth0_b doesn't exist" >> $PHARO_ETH_LOG
				/sbin/ifconfig -a >> $PHARO_ETH_LOG
			fi
		else
			echo "In test I/O card: connected to the front Ethernet port." >> $PHARO_ETH_LOG
		fi
	else
		echo "Error: fpga is not accessible." >> $PHARO_ETH_LOG
	fi
}

#
# main
#
case "$1" in
'start')
    ##################################################################

    ECHO=echo
    export ECHO

	if [ "$FABOS_START" = 'off' ]; then
		$ECHO -n -e "##### FOS services switched off from bootprompt #####\n"
		fabos_complete 11
		exit 1;
	fi

	install_crontab
	echo -n -e "##### Starting FABOS #####\n"
	#
	# set up fabos debug log
	# fabos state :
	#	0 - success
	#	1 - 1st failure, enable log for next reboot
	#	2 - 2nd failure, if succeed this time, backup current log to /var/log/fabos.log.prev
	#	3 - 3rd failure, retry
	#	4 - 4th failure, retry
	#	5 - 5th failure, display fabos log and reset back to state 0
	# Log maximum 5 continues failures. Any time if success, back to state 0
	#
	# On embedded platforms, disable this failure detection since there could be
	# resets/powercycles initiated from the OEM chassis during the FOS init process

	case ${SWBD##SWBD} in
	82 | 152 | 157 | 158 | 117 | 129 | 130 | 149 | 150 | 156 | 167)
		$ECHO "Disabling FOS failure detection feature"
		fabos_state=0
		;;
	*)
		$ECHO "Enabling FOS failure detection feature"
		if [ -f $fabos_log ]; then
			fabos_state="`awk -F, '/fabos_state/ { n=$NF }END{ print n }' $fabos_log`"
		else
			fabos_state=0
		fi
		;;
	esac

	fabos_state=$[${fabos_state:0:1} + 1]
	if [ $fabos_state -eq 4 ]; then
		enable_fabos_log=1
		echo enable fabos log
		[ $fabos_state -gt 1 ] && echo "switch abnormal reboot $fabos_state time(s)"
	elif [ $fabos_state -gt 4 ]; then
		bad_driver=`awk -F, '{ \
		  if ($NF == "loading") { \
			driver=$(NF-1) \
		  } else { \
			if ( NF > 1 && $NF == "loaded" && driver != "" ) { \
			  driver="" \
			} \
		  } \
		} END { \
		  if (driver != "") { print driver } \
		}' $fabos_log`
		if [ -n "$bad_driver" ]; then
			echo ==============================================================
			echo Error: insmod $bad_driver causing previous reboot !!!
			echo ==============================================================
			cat $fabos_log
			echo ==============================================================
			echo FABOS stop !
			echo Power cycle the switch to resume FABOS
			echo ==============================================================
			echo `date "+%D %T"`,fabos_state,0 >> $fabos_log && sync

			exit 0
		else
			# backup fabos log if 2rd reboot not caused by insmod
			[ $fabos_state -eq 3 ] && cp -v $fabos_log ${fabos_log}.prev
			fabos_state=1
		fi
	fi
	echo `date "+%D %T"`,fabos_state,$fabos_state > $fabos_log && sync

	handle_clean_install

	if [ "$FABOS_START" = 'off' ]; then
		$ECHO -n -e "##### FOS services switched off from bootprompt #####\n"
		fabos_complete 12
		exit 1;
	fi

	case ${SWBD##SWBD} in
	141 | 142 | 148 | 161 | 162 | 165 | 166 | 169 | 170 | 171 | 172 | 173 | 178)
		if [ -d /nfabos/bin ]; then
			$ECHO -n "### Keep usb power on for NFDiag ### "

			# disable hotplug script to preserves sdb & sdb1
			# device file and keeps usb controller enable
			# when usb device is removed.
			echo /dev/null > /proc/sys/kernel/hotplug
		else
        		if [[ ("$SWBD" == "SWBD148") || ("$SWBD" == "SWBD161") || ("$SWBD" == "SWBD162") || ("$SWBD" == "SWBD169") || ("$SWBD" == "SWBD170") || ("$SWBD" == "SWBD171") || ("$SWBD" == "SWBD172") || ("$SWBD" == "SWBD173") || ("$SWBD" == "SWBD178")]]; then
				usb_power_off 2-0:1.0
			else
				usb_power_off 1-0:1.0
			fi
		fi
        ;;
	*)
	esac

	$ECHO "Starting Fabric OS Services..."
	# Set stack limit to unlimited
	ulimit -s unlimited
	echo "Loading FOS_LINUX_MISC  module"
	modutil load fos_linux_misc-module

	case ${SWBD##SWBD} in
            42 | 62 | 77 | 141 | 142 | 165 | 166)
                ;;
            *)
		/bin/nice -n -15 /sbin/oom_handler &
                ;;
        esac


	# Check if the SEC engine is enabled. For this we look at
 	# the new and improved proc/cpuinfo and grab the SVR value
	# If the 4th nibble of the value is 8 or greater it has SEC
	# e.g.  80592011 has SEC whereas 80522011 has no SEC.
	cat /proc/cpuinfo | grep -q "svr = "
	if [ $?  -eq 0 ] ; then 
		export rngyes=`cat /proc/cpuinfo  | grep svr | sed -e's/^.* = //' | cut -c4`
		if  [ $rngyes -ge 8 ]; then 
		    if [ !  -c /dev/hwrng ]; then
			echo "Device RNG does not exist. Creating.."
			/bin/mknod  /dev/hwrng c 10 183
		    fi
		    if [  ! -d /sys/kernel/debug/caam ]; then
			/bin/mount -t debugfs debugfs /sys/kernel/debug
			echo 1 > /sys/kernel/debug/caam/ctl/hwrng_enabled 2> ${NULL}
			/bin/umount /sys/kernel/debug
		    else 
			echo 1 > /sys/kernel/debug/caam/ctl/hwrng_enabled 2> ${NULL}
		    fi
		    if [  -x /sbin/rngd ]; then
			/sbin/rngd -r /dev/hwrng
		    fi
		else 
		    echo "No  SEC Engine on this System"; 
		fi
	fi

	#
	# Many things depend on the proper HIL library. Make sure it
	# gets setup first thing, if needed.
	#

	# move to sysinit script since FIPS needs it before fabos
	# mk_hil


    case ${SWBD##SWBD} in
    '141' | '142' | '148' | '156' | '157' | '158' | '161' | '162' | '165' | '166' | '167' | '169' | '170' | '171' | '172' | '173' | '178')
        #free_space=`/bin/df /| grep -v Filesystem | awk '{print $4}'`
        #if [ $free_space -gt 358400 ];then
        trace_file_rotation
       #fi

        # Get WMD checksum stored in /var/wmd_cksum
        #if [ -f /var/wmd_cksum ]; then
        #   cksum=`cat /var/wmd_cksum`
        #else
        #   touch /var/wmd_cksum
        #   chmod 644 /var/wmd_cksum
        #    cksum=0
        ##fi
        # Get wmd_disable environmet variable
        if [[ ($SWBD == "SWBD148") || ($SWBD == "SWBD171") ]]; then
            if [ ! -f /var/log/cleanup_flag ]; then
                /bin/rm -f /var/log/core.fcext_se.* &
                /bin/rm -f /var/log/Ftrace_* &
                touch /var/log/cleanup_flag
            fi
        fi
        WMD_DISABLE=`bootenv wmd_disable 2> ${NULL}`
        if [ -z $WMD_DISABLE ]; then
            WMD_DISABLE=0
        fi
        echo "Loading Warm Memory Dumper module"
        modutil load wmdumper-module wmd_disable=$WMD_DISABLE
        echo "Warm Memory Dumper module loaded"
        mk_device wm_dumper wm_dumper 0
   		if [[ ($SWBD == "SWBD148") || ($SWBD == "SWBD171") || ($SWBD == "SWBD178")]]; then 
	        # Make sure DP loads FOS all the time after reboot/panic
        	$ECHO "Initializing FOS DP image symlinks"
		fi
		if [[("$SWBD" == "SWBD165") || ("$SWBD" == "SWBD166")]]; then
			rm /tftpboot/dp_bootcmds.img
			ln -s /tftpboot/dp_bootcmds_hrp.img /tftpboot/dp_bootcmds.img
		elif [[ ($SWBD == "SWBD148") || ($SWBD == "SWBD171") ]]; then
			rm /tftpboot/dp_bootcmds.img
			ln -s /tftpboot/dp_bootcmds_skb.img /tftpboot/dp_bootcmds.img
        elif [[ ($SWBD == "SWBD178") ]]; then
            rm /tftpboot/dp_bootcmds.img
            ln -s /tftpboot/dp_bootcmds_awing.img /tftpboot/dp_bootcmds.img

		fi
    ;;
    esac
	case ${SWBD##SWBD} in
		36|47|50|52|55|57|68|79|80|81|85|88|89)
		;;
		*)
		boot_count
		;;
	esac

    if $CHECK fabos; then
	    # Set the limit on the core file size
	    setulimit

            # In case the file was created with wrong permission, remove it.
            # The file is new in 4.3, the "removal" is unneccessary when 4.3 is
	    # delivered to external GA, should be removed. 
	    /bin/rm -f /etc/fabos/tb_ticks_per_jiffy

	    # pass this to fablog module
	    if $CHECK mtracer; then
		MTRACER_ENABLE=1
	    else
		MTRACER_ENABLE=0
	    fi

	    # load basic-module before any other modules are loaded
	    # (pd modules)
	    load_common
	    
	    # load_brcdeccmod
	    # if ECC module was loaded, start up the ECC reporting daemon
	    if [ -f /proc/driver/ecc/model ]; then
		/fabos/libexec/eccd
	    fi

	    # check for panic dump and save if exists
	    /fabos/rbin/pdcheck.sh
	    # Upload any PD_MISC parameters in kernel that can be obtained
	    # before the full fledged fabos
	    /fabos/rbin/pdul_misc_pre.sh

            # on zentron co-cpu, chkconfig off all the daemons except a few
            case ${SWBD##SWBD} in
	    '63')
                chkconfigoff_63
		;;
            esac
	    # Set-up diagnostics
	    rm -rf /diag; ln -s /proc/diag /diag


		# Enable HA for DCE services based on whether or not
		# /etc/fabos/dce_ha/dceha.conf exists.
		# For discovery release disable HA always
		# For eureka HA enable HA always
		ETHSW_HA_ENABLE=1

	    # configure fablog tracker
	    if [ -f /etc/tracker.cfg ]; then
		. /etc/tracker.cfg
	    fi

	    swbd"${SWBD##SWBD}"_module
	    
	    if [ $? -ne 0 ]; then
		unsupported ${SWBD##SWBD} 1
	    fi
	    
	    if [ -f /proc/asan_acl_dir/asan_acl ]; then
		    cat /proc/asan_acl_dir/asan_acl
		    cat /proc/asan_acl_dir/asan_page
	    fi
	
	    case ${SWBD##SWBD} in
		'117')
		#
		# set eth0 to the backplane ethernet port when the
		# swith is in the chassis; set eth1 to the front
		# ethernet port when the switch is in test the I/O card.
		# fpga register 0xB6 bit 0:
		#	0 = Pharos plugged in IBM backplane
		#	1 = Pharos plugged in test I/O card
		#
		  swap_eth_ports
		# /fabos/factory/sigdet.sh &
		  ;;
		*)
		  ;;
	    esac

	    make_devices
		#SKYBOLT - check chassis var later
	    CHASS=`sin -c| chassbd 2> ${NULL}`
	    zentron_ip
	    # commenting the following as part of defect TR349461
	    # prepare_netboot

	    # skip these two utilities on cocpu
	    case ${SWBD##SWBD} in
		'63')
		   ;;
		*)
  	          echo "starting ipadmd..."
		    /fabos/libexec/ipadmd -d3
		    /fabos/libexec/telnetmond
		   ;;
	    esac

		# Enable FMC based on eth_rate_limit configuration.
		case ${SWBD##SWBD} in
		'165' | '166')
			FMC_CFG=$(/fabos/cliexec/config get system.eth_rate_limit 2)
			if [ "$FMC_CFG" = "1" ] ; then
				echo "Enabling FMan Rate Limiting.."
				dir=/etc/fmc/config
				/sbin/fmc -c $dir/fmc_config.xml -p $dir/fmc_policy.xml -a
			fi
			;;
		*)
			;;
		esac
	
	# check CLP
	/fabos/cliexec/licadmin -b 2>/dev/null

	    # Get the switch configuration based on the platform
	    case ${SWBD##SWBD} in
		'21' | '42')
		   hasmd -p ${SWBD##SWBD} -o 5 -d ${MODE} &
		    ;;
		'63' | '76')
		   hasmd -p ${SWBD##SWBD} -d ${MODE} &
		     ;;
		'62' | '77' | '141' | '142' | '148' | '171' | '165' | '166')
		   echo "HASM enable auto-reboot"
		   if [  -f /etc/fabos/config/no_reboot_recover ]; then
		       rm -f /etc/fabos/config/no_reboot_recover
			   rm -f /mnt/etc/fabos/config/no_reboot_recover
			fi
		   hasmd -p ${SWBD##SWBD} -d ${MODE} &
		     ;;
		'46' | '79' | '80' | '83')
		    if $CHECK superd ; then
			superd_46 ${SWBD} $XPT ${MODE} &
		    else
			hasmd -p ${SWBD##SWBD} -d ${MODE} &
		    fi
		    ;;

		'67')
		    if $CHECK superd ; then
			superd_67 ${SWBD} $XPT -d ${MODE} &
		    else
			hasmd -p ${SWBD##SWBD} -d ${MODE} &
		    fi
		    ;;

		'161' | '162' | '169' | '170' | '171' | '172' | '173' | '178' | '156' | '157' | '158' | '150' | '149' | '148' | '134' | '133' | '130' | '129' | '125' | '124' | '118' | '109' | '92' | '87' | '86' | '82' | '75' | '73' | '72' | '71' | '70' | '66' | '64' | '61' | '58' | '51' | '45' | '44' | '43' | '37' | '34' | '32' | '29' | '27' | '26' | '23' | '12')
#
# If superd config file is not present, by default load superd.
# In stealth platform, this is the case with release.plist where
# we won't install daemons already part of superd to reduce flash usage

    		    if [ ! -f '/etc/config/superd' ] ; then
			superd ${SWBD} $XPT ${MODE} &
		    elif $CHECK superd ; then
			superd ${SWBD} $XPT ${MODE} &
		    else
			hasmd -p ${SWBD##SWBD} -d ${MODE} &
		    fi
		    ;;

		117)
			# Distinguish between Pharos and Pharos Lite with the -o option

			OPTION="-o $(cat /proc/system/Lite)"

			if [ ! -f '/etc/config/superd' ] ; then
				superd ${SWBD} $XPT ${MODE} $OPTION &
			elif $CHECK superd ; then
				superd ${SWBD} $XPT ${MODE} $OPTION &
			else
				hasmd -p ${SWBD##SWBD} -d ${MODE} $OPTION &
			fi
			;;

		167)
			# Distinguish between Tianlong and Shenlong with the -o option

			OPTION="$(cat /proc/system/Tianlong)"

			if [ ! -f '/etc/config/superd' ] ; then
				superd ${SWBD} $XPT ${MODE} $OPTION &
			elif $CHECK superd ; then
				superd ${SWBD} $XPT ${MODE} $OPTION &
			else
				hasmd -p ${SWBD##SWBD} -d ${MODE} -o $OPTION &
			fi
			;;

		*)
		    if $CHECK superd ; then
			superd ${SWBD} $XPT ${MODE} &
		    else
			hasmd -p ${SWBD##SWBD} -d ${MODE} &
		    fi
		    ;;
	    esac


	    # Let us log errors that are saved earlier and log them
	    /fabos/rbin/pdcheck_errs.sh
	    # Upload any PD_MISC parameters in kernel that can be obtained
	    # _AFTER_ the fabos is loaded full and running
	    /fabos/rbin/pdul_misc_post.sh &

		if [ "$FOS_LINUX_BRINGUP" == "1" ] ; then
			echo 1 > /proc/sys/kernel/hung_task_panic
		fi
		if [ "$FOS_LINUX_BRINGUP" != "1" ] ; then
	    # set debug (maintained until GA) (Talk to Hor-May Chen)
	    doSetDbg

	    # set up flow control for the console 
	    /fabos/cliexec/shellFlowControl.sh setup > /dev/null

	    # IPSec is deprecated in Fab OS 9.0 and higher release.
	    # Disabling following code to stop loading of iked and spmd process.
		if false; then
			# spmd, iked - ipsec
			status=`grep stat /etc/racoon2/sadb.conf 2> /dev/null | cut -d ' ' -f 2`
			SPMD=/sbin/spmd
			if [ "$status" != "" ] ; then
				if [ "$status" == "on" ]; then
					IKED=/rbin/iked
					IPSCFG=/etc/racoon2/racoon2.conf
					if test -x $SPMD; then
						$SPMD -f $IPSCFG > /dev/null
						sleep 2
						if test -x $IKED; then
							$IKED -f $IPSCFG > /dev/null
						fi
					fi
				else
					$SPMD -k
				fi
			fi
		fi
#
# Determine if PCI timeout detect should be enabled or not
#
		case ${SWBD##SWBD} in
		'62' | '77')
			if $CHECK pcitimeout; then
			    echo "Probe for PCI timeout detect"
			    echo "on" > /proc/cp$CPID/pcitimeout/enable
			else
			    echo "Disable PCI timeout detect"
			    echo "off" > /proc/cp$CPID/pcitimeout/enable
			fi
			;;

		'165' | '166')
			if $CHECK pcitimeout; then
			    echo "Probe for PCI event detect"
			    echo 1 > /proc/cp$CPID/pcie/enable
			else
			    echo "Disable PCI event detect"
			    echo 0 > /proc/cp$CPID/pcie/enable
			fi
			;;
		'148' | '162' | '173' | '178' )
			if $CHECK pcitimeout; then
			    echo "Probe for PCI event detect"
			    echo 1 > /proc/system/pcie/enable
			else
			    echo "Disable PCI event detect"
			    echo 0 > /proc/system/pcie/enable
			fi
			;;
		'67')
                        /fabos/libexec/bpconsole
                        ;;
		*)
			;;
		esac

		if test "$SWBD" != "SWBD63"; then
            save_ethernet_ip &
		fi
fi  #FOS_LINUX_BRINDUP
				
	else
		echo "Fabos checked off ..."
		/bin/rm /dev/raslog 2>/dev/null
		/bin/rm /dev/trace 2>/dev/null

		case ${SWBD##SWBD} in
		'62' | '77')
			modutil load enetswch-module
	        modutil load smd-module
	        modutil load smdp-module

			mk_device smd smd 0
			mk_device smdplat smdplat 0
			;;
		'63')
	        modutil load smd-module
	        modutil load smdp-module

			mk_device smd smd 0
			mk_device smdplat smdplat 0
			;;
		*)
			;;
		esac

		CPID=`sin | cpid 2> ${NULL}`
		CHASS=`sin -c| chassbd 2> ${NULL}`

		zentron_ip
    fi

	# set fabos state back to 0 for success
	fabos_complete 0

    $ECHO "."
    ;;

'stop')
    $ECHO "Stopping Fabric OS services..."

	# stop swd and heartbeat
	/fabos/cliexec/hashutdown > ${NULL} 2>&1

	# flush raslog message storage and freeze the logging
	/fabos/cliexec/errlogtest -f stop -f

	# stop system services first
	SYSDAEMONS='hasmd'
	${KILLALL} -TERM $SYSDAEMONS > ${NULL} 2>&1
	${KILLALL} $SYSDAEMONS > ${NULL} 2>&1

	# stop all the switch based daemons
	stop_daemons

	# stop all chassis based daemons
	DAEMONS='hmond proxy diagd porttestd logind'
	${KILLALL} -TERM $DAEMONS > ${NULL} 2>&1
	${KILLALL} $DAEMONS > ${NULL} 2>&1

	# stop spmd iked (ipsec)
	DAEMONS='spmd iked'
	${KILLALL} -TERM $DAEMONS > ${NULL} 2>&1
	${KILLALL} $DAEMONS > ${NULL} 2>&1

	${KILLALL} srmd > ${NULL} 2>&1

	# Certain platforms need to insure portside ASICs stopped on reboot
	case ${SWBD##SWBD} in
		'46')
			# Sprint and Sabre CP side needs to reboot BP side
			(rsh 127.1.10.1 reboot -f &)
			sleep 2
			;;

		*)
		;;
	esac

	$ECHO "Done."
	;;

*)
	echo "Usage: $0 {start | stop}"
    ;;

esac
