#!/bin/sh

if [ $# -eq 1 ];then
    NewROMFile="if=$1"
    BackupROMFile=""
elif [ $# -eq 2 ];then
    NewROMFile="if=$1"
    BackupROMFile="if=$2"
else
    echo "Usage method error!"
    echo "Example:"
    echo "    socflash_dual.sh NewROMFile"
    echo "    socflash_dual.sh NewROMFile BackupROMFile"
    exit 1
fi

#check architecture
CMD=`uname -m | cut -c 1-6`

echo "Start update BMC Image2..."
if [ "$CMD" = "x86_64" ]; then
   chmod 777 socflash_x64
   ./socflash_x64 $NewROMFile $BackupROMFile offset=0x2000000
else
   chmod 777 socflash
   ./socflash $NewROMFile $BackupROMFile offset=0x2000000
fi

echo "Wait for a moment then will start update BMC Image1..."
sleep 30

echo "Start update BMC Image1..."
if [ "$CMD" = "x86_64" ]; then
   chmod 777 socflash_x64
   ./socflash_x64 $NewROMFile $BackupROMFile 
else
   chmod 777 socflash
   ./socflash $NewROMFile $BackupROMFile
fi

