#!/bin/sh

gen_confall_UC7420() {
	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_UC7420_V"$MAJOR"."$MINOR"_Build_"$BUILDTIME >>./confall
	else
		echo "output FWR_UC7420_V"$MAJOR"."$MINOR"."$OEM"_Build_"$BUILDTIME >>./confall
	fi

	echo "apid 0xE0007420" >> ./confall
	echo "apid 0x80007420" >> ./confall
	echo "apid 0xC0007420" >> ./confall
	echo "apid 0xE0007410" >> ./confall
	echo "apid 0x80007410" >> ./confall
	echo "apid 0xC0007410" >> ./confall

	if [ $BOEM -eq 0 ]; then
		echo "input /tftpboot/UC7000_$BMAJOR.$BMINOR.bos redboot bios_ver $BMAJOR.$BMINOR.$BOEM.$BTESTING 0" >> ./confall
	elif [ $BTESTING -eq 0 ]; then
		echo "input /tftpboot/UC7000_$BMAJOR.$BMINOR.$BOEM.bos redboot bios_ver $BMAJOR.$BMINOR.$BOEM.$BTESTING 0" >> ./confall
	else
		echo "input /tftpboot/UC7000_$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

}

gen_confusrdisk_UC7420() {
	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_UC7420_usrdisk_V"$MAJOR"."$MINOR"_Build_"$BUILDTIME >> ./confusrdisk
	else
		echo "output FWR_UC7420_usrdisk_V"$MAJOR"."$MINOR"."$OEM"_Build_"$BUILDTIME >> ./confusrdisk
	fi

	echo "apid 0xE0007420" >> ./confusrdisk
	echo "apid 0x80007420" >> ./confusrdisk
	echo "apid 0xC0007420" >> ./confusrdisk
	echo "apid 0xE0007410" >> ./confusrdisk
	echo "apid 0x80007410" >> ./confusrdisk
	echo "apid 0xC0007410" >> ./confusrdisk
	echo "input /tftpboot/noaddversion/$USRDISK-$MAJOR.$MINOR.$OEM.$TESTING erase usrdisk_ver $MAJOR.$MINOR.$OEM.$TESTING 3" >> ./confusrdisk
}

gen_confhfmall_UC7420() {
	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_UC7420_V"$MAJOR"."$MINOR"_Build_"$BUILDTIME".hfm" >>./confhfmall
	else
		echo "output FWR_UC7420_V"$MAJOR"."$MINOR"."$OEM"_Build_"$BUILDTIME".hfm" >>./confhfmall
	fi

	echo "apid 0xE0007420" >> ./confhfmall
	echo "apid 0x80007420" >> ./confhfmall
	echo "apid 0xC0007420" >> ./confhfmall
	echo "apid 0xE0007410" >> ./confhfmall
	echo "apid 0x80007410" >> ./confhfmall
	echo "apid 0xC0007410" >> ./confhfmall
	echo "modelname UC-74XX-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_UC7420() {
	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_UC7420_usrdisk_V"$MAJOR"."$MINOR"_Build_"$BUILDTIME".hfm" >>./confhfm_usrdisk
	else
		echo "output FWR_UC7420_usrdisk_V"$MAJOR"."$MINOR"."$OEM"_Build_"$BUILDTIME".hfm" >>./confhfm_usrdisk
	fi

	echo "apid 0xE0007420" >> ./confhfm_usrdisk
	echo "apid 0x80007420" >> ./confhfm_usrdisk
	echo "apid 0xC0007420" >> ./confhfm_usrdisk
	echo "apid 0xE0007410" >> ./confhfm_usrdisk
	echo "apid 0x80007410" >> ./confhfm_usrdisk
	echo "apid 0xC0007410" >> ./confhfm_usrdisk
	echo "modelname UC-74XX-LX" >> ./confhfm_usrdisk

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

}

# Generate: confall
gen_confall_UC7420

# Generate: confusrdisk
gen_confusrdisk_UC7420

# Generate: confhfmall for new firmware format
gen_confhfmall_UC7420
gen_confhfm_usrdisk_UC7420

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