# /etc/profile: system-wide .profile file for the Bourne shells
trap "" 2

export PATH=/home/bin:/home/scripts:/opt/bin:/bin:/sbin:/usr/bin:/usr/local/jamvm/bin:/opt/scripts
export LD_LIBRARY_PATH=/lib/public:/lib/private:/lib/gpl:/lib
KERNELVER=2.6.30
touch /var/modules.dep

# smsc9500 ifconfig ethX up problem...
export AtiProductType="`cat /proc/nvram/AtiBoardId`"

#if [ "$AtiProductType" = "IMG1400" ]; then
#echo "CR5962: Not increasing kernel min memory reserve **** Do not release until this is resolved"
#else
echo 3072 > /proc/sys/vm/min_free_kbytes
#fi
# TMOUT=0 means no busybox shell timeout.
# if you want the busybox shell to timeout after some number of seconds of inactivity,
# change the 0 to the number of seconds, e.g. 300.
export TMOUT=0

echo
firsttime=`echo /var/udhcpd/udhcpd.lease*`
if [ "$firsttime" = "/var/udhcpd/udhcpd.lease*" ]; then
 echo "Loading drivers and kernel modules... "
 echo
# no-op
# create directory in /var mounted for TMPFS
 mknod /var/fuse c 10 229
 chmod a+rw /var/fuse
 mkdir -p /var/log /var/run /var/state/dhcp /var/ppp /var/udhcpd /var/zebra /var/siproxd /var/cache /var/tmp /var/samba /var/samba/share /var/samba/homes /var/samba/private /var/samba/locks

#ATI_PRODUCT_CONFIG
 # Start logs for boot issues.
# syslogd -n -C -l 7 &
# klogd -n &
#^ATI_PRODUCT_CONFIG

 cp  /etc/smb.conf /var/samba/ 2>/dev/null

 echo > /var/udhcpd/udhcpd.leases
 ifconfig lo 127.0.0.1 netmask 255.0.0.0 broadcast 127.255.255.255 up
# /etc/modules_install /lib/modules/$KERNELVER/extra
 test -e /lib/modules/$KERNELVER/extra/bcm_log.ko && insmod /lib/modules/$KERNELVER/extra/bcm_log.ko
 test -e /lib/modules/$KERNELVER/extra/chipinfo.ko && insmod /lib/modules/$KERNELVER/extra/chipinfo.ko
 test -e /lib/modules/$KERNELVER/extra/bcm_ingqos.ko && insmod /lib/modules/$KERNELVER/extra/bcm_ingqos.ko
 test -e /lib/modules/$KERNELVER/extra/bcm_bpm.ko && insmod /lib/modules/$KERNELVER/extra/bcm_bpm.ko
 test -e /lib/modules/$KERNELVER/extra/pktflow.ko && insmod /lib/modules/$KERNELVER/extra/pktflow.ko fcacheMaxEntries=1024
 test -e /lib/modules/$KERNELVER/extra/pktcmf.ko && insmod /lib/modules/$KERNELVER/extra/pktcmf.ko
 test -e /lib/modules/$KERNELVER/extra/bcmfap.ko && insmod /lib/modules/$KERNELVER/extra/bcmfap.ko
 test -e /etc/cmf/cmfcfg && /etc/cmf/cmfcfg
 test -e /lib/modules/$KERNELVER/extra/profdrvdd.ko && insmod /lib/modules/$KERNELVER/extra/profdrvdd.ko
 test -e /lib/modules/$KERNELVER/extra/bcmxtmcfg.ko && insmod /lib/modules/$KERNELVER/extra/bcmxtmcfg.ko
 test -e /lib/modules/$KERNELVER/extra/ext_bonding.ko && insmod /lib/modules/$KERNELVER/extra/ext_bonding.ko
 test -e /lib/modules/$KERNELVER/extra/atmapi.ko && insmod /lib/modules/$KERNELVER/extra/atmapi.ko
 test -e /lib/modules/$KERNELVER/extra/adsldd.ko && insmod /lib/modules/$KERNELVER/extra/adsldd.ko
 test -e /lib/modules/$KERNELVER/extra/blaa_dd.ko && insmod /lib/modules/$KERNELVER/extra/blaa_dd.ko
 test -e /lib/modules/$KERNELVER/extra/bcmprocfs.ko && insmod /lib/modules/$KERNELVER/extra/bcmprocfs.ko
