summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorTodd Broch <tbroch@chromium.org>2014-09-18 14:36:09 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-09-22 21:15:41 +0000
commit3bfb7ee2a17c436904c9993d289eacd01658c0dc (patch)
tree216f85902ca1dc1d659488dfe210d76fbf8987ef /util
parent6395dbea0c2ff1268db82c8bf3d2d03bbb8d05af (diff)
downloadchrome-ec-3bfb7ee2a17c436904c9993d289eacd01658c0dc.tar.gz
pd: make flash_pd.py forward compatible.
Older versions of flash VDM supported a 'rw_hash' command that has since been deprecated in favor of 'info' command. This CL makes flash_pd.py try either in order to determine whether the pd flash erase was successful. BRANCH=none BUG=chrome-os-partner:28330 TEST=manual, succesfully run on zinger with only 'info' command support util/flash_pd.py -m 1 zinger_ec.RW.flat 2014-09-18 14:35:39,305 - root - INFO - Current PD FW version is zinger_v1.1.2192-5cd 2014-09-18 14:35:39,305 - root - INFO - Flashing 11532 bytes 2014-09-18 14:35:45,779 - root - INFO - Successfully erased flash. 2014-09-18 14:35:45,890 - root - INFO - Chunk 0 of 481 done. ... 2014-09-18 14:36:39,133 - root - INFO - Chunk 480 of 481 done. 2014-09-18 14:36:46,072 - root - INFO - Flashing DONE. 2014-09-18 14:36:46,072 - root - INFO - SHA-1: f6b296ba d474edc4 2e917ad0 33cd16cb 0f51a3fc 2014-09-18 14:36:46,090 - root - INFO - New PD FW version is zinger_v1.1.2226-bea Change-Id: I32f8b06fa546aa99c8290b6b73faa9b8df05e4fb Signed-off-by: Todd Broch <tbroch@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/218878 Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'util')
-rwxr-xr-xutil/flash_pd.py42
1 files changed, 31 insertions, 11 deletions
diff --git a/util/flash_pd.py b/util/flash_pd.py
index f6ea1f2230..4190caa02e 100755
--- a/util/flash_pd.py
+++ b/util/flash_pd.py
@@ -125,13 +125,14 @@ class FlashPD(client.ServoClient):
logging.debug("Expect '%s' missing", val)
return (done, l)
- def flash_command(self, cmd, expect='DONE 0', retries=2):
- """Send PD Flash command and interrogate output.
+ def pd_command(self, cmd, expect='DONE 0', retries=2, ignore_fail=False):
+ """Send PD command and interrogate output.
Args:
- cmd : string of 'pd port flash' command to execute
- expect : string of expected response after 'cmd'
- retries : integer number of times to repeat command if it fails.
+ cmd : string of 'pd <port>' command to execute
+ expect : string of expected response after 'cmd'
+ retries : integer number of times to repeat command if it fails.
+ ignore_fail : boolean to ignore failure
Returns:
tuple :
@@ -144,18 +145,23 @@ class FlashPD(client.ServoClient):
"""
tries = retries + 1
for i in xrange(tries):
- self._serial.write('pd %d flash %s\n' % (self._options.multiport, cmd))
+ self._serial.write('pd %d %s\n' % (self._options.multiport, cmd))
(found, line) = self.expect(expect)
if i:
time.sleep(1)
- logging.debug("pd flash cmd Retry%d for '%s'", i, cmd)
+ logging.debug("pd cmd Retry%d for '%s'", i, cmd)
if found:
break
- if (i + 1) == tries and not found:
- raise FlashPDError("Failed pd flash cmd: '%s' after %d retries\n" %
+ if (i + 1) == tries and not found and not ignore_fail:
+ raise FlashPDError("Failed pd cmd: '%s' after %d retries\n" %
(cmd, retries))
return (found, line)
+ def flash_command(self, cmd, expect='DONE 0', retries=2, ignore_fail=False):
+ """Helper method."""
+ flash_cmd = 'flash %s' % cmd
+ return self.pd_command(flash_cmd, expect, retries, ignore_fail)
+
def get_version(self):
"""Retreive PSU firmware version.
@@ -217,10 +223,24 @@ def flash_pd(options):
# erase all RW partition
ec.flash_command('erase')
- # verify that erase was successful by reading hash of RW
- (done, _) = ec.flash_command('rw_hash', expect=ERASED_RW_HASH)
+ # TODO(tbroch) deprecate rw_hash if/when command is completely deprecated in
+ # favor of 'info'
+ # verify that erase was successful by reading hash empty RW
+ (done, _) = ec.flash_command('rw_hash', expect=ERASED_RW_HASH, retries=0,
+ ignore_fail=True)
if done:
done = ec.expect('DONE')
+ else:
+ # try info command and guarantee we're in RO
+ (done, line) = ec.flash_command('info', expect=r'INFO')
+ m = re.match(r'INFO.*(18d1\S{4})', line)
+ if done and m:
+ done = ec.expect('DONE 0')
+ in_rw = int(m.group(1), 16) & 0x1
+ if in_rw:
+ raise FlashPDError('Not in RO after erase')
+ # Google UFP devices share their hash to DFP after info command so check it
+ (done, _) = ec.pd_command('hash', expect=ERASED_RW_HASH)
if not done:
raise FlashPDError('Erase failed')