#!/bin/sh

export LD_LIBRARY_PATH=/tmp/lib:$LD_LIBRARY_PATH:

cd /tmp/

chmod 777 web/images/*
chmod 777 web/css/*
chmod 777 web/js/*
chmod 777 web/*
chmod 777 ko/extdrv/*
chmod 777 ko/*
chmod 777 lib/*
chmod 777 *
chmod 777 nginx/sbin/*

edid_config=$(cat /box/box.ini | grep 'edid_index:')
edid=${edid_config:11:1}
edid_size=`echo "$edid" | wc -c`
if [ "$edid_size" = "2" ]
then
	cp /tmp/edid/$edid.* /tmp/edid.bin
	echo edid is index $edid
fi

cd /tmp/ko
./load3521d -i

telnetd&
#killall telnetd

#GPIO12_0 HDMI
#GPIO12_1 RJ45
#GPIO12_2 POWER
#GPIO13_5 RESET

#GPIO13 DIR
#himm 0x12220400

#GPIO12 DIR
himm 0x12210400 0xF

#POWER LED ON
himm 0x12210010 0x0

#RJ45 LED OFF
himm 0x12210008 0x2

#HDMI LED OFF
himm 0x12210004 0x1

#UART1
himm 0x120f00f8 1
himm 0x120f00fc 1

#UART2
#himm 0x120f0100 1
#himm 0x120f0104 1

#UART1 -> GPIO6_5 GPIO6_7
#himm 0x120f00f8 0
#himm 0x120f00fc 0
#himm 0x121b0400 0xA0

#UART2 -> GPIO11_4 GPIO11_5
#himm 0x120f0100 0
#himm 0x120f0104 0
#himm 0x12200400 0x30

echo 20480000 > /proc/sys/net/core/wmem_default
echo 40960000 > /proc/sys/net/core/wmem_max

mtu_config=$(cat /box/box.ini | grep 'mtu_size:')
mtu=${mtu_config:9}
mtu_size=`echo "$mtu" | wc -c`
if [ "$mtu_size" = "4" ] || [ "$mtu_size" = "5" ]
then
        ifconfig eth0 mtu $mtu
        echo mtu size is $mtu
fi

ifconfig lo up
/tmp/nginx/sbin/nginx -p /tmp/nginx/

cd /tmp/
./reset &
./box.v400_hdmi