# test -e /lib/modules/$KERNELVER/kernel/net/ipv6/ipv6.ko && insmod /lib/modules/$KERNELVER/kernel/net/ipv6/ipv6.ko
 test -e /lib/modules/$KERNELVER/kernel/net/atm/br2684.ko && insmod /lib/modules/$KERNELVER/kernel/net/atm/br2684.ko
 test -e /lib/modules/$KERNELVER/extra/linux-kernel-bde.ko && insmod /lib/modules/$KERNELVER/extra/linux-kernel-bde.ko
 test -e /lib/modules/$KERNELVER/extra/linux-user-bde.ko && insmod /lib/modules/$KERNELVER/extra/linux-user-bde.ko

 if [ -f /proc/nvram/AtiFeatureMoca ]
 then
  # enet depends on moca depends on i2c
  test -e /lib/modules/$KERNELVER/extra/i2c_bcm6xxx.ko && insmod /lib/modules/$KERNELVER/extra/i2c_bcm6xxx.ko
  test -e /lib/modules/$KERNELVER/extra/bcm3450.ko && insmod /lib/modules/$KERNELVER/extra/bcm3450.ko
  test -e /lib/modules/$KERNELVER/extra/gpon_i2c.ko && insmod /lib/modules/$KERNELVER/extra/gpon_i2c.ko
 test -e /lib/modules/$KERNELVER/extra/laser_i2c.ko && insmod /lib/modules/$KERNELVER/extra/laser_i2c.ko
  test -e /lib/modules/$KERNELVER/extra/bcmmoca.ko && insmod /lib/modules/$KERNELVER/extra/bcmmoca.ko
 fi

 if [ -f /proc/nvram/AtiEthSwitchMap ]
 then
  test -e /lib/modules/$KERNELVER/extra/bcm_enet.ko && insmod /lib/modules/$KERNELVER/extra/bcm_enet.ko AtiEthSwitchMapParm="`cat /proc/nvram/AtiEthSwitchMap`"
 else
  test -e /lib/modules/$KERNELVER/extra/bcm_enet.ko && insmod /lib/modules/$KERNELVER/extra/bcm_enet.ko
 fi
 test -e /lib/modules/$KERNELVER/extra/bcmsw.ko && insmod /lib/modules/$KERNELVER/extra/bcmsw.ko && ifconfig bcmsw up
 test -e /lib/modules/$KERNELVER/extra/bcm_usb.ko && insmod /lib/modules/$KERNELVER/extra/bcm_usb.ko
 test -e /lib/modules/$KERNELVER/extra/bcmarl.ko && insmod /lib/modules/$KERNELVER/extra/bcmarl.ko

atipots=`cat /proc/nvram/AtiFeaturePots 2> /dev/null`
 if [ "$atipots" != "" ] && [ "$atipots" != "0" ]; then
  test -e /lib/modules/$KERNELVER/extra/dect.ko && insmod /lib/modules/$KERNELVER/extra/dect.ko 
  test -e /lib/modules/$KERNELVER/extra/dectshim.ko && insmod /lib/modules/$KERNELVER/extra/dectshim.ko 
  test -e /lib/modules/$KERNELVER/extra/dspdd.ko && insmod /lib/modules/$KERNELVER/extra/dspdd.ko
  test -e /lib/modules/$KERNELVER/extra/endpointdd.ko && insmod /lib/modules/$KERNELVER/extra/endpointdd.ko
 fi

 test -e /lib/modules/$KERNELVER/extra/p8021ag.ko && insmod /lib/modules/$KERNELVER/extra/p8021ag.ko

 if [ -f /proc/nvram/AtiFeatureRfModuleSpi ]
 then
  test -e /lib/modules/$KERNELVER/extra/om_tv_xcvr.ko && insmod /lib/modules/$KERNELVER/extra/om_tv_xcvr.ko AtiRfModuleSpiCsParam="`cat /proc/nvram/AtiRfModuleSpiCs`" AtiRfModuleMaxSpeedHzParam="`cat /proc/nvram/AtiRfModuleMaxSpeedHz`" AtiRfModuleSpiBusNumParam="`cat /proc/nvram/AtiRfModuleSpiBusNum`" AtiRfModuleSpiModeParam="`cat /proc/nvram/AtiRfModuleSpiMode`" AtiRfModulePresentParam="`cat /proc/nvram/AtiGpioRfModulePresent`"
 fi

