#!/bin/sh /etc/rc.common
START=99

SPATH="init.d/zzck_fs2_crc"

start() {
	fs2_st=`/sbin/mtd fw_printenv 1 |/bin/grep fs2_status |/bin/sed -e "s/^.*=//"`
	#echo "[$SPATH] fs2_status: $fs2_st " > /dev/console

	if [ "$fs2_st" == "good" ]; then
		fs2_crc=`/sbin/mtd fw_printenv 1 |/bin/grep fs2_crc |/bin/sed -e "s/^.*=//"`
		cal_crc=`/sbin/mtd crc32 /dev/mtd4`
		#echo "[$SPATH] check fs2_crc=$fs2_crc equal to cal_crc=$cal_crc " > /dev/console
		[ "$fs2_crc" == "$cal_crc" ] || {
			/sbin/mtd fw_setenv fs2_status error
			echo "[$SPATH] FS2 checksum error, recover FS2 at next reboot! " > /dev/console
		}
	elif [ "$fs2_st" == "new_ok" ]; then
		cal_crc=`/sbin/mtd crc32 /dev/mtd4`
		/sbin/mtd fw_setenv fs2_crc $cal_crc
		/sbin/mtd fw_setenv fs2_status good
		#echo "[$SPATH] set fs2_crc=$cal_crc and fs2_status=good" > /dev/console
	else
		#do nothing
		echo "[$SPATH] fs2_status=$fs2_st, recover FS2 at next reboot! " > /dev/console
	fi
}
