cros_write_firmware should report proper exit status

When cros_write_firmware fails, it does not report the failure to the
caller (the shell), which makes it impossible to use this utility in
any automation.

This change ensures that the failure status is reported properly.

BUG=chrome-os-partner:15610
TEST=manual
    . while in chroot
    $ dut-control spi1_vref:pp3300
    $ sudo -n cros_write_firmware -b daisy -w usb -d exynos5250-snow -F spi -i /tmp/3604/image-snow.bin -V
    Could not find Exynos board on USB port
    $ echo $?
    1
    $ dut-control spi1_vref:off
    $ sudo -n cros_write_firmware -b daisy -w usb -d exynos5250-snow -F spi -i /tmp/3604/image-snow.bin -V
    $ echo $?
    0
    $

Change-Id: Iab759c954f2de5dcd901d496281b2434eae1cbf2
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/42344
Reviewed-by: Simon Glass <sjg@chromium.org>
diff --git a/host/cros_write_firmware b/host/cros_write_firmware
index b06de7f..c914193 100755
--- a/host/cros_write_firmware
+++ b/host/cros_write_firmware
@@ -60,23 +60,15 @@
   # Set up the fdt and options that we want.
   fdt = bundle.SelectFdt(options.fdt)
 
-  try:
-    # Write it to the board.
-    flasher = options.uboot_flasher
-    if not flasher:
-      flasher = bundle.uboot_fname
-    file_list = bundle.GetFiles()
-    write_firmware.DoWriteFirmware(output, tools, fdt, flasher,
-        file_list, options.image, bundle, update, verify, dest,
-        flash_dest=options.flash_dest, servo=options.servo,
-        method=options.method)
-
-  except (CmdError, ValueError) as err:
-    # For verbosity 4 we want to display all possible information
-    if options.verbosity >= 4:
-      raise
-    else:
-      output.Error(str(err))
+  # Write it to the board.
+  flasher = options.uboot_flasher
+  if not flasher:
+    flasher = bundle.uboot_fname
+  file_list = bundle.GetFiles()
+  write_firmware.DoWriteFirmware(output, tools, fdt, flasher,
+      file_list, options.image, bundle, update, verify, dest,
+      flash_dest=options.flash_dest, servo=options.servo,
+      method=options.method)
 
 
 def main():
@@ -138,8 +130,16 @@
     with Tools(output) as tools:
       if options.includedirs:
         tools.search_paths += options.includedirs
-      _DoWriteFirmware(options, output, tools, not options.full_erase,
-          options.verify, dest=options.write)
+      try:
+        _DoWriteFirmware(options, output, tools, not options.full_erase,
+                         options.verify, dest=options.write)
+      except (CmdError, ValueError) as err:
+        # For verbosity 4 we want to display all possible information
+        if options.verbosity >= 4:
+          raise
+        else:
+          output.Error(str(err))
+          sys.exit(1)
 
 
 def _Test():