# other modules
 test -e /lib/modules/$KERNELVER/extra/isdn.ko && insmod /lib/modules/$KERNELVER/extra/isdn.ko
 test -e /lib/modules/$KERNELVER/kernel/drivers/isdn/capi/capi.ko && insmod /lib/modules/$KERNELVER/kernel/drivers/isdn/capi/capi.ko 

 test -e /lib/modules/$KERNELVER/extra/bcmgpon.ko && insmod /lib/modules/$KERNELVER/extra/bcmgpon.ko

 test -e /lib/modules/$KERNELVER/extra/bcmvlan.ko && insmod /lib/modules/$KERNELVER/extra/bcmvlan.ko
 test -e /lib/modules/$KERNELVER/extra/pwrmngtd.ko && insmod /lib/modules/$KERNELVER/extra/pwrmngtd.ko
 test -e /lib/modules/$KERNELVER/kernel/drivers/char/hw_random/rng-core.ko && insmod /lib/modules/$KERNELVER/kernel/drivers/char/hw_random/rng-core.ko
 test -e /lib/modules/$KERNELVER/extra/bcmtrng.ko && insmod /lib/modules/$KERNELVER/extra/bcmtrng.ko

if [ -f /proc/nvram/AtiFeatureGpon ]
then
 if [ ! -f /proc/nvram/AtiFeatureBcmSfpMgmt ]
 then
 test -e /lib/modules/$KERNELVER/extra/i2c_bcm6xxx.ko && insmod /lib/modules/$KERNELVER/extra/i2c_bcm6xxx.ko
 test -e /lib/modules/$KERNELVER/extra/gpon_i2c.ko && insmod /lib/modules/$KERNELVER/extra/gpon_i2c.ko
 test -e /lib/modules/$KERNELVER/extra/laser_i2c.ko && insmod /lib/modules/$KERNELVER/extra/laser_i2c.ko
 test -e /lib/modules/$KERNELVER/extra/laser_dev.ko && insmod /lib/modules/$KERNELVER/extra/laser_dev.ko
 fi
 test -e /lib/modules/$KERNELVER/extra/bcm3450.ko && insmod /lib/modules/$KERNELVER/extra/bcm3450.ko
 test -e /lib/modules/$KERNELVER/extra/eponlue.ko && insmod /lib/modules/$KERNELVER/extra/eponlue.ko

# gponolt test tool
 test -e /bin/gponolt && /bin/gponolt --daemon
fi 
 
#if defined(ATI_PRODUCT_ID)
if [ -f /proc/nvram/AtiFeatureBcmSfpMgmt ]
then
 test -e /lib/modules/$KERNELVER/extra/i2c_bcm6xxx.ko && insmod /lib/modules/$KERNELVER/extra/i2c_bcm6xxx.ko
 test -e /lib/modules/$KERNELVER/extra/gpon_i2c.ko && insmod /lib/modules/$KERNELVER/extra/gpon_i2c.ko
 test -e /lib/modules/$KERNELVER/extra/laser_i2c.ko && insmod /lib/modules/$KERNELVER/extra/laser_i2c.ko
 test -e /lib/modules/$KERNELVER/extra/laser_dev.ko && insmod /lib/modules/$KERNELVER/extra/laser_dev.ko
