From 15b68b52642d62e8a43f63a7f9dfdc8d650cd914 Mon Sep 17 00:00:00 2001 From: Stanislav Vlasic Date: Wed, 30 May 2018 16:34:14 +0200 Subject: [PATCH] Added option to wait for device to be connected (on by default) Script looks for device every two seconds until device is found or script is aborted. If Ctrl-C is detected script performs cleanup and exits. --- aml-flash | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/aml-flash b/aml-flash index 1e8fadb..bf19e33 100755 --- a/aml-flash +++ b/aml-flash @@ -12,6 +12,7 @@ destroy= update_return= debug=0 simu=0 +wait_device=1 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' @@ -34,6 +35,7 @@ show_help() echo " --*-file => Force overload of partition files" echo " --password => Unlock usb mode using password file provided" echo " --destroy => Erase the bootloader and reset the board" + echo " --no-wait => Do not wait for device to be pluged in" } # Check if a given file exists and exit if not @@ -59,6 +61,7 @@ cleanup() } cleanup_trap() { + echo -e "\nOperation stopped. Cleaning up..." cleanup exit 1 } @@ -182,6 +185,9 @@ for opt do --debug) debug=1 ;; + --no-wait) + wait_device=0 + ;; *) if [[ ${opt%=*} == "--"*"-file" ]]; then newvar=`echo ${opt%=*} | sed 's/--//' | sed 's/-file/_file/'` @@ -215,18 +221,28 @@ if [[ "$soc" != "gxl" ]] && [[ "$soc" != "axg" ]] && [[ "$soc" != "txlx" ]] && [ echo "Soc type is invalid, should be either gxl,axg,txlx,m8" exit 1 fi + +# Set trap +# -------- +trap cleanup_trap SIGHUP SIGINT SIGTERM + run_update_return identify 7 if [[ "$simu" != "1" ]]; then if ! `echo $update_return | grep -iq firmware`; then - echo "Amlogic device not found" - exit 1 + if [[ "$wait_device" != "1" ]]; then + echo "Amlogic device not found" + exit 1 + else + echo "Waiting for Amlogic device to be connected..." + while [ ! `echo $update_return | grep -iq firmware` ] + do + sleep 2 + run_update_return identify 7 + done + fi fi fi -# Set trap -# -------- -trap cleanup_trap SIGHUP SIGINT SIGTERM - # Check if the board is locked with a password # -------------------------------------------- need_password=0