
/home/setwdg 1 8

killall server

killall peripheral

killall alarmmng

killall rcfg

killall live555MediaServer

killall netmgmt

killall rmm

killall dvr_timer

killall mysystem

killall wdg

killall exnet

killall dispatch

rmmod cpldio_wdg
rmmod cpldio_wdg.ko

filehome=./home
filerootfs=./rootfs


if [ -f ./flash_eraseall ]; then
    echo "flash_eraseall ok"
else
    echo "no file flash_eraseall error"
    echo "retcode=1"
    sleep 5
    reboot
fi

if [ -f ./crcCheck ]; then
    echo "crcCheck ok"   
else
    echo "no file crcCheck error"
    echo "retcode=1"
    sleep 5
    reboot
fi

TMPROOTFS=$(sed  '/rootfs/!d' /proc/mtd |awk -F':' '{print $1}')
TMPHOMEFS=$(sed  '/home1/!d' /proc/mtd |awk -F':' '{print $1}')
if [ -z "$TMPHOMEFS" ] ; then
    TMPHOMEFS=$(sed  '/home/!d' /proc/mtd |awk -F':' '{print $1}')
fi

TMPCONF=$(sed  '/conf/!d' /proc/mtd |awk -F':' '{print $1}')

echo $TMPCONF
echo $TMPHOMEFS
echo $TMPROOTFS

CRCHOME=1
CRCROOTFS=1

reboot --help
dd --help

if [ -f $filehome ]; then
    ./crcCheck $filehome hi3512-home > ./tempcrchome
    CRCHOME=$(sed  '/retcode/!d' ./tempcrchome |awk -F'=' '{print $2}')
    if [ "0" != $CRCHOME ] ; then
        echo $filehome "crc check error"
        echo "retcode=1"
        sleep 5
        reboot
    fi
fi

if [ -f $filerootfs ]; then
    ./crcCheck $filerootfs hi3512-rootfs > ./tempcrcrootfs
    CRCROOTFS=$(sed  '/retcode/!d' ./tempcrcrootfs |awk -F'=' '{print $2}')
    if [ "0" != $CRCROOTFS ] ; then
        echo $filerootfs "crc check error"
        echo "retcode=1"
        sleep 5
        reboot
    fi
fi

if [ "0" == $CRCHOME -o "0" == $CRCROOTFS ] ; then
    echo "crc check ok, update begin..."
    echo "retcode=0"
    sleep 5
    killall server
else
    echo $filehome "or" $filerootfs "crc check error "    
    echo "retcode=1"
    sleep 5
    reboot
fi

if [ "0" == $CRCHOME ] ; then
    ./flash_eraseall /dev/$TMPHOMEFS
    dd if=$filehome of=/dev/$TMPHOMEFS skip=1 count=163840 bs=64
fi

if [ "0" == $CRCROOTFS ] ; then  
    ./flash_eraseall /dev/$TMPCONF
    dd if=/etc/ui.conf of=/dev/$TMPCONF count=128 bs=1024

    ./flash_eraseall /dev/$TMPROOTFS
    dd if=$filerootfs of=/dev/$TMPROOTFS skip=1 count=163840 bs=64
fi

echo "update ok, auto reboot"

reboot