fi

 test -e /lib/modules/$KERNELVER/kernel/net/netfilter/nfnetlink.ko && insmod /lib/modules/$KERNELVER/kernel/net/netfilter/nfnetlink.ko
 test -e /lib/modules/$KERNELVER/kernel/net/netfilter/nf_conntrack.ko && insmod /lib/modules/$KERNELVER/kernel/net/netfilter/nf_conntrack.ko
 test -e /lib/modules/$KERNELVER/kernel/net/ipv4/netfilter/nf_defrag_ipv4.ko && insmod /lib/modules/$KERNELVER/kernel/net/ipv4/netfilter/nf_defrag_ipv4.ko
 test -e /lib/modules/$KERNELVER/kernel/net/ipv4/netfilter/nf_conntrack_ipv4.ko && insmod /lib/modules/$KERNELVER/kernel/net/ipv4/netfilter/nf_conntrack_ipv4.ko

 if [ -f /proc/nvram/AtiFeatureWireless ]
 then
  #check for atheros PCI device - pysudo PnP
  export atheros=`lspci -m | grep "\"Class 0280\" \"168c\""`
  if [ "$atheros" != "" ]
  then
   #
   # Ok; there is some kind of Atheros network controller on the PCI bus
   #
   # See CR6463 for a description of lspci output & how it is interpreted
   #
   AR5B97=`lspci -m    | grep "\"Class 0280\" \"168c\" \"002e\" \"168c\" \"30a4\""`  # AR9287/AR5B97 802.11bgn 2.4 GHz 2x2 device
   AR5BHB112=`lspci -m | grep "\"Class 0280\" \"168c\" \"0030\" \"103c\" \"1627\""`  # AR9380/HB112 802.11abgn 2.4/5.0 GHz 3x3 device
   AR5BHB116=`lspci -m | grep "\"Class 0280\" \"168c\" \"0030\" \"168c\" \"3116\""`  # AR9382/HB116 802.11abgn 2.4/5.0 GHz 2x2 device

   if [[ "$AR5B97" != "" || "$AR5BHB112" != "" || "$AR5BHB116" != "" ]]
   then
    # This is a supported Atheros model, so lets go ahead & do the common
    # require stuff - load the kernel kernel modules & create the devices
    # for the first 2.4GHz radio
    #
    if [ -e /lib/modules/atheros/adf.ko ] 
    then
     #
     # We're using the Atheros driver
     #
     test -e /lib/modules/atheros/adf.ko && insmod /lib/modules/atheros/adf.ko
     test -e /lib/modules/atheros/asf.ko && insmod /lib/modules/atheros/asf.ko
     test -e /lib/modules/atheros/ath_hal.ko && insmod /lib/modules/atheros/ath_hal.ko
     test -e /lib/modules/atheros/ath_dfs.ko && insmod /lib/modules/atheros/ath_dfs.ko
     test -e /lib/modules/atheros/ath_rate_atheros.ko && insmod /lib/modules/atheros/ath_rate_atheros.ko
     test -e /lib/modules/atheros/ath_dev.ko && insmod /lib/modules/atheros/ath_dev.ko
     test -e /lib/modules/atheros/umac.ko && insmod /lib/modules/atheros/umac.ko
     test -e /lib/modules/atheros/ath_pktlog.ko && insmod /lib/modules/atheros/ath_pktlog.ko
     # create an interface for each SSID.
     # when we support multiple radios, this will have to change some...
     ifconfig wifi0 down;iwpriv wifi0 setHwaddr `cat /proc/nvram/AtiMacAddBase`
     # Create dummy interface to use up non-local mac address
     wlanconfig wlan0 create wlandev wifi0 wlanmode ap
     # Create an SSID interface for each possible SSID, 4 for now
     wlanconfig ethW1s1 create wlandev wifi0 wlanmode ap
     wlanconfig ethW1s2 create wlandev wifi0 wlanmode ap
     wlanconfig ethW1s3 create wlandev wifi0 wlanmode ap
     wlanconfig ethW1s4 create wlandev wifi0 wlanmode ap
     # Create vlan control interface 0
     ifconfig ethW1s1 up
     ifconfig ethW1s2 up
     ifconfig ethW1s3 up
     ifconfig ethW1s4 up
     vlanctl --if-create ethW1s1 0
     vlanctl --if-create ethW1s2 0
     vlanctl --if-create ethW1s3 0
     vlanctl --if-create ethW1s4 0
     vlanctl --if ethW1s1 --rx --tags 0 --filter-vlan-dev-mac-addr 0 --set-rxif ethW1s1.v0 --rule-insert-first
     vlanctl --if ethW1s2 --rx --tags 0 --filter-vlan-dev-mac-addr 0 --set-rxif ethW1s2.v0 --rule-insert-first
     vlanctl --if ethW1s3 --rx --tags 0 --filter-vlan-dev-mac-addr 0 --set-rxif ethW1s3.v0 --rule-insert-first
     vlanctl --if ethW1s4 --rx --tags 0 --filter-vlan-dev-mac-addr 0 --set-rxif ethW1s4.v0 --rule-insert-first
     ifconfig ethW1s1 down;ifconfig ethW1s2 down;ifconfig ethW1s3 down;ifconfig ethW1s4 down;ifconfig wifi0 down
     export wlanports="ethW1s1 802.11bgn"

