#!/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/*

cd /tmp/ko
./load3516a -i -sensor bt1120 -osmem 256 -offline

#GPIO9_4 RESET CONFIG
himm 0x200F0080 0

#GPIO10_5
himm 0x200F00A4 0
#DIR
himm 0x201E0400 0x20
#HDMI ENABLE
#himm 0x201E0080 0x0
#SDI 20BIT
himm 0x201E0080 0x20

#GPIO0_2 GPIO0_3 GPIO0_4
himm 0x200F00DC 0
himm 0x200F00E0 0
himm 0x200F00E4 0
#DIR
himm 0x20140400 0x1E
#HIGH
himm 0x20140040 0x10

cd /tmp/
./reset &
#./remserial -p 5150 -s "9600 raw" /dev/ttyAMA1 &

#UART1
himm 0x200F007C 1
himm 0x200F0084 1

#GPIO9_2/UART1_RTSN
#GPIO9_3/UART1_RXD
#GPIO9_5/UART1_TXD

himm 0x200F0078 0
himm 0x200F007C 0
himm 0x200F0084 0

#GPIO9 DIR
himm 0x201D0400 0xAF

sleep 1

#HDMI ENABLE
himm 0x201E0080 0x0

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/

./box
