#!/bin/sh

# Network boot fimage from flash overwriting the rescue partition.

if ! which awk > /dev/null; then
	echo "Cannot find awk in your PATH!"
	exit 1
fi

if ! which bc > /dev/null; then
	echo "Cannot find bc in your PATH!"
	exit 1
fi

if ! which sed > /dev/null; then
	echo "Cannot find sed in your PATH!"
	exit 1
fi


PSIZE_RESCUE=`awk '!/\#/ { if ( $4 == "rescue" ) print $2 }' ptablespec \
		| tr a-f A-F`
PSIZE_KERNEL=`awk '!/\#/ { if ( $4 == "kernel" ) print $2 }' ptablespec \
		| tr a-f A-F`
PSIZE_JFFS=`awk '!/\#/ { if ( $4 == "jffs2" ) print $2 }' ptablespec \
		| tr a-f A-F`

SIZE=0x`echo "obase=16;ibase=16;$PSIZE_RESCUE + $PSIZE_KERNEL + $PSIZE_JFFS" \
	| sed -e 's/0x//g' | bc`

boot_linux -F -s $SIZE -i fimage $*