#     mkdir /var/wireless
#     cp /etc/hostapd.top /var/wireless/.
#     cp /etc/80211g.ap_radio /var/wireless/.
#     cp /etc/company.ap_bss /var/wireless/.

     # Get a list of ports...
     # should be automated in some way
     # But `iwconfig 2> /dev/null | grep 802.11` will not work because
     # it show the current mode, not the capablities...
    elif [ -e /lib/modules/compat-wireless/compat.ko ]
    then
     #
     # We're using the open source driver
     #
     test -e  && insmod /lib/modules/compat-wireless/compat.ko
     test -e /lib/modules/compat-wireless/rfkill_backport.ko && insmod /lib/modules/compat-wireless/rfkill_backport.ko
     test -e /lib/modules/compat-wireless/cfg80211.ko && insmod /lib/modules/compat-wireless/cfg80211.ko
     test -e /lib/modules/compat-wireless/mac80211.ko && insmod /lib/modules/compat-wireless/mac80211.ko
     test -e /lib/modules/compat-wireless/ath.ko && insmod /lib/modules/compat-wireless/ath.ko
     test -e /lib/modules/compat-wireless/ath9k_hw.ko && insmod /lib/modules/compat-wireless/ath9k_hw.ko
     test -e /lib/modules/compat-wireless/ath9k_common.ko && insmod /lib/modules/compat-wireless/ath9k_common.ko
     test -e /lib/modules/compat-wireless/ath9k.ko && insmod /lib/modules/compat-wireless/ath9k.ko blink=1
     export wlanports=`iwconfig 2> /dev/null | grep 802.11`
#   else 
#    #WLAN Module
#    test -e /lib/modules/$KERNELVER/extra/wl.ko && insmod /lib/modules/$KERNELVER/extra/wl.ko
#    test -e /etc/wlan/rtecdc.trx && mount -t usbfs none /proc/bus/usb && /bin/bcmdl /etc/wlan/rtecdc.trx && sleep 2 && insmod /lib/modules/$KERNELVER/extra/wl-usb.ko
    fi
   fi

   if [[ "$AR5BHB112" != "" || "$AR5BHB116" != "" ]]
   then
    #
    # Ok; we've already configured the first 2.4GHz Atheros radio in the
    # clause above, so now we just need to do the incremental stuff for the
    # second 5GHz radio
    #
    if [ -e /lib/modules/atheros/adf.ko ] 
    then
     #
     # We're using the Atheros driver
     #
     # Create an SSID interface for each possible SSID, 4 for now
     wlanconfig ethW2s1 create wlandev wifi0 wlanmode ap
     wlanconfig ethW2s2 create wlandev wifi0 wlanmode ap
     wlanconfig ethW2s3 create wlandev wifi0 wlanmode ap
     wlanconfig ethW2s4 create wlandev wifi0 wlanmode ap
     # Create vlan control interface 0
     ifconfig ethW2s1 up
     ifconfig ethW2s2 up
     ifconfig ethW2s3 up
     ifconfig ethW2s4 up
     vlanctl --if-create ethW2s1 0
     vlanctl --if-create ethW2s2 0
     vlanctl --if-create ethW2s3 0
     vlanctl --if-create ethW2s4 0
     vlanctl --if ethW2s1 --rx --tags 0 --filter-vlan-dev-mac-addr 0 --set-rxif ethW2s1.v0 --rule-insert-first
     vlanctl --if ethW2s2 --rx --tags 0 --filter-vlan-dev-mac-addr 0 --set-rxif ethW2s2.v0 --rule-insert-first
     vlanctl --if ethW2s3 --rx --tags 0 --filter-vlan-dev-mac-addr 0 --set-rxif ethW2s3.v0 --rule-insert-first
     vlanctl --if ethW2s4 --rx --tags 0 --filter-vlan-dev-mac-addr 0 --set-rxif ethW2s4.v0 --rule-insert-first
     ifconfig ethW2s1 down;ifconfig ethW2s2 down;ifconfig ethW2s3 down;ifconfig ethW2s4 down;ifconfig wifi0 down

     #
     # Finally; append 2nd radio details to wlanports...
     #
     #export wlanports="$wlanports ethW2s1 802.11abgn"
    elif [ -e /lib/modules/compat-wireless/compat.ko ]
    then
     #
     # We're using the open source driver
     #
     echo Some Kevin magic required here to deal with ethW2 when using open source driver
     # Some Kevin magic required here to deal with ethW2 when using open source driver
     # Some Kevin magic required here to deal with ethW2 when using open source driver
     # Some Kevin magic required here to deal with ethW2 when using open source driver
     # Some Kevin magic required here to deal with ethW2 when using open source driver
     #
    fi
   fi
  fi
 fi
