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

source librecovery

MAX_IMAGE_SIZE=$((31 * 1024 * 1024))

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

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

is_writable_blockdev "${KERNEL_PARTITION}" || abort "Target block device '${KERNEL_PARTITION}' is not a writable block device"
! is_empty "${VMLINUX}" || abort "No kernel image given"
is_readable_file "${VMLINUX}" || abort "Cannot access '${VMLINUX}'"

is_file_size_le "${VMLINUX}" "${MAX_IMAGE_SIZE}" || abort "Kernel image is too big"
write_blkdev "${VMLINUX}" "${KERNEL_PARTITION}" || abort "Failed to flash kernel image"
