##############################################################################

#
#	mkflashjffs2 -- construct an entire NETtel/SecureEdge x86 flash image.
#
#	(C) Copyright 2001, Greg Ungerer (gerg@snapgear.com)
#

##############################################################################

#
#	Define the files to use.
#
FLASH=images/flash.bin
KERNEL=images/bzImage
JFFSIMG=images/jffs2.img

##############################################################################

usage()
{
	echo "usage: mkflashjffs2"
	exit 1
}

##############################################################################

#
#	Check for any args...
#
if [ $# -gt 0 ]
then
	usage
fi

#
#	Kernel first.
#
cat $KERNEL > $FLASH
SIZE=`wc $FLASH | awk '{ print $3}'`
PAD=`expr 1048576 - $SIZE`
echo "KERNEL: flash size=$SIZE padding=$PAD"
dd if=/dev/zero count=1 bs=$PAD 2> /dev/null | tr \\000 \\377 >> $FLASH

#
#	JFFS2 filesystem.
#
cat $JFFSIMG >> $FLASH
SIZE=`wc $FLASH | awk '{ print $3}'`
echo "IMG: flash size=$SIZE"

cp $FLASH /tftpboot
exit 0
