#!/bin/bash
sn_num=$1
mn_num=$2
busnum=$3

burn_sn_1(){
	./server_ncmt eepenable spi24 1000 10000  $busnum
	sleep 1
	echo "eepenable SUCESSS"
	sleep 2
	./server_ncmt eeperasesector 0x0 $busnum
	sleep 1
	echo "eeperasesector SUCESSS"
	sleep 2
	read -p "please hotplug the $busnum nvme disk,press any key to continue"
	sleep 5
	echo "start burning firmware and rewrite sn and mn"
	./server_ncmt all24 eeprom.inspur_bics4.bin  superblock.inspur_bics4.bin firmware.tar  MBL.elf $sn_num $mn_num $busnum
}


burn_sn_2(){
	echo "start burning firmware and rewrite sn and mn"
	./server_ncmt all24 eeprom.inspur_bics4.bin  superblock.inspur_bics4.bin firmware.tar  MBL.elf $sn_num $mn_num $busnum
}

burn_1(){
	./server_ncmt eepenable spi24 1000 10000  $sn_num
	sleep 1
	echo "eepenable SUCESSS"
	sleep 2
	./server_ncmt eeperasesector 0x0 $sn_num
	sleep 1
	echo "eeperasesector SUCESSS"
	sleep 2
	read -p "please hotplug the $busnum nvme disk,press any key to continue"
	sleep 5
	echo "start burning firmware"
	./server_ncmt all24 eeprom.inspur_bics4.bin  superblock.inspur_bics4.bin firmware.tar  MBL.elf $sn_num
}

burn_2(){
	
	echo "start burning firmware"
	./server_ncmt all24 eeprom.inspur_bics4.bin  superblock.inspur_bics4.bin firmware.tar  MBL.elf $sn_num
}

############Main#################

if [ $# -eq 1 ];then
    echo "*****************only burn*********************"
    read -p "if you want eepenable/eeperasesector before burn(y/n)" eepenable1
    if [[ $eepenable1 = 'y' ]];then 
	burn_1	
    else
        burn_2
    fi
elif [ $# -eq 3 ];then
    echo "*****************burn with sn*********************"
    read -p "if you want eepenable/eeperasesector before burn(y/n)" eepenable2
    if [[ $eepenable2 = 'y' ]];then 
	burn_sn_1	
    else
	burn_sn_2
    fi
fi
