scripts: Prevent failure of ip assigning 38/204238/1
authorDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 18 Apr 2019 01:36:43 +0000 (10:36 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Mon, 22 Apr 2019 08:17:56 +0000 (17:17 +0900)
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 <dwoo08.lee@samsung.com>
scripts/flash-init.sh

index 7ccf3ca..aba4d7e 100755 (executable)
@@ -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}"
 }
 
 #------------------------------------------------