#endif defined(ATI_PRODUCT_ID)

 # if engineering debug tools are being built, as indicated by presence of
 # dumpsysinfo.sh, then save a copy of bootup messages for dumping later
 test -e /opt/scripts/dumpsysinfo.sh && /bin/dmesg > /var/tmp/bootupmessages

 #if defined(ATI_PRODUCT_ID)
 # Take Ethernet PHYs out of reset
 if [ -f /proc/nvram/AtiPhyResetEth0 ]
 then
   echo "16 01" > /proc/led
 fi
 if [ -f /proc/nvram/AtiPhyResetEth1 ]
 then
   echo "17 01" > /proc/led
 fi
 if [ -f /proc/nvram/AtiPhyResetEth2 ]
 then
   echo "18 01" > /proc/led
 fi
 if [ -f /proc/nvram/AtiPhyResetEth3 ]
 then
   echo "19 01" > /proc/led
 fi
 if [ -f /proc/nvram/AtiPhyResetEth4 ]
 then
   echo "1a 01" > /proc/led
 fi
 if [ -f /proc/nvram/AtiPhyResetEth5 ]
 then
   echo "1b 01" > /proc/led
 fi
 if [ -f /proc/nvram/AtiPhyResetEth6 ]
 then
   echo "1c 01" > /proc/led
 fi
 if [ -f /proc/nvram/AtiPhyResetEth7 ]
 then
   echo "1d 01" > /proc/led
 fi


# SFP IOs
 if [ -f /proc/gpio/AtiGpioSfpLOSDir ]
 then
   echo "in" > /proc/gpio/AtiGpioSfpLOSDir
 fi
 if [ -f /proc/gpio/AtiGpioSfpPresentDir ]
 then
   echo "in" > /proc/gpio/AtiGpioSfpPresentDir
 fi
 if [ -f /proc/gpio/AtiGpioSfpRateSelDir ]
 then
   echo "out" > /proc/gpio/AtiGpioSfpRateSelDir
   sleep 1
   echo "1" > /proc/gpio/AtiGpioSfpRateSel
 fi
 if [ -f /proc/gpio/AtiGpioSfpTxDisableDir ]
 then
   echo "out" > /proc/gpio/AtiGpioSfpTxDisableDir
   echo "0" > /proc/gpio/AtiGpioSfpTxDisable
 fi
 if [ -f /proc/gpio/AtiGpioSfpTxFaultDir ]
 then
   echo "in" > /proc/gpio/AtiGpioSfpTxFaultDir
 fi

 #
 # Enable CPU Rate limiting for the switch
 #
