#!/bin/sh
#####################################################################
#
# chgki
#
# Shell script to change uImage on flash memory
#
# 2013/04/26
#
# Usage: chgki uImage
#
##################################################################### 

# Check argument
if [ $# -lt 1 ]; then
	echo "Usage: chgki {uImage-file}"
	exit 1
fi

/usr/sbin/chkui $1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
        echo "$1 may be damaged, cancel update."
        exit 1
fi

# Detemine image file
echo "$1" | grep / >& /dev/null
if [ $? -eq 0 ]; then
	IMGFILE="$1"
else
	IMGFILE="`pwd`/$1"
fi

# Update a image on flash
echo "Changing a uImage on flash memory"
/usr/sbin/fuc -sd ki $IMGFILE

