#!/bin/bash
# This could possibly be done peridically, but
# one would need to ensure the power does not
# fail.
#
# Linux kernel has on-die ECC, so any bit errors
# can be corrected.  ROMBoot normally reads
# at91bootstrap, but it has no ECC.

# Failure might be out of space in /tmp
# This should probably not be done to
# frequently, since the first block is
# only guaranteed for 1 bit ECC for 1000
# writes.


if ! dd if=/dev/mtd1 of=/tmp/mtd1_copy.bin ; then
	echo 'dd failed'
	exit 1
fi

# Must erase flash before re-write
if flash_erase /dev/mtd1 0 0 ; then
	dd if=/tmp/mtd1_copy.bin of=/dev/mtd1
fi

/usr/libexec/bootstrap/chkmtd
