Make sure that cros_write_firmware returns errors when appropriate
The cros_write_firmware utility does not always return error status,
it should return success is and only if the image was successfully
written to a removable device.
With this change the nonzero error is returned both when the utility
is interrupted while waiting for a device to be plugged in and when
there is more than one removable device found without clearly
indicating which one to use..
BUG=none
TEST=manual
. plug in two removable devices and run the utility, get the
following:
vvvvvvvvvvvvvvvvvvvvvvv
Please specify destination as '-w sd:<disk_description>'
- <disk_description> can be either . for the only disk,
or the full device name, one of listed below:
/dev/sde - Realtek USB3.0 Card Reader 2.0 GB
/dev/sdg - Realtek USB3.0 Card Reader 3.9 GB
^^^^^^^^^^^^^^^^^^^^^^^^
. hit ^C while the utility is waiting for the card to be plugged in,
get the following:
vvvvvvvvvvvvvvvvvvvvvvv
No removable device found, interrupted
^^^^^^^^^^^^^^^^^^^^^^^^
In both cases exit status is set to 1
Change-Id: Icc385274b04557d058d0cbe01c9a640f3d794fc8
Reviewed-on: https://gerrit.chromium.org/gerrit/49438
Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>
Tested-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
diff --git a/host/lib/write_firmware.py b/host/lib/write_firmware.py
index 10c7693..70fec94 100644
--- a/host/lib/write_firmware.py
+++ b/host/lib/write_firmware.py
@@ -728,7 +728,7 @@
disks = self._ListUsbDisks()
time.sleep(.2)
except KeyboardInterrupt:
- return
+ raise CmdError("No removable device found, interrupted")
if dest.startswith(':'):
name = dest[1:]
@@ -744,22 +744,16 @@
if disk:
self.WriteToSd(flash_dest, disk, uboot, payload)
else:
- self._out.Error("Please specify destination -w 'sd:<disk_description>':")
- self._out.Error(' - description can be . for the only disk, or')
- self._out.Error(' the full device name, one of listed below:')
- msg = 'Found %d available disks.' % len(disks)
- if not disks:
- msg += ' Please insert an SD card and try again.'
- self._out.UserOutput(msg)
-
+ msg = ["Please specify destination as '-w sd:<disk_description>'",]
+ msg.append(' - <disk_description> can be either . for the only disk,')
+ msg.append(' or the full device name, one of listed below:')
# List available disks as a convenience.
for disk in disks:
- self._out.UserOutput(' %s: %s %d.%d GB' % (
+ msg.append(' %s - %s %.1f GB' % (
disk[0],
' '.join(str(x) for x in disk[1:3]),
- disk[3] / 10, # Integer number of GBs
- disk[3] % 10, # Decimal number of GBs
- ))
+ disk[3] / 10.0))
+ raise CmdError('\n'.join(msg))
def Em100FlashImage(self, image_fname):
"""Send an image to an attached EM100 device.