diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2017-12-20 10:15:39 +0100 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-01-10 15:44:28 -0800 |
commit | 906a1b513883ec6c747d0aa45df3163977942eef (patch) | |
tree | 14cf37f1a70349b2137a00a2938722e165fd7d28 | |
parent | 9a89170ed4878df8a04cb7d82ea3afc102179107 (diff) | |
download | chrome-ec-906a1b513883ec6c747d0aa45df3163977942eef.tar.gz |
stm32mon: change erase timeout
On some chips, the full erase operation can take really long:
e.g 13s for 2MB mass-erase on the STM32H7x3 family.
Add a new mechanism retrying the ACK detection rather than extending
the default timeout which would imply very slow behavior in other cases
(e.g. connection).
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
BRANCH=none
BUG=b:67081508
TEST=flash_ec --board=meowth_fp
Change-Id: I428f56341c31c327debb9a3d2eba9b12c768ba86
Reviewed-on: https://chromium-review.googlesource.com/856976
Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r-- | util/stm32mon.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/util/stm32mon.c b/util/stm32mon.c index f8d1cb8542..f5952c2fe7 100644 --- a/util/stm32mon.c +++ b/util/stm32mon.c @@ -98,6 +98,7 @@ struct stm32_def { }; #define DEFAULT_TIMEOUT 4 /* seconds */ +#define EXT_ERASE_TIMEOUT 20 /* seconds */ #define DEFAULT_BAUDRATE B38400 #define PAGE_SIZE 256 #define INVALID_I2C_ADAPTER -1 @@ -378,11 +379,14 @@ int send_command(int fd, uint8_t cmd, payload_t *loads, int cnt, } /* Wait for the ACK */ - if (wait_for_ack(fd) < 0) { - fprintf(stderr, "payload %d ACK failed for CMD%02x\n", + res = wait_for_ack(fd); + if (res < 0) { + if (res != -ETIMEDOUT) + fprintf(stderr, + "payload %d ACK failed for CMD%02x\n", c, cmd); free(data); - return -1; + return res; } free(data); } @@ -600,6 +604,7 @@ int command_ext_erase(int fd, uint16_t count, uint16_t start) uint16_t count_be = htons(count); payload_t load = { 2, (uint8_t *)&count_be }; uint16_t *pages = NULL; + int retries = EXT_ERASE_TIMEOUT / DEFAULT_TIMEOUT; if (count < 0xfff0) { int i; @@ -614,7 +619,11 @@ int command_ext_erase(int fd, uint16_t count, uint16_t start) pages[i+1] = htons(start + i); } + printf("Erasing...\n"); res = send_command(fd, CMD_EXTERASE, &load, 1, NULL, 0, 1); + /* Erase can take long time (e.g. 13s+ on STM32H7) */ + while ((res == -ETIMEDOUT) && --retries) + res = wait_for_ack(fd); if (res >= 0) printf("Flash erased.\n"); |