upload_and_update.py: Add --noprepare option

When the BMC is already in state for update, e.g. already rebooted with
loop deviced mounted for rofs, or in netboot without rofs mounted, it is
possible to directly do the update without "prepare".

This option is added for such case, so it saves a "prepare" progress
and thus saves a reboot time.

Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/leiyu/obmc-utils/upload_and_update.py b/leiyu/obmc-utils/upload_and_update.py
index eca1d87..8a73b8f 100755
--- a/leiyu/obmc-utils/upload_and_update.py
+++ b/leiyu/obmc-utils/upload_and_update.py
@@ -4,6 +4,7 @@
                             <--tftp user@tftp-ip:/path/to/tftproot>
                             [--password SSH-PASSWORD-TO-TFTP]
                             --bmc <bmc-ip>
+                            [--noprepare]
                             [-v]
 
 This scripts copies OpenBMC tarball to TFTP server,
@@ -141,21 +142,26 @@
     check_call(cmds, stdout=FNULL, stderr=FNULL)
 
 
-def update(tftp, tarball, bmc):
+def update(tftp, tarball, bmc, noprepare):
     print 'Update...'
 
-    login(bmc)
-    print 'Prepare BMC to update'
-    prepare(bmc)
+    if not noprepare:
+        login(bmc)
 
-    # After prepare, BMC will reboot, let's wait for it
-    print 'Waiting BMC to reboot...'
-    sleep(30)
-    while not checkBmcAlive(bmc):
+        print 'Prepare BMC to update'
+        prepare(bmc)
+
+        # After prepare, BMC will reboot, let's wait for it
+        print 'Waiting BMC to reboot...'
+        sleep(30)
+        while not checkBmcAlive(bmc):
+            sleep(5)
+        print 'BMC is back'
+
+    while not login(bmc):
+        print 'Login fails, retry...'
         sleep(5)
-    print 'BMC is back'
 
-    login(bmc)
     print 'Logged in'
 
     print 'Preserve network...'
@@ -192,6 +198,8 @@
                         help='The password of TFTP server')
     parser.add_argument('-b', '--bmc', required=True, dest='bmc',
                         help='The BMC IP address')
+    parser.add_argument('-n', '--noprepare', action='store_true',
+                        help='Do not invoke prepare, update directly')
     parser.add_argument('-v', '--verbose', action='store_true',
                         help='Print verbose log')
 
@@ -214,7 +222,7 @@
         exit(1)
 
     upload(args['tftp'], args['password'], args['tarball'])
-    update(args['tftp'], args['tarball'], args['bmc'])
+    update(args['tftp'], args['tarball'], args['bmc'], args['noprepare'])
 
     print 'Completed!'