From 3df06a4491f80a734dd72638ab17b20086b4a1cc Mon Sep 17 00:00:00 2001 From: Vadim Bendebury Date: Thu, 1 Jun 2017 22:01:39 -0700 Subject: cr50: usb_updater: do not send setup request unless necessary There are only two usb_updater actions which require establishing a connection with the Cr50: transferring the firmware image during update and reporting the version of the running image (because the version is reported when the connection is established). This patch refactors usb_updater code to establish the connection only when necessary. BRANCH=cr50 BUG=b:35587387,b:35587053 TEST=verified that 'usb_updater -c' succeeds both issued over USB and TPM Change-Id: I6a0c82eb440c092263d4802f124f458f148a8ab5 Signed-off-by: Vadim Bendebury Reviewed-on: https://chromium-review.googlesource.com/525095 Reviewed-by: Aseda Aboagye (cherry picked from commit 885c02a92d35607bf410e27f27c0b35e67827cf5) Reviewed-on: https://chromium-review.googlesource.com/658350 Reviewed-by: Philip Chen Tested-by: Philip Chen Commit-Queue: Philip Chen --- extra/usb_updater/usb_updater.c | 47 +++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/extra/usb_updater/usb_updater.c b/extra/usb_updater/usb_updater.c index ef0756794a..340fc791be 100644 --- a/extra/usb_updater/usb_updater.c +++ b/extra/usb_updater/usb_updater.c @@ -1035,13 +1035,6 @@ static int transfer_image(struct transfer_descriptor *td, num_txed_sections++; } - /* - * Move USB receiver sate machine to idle state so that vendor - * commands can be processed later, if any. - */ - if (td->ep_type == usb_xfer) - send_done(&td->uep); - if (!num_txed_sections) printf("nothing to do\n"); else @@ -1358,26 +1351,38 @@ int main(int argc, char *argv[]) } } - setup_connection(&td); + if (corrupt_inactive_rw) + invalidate_inactive_rw(&td); + + if (data || show_fw_ver) { + + setup_connection(&td); + + if (data) { + transferred_sections = transfer_image(&td, + data, data_len); + free(data); + } - if (show_fw_ver) { - printf("Current versions:\n"); - printf("RO %d.%d.%d\n", targ.shv[0].epoch, targ.shv[0].major, - targ.shv[0].minor); - printf("RW %d.%d.%d\n", targ.shv[1].epoch, targ.shv[1].major, - targ.shv[1].minor); + /* + * Move USB updater sate machine to idle state so that vendor + * commands can be processed later, if any. + */ if (td.ep_type == usb_xfer) send_done(&td.uep); - } - - if (data) { - transferred_sections = transfer_image(&td, data, data_len); - free(data); if (transferred_sections) generate_reset_request(&td); - } else if (corrupt_inactive_rw) { - invalidate_inactive_rw(&td); + + if (show_fw_ver) { + printf("Current versions:\n"); + printf("RO %d.%d.%d\n", targ.shv[0].epoch, + targ.shv[0].major, + targ.shv[0].minor); + printf("RW %d.%d.%d\n", targ.shv[1].epoch, + targ.shv[1].major, + targ.shv[1].minor); + } } if (td.ep_type == usb_xfer) { -- cgit v1.2.1