#!/bin/ash
#
# install_fw:
# This script performs the fw installation for the RLM.
# Usage: install_fw <dest_partition> <install_type> <force option>
#        <dest_partition> = partition in which fw is going to be installed
#                           can be "primary" or "backup"
#        <install_type>   = eth (for ethernet based update) or sp (via ONTAP) 
#        <force option>   = -f to force flash burn, none otherwise
# 
# Huynh Mai
#
# Return Values:
#     101 = Invalid arguments
#     102 = Error Flashing u-boot
#     103 = Error Flashing linux
#     104 = Error Flashing JFFS2
#     105 = Metadata info not present in new package
#     106 = Metadata Info not present in primary
#     107 = Metadata Info not present in backup
#     108 = Missing u-boot.bin in new package
#     109 = Missing uImage in new package
#     110 = Error Flashing JFFS2 image
#     111 = Missing Root.bin in new package
#     113 = u-boot Checksum Failure
#     114 = Linux Checksum Failure
#     115 = ROOTFS File Checksum Failure
#     116 = Missing Config.bin in new package
#     117 = Error Flashing JFFS2 logs image
#     118 = File couldn't be copied. Possible mount problems
#     119 = Corrupt primary detected. 
#     120 = sp update -f necessary for upgrade
#     121 = Unable to change permissions for primary post-install script
#     122 = REMOVED (AVAILABLE FOR USE)
#     123 = Error executing primary post-install script
#     124 = REMOVED (AVAILABLE FOR USE)
#     125 = FW doesn't support boot block architecture
#

FW_SETENV=/usr/local/bin/fw_setenv
FW_PRINTENV=/usr/local/bin/fw_printenv

ETH_FW_PACKAGE_DIR=/tmp/fud_eth/RLM_FW
SP_FW_PACKAGE_DIR=/tmp/ORFTP/fud_sp

PRIMARY_INSTALL=/etc/rlm_install/primary
BACKUP_INSTALL=/etc/rlm_install/backup

LINUX_VERSION_STRING=linux_version=
LINUX_CHECKSUM_STRING=linux_checksum=
LINUX_SIZE=linux_size=
ROOTFS_SIZE=rootfs_size=
LOGS_SIZE=logs_size=

PRIMARY_ROOTFS=/mnt/jffs2_rootfs_primary;
BACKUP_ROOTFS=/mnt/jffs2_rootfs_backup;
JFFS2_LOGS_MOUNT=/mnt/logs;

NAND_ERASE="/usr/bin/flash_eraseall -q"
NAND_WRITE="/usr/bin/nandwrite -p"
SPI_ERASE="/usr/bin/flash_erase"
SPI_WRITE="/usr/bin/flashcp"

LOG="/var/log/messages"

# Remount_Rootfs():
# Remounts the primary and backup root-filesystems after install.
# 
# No arguments
#
Remount_Rootfs() {
    echo "Remounting primary rootfs";
    mount -o remount,ro -t jffs2 $PRIMARY_ROOTFS_PARTITION $PRIMARY_ROOTFS
    
    echo "Remounting backup rootfs";
    mount -o remount,ro -t jffs2 $BACKUP_ROOTFS_PARTITION $BACKUP_ROOTFS

    echo "Remounting JFFS2 logs";
    mount -o remount,rw -t jffs2 $JFFS2_LOGS_BLOCK_PARTITION $JFFS2_LOGS_MOUNT
}

# Umount_all():
# Unmounts the primary, backup 
# 
# No arguments
#
Umount_primary()
{
    echo "Unmounting primary rootfs";
    umount -f $PRIMARY_ROOTFS
}

Umount_backup()
{
    echo "Unmounting backup rootfs";
    umount -f $BACKUP_ROOTFS
}

# Mount_all():
# Mounts the primary, backup and logs root-filesystems.
# 
# No arguments
#
Mount_primary()
{
    echo "Mounting primary rootfs";
    mount -o ro -t jffs2 $PRIMARY_ROOTFS_BLOCK_PARTITION $PRIMARY_ROOTFS
} 

Mount_backup()
{
    echo "Mounting backup rootfs";
    mount -o ro -t jffs2 $BACKUP_ROOTFS_BLOCK_PARTITION $BACKUP_ROOTFS
}
    
#
# $1: Device to read from
# $2: File to dump to
# $3: Length
#

read_nbyte_from_nand_device () {
    nandread $1 $3 > $2
}

