From 43f87fca042a7dab32a5ec8bd57b22e786491ddc Mon Sep 17 00:00:00 2001 From: Dongwoo Lee Date: Thu, 18 Apr 2019 10:36:43 +0900 Subject: [PATCH] scripts: Prevent failure of ip assigning If init script tries to assign ip before usb nic is ready, it fails and the target is rebooted. To prevent this, tries several times for assigning, and determine failure after exceeding maximum tries. Change-Id: Iaa8dfbcee57985c69055e4742818f8256fba1cdd Signed-off-by: Dongwoo Lee --- scripts/flash-init.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/flash-init.sh b/scripts/flash-init.sh index 7ccf3ca..aba4d7e 100755 --- a/scripts/flash-init.sh +++ b/scripts/flash-init.sh @@ -71,16 +71,25 @@ print_ip() { if [ "z$IPADDR" == "z" ]; then IPADDR="192.168.0.100" - RESULT=`"$IFCONFIG" $NETIF $IPADDR up` - - if [ "z$RESULT" != "z" ]; then + RETRY_MAX=5 + RETRY=0 + while [ $RETRY -lt $RETRY_MAX ]; do + RESULT=`"$IFCONFIG" $NETIF $IPADDR up 2>&1` + if [ "z$RESULT" == "z" ]; then + echo "IP address is not set, using default (192.168.0.100)" + break + fi + + RETRY=$((RETRY + 1)) + echo "Retry to set IP address #${RETRY}" + sleep 1 + done + + if [ $RETRY -eq $RETRY_MAX ]; then echo "Failed to set IP address, Reboot..." "$REBOOT" fi - - echo "IP address is not set, using default (192.168.0.100)" fi - echo "IP address is set to ${IPADDR}" } #------------------------------------------------ -- 2.7.4