#!/bin/sh

gen_confall_DA660() {

	### Write to ./confall
	echo "# eg: output target-2.0.frm" > ./confall
	echo "# eg: input source-file-name filename versionname version mtdno" >> ./confall

	if [ $OEM -eq 0 ]; then
		echo "output FWR_DA660_V"$MAJOR"."$MINOR"_Build_"$BUILDTIME >> ./confall
	else
  		echo "output FWR_DA660_V"$MAJOR"."$MINOR"."$OEM"_Build_"$BUILDTIME >> ./confall
	fi

	echo "apid 0xE0000660" >> ./confall

	if [ $BOEM -eq 0 ]; then
		echo "input /tftpboot/DA66X_$BMAJOR.$BMINOR.bos redboot bios_ver $BMAJOR.$BMINOR.$BOEM.$BTESTING 0" >> ./confall
	elif [ $BTESTING -eq 0 ]; then
		echo "input /tftpboot/DA66X_$BMAJOR.$BMINOR.$BOEM.bos redboot bios_ver $BMAJOR.$BMINOR.$BOEM.$BTESTING 0" >> ./confall
	else
		echo "input /tftpboot/DA66X_$BMAJOR.$BMINOR.$BOEM.$TESTING.bos redboot bios_ver $BMAJOR.$BMINOR.$BOEM.$BTESTING 0" >> ./confall
	fi

	echo "input /tftpboot/noaddversion/$KERNEL-$MAJOR.$MINOR.$OEM.$TESTING kernel kernel_ver $MAJOR.$MINOR.$OEM.$TESTING 1" >> ./confall

	echo "input /tftpboot/noaddversion/$MXDISK-$MAJOR.$MINOR.$OEM.$TESTING mini-file-system mxdisk_ver $MAJOR.$MINOR.$OEM.$TESTING 2" >> ./confall

	echo "input /tftpboot/noaddversion/$USRDISK-$MAJOR.$MINOR.$OEM.$TESTING user-file-system usrdisk_ver $MAJOR.$MINOR.$OEM.$TESTING 3" >> ./confall

	echo "# You must fix to use 'configuration' file name" >> ./confall
	echo "input ../mkrom/rfis directory dir_ver $MAJOR.$MINOR.$OEM.$TESTING 6" >> ./confall
}

gen_confkernel_DA660() {

	rm -f ./confkernel

	if [ "${OEM}" -eq "0" ]; then
		echo "output FWR_DA660_kernel_V${MAJOR}.${MINOR}_Build_${BUILDTIME}" >> ./confkernel
	else
  		echo "output FWR_DA660_kernel_V${MAJOR}.${MINOR}.${OEM}_Build_${BUILDTIME}" >> ./confkernel
	fi

	echo "apid 0xE0000660" >> ./confkernel

	if [ "${BOEM}" -eq "0" ]; then
		echo "input /tftpboot/DA66X_${BMAJOR}.${BMINOR}.bos redboot bios_ver ${BMAJOR}.${BMINOR}.${BOEM}.${BTESTING} 0" >> ./confkernel
	elif [ "${BTESTING}" -eq 0 ]; then
		echo "input /tftpboot/DA66X_${BMAJOR}.${BMINOR}.${BOEM}.bos redboot bios_ver ${BMAJOR}.${BMINOR}.${BOEM}.${BTESTING} 0" >> ./confkernel
	else
		echo "input /tftpboot/DA66X_${BMAJOR}.${BMINOR}.${BOEM}.${TESTING}.bos redboot bios_ver ${BMAJOR}.${BMINOR}.${BOEM}.${BTESTING} 0" >> ./confkernel
	fi

	echo "input /tftpboot/noaddversion/${KERNEL}-${MAJOR}.${MINOR}.${OEM}.${TESTING} kernel kernel_ver ${MAJOR}.${MINOR}.${OEM}.${TESTING} 1" >> ./confkernel

	echo "# You could need to fix to configuration file name" >> ./confkernel
	echo "input ../mkrom/rfis directory dir_ver ${MAJOR}.${MINOR}.${OEM}.${TESTING} 6" >> ./confkernel
}

