#!/bin/sh
#
# Copyright (C) 2016 Dream Property GmbH
#

source librecovery

usage()
{
	echo "Usage: ${0} [-hqtv] <vmlinux.gz>"
	exit ${1}
}

xgetopts $@
shift $((${OPTIND} - 1))
[ "$#" -eq 1 ] || usage 1
VMLINUX=`xrealpath ${1}`

MTD_DEVICE=/dev/mtd2

is_writable_chardev "${MTD_DEVICE}" || abort "Target device '${MTD_DEVICE}' is not a writable character device"
! is_empty "${VMLINUX}" || abort "No kernel image given"
is_readable_file "${VMLINUX}" || abort "Cannot access '${VMLINUX}'"

erase "${MTD_DEVICE}" || abort "Failed to erase ${MTD_DEVICE}"
write_nand "${MTD_DEVICE}" "${VMLINUX}" || abort "Failed to flash kernel image"
