#!/bin/sh

. /env/config

if [ x$1 = xnand ]; then
	part=/dev/nand0.barebox
elif [ x$1 = xnor ]; then
	part=/dev/nor0.barebox
else
	echo "usage: $0 nor|nand"
	exit 1
fi

loadb -f barebox.bin -c

unprotect $part
echo
echo "erasing partition $part"
erase $part

echo
echo "flashing barebox.bin to $part"
echo
cp barebox.bin $part
crc32 -f barebox.bin
crc32 -f $part
