#!/bin/sh

PCI_DEV_HAS=`grep -i '19e53532' /proc/bus/pci/devices`
PROD_TYPE_HD=`grep -i '(hdr' /proc/cmdline`
PROD_TYPE_SD=`grep -i '(sdr' /proc/cmdline`
EXT_GPIO_DRV_INS=`grep -i '(dvu' /proc/cmdline`   
TD3224HEB_DRV_INS=`grep -i '(dvz' /proc/cmdline`

if [ "$PCI_DEV_HAS" == "" ];then

  if [ "$EXT_GPIO_DRV_INS" = "" ]; then
  	echo "set default buzzer gpio control"
   	himm 0x200f004c 0x0    	
  fi 
	
	if [ "$PROD_TYPE_HD" = "" ];then
		if [ "$PROD_TYPE_SD" = "" ];then
			echo "current used product type 16d1 or 16960h or nvr"
			cd /mnt/mtd/modules && ./load3531 -i 16d1
		else
			echo "current used product type 8 720p"
			cd /mnt/mtd/modules && ./load3531 -i 8720p
		fi
	else
		echo "current used product type 4hd"
		cd /mnt/mtd/modules && ./load3531 -i 4hd
	fi
	
else

	if [ "$TD3224HEB_DRV_INS" == "" ]; then
		himm 0x200f004c 0x0
		
		if [ "$PROD_TYPE_HD" = "" ];then
			if [ "$PROD_TYPE_SD" = "" ];then
				echo "current used product type 960h"
				cd /mnt/mtd/modules && ./load3531_cascade -i 960h
			else
				himm  0x101c0010 0x881
				if [ "`himd.l 0x101c0014 | grep '0000:  00000243'`" != "" ];then
					himm 0x101c0014 0xdb4b;himm  0x101c0010 0xc03
					himm 0x101c0014 0xdb4b;himm  0x101c0010 0x1403
				fi
				echo "current used product type 8 720p"
				cd /mnt/mtd/modules && ./load3531_cascade -i 8720p
			fi
		else
			echo "current used product type hd"
			cd /mnt/mtd/modules && ./load3531_cascade -i hd
		fi
	else
	
		echo "current TD253224HEB product"
		cd /mnt/mtd/modules && ./load3531_cascade -i 960h
		
	fi
	
fi

modprobe nfs

rm /upgrade/ -rf
rm /mnt/mtd/preupgrade.sh
rm /mnt/mtd/productcheck

telnetd &

export mac=$(cat /etc/init.d/mac.dat)
ifconfig eth0 down
ifconfig eth0 hw ether $mac
ifconfig eth0 up

ifconfig lo up
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0

mount -t usbfs none /proc/bus/usb

ln -s /mnt/mtd/WebSites/logo /mnt/mtd/WebServer

if [ -f /mnt/mtd/debug.sh ]; then
	cd /mnt/mtd && ./DVRService &
	cd /mnt/mtd && ./debug.sh
	cd /mnt/mtd && ./td3531 &
else
	cd /mnt/mtd && ./XDVRStart.hisi ./td3531 &
fi

