#!/bin/sh /etc/rc.common

START=99

commit_current_sw() {
	. /lib/upgrade/common.sh
	local error=0

	if [ "$(rootfs_type)" = "tmpfs" ]; then
		logger -t rtl9607c_sw_commit "Skip sw_commit for ramfs boot"
		return 0
	fi

	local active="$(fw_printenv -n sw_active)"
	local commit="$(fw_printenv -n sw_commit)"
	if [ "$active" != 0 ] && [ "$active" != 1 ]; then
		logger -p err -t rtl9607c_sw_commit "Invalid active slot '$active'!"
		return 1
	fi
	if [ "$active" != "$commit" ]; then
		fw_setenv sw_commit "$active"
		error="$?"
		if [ "$error" = 0 ]; then
			logger -t rtl9607c_sw_commit "Mark partition "$active" as committed"
		else
			logger -p err -t rtl9607c_sw_commit "Failed to mark committed partition!"
		fi
	fi
	return "$error"
}

boot() {
	case $(board_name) in
	eltex,rg-5520)
		commit_current_sw
		;;
	esac
}
