N=1000000

if printf 'r\n6\nq\n' | /opt/fpga_io_interactive 2>&1 | grep '0x21f7'; then echo 'FPGA schon geladen'; else 
	echo 'FPGA NICHT geladen.'
	/opt/fpga_load /opt/ImgFromJavaTool.bit
fi

modprobe KM_CvKernelAccess
#echo 'load km commented out!'

i=0
while [ "$i" -lt "$N" ]; do
        echo "i=$i"                                            
        if ! nanddump -a /dev/mtd13 | /Test_CheckNandDumpOutput
        then                                     
                printf "\n\nFailed when i=$i\n\n"
                sleep 2         
                dmesg | tail -50
                break
        fi

	i=$(( $i + 1 ))
done


echo 'end erreicht'
modprobe -r KM_CvKernelAccess
