#!/bin/sh

HOST=$1

rm -f /tmp/u-boot.bin
curl "$HOST/u-boot-sunxi-with-spl.bin" -o /tmp/u-boot.bin || exit

fw_printenv > /dev/null 2>&1
if [ $? == 0 ]; then
	echo "Updating u-boot in MMC"
	dd if=/tmp/u-boot.bin of=/dev/mmcblk0p1 conv=notrunc
else
	echo "Updating u-boot in SPI flash"
	flash_erase /dev/mtd0 0 0
	dd if=/tmp/u-boot.bin of=/dev/mtd0 conv=notrunc
fi

#reboot
