#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org

START=95
boot() {
	mount_root done
	rm -f /sysupgrade.tgz
	local hk_board=$(grep -w  "IPQ807x" /proc/device-tree/model | awk -F: '{print $1}')

        [ -n "$hk_board" ] && {
		local mount_check=$(ls /lib/firmware/IPQ8074/WIFI_FW/ | grep "bdwlan.bin")
		if [ -z "$mount_check" ];then
			. /etc/init.d/wifi_fw_mount
			mount_wifi_fw
		fi
	}

	# process user commands
	[ -f /etc/rc.local ] && {
		sh /etc/rc.local
	}

	# set leds to normal state
	. /etc/diag.sh
	set_state done

	if [ -e "/mnt/rebootType" ]; then
		rebootType=$(cat /mnt/rebootType)
	else
		rebootType="unknown"
	fi

	#echo "=====rebootType:$rebootType==========" >/dev/console

	if [ "$rebootType" == "reboot" ]; then
		rebootlog="user reboot system"
	elif [ "$rebootType" == "restore" ]; then
		rebootlog="restore backup file and reboot system"
	elif [ "$rebootType" == "upgrade" ]; then
		rebootlog="firmware upgrade and reboot system"
	elif [ "$rebootType" == "reset" ]; then
		rebootlog="reboot system in factory default status"
	elif [ "$rebootType" == "unknown" ]; then
		rebootlog="reboot system in unknown status"
	fi
	logger "$rebootlog" -t reboot -p 5
	echo "unknown">/mnt/rebootType
	#/usr/sbin/printlog -d "reboot" -i "reboot system"

	logger "System startup" -t boot -p 5

}
