From 585c67268618dd64a265b144750178b167819c2b Mon Sep 17 00:00:00 2001 From: Christian Hewitt Date: Sun, 26 Feb 2023 11:12:24 +0000 Subject: [PATCH] emmctool: check file exists before writing and error on box images --- packages/tools/emmctool/scripts/emmctool | 28 +++++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/tools/emmctool/scripts/emmctool b/packages/tools/emmctool/scripts/emmctool index 653d25e016..cd76b47b0d 100755 --- a/packages/tools/emmctool/scripts/emmctool +++ b/packages/tools/emmctool/scripts/emmctool @@ -148,19 +148,31 @@ do_write(){ do_umount case $(dtname) in - radxa,zero) + radxa,zero*) do_writeprotect ;; esac - if [ "${2: -7}" == ".img.gz" ]; then - echo "info: writing ${2} to ${EMMC}" - gunzip -c "${2}" | dd of="${EMMC}" bs=1M - elif [ "${2: -4}" == ".img" ]; then - echo "info: writing ${2} to ${EMMC}" - dd if="${2}" of="${EMMC}" bs=1M + if [ -e "${2}" ]; then + case "${2}" in + *box.img.gz|*box.img) + echo "error: ${2} is not a bootable image, aborting!" + exit 1 + ;; + *.img.gz) + echo "info: writing ${2} to ${EMMC}" + gunzip -c "${2}" | dd of="${EMMC}" bs=1M + ;; + *.img) + echo "info: writing ${2} to ${EMMC}" + dd if="${2}" of="${EMMC}" bs=1M + ;; + *) + echo "error: ${2} is not a valid image file!" + exit 1 + esac else - echo "error: ${2} is not a valid image file!" + echo "error: ${2} not found!" exit 1 fi }