gen_confusrdisk_DA660(){

	echo "# eg: output target-file-name" > ./confusrdisk
	echo "# eg: input source-file-name filename versionname version mtdno" >> ./confusrdisk

	if [ $OEM -eq 0 ]; then
		echo "output FWR_DA660_usrdisk_V"$MAJOR"."$MINOR"_Build_"$BUILDTIME >> ./confusrdisk
	else
		echo "output FWR_DA660_usrdisk_V"$MAJOR"."$MINOR"."$OEM"_Build_"$BUILDTIME >> ./confusrdisk
	fi

	echo "apid 0xE0000660" >> ./confusrdisk

	echo "input /tftpboot/noaddversion/$USRDISK-$MAJOR.$MINOR.$OEM.$TESTING user-file-system usrdisk_ver $MAJOR.$MINOR.$OEM.$TESTING 3" >> ./confusrdisk
}

gen_confhfmall_DA660() {

	### Write to ./confhfmall
	echo "# eg: output target-2.0.hfm" > ./confhfmall
	echo "#input /path/to/input_file filename version MTD_number flashstart flashend flashlength DRAMstartaddr" >> ./confhfmall

	if [ "$OEM" -eq "0" ]; then
		echo "output FWR_DA660_V"$MAJOR"."$MINOR"_Build_"$BUILDTIME".hfm" >> ./confhfmall
	else
		echo "output FWR_DA660_V"$MAJOR"."$MINOR"."$OEM"_Build_"$BUILDTIME".hfm" >> ./confhfmall
	fi

	echo "apid 0xE0000660" >> ./confhfmall
	echo "modelname DA-660-LX" >> ./confhfmall

	echo "input /tftpboot/noaddversion/$KERNEL-$MAJOR.$MINOR.$OEM.$TESTING kernel $MAJOR.$MINOR.$OEM.$TESTING 1 0x50060000 0x50160000 0x00100000 0x00000000" >> ./confhfmall

	echo "input /tftpboot/noaddversion/$MXDISK-$MAJOR.$MINOR.$OEM.$TESTING mini-file-system $MAJOR.$MINOR.$OEM.$TESTING 2 0x50160000 0x50560000 0x00400000 0x00000000" >> ./confhfmall

	echo "input /tftpboot/noaddversion/$USRDISK-$MAJOR.$MINOR.$OEM.$TESTING root-file-system $MAJOR.$MINOR.$OEM.$TESTING 3 0x50560000 0x51F60000 0x01a00000 0x00000000" >> ./confhfmall

}

gen_confhfm_usrdisk_DA660() {
	### Write to ./confhfm_usrdisk
	echo "# eg: output target-2.0.hfm" > ./confhfm_usrdisk
	echo "#input /path/to/input_file filename version MTD_number flashstart flashend flashlength DRAMstartaddr" >> ./confhfm_usrdisk

	if [ "$OEM" -eq "0" ]; then
		echo "output FWR_DA660_usrdisk_V"$MAJOR"."$MINOR"_Build_"$BUILDTIME".hfm" >> ./confhfm_usrdisk
	else
		echo "output FWR_DA660_usrdisk_V"$MAJOR"."$MINOR"."$OEM"_Build_"$BUILDTIME".hfm" >> ./confhfm_usrdisk
	fi

	echo "apid 0xE0000660" >> ./confhfm_usrdisk
	echo "modelname DA-660-LX" >> ./confhfm_usrdisk

	echo "input ./erase erase $MAJOR.$MINOR.$OEM.$TESTING 3 0x50560000 0x51F60000 0x01a00000 0x00000000" >> ./confhfm_usrdisk
}

# Generate: confall
gen_confall_DA660

# Generate: confkernel
gen_confkernel_DA660

# Generate: confusrdisk
#gen_confusrdisk_DA660

# Generate: confhfmall
gen_confhfmall_DA660
gen_confhfm_usrdisk_DA660

./mkfrm confall
./mkfrm confkernel
#./mkfrm confusrdisk
./mkhfm confhfmall
./mkhfm confhfm_usrdisk
mv -f FWR* /tftpboot
