#!/bin/sh

. /usr/local/bin/sig_catcher

SEL_PARAM="sp.notice"
SEL_LOGGER="sel_logger"



usage() {
	echo "No parameters needed."
	exit 1
}

if [ $# -gt 0 ]; then
	usage
fi

platform=$(cat /var/run/platform)
brdrev=$(cat /var/run/boardrev)
lml_rev_p2i=2

if [ "$platform" == "Lodi" ] || [ "$platform" == "Madera" ] || [ "$platform" == "Livermore" ] ; then
	if [ "$brdrev" -lt "$lml_rev_p2i" ] ; then
		echo "Command not supported on $brdrev boardrev of this platform"
		exit 1
	fi

	echo "Programming Controller Switch EEPROM. Reset switch for changes to be effective."
	switch_file=$(ls /firmware/$platform/switch/controller_switch_img.bin)
	if [ -f "$switch_file" ]; then
		/usr/local/bin/switch ep_pgm < "$switch_file"
		upg_ret_val=$?
		# TODO: revisit/resolve permission problem.
		if [ $upg_ret_val -eq 0 ]; then
			/usr/local/bin/switch_config_version.sh -f > /var/run/switch_version_controller
		fi
	else
		echo "$switch_file cannot be found."
		upg_ret_val=1
	fi
else
	echo "Command not supported on this platform"
	exit 1
fi
return $upg_ret_val