#
# spi_md5sum ():
# This function computes the MD5SUM with specified length of a SPI partition
# $1 = file to compute the checksum
# $2 = limit
#
spi_md5sum () {
    TMP_CHKSUM=`dd if=$1 bs=8192 | trunc $2 | md5sum | sed -e "s/\(.*\) \(.*\)/\1/"`;
    echo $TMP_CHKSUM $1
}

#
# nand_md5sum ():
# This function computes the MD5SUM with specified length of a nand partition
# $1 = Source 
# $2 = limit 
#

nand_md5sum () {
    TMP_CHKSUM=`nandread $1 $2 | md5sum | sed -e "s/\(.*\) \(.*\)/\1/"`;
    echo $TMP_CHKSUM $1
}

#
# program_spi_partition()
# this function program the SPI flash
#   $1: MTD Device 
#   $2: File to be programmed

program_spi_partition() {
    echo "--Erasing $1"
    $SPI_ERASE $1 0 8 >> $LOG 2>>$LOG

    echo "--Writing $2 to $1"
    $SPI_WRITE $2 $1 >>$LOG 2>>$LOG
}

#   program_nand_partition
#   This function write a NAND partition
#   $1: MTD Device 
#   $2: File to be programmed

program_nand_partition() {

    echo "--Erasing $1"
    $NAND_ERASE $1 >> $LOG 2>>$LOG

    echo "--Writing $2 to $1"
    $NAND_WRITE $1 $2 >> $LOG 2>>$LOG
}

#
#
# Force_Burn():
# $1 = u-boot source location
# $2 = u-boot dest location
# $3 = linux source location
# $4 = linux dest location
# $5 = Root FS image source location
# $6 = Root FS image dest location
#

Force_Burn() {
    program_spi_partition $2 $1
    if ! [ $? = 0 ] ; then
        echo "ERROR Flashing u-boot";
        exit 102;
    fi
    
    program_nand_partition $4 $3
    if ! [ $? = 0 ] ; then
        echo "ERROR Flashing Linux";
        exit 103;
    fi

    program_nand_partition $6 $5
    if ! [ $? = 0 ] ; then
        echo "ERROR Flashing JFFS2 image";
        exit 110;
    fi
    sync;
}    

# Burn_fw():
# $1 = Source package
# $2 = Destination 
# $3 = u-boot source location
# $4 = u-boot dest location
# $5 = linux source location
# $6 = linux dest location
# $7 = Root FS source location
# $8 = Root FS dest location
#

Burn_fw() {

date;
    Burn_uboot $1 $2 $3 $4;
date;
    Burn_linux $1 $2 $5 $6;
date;
    Burn_jffs2_rootfs $1 $2 $7 $8;
date;
    sync;

}

#
# Burn_uboot():
# Routine that burns uboot into the dest partition if necessary
# 
# Args:
#     $1 = Source package
#     $2 = Destination
#     $3 = u-boot source
#     $4 = u-boot dest
#
Burn_uboot() {

echo "Installing Boot Loader..."

    UBOOT_NEW=`grep $UBOOT_VERSION_STRING $1/Metadata | sed -e "s/\$UBOOT_VERSION_STRING//g"`;
    UBOOT_CURR=`grep $UBOOT_VERSION_STRING $2/Metadata | sed -e "s/\$UBOOT_VERSION_STRING//g"`;
    
echo $UBOOT_NEW;
echo $UBOOT_CURR;
    
    if [ "$UBOOT_NEW" = "$UBOOT_CURR" ] ; then
        echo "u-boot version unchanged.";
    else
        echo "Flashing u-boot version..." $UBOOT_NEW;

        if ! [ -f $3 ] ; then
            echo "ERROR: Missing $3 in $NEW_PACKAGE/uboot";
            exit 108;
        fi

        program_spi_partition $4 $3

        if [ $? = 0 ] ; then

            echo "Flashing u-boot complete, verifying checksum..."
            # Verifying u-boot checksum
            UBOOT_CHECKSUM_CURR=`grep $UBOOT_CHECKSUM_STRING $1/Metadata | sed -e "s/\$UBOOT_CHECKSUM_STRING//g"`;
            UBOOT_XSUM_SIZE=`grep $UBOOT_SIZE $1/Metadata | sed -e "s/\$UBOOT_SIZE//g"`;
            UBOOT_CHECKSUM_NEW=`spi_md5sum $4 $UBOOT_XSUM_SIZE`;
            echo "New Checksum"
            echo $UBOOT_CHECKSUM_NEW;

            if ! [ "$UBOOT_CHECKSUM_CURR $4" = "$UBOOT_CHECKSUM_NEW" ] ; then
                echo "u-boot Checksum Failure";
            exit 113;
            else
                echo "u-boot Checksum Verified";
            fi
        else
            echo "ERROR Flashing u-boot";
            exit 102;
        fi
    fi
}

