#!/bin/sh
# Script file to make application image.
#
# Copyright (c) Realtek Semiconductor Inc. 2003
#
#  Usage: 
#    -b block_size, specify the block size to fit in all application image.
#	Each block is in 1024 bytes.
#    -s app_script, specify the script file to build file system for target.
#    -o output_file, specify the output filename
#
# $Id: mk6104k,v 1.1.1.1 2003/10/03 04:56:45 root Exp $
#
. ../../target.def

CURRDIR=`pwd`
MKTOP=$CURRDIR/image
TMPIMG=$CURRDIR/tmpimg.img
#RAMDISKSIZE=4500
MOUNTPOINT=$CURRDIR/mnt.gw
KERNEL_TOP=`cd ../..;pwd`

if [ -d $MOUNTPOINT ]; then
	echo ""
else
	mkdir $MOUNTPOINT
fi

if [ "$PLATFORM" == "-D_ADM5120_" ]; then
	TARGETIMAGE=$KERNEL_TOP/linux-kernel/arch/mips/ramdisk/ramdisk.gz
	RAMDISKSIZE=4256
	./app_adm_script
elif [ "$PLATFORM" == "-D_RDC3210_" ]; then
	TARGETIMAGE=$KERNEL_TOP/linux-kernel/appimg
	RAMDISKSIZE=4096
	./app_rdc_script
fi

#./buildfs -b 5020 -s app_gw_script -o ../../linux-2.4.18/appimg/appimg

rm -f $TMPIMG
dd if=/dev/zero of=$TMPIMG bs=1k count=$RAMDISKSIZE
/sbin/mke2fs -vFm0 $TMPIMG $RAMDISKSIZE
mount -o loop $TMPIMG $MOUNTPOINT
cp -a $MKTOP/* $MOUNTPOINT
cd $MOUNTPOINT
chown -R root.root *
cd $CURRDIR

if [ "$PLATFORM" == "-D_ADM5120_" ]; then
	umount $MOUNTPOINT || exit 1
	rm -rf $MOUNTPOINT
        gzip -9vfc $TMPIMG > $TARGETIMAGE
#	bzip2 -9vfc $TMPIMG > $TARGETIMAGE

else
	umount $MOUNTPOINT || exit 1
	rm -rf $MOUNTPOINT
	gzip -9vfc $TMPIMG > $TARGETIMAGE
fi
