diff options
author | Mary Ruthven <mruthven@chromium.org> | 2019-11-20 18:40:41 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-01-13 13:39:10 +0000 |
commit | 3f4ce6be5dbe2f64ff54d486b83203b1bb9e80c8 (patch) | |
tree | aee75fee757d197dc03798c3a5bdc4ff9ec7c52a | |
parent | 656e7a3ed53454e689b218597049067913273705 (diff) | |
download | chrome-ec-3f4ce6be5dbe2f64ff54d486b83203b1bb9e80c8.tar.gz |
gsctool: delay RO update for old cr50 images
If Cr50 is running older than 0.3.20, delay the RO update 1 minute after
the RW update, so Cr50 doesn't reject the RO blocks because their
offsets are less than the RW offsets.
BUG=b:144873413
BRANCH=octopus
TEST=update board running RO 0.0.10 RW 0.3.18 to the RO 0.0.11 RW 0.3.22
image.
Change-Id: I0179cc235c692133b08cd3430d71069b2f94bf69
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1929481
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1990940
Reviewed-by: Henry Sun <henrysun@google.com>
Commit-Queue: Henry Sun <henrysun@google.com>
Tested-by: Henry Sun <henrysun@google.com>
-rw-r--r-- | extra/usb_updater/gsctool.c | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/extra/usb_updater/gsctool.c b/extra/usb_updater/gsctool.c index 55ad346d84..ce7c03baea 100644 --- a/extra/usb_updater/gsctool.c +++ b/extra/usb_updater/gsctool.c @@ -1079,21 +1079,75 @@ static void send_done(struct usb_endpoint *uep) do_xfer(uep, &out, sizeof(out), &out, 1, 0, NULL); } +/* + * Old cr50 images fail the update if sections are sent out of order. They + * require each block to have an offset greater than the block that was sent + * before. RO has a lower offset than RW, so old cr50 images reject RO if it's + * sent right after RW. + * This offset restriction expires after 60 seconds. Delay the RO update long + * enough for cr50 to not care that it has a lower offset than RW. + * + * Make the delay 65 seconds instead of 60 to cover differences in the speed of + * H1's clock and the host clock. + */ +#define NEXT_SECTION_DELAY 65 + +/* Support for flashing RO immediately after RW was added in 0.3.20/0.4.20. */ +static int supports_reordered_section_updates(struct signed_header_version *rw) +{ + return (rw->epoch || rw->major > 4 || + (rw->major >= 3 && rw->minor >= 20)); +} + /* Returns number of successfully transmitted image sections. */ static int transfer_image(struct transfer_descriptor *td, uint8_t *data, size_t data_len) { - size_t i; + size_t j; int num_txed_sections = 0; + int needs_delay = !supports_reordered_section_updates(&targ.shv[1]); + + /* + * In case both RO and RW updates are required, make sure the RW + * section is updated before the RO. The array below keeps sections + * offsets in the required order. + */ + const size_t update_order[] = {CONFIG_RW_MEM_OFF, + CONFIG_RW_B_MEM_OFF, + CONFIG_RO_MEM_OFF, + CHIP_RO_B_MEM_OFF}; + + for (j = 0; j < ARRAY_SIZE(update_order); j++) { + size_t i; + + for (i = 0; i < ARRAY_SIZE(sections); i++) { + if (sections[i].offset != update_order[j]) + continue; + + if (sections[i].ustatus != needed) + break; + if (num_txed_sections && needs_delay) { + /* + * Delays more than 5 seconds cause the update + * to timeout. End the update before the delay + * and set it up after to recover from the + * timeout. + */ + if (td->ep_type == usb_xfer) + send_done(&td->uep); + printf("Waiting %ds for %s update.\n", + NEXT_SECTION_DELAY, sections[i].name); + sleep(NEXT_SECTION_DELAY); + setup_connection(td); + } - for (i = 0; i < ARRAY_SIZE(sections); i++) - if (sections[i].ustatus == needed) { transfer_section(td, data + sections[i].offset, sections[i].offset, sections[i].size); num_txed_sections++; } + } if (!num_txed_sections) printf("nothing to do\n"); |