#######################Added by Jim###########################

NVM_ROOT_FOLDER="/marvell/tel/NVM"
COMCFG_1="/marvell/tel/NVM/COMCfg_1.csv"
COMCFG_125="/marvell/tel/NVM/COMCfg_125.csv"
GSM_CAL_DATA_1="/marvell/tel/NVM/GsmCalData_1.nvm"
WB_CAL_DATA_1="/marvell/tel/NVM/WbCalData_1.nvm"
GSM_CAL_DATA_125="/marvell/tel/NVM/GsmCalData_125.nvm"
WB_CAL_DATA_125="/marvell/tel/NVM/WbCalData_125.nvm"

Boardversion=0
Boardversion=`cat /sys/devices/virtual/yh_nodes/misc/hardware_version` 

if [ $Boardversion -ge 9 ]; then
    if [ -e $COMCFG_125 ]; then
        busybox rm -f    $NVM_ROOT_FOLDER/COMCfg.csv
        busybox cp -p   $COMCFG_125    $NVM_ROOT_FOLDER/COMCfg.csv
        if [ -e $GSM_CAL_DATA_125 ] &&  [ ! -e  $NVM_ROOT_FOLDER/GsmCalData.nvm ]; then
            busybox cp -p    $GSM_CAL_DATA_125    $NVM_ROOT_FOLDER/GsmCalData.nvm
        fi
        if [ -e $WB_CAL_DATA_125 ] &&  [ ! -e  $NVM_ROOT_FOLDER/WbCalData.nvm ]; then
            busybox cp -p    $WB_CAL_DATA_125    $NVM_ROOT_FOLDER/WbCalData.nvm
        fi
    fi
else
    if [ -e $COMCFG_1 ]; then
        busybox rm -f    $NVM_ROOT_FOLDER/COMCfg.csv
        busybox cp -p    $COMCFG_1    $NVM_ROOT_FOLDER/COMCfg.csv
        if [ -e $GSM_CAL_DATA_1 ] &&  [ ! -e  $NVM_ROOT_FOLDER/GsmCalData.nvm ]; then
            busybox cp -p    $GSM_CAL_DATA_1    $NVM_ROOT_FOLDER/GsmCalData.nvm
        fi
        if [ -e $WB_CAL_DATA_1 ] && [ ! -e  $NVM_ROOT_FOLDER/WbCalData.nvm ]; then
            busybox cp -p    $WB_CAL_DATA_1    $NVM_ROOT_FOLDER/WbCalData.nvm
        fi
    fi
fi
#######################Added by Jim End###########################


## hw.sh - apply debug service first
insmod ./hwmap.ko
mknod /dev/hwmap c 237 0
chmod 660 /dev/hwmap

# Release COMM from reset
./hwacc w 0x40F5001C   1
echo 1 > /sys/power/cp

echo "Marvell" > "/sys/power/wake_lock"
export NVM_ROOT_DIR="/marvell/tel/NVM"

## YH busybox
#if [ ! -e $NVM_ROOT_DIR ]; then
	busybox mkdir -p $NVM_ROOT_DIR
#fi
ln -s /system/busybox busybox
chmod 777 busybox
## do it in init or init_bsp. YH
## busybox cp /marvell/etc/asound.conf /etc/asound.conf
chmod 766 /marvell/etc/diag_bsp.cfg
mkdir /data/etc
# Set error log location to /data volume, default is NVM
# Should be before mtsd starts as diag should be able to override the setting
if [ ! -e /data/log ]; then mkdir /data/log; fi # do not use mkdir -p as it fails due to ro fs (busybox mkdir -p is ok)
echo "/data/log" > /tmp/diag_log_path
busybox cp /marvell/etc/asound.conf /data/etc/asound.conf

echo 0 > /proc/sys/kernel/hung_task_timeout_secs
#busybox sh rtc_offset.sh
busybox sh diag_port_conf.sh
insmod osadev.ko
insmod seh.ko
#busybox insmod mslbddk.ko use_dma_tx=0,1,1,1,1,0,0 use_dma_rx=0,1,1,1,1,0,0
insmod acipcdev.ko
insmod cci_datastub.ko
#AlexK
#sleep 1
insmod citty.ko
insmod ccinetdev.ko
insmod cidatatty.ko


chmod 777 /sys/devices/platform/pxa-u2o/composite
busybox ln -s /dev/ttyDIAG0 /dev/ttygserial
busybox ln -s /dev/ttyGS0 /dev/ttymodem
insmod ppp.ko

./mtsd &
sleep 1

port=`cat /tmp/at_port.txt`
if [ $port == 'UART' ]; then
	#Set AT and Diag over UART
    ./mtilatcmd  -u 1&
    
else
	./mtilatcmd -m /dev/ttymodem&	
fi

./mtilatcmd &


# Uncomment one of the following lines to change the USB default configuration after reboot (for debug)
# 1. ADB ACM USB_MASS_STORAGE DIAG (default)
# echo adb,acm,usb_mass_storage,diag > /sys/devices/platform/pxa-u2o/composite
# 2. ACM DIAG
echo acm,diag > /sys/devices/platform/pxa-u2o/composite
# 3. ADB ACM USB_MASS_STORAGE
# echo adb,acm,usb_mass_storage > /sys/devices/platform/pxa-u2o/composite
# 4. ACM USB_MASS_STORAGE
# echo acm,usb_mass_storage > /sys/devices/platform/pxa-u2o/composite
# 5. USB_MASS_STORAGE
# echo usb_mass_storage > /sys/devices/platform/pxa-u2o/composite
# 6. RNDIS
# echo rndis > /sys/devices/platform/pxa-u2o/composite




mount -t vfat /dev/block/mmcblk1p1  /sdcard
# try /dev/block/mmcblk0 if mmcblk0p1 fails
mount -t vfat /dev/block/mmcblk0  /sdcard

#busybox sh rtc_offset.sh

# Enable GPS support
insmod gps_sirf.ko
chown system.system /dev/gps_sirf
chown system.system /dev/ttyS2

#insmod ./hwmap.ko
#busybox mknod /dev/hwmap c 237 0

# init WTPSP command
insmod /marvell/tel/wtpsp.ko
## use YH busybox
busybox mknod /dev/wtm c 150 0

#The Diag driver works with /mnt/mmc
#Therefore it is linked to /mnt/SD1
#ln -s /mnt/SD1 /mnt/mmc



# delay 1 second to get udevd notified about the devices creation
# in the modules above, before atcmdsrv and audioserver start
chmod 666 /dev/seh



./audioserver -D yes&
./eeh -D yes -M yes&
#chen: added validation if to prodoction mode to allow small file write interface
./validationif &

#The below commands will force product point 1
echo unset d0cs > /sys/power/deepidle
echo unset d1 > /sys/power/deepidle
echo unset d2 > /sys/power/deepidle
echo unset cg > /sys/power/deepidle

busybox sh "/marvell/tel/load_mfg_8787.sh"

echo 1 > /sys/class/graphics/fb0/blank

## YH, We do not need this log to /data/
## Uncomment some of the following lines to create logcat files on target (for debug)

## export LOGCAT_DIR=/data/log
## mkdir $LOGCAT_DIR
## chmod 777 $LOGCAT_DIR
## logcat -b main -f $LOGCAT_DIR/logcat.log -r 1024 -n 5 &
## logcat -b radio -f $LOGCAT_DIR/logcat-radio.log -r 1024 -n 5 &
## chmod 777 $LOGCAT_DIR/logcat*



