# TILO - Trivial Image LOader
#
# by Jan Vondrak (C) 1998
#
# This is just a simple wrapper for maketilo...

if [ $# -lt 4 ]
then
	echo "Usage: tilo <arch> <kernel> <root image> <output TILO image>"
	exit 1
fi 

echo Converting ELF to a.out:

KERNEL=$2
elftoaout $KERNEL -o $KERNEL.out
cp -af $KERNEL.out ../../../kernels/$1
tail --bytes +33 $KERNEL.out >$KERNEL.raw
rm $KERNEL.out

echo GZipping...

gzip -c9 $2.raw >$2.gz
SUN4C_PSIZE=`ls -l $2.gz | awk '{print$5}'`
SUN4C_SIZE=`ls -l $2.raw | awk '{print$5}'`
SUN4C_ROOT=`nm $2 | awk '/A end$/{print$1}'`
rm $2.raw
echo kernel ... raw size = $SUN4C_SIZE, packed size = $SUN4C_PSIZE

ROOT_SIZE=`ls -l $3 | awk '{print$5}'`
echo Root image       ... packed size = $ROOT_SIZE

if [ $1 = "vmlinux32" ]; then
`echo $0 | sed 's/tilo$/maketilo/'` sun4c=$2.gz size4c=$SUN4C_SIZE root4c=$SUN4C_ROOT root=$3 out=$4.new
else
`echo $0 | sed 's/tilo$/maketilo/'` sun4u=$2.gz size4u=$SUN4C_SIZE root4u=$SUN4C_ROOT root=$3 out=$4.new
fi

rm $2.gz

dd if=$4.new of=$4 conv=sync
rm $4.new
TILO_SIZE=`ls -l $4 | awk '{print$5}'`
echo TILO size = $TILO_SIZE