ATIBOARDID=`cat /proc/nvram/AtiBoardId 2> /dev/null`
 if [[ "$ATIBOARDID" == "IMG1400" || "$ATIBOARDID" == "EDM1400" ]]
 then
   echo ""
 else 
   ethswctl -c pktrate -v 0 -x 20000
   ethswctl -c pktratecfg -v 0 -x 1
 fi

 # mdk can not run under cms, too many start up interdepenencies...
 # redirect stderr to a NULL device
 swmdk 2> /dev/null &
 #give MDK a chance to start before anyone talks to it
 sleep 1

# This chunk is moved to gponwan
#if [ -f /proc/nvram/AtiFeatureGPONAEModeEnable ]
#then
#  # GPON devices are slow FPS!
#  ethswctl -c pktrate -v 0 -x 15000
#  if [ -f /proc/nvram/AtiFeatureGPONAEModeSGMIIEnable ]
#  then
#    gponctl aeMode --sgmii
#  else
#    (gponctl aeMode;sleep 1;gponctl aeStop;sleep 1;gponctl aeStart) &
#  fi
#fi

 if [ -f /proc/nvram/AtiFeatureHPNA ] 
 then
     if [ -f /proc/nvram/AtiHpnaPhyId ] && [ -f /proc/nvram/AtiMacAddBase ]
     then
         # Bring the USB-MII bridge out of reset
         echo "14 01">/proc/led
         # Give time for USB device (USB-MII brdige) to register with the USB interface
         sleep 1

         #        
         # Determine the HPNA base and management interfaces.
         # This relies on the output containing a line of the following form:
         # "IfName: eth5"
         #
         hpnaIfNameStr=`cmd9500 -c GET_CONFIG | grep "IfName:"`
         hpnaBaseIfName=${hpnaIfNameStr:8}
         hpnaMgmtIfName=${hpnaBaseIfName}.v0
     
         #
         # Environment variables in case anyone needs those
         #
         export ATI_HPNA_BASE_IFNAME=${hpnaBaseIfName}
         export ATI_HPNA_MGMT_IFNAME=${hpnaMgmtIfName}
         export ATI_HPNA_PHY_ID=`cat /proc/nvram/AtiHpnaPhyId`

         #
         # Configure the USB-MII bridge
         #
         # Force link
         cmd9500 -c SET_LINK -d 0x88
         # Set full duplex
         cmd9500 -c WRITE_MAC -a 0x100 -d 0x0094000c
         # Enable flow control
         cmd9500 -c WRITE_MAC -a 0x11C -d 0x02
         
         #
         # Increase Tx Queue Length (QLEN) from 1000 (default) to 3000 for the USB interface
         #
         ip link set dev ${ATI_HPNA_BASE_IFNAME} qlen 3000
         
         #
         # Create ethX.v0 interface for HPNA management.
         #
         ifconfig ${ATI_HPNA_BASE_IFNAME} up
         vlanctl --if-create ${ATI_HPNA_BASE_IFNAME} 0
         #
         # Create a VLAN filter rule that puts all of the HPNA management frames (Eth. type 0x886C)
         # to the ethX.v0 interface. The rule is forced to the top of the rule table (by
         # using --rule-insert-first) in order to take priority over VLAN tagging rules on the same
         # ethX interface.
         #
         vlanctl --if ${ATI_HPNA_BASE_IFNAME} --rx --tags 0 --filter-ethertype 0x886c --set-rxif ${ATI_HPNA_MGMT_IFNAME} --rule-insert-first
     else
         echo "Could not initialize HPNA management interface. Environment variables not configured right."
     fi
 fi

 if [ -f /proc/nvram/AtiKernelBootStateAddr ]
 then
   /opt/scripts/sw 0x`cat /proc/nvram/AtiKernelBootStateAddr` 0
 fi
 if [ -f /proc/nvram/AtiResetReason ]
 then
   echo ________________Boot Log______________________________________ > /proc/atilog
   echo `date` "Last Reboot Reason: " `cat /proc/nvram/AtiResetReason` > /proc/atilog
   echo ______________________________________________________________ > /proc/atilog
 fi
 #endif defined(ATI_PRODUCT_ID)

 # As final step in system bootup, start smd, which will start configuration
 # management system (CMS)

smd
#if defined(ATI_PRODUCT_ID)
sleep 5
reboot
#endif defined(ATI_PRODUCT_ID)
fi