#
# Burn_linux():
# Burns linux into the dest partition if necessary
#
# Args:
#     $1 = Source package
#     $2 = Destination
#     $3 = linux source
#     $4 = linux dest
#
Burn_linux() {

echo "Installing OS..."

# echo "Burn_linux $1 $2 $3 $4";

# Check if linux has changed, dd it if necessary, verify checksums
    LINUX_NEW=`grep $LINUX_VERSION_STRING $1/Metadata | sed -e "s/$LINUX_VERSION_STRING//g"`;
    LINUX_CURR=`grep $LINUX_VERSION_STRING $2/Metadata | sed -e "s/\$LINUX_VERSION_STRING//g"`;

#    echo $LINUX_NEW;
#    echo $LINUX_CURR;

    if [ "$LINUX_NEW" = "$LINUX_CURR" ] ; then
    echo "linux version unchanged.";
    else
    echo "Flashing linux version" $LINUX_NEW;

    if ! [ -f $3 ] ; then
        echo "ERROR: Missing uImage in $NEW_PACKAGE/linux";
        exit 109;
    fi


    program_nand_partition $4 $3

    if [ $? = 0 ] ; then
        echo "Flashing linux complete, verifying checksum..."
# Verifying linux checksum
        LINUX_CHECKSUM_CURR=`grep $LINUX_CHECKSUM_STRING $1/Metadata | sed -e "s/\$LINUX_CHECKSUM_STRING//g"`;
        echo $LINUX_CHECKSUM_CURR $4;
        LINUX_CHECKSUM_SIZE=`grep $LINUX_SIZE $1/Metadata | sed -e "s/\$LINUX_SIZE//g"`;
        LINUX_CHECKSUM_NEW=`nand_md5sum $4 $LINUX_CHECKSUM_SIZE`;
        echo $LINUX_CHECKSUM_NEW;

        if ! [ "$LINUX_CHECKSUM_CURR $4" = "$LINUX_CHECKSUM_NEW" ] ; then
        echo "Linux Checksum Failure";
        exit 114;
        else
        echo "Linux Checksum Verified";
        fi
    else
        echo "ERROR Flashing linux";
        exit 103;
    fi
    fi

}

#
# Burn_jffs2_rootfs():
# Burns the JFFS2 root FS files into the dest partition
#
# Args:
#     $1 = Source package
#     $2 = Destination
#     $3 = Root FS source location
#     $4 = Root FS dest location
#

