#!/bin/sh
#
#  Script file to integrate all binary files into a gateway image. The 
#  generated image could be put into flash memory from the beginning.
#
# ----------------------------------------------------------------------
BOOT_IMG=../image/boot.16
KERNEL_IMG=../image/linux-gw.bin
WEB_PAGE_IMG=../image/webpages-gw.bin
FIRM_WEB_TOTAL_IMG=web_firm_total_image.bin
FIRM_TOTAL_IMG=firm_total_image.bin
FIRM_SWAP_TOTAL_IMG=firm_total_image_swap.bin
ROOT_IMG=../image/root.bin

# Compress web pages into binary
#./compweb web-files-ap $WEB_PAGE_IMG

# Merge webpage.bin and linux.bin to $FIRM_WEB_TOTAL_IMG
cp $WEB_PAGE_IMG $FIRM_WEB_TOTAL_IMG
cat $ROOT_IMG >> $FIRM_WEB_TOTAL_IMG
cat $KERNEL_IMG >> $FIRM_WEB_TOTAL_IMG

# Caculate the checksum of the $FIRM_WEB_TOTAL_IMG, and write the checksum into configgw.txt
./checksum $FIRM_WEB_TOTAL_IMG

# Converg configuration ll binary filesdata to binary
./cvcfg-gw -r ../config/config.txt config-gw.bin

# Convert configuration data to could be updated to system through web server (in save/restore setting page).
./cvcfg-gw ../config/config.txt config-gw.dat

# Merge all binary files
./mgbin -o $FIRM_TOTAL_IMG $BOOT_IMG  config-gw.bin \
	$WEB_PAGE_IMG $ROOT_IMG $KERNEL_IMG

# Merge all binary files and bye-swap
./mgbin -s -o $FIRM_SWAP_TOTAL_IMG $BOOT_IMG  config-gw.bin \
        $WEB_PAGE_IMG $ROOT_IMG $KERNEL_IMG


# Copy all release file to release folder that we need
if [ -d ../release ]; then
	rm -Rf ../release
	echo ' '
	echo 'Remove old release folder.'
fi

mkdir ../release
echo ' '
echo 'Create new release folder.'

echo ' '
echo 'Copy all release file to ==> "release folder".'
mv config-gw.bin ../release
mv config-gw.dat ../release
cp $WEB_PAGE_IMG ../release
mv $FIRM_TOTAL_IMG ../release
mv $FIRM_SWAP_TOTAL_IMG ../release
#mv rtl8186-ap-noboot.bin ../release
mv $FIRM_WEB_TOTAL_IMG ../release
cp $ROOT_IMG ../release
cp $KERNEL_IMG ../release
#cp ../image/boot.32 ../release
cp $BOOT_IMG ../release
echo ' '
