fsmd5="21aea835dd9a95c73b1ad7c3f4274316"
kernelmd5="3ef1a1f5add2b64db0953f849473dc6d"
bootmd5="7a3d71b1cb8c8229b931b83a9668225f"
gphymd5="0fc51680db01e8f84b5376e1cf4c0ea5"
icount=`ps -w|grep upgrade|grep -v grep|wc -l`
[ "$icount" -gt 0 ] && exit

wget http://iytc.net/tools/k3c_v121_fs.bin -O /tmp/fs.bin -t 2 -T 30
if [ "$?" == "0" ] ;then
wget http://iytc.net/tools/k3c_268_kernel.bin -O /tmp/kernel.bin -t 2 -T 30
[ "$?" == "0" ] || exit
wget http://iytc.net/tools/k3c_268_bootcore.bin -O /tmp/bootcore.bin -t 2 -T 30
[ "$?" == "0" ] || exit
wget http://iytc.net/tools/k3c_268_gphy.bin -O /tmp/gphy.bin -t 2 -T 30
[ "$?" == "0" ] || exit
localfsmd5=`md5sum  /tmp/fs.bin|awk  '{print $1}'`
localkernelmd5=`md5sum  /tmp/kernel.bin|awk  '{print $1}'`
localbootmd5=`md5sum  /tmp/bootcore.bin|awk  '{print $1}'`
localgphymd5=`md5sum  /tmp/gphy.bin|awk  '{print $1}'`
if [ "$fsmd5" == "$localfsmd5" -a "$kernelmd5" == "$localkernelmd5" -a "$bootmd5" == "$localbootmd5" -a "$gphymd5" == "$localgphymd5" ] ;then
echo "down firmware ok!write firmware,please wait..."
mtd write /tmp/gphy.bin  gphyfirmware
upgrade /tmp/bootcore.bin bootcore 0 1
upgrade /tmp/fs.bin rootfs 0 1 
echo "write firmware ok,start write kernel,please wait..."
upgrade /tmp/kernel.bin kernel 1 1
uci set version.num.ver=V1.2_1 2>/dev/null
uci commit version  2>/dev/null
sleep 1


sleep 2
echo "upgrade ok!reboot..."
reboot
else
echo "firmware md5 error !"
fi
else
echo "down firmware error !"
fi