Burn_jffs2_rootfs() {

    echo "Installing Applications...";

#echo "Burn_jffs2_rootfs $1 $2 $3 $4";
# And run post-install script

    if [ "$1" = "/tmp/fud_eth/RLM_FW/install" ] ; then
        echo "Burning new JFFS2 $PART_NAME image";
        Umount_$PART_NAME;
        program_nand_partition $ROOTFS_PARTITION $NEW_PACKAGE/root-fs-image/Root.bin
        Mount_$PART_NAME;

        if ! [ $? = 0 ] ; then
            echo "ERROR Flashing JFFS2 $PART_NAME image";
            exit 104;
        fi
    else
        Differential_file_update $REGFILES_ADD $SYMLINKS_ADD \
        $REGFILES_DEL $SYMLINKS_DEL $3 $4 \
        $NEW_PACKAGE/install/checksum.regfiles;

        chmod 755 $POST_INSTALL_SCRIPT;
        if ! [ $? = 0 ] ; then
            echo "Unable to change permissions for $POST_INSTALL_SCRIPT";
            exit 121;
        fi

        $POST_INSTALL_SCRIPT $4;
        if ! [ $? = 0 ] ; then
            echo "Error executing $POST_INSTALL_SCRIPT";
            exit 123;
        fi
    fi


# cp all metadata information
    echo "Installing New Metadata..."
#    rm -f $2/*;
    cp -f $1/* $2/;
    cd $1; for file in *; do
    FILE_CHECKSUM_ORIG=`md5sum $file`;
    FILE_CHECKSUM_CURR=`cd $2; md5sum $file`;
    cd $1;
#   echo $FILE_CHECKSUM_CURR;
#   echo $FILE_CHECKSUM_ORIG;
    if ! [ "$FILE_CHECKSUM_CURR" = "$FILE_CHECKSUM_ORIG" ] ; then
        echo "File $2/$file Checksum Failure";
        exit 115;
    fi
    done;
    echo "Metadata installed, Checksums Verified.";
}

#
# Differential_file_update():
# Updates the JFFS2 root FS files with the correct set of files
#
# Args:
#     $1 = Regular files added/changed
#     $2 = Symlinks added/changed
#     $3 = Regular files removed
#     $4 = Symlinks removed
#     $5 = Root FS source location
#     $6 = Root FS dest location
#     $7 = checksum.regfiles for the files to be installed
#
Differential_file_update() {

# List all differences files
    for i in $1 $2 $3 $4; do
    if [ -f $i ] ; then
            echo $i;
        echo `cat $i`;
    fi
    done

# rm all deleted files and symlinks
    if [ -f $3 ] ; then
    for fileName in `cat $3`; do
        rm -f $6$fileName;
    done
    fi
    if [ -f $4 ] ; then
    for fileName in `cat $4`; do
        rm -f $6$fileName;
    done
    fi

# cp all new and changed files and symlinks, verify checksums
    if [ -f $1 ] ; then
    for fileName in `cat $1`; do

# Is this file a config file, if so copy it to JFFS2 logs.(only for primary)

        CONFIG_FILE=`echo $fileName | grep "/mnt/logs"`;
        if [ "$CONFIG_FILE" = "$fileName" ] ; then
        if [ $PART_NAME = "primary" ] ; then
            NEWDIR=`echo $fileName | sed -e "s/\(.*\)\/\(.*\)/\1/"`;
            mkdir -p $NEWDIR;
            rm -f $fileName;
            cp -dpf $5$fileName $fileName;
            if ! [ $? = 0 ] ; then
            echo "File $fileName couldn't be copied";
            exit 118;
            fi

            FILE_CHECKSUM_CURR=`md5sum $fileName | sed -e "s/\(.*\) \(.*\)/\1/"`;
            FILE_CHECKSUM_ORIG=`grep " $fileName$" $7`;

            if ! [ "$FILE_CHECKSUM_CURR $fileName" = "$FILE_CHECKSUM_ORIG" ] ; then
            echo $FILE_CHECKSUM_CURR $fileName;
            echo $FILE_CHECKSUM_ORIG;
            echo "File $fileName Checksum Failure";
            exit 115;
            fi
        fi
        else
        NEWDIR=`echo $6$fileName | sed -e "s/\(.*\)\/\(.*\)/\1/"`;
        mkdir -p $NEWDIR;
        rm -f $6$fileName;
        cp -dpf $5$fileName $6$fileName;
        if ! [ $? = 0 ] ; then
            echo "File $fileName couldn't be copied";
            exit 118;
        fi

        FILE_CHECKSUM_CURR=`md5sum $6$fileName | sed -e "s/\(.*\) \(.*\)/\1/"`;
        FILE_CHECKSUM_ORIG=`grep " $fileName$" $7`;

        if ! [ "$FILE_CHECKSUM_CURR $fileName" = "$FILE_CHECKSUM_ORIG" ] ; then
            echo $FILE_CHECKSUM_CURR $fileName;
            echo $FILE_CHECKSUM_ORIG;
            echo "File $fileName Checksum Failure";
            exit 115;
        fi
        fi
    done
    fi

    if [ -f $2 ] ; then
    COUNT=0;
    for fileName in `cat $2`; do
        if [ $(($COUNT%2)) -eq 0 ] ; then
        FILENAME=$fileName;
        else
        rm -f $6$FILENAME;
        ln -sf $fileName $6$FILENAME;
        fi
        COUNT=$(($COUNT + 1));
    done
    fi
}

# Verify command line arguments
if [ $# -lt 2 ] || [ $# -gt 3 ] ; then
    echo "Usage: install_fw <dest_partition> <install_type> <force option>";
    exit 101;
fi
if [ $2 = "eth" ] ; then
    NEW_PACKAGE=$ETH_FW_PACKAGE_DIR
elif [ $2 = "sp" ] ; then
    NEW_PACKAGE=$SP_FW_PACKAGE_DIR
else 
    echo "Usage: install_fw <dest_partition> <install_type> <force option>";
    exit 101;
fi


DIFFS_DIR=$NEW_PACKAGE/differences
POST_INSTALL_SCRIPT=$NEW_PACKAGE/install/post-install-script

REGFILES_ADD=$DIFFS_DIR/add.regfiles
REGFILES_DEL=$DIFFS_DIR/del.regfiles
SYMLINKS_ADD=$DIFFS_DIR/add.symlinks
SYMLINKS_DEL=$DIFFS_DIR/del.symlinks


# If last bit of tiny ROM is 0, then our NAND is flipped (primary is the bottom half)
hexdump /dev/mtd0 | grep "ffff ffff ffff ffff ffff ffff ffff fffe" > /dev/null
not_bottom=$?

if [ $not_bottom -eq 0 ] ; then
    PRIMARY_UBOOT_PARTITION=/dev/mtd4
    BACKUP_UBOOT_PARTITION=/dev/mtd1
    PRIMARY_LINUX_PARTITION=/dev/mtd8
    BACKUP_LINUX_PARTITION=/dev/mtd6
    PRIMARY_ROOTFS_PARTITION=/dev/mtd9
    PRIMARY_ROOTFS_BLOCK_PARTITION=/dev/mtdblock9
    BACKUP_ROOTFS_PARTITION=/dev/mtd7
    BACKUP_ROOTFS_BLOCK_PARTITION=/dev/mtdblock7
    PRIMARY_UBOOT_FILE=secondary-u-boot.bin
    BACKUP_UBOOT_FILE=u-boot.bin
    PRI_UBOOT_VERSION_STRING=sec_u-boot_version=
    PRI_UBOOT_CHECKSUM_STRING=sec_u-boot_checksum=
    PRI_UBOOT_SIZE=sec_u-boot_size=
    SEC_UBOOT_VERSION_STRING=pri_u-boot_version=
    SEC_UBOOT_CHECKSUM_STRING=pri_u-boot_checksum=
    SEC_UBOOT_SIZE=pri_u-boot_size=
else
    PRIMARY_UBOOT_PARTITION=/dev/mtd1
    BACKUP_UBOOT_PARTITION=/dev/mtd4
    PRIMARY_LINUX_PARTITION=/dev/mtd6
    BACKUP_LINUX_PARTITION=/dev/mtd8
    PRIMARY_ROOTFS_PARTITION=/dev/mtd7
    PRIMARY_ROOTFS_BLOCK_PARTITION=/dev/mtdblock7
    BACKUP_ROOTFS_PARTITION=/dev/mtd9
    BACKUP_ROOTFS_BLOCK_PARTITION=/dev/mtdblock9
    PRIMARY_UBOOT_FILE=u-boot.bin
    BACKUP_UBOOT_FILE=secondary-u-boot.bin
    PRI_UBOOT_VERSION_STRING=pri_u-boot_version=
    PRI_UBOOT_CHECKSUM_STRING=pri_u-boot_checksum=
    PRI_UBOOT_SIZE=pri_u-boot_size=
    SEC_UBOOT_VERSION_STRING=sec_u-boot_version=
    SEC_UBOOT_CHECKSUM_STRING=sec_u-boot_checksum=
    SEC_UBOOT_SIZE=sec_u-boot_size=
fi

JFFS2_LOGS_PARTITION=/dev/mtd10
JFFS2_LOGS_BLOCK_PARTITION=/dev/mtdblock10

# Start the install process
# Entry point
grep -c use_tiny_rom $NEW_PACKAGE/install/Metadata > /dev/null
if [ $?  != 0 ]; then
    echo "ERROR: this FW does not support boot block architecture";
    exit 125;
fi


PART_NAME=$1

if [ $PART_NAME = "primary" ] ; then
    UBOOT_PARTITION=$PRIMARY_UBOOT_PARTITION
    LINUX_PARTITION=$PRIMARY_LINUX_PARTITION
    ROOTFS_PARTITION=$PRIMARY_ROOTFS_PARTITION
    ROOTFS=$PRIMARY_ROOTFS
    CURR=$PRIMARY_INSTALL
    UBOOT_FILE=$PRIMARY_UBOOT_FILE
    UBOOT_VERSION_STRING=$PRI_UBOOT_VERSION_STRING;
    UBOOT_CHECKSUM_STRING=$PRI_UBOOT_CHECKSUM_STRING;
    UBOOT_SIZE=$PRI_UBOOT_SIZE;
elif [ $PART_NAME = "backup" ] ; then
    UBOOT_PARTITION=$BACKUP_UBOOT_PARTITION
    LINUX_PARTITION=$BACKUP_LINUX_PARTITION
    ROOTFS_PARTITION=$BACKUP_ROOTFS_PARTITION
    ROOTFS=$BACKUP_ROOTFS
    CURR=$BACKUP_INSTALL
    UBOOT_FILE=$BACKUP_UBOOT_FILE
    UBOOT_VERSION_STRING=$SEC_UBOOT_VERSION_STRING;
    UBOOT_CHECKSUM_STRING=$SEC_UBOOT_CHECKSUM_STRING;
    UBOOT_SIZE=$SEC_UBOOT_SIZE;
else
    echo "Usage: install_fw <dest_partition> <install_type> <force option>";
    exit 101;
fi

installing=$($FW_PRINTENV | grep "INSTALLING=" | sed -e "s/INSTALLING=//g");

if [ "$3" = "-f" ] || [ "$3" = "-F" ] || [ "$installing" -eq "1" ] ; then

    echo "Starting forced update of $1...";
    if ! [ -f $NEW_PACKAGE/uboot/$UBOOT_FILE ] ; then
        echo "ERROR: Missing $UBOOT_FILE in $NEW_PACKAGE/uboot";
        exit 108;
    elif ! [ -f $NEW_PACKAGE/linux/uImage ] ; then
        echo "ERROR: Missing uImage in $NEW_PACKAGE/linux";
        exit 109;
    elif ! [ -f $NEW_PACKAGE/root-fs-image/Root.bin ] ; then
        echo "ERROR: Missing Root.bin in $NEW_PACKAGE/root-fs-image";
        exit 111;
    fi
    if [ "$3" = "-F" ] ; then
        if ! [ -f $NEW_PACKAGE/root-fs-image/Config.bin ] ; then
            echo "ERROR: Missing Config.bin in $NEW_PACKAGE/root-fs-image";
            exit 116;
        fi
    fi

    $FW_SETENV INSTALLING 1 > /dev/null 2>&1;

    Umount_$PART_NAME;

    Force_Burn $NEW_PACKAGE/uboot/$UBOOT_FILE $UBOOT_PARTITION \
    $NEW_PACKAGE/linux/uImage $LINUX_PARTITION \
    $NEW_PACKAGE/root-fs-image/Root.bin $ROOTFS_PARTITION;

    Mount_$PART_NAME;

    # Save this so we update later when we reboot
    if [ "$3" = "-F" ] ; then
        /usr/local/bin/wipeclean
        sync
    fi

    $FW_SETENV INSTALLING 0 > /dev/null 2>&1;

    exit;
fi

if [ -f $NEW_PACKAGE/install/checksum.regfiles.0 -a \
    ! -f $NEW_PACKAGE/install/checksum.regfiles ] ; then
    echo "Copying checksum.regfiles.0 to checksum.regfiles"
    cp $NEW_PACKAGE/install/checksum.regfiles.0 $NEW_PACKAGE/install/checksum.regfiles
fi

if ! [ -f $NEW_PACKAGE/install/Metadata -a \
-f $NEW_PACKAGE/install/checksum.regfiles -a \
-f $NEW_PACKAGE/install/info.symlinks -a \
-f $NEW_PACKAGE/install/post-install-script ] ; then

    echo "ERROR: No metadata information in $NEW_PACKAGE/install";
    exit 105;

elif ! [ -f $CURR/Metadata -a \
-f $CURR/checksum.regfiles -a \
-f $CURR/info.symlinks -a \
-f $CURR/post-install-script ] ; then

    echo "ERROR: No Metadata Information in $CURR";
    exit 106;

else
    $FW_SETENV INSTALLING 1 > /dev/null 2>&1;

    Burn_fw $NEW_PACKAGE/install $CURR \
    $NEW_PACKAGE/uboot/$UBOOT_FILE $UBOOT_PARTITION \
    $NEW_PACKAGE/linux/uImage $LINUX_PARTITION \
    $NEW_PACKAGE/root-fs $ROOTFS;

    Remount_Rootfs;

    $FW_SETENV INSTALLING 0 > /dev/null 2>&1;
fi

exit;
