From 36679bb544f84307e9d93a36bf729c1b25ce3db2 Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Tue, 23 Jan 2018 14:04:22 +0100 Subject: stm32mon: skip empty blocks Skip the empty blocks when writing even if they are in the middle of the firmware. This greatly improves flashing speed when the firmware contains a signature at the end of the RW. Signed-off-by: Vincent Palatin BRANCH=none BUG=b:36125319 TEST=./util/flash_ec --board=meowth_fp Change-Id: I3cd1c1bd2670be23d3d9daf9b87d9af0bdfc8963 Reviewed-on: https://chromium-review.googlesource.com/880956 Commit-Ready: Vincent Palatin Tested-by: Vincent Palatin Reviewed-by: Alexandru M Stan --- util/stm32mon.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/util/stm32mon.c b/util/stm32mon.c index c4c5de4fbf..8e7c8b31da 100644 --- a/util/stm32mon.c +++ b/util/stm32mon.c @@ -568,7 +568,8 @@ int command_read_mem(int fd, uint32_t address, uint32_t size, uint8_t *buffer) int command_write_mem(int fd, uint32_t address, uint32_t size, uint8_t *buffer) { - int res; + int res = 0; + int i; uint32_t remaining = size; uint32_t addr_be; uint32_t cnt; @@ -580,17 +581,22 @@ int command_write_mem(int fd, uint32_t address, uint32_t size, uint8_t *buffer) while (remaining) { cnt = (remaining > PAGE_SIZE) ? PAGE_SIZE : remaining; - addr_be = htonl(address); - outbuf[0] = cnt - 1; - loads[1].size = cnt + 1; - memcpy(outbuf + 1, buffer, cnt); - - draw_spinner(remaining, size); - fflush(stdout); - res = send_command(fd, CMD_WRITEMEM, loads, 2, NULL, 0, 1); - if (res < 0) - return -EIO; - + /* skip empty blocks to save time */ + for (i = 0; i < cnt && buffer[i] == 0xff; i++) + ; + if (i != cnt) { + addr_be = htonl(address); + outbuf[0] = cnt - 1; + loads[1].size = cnt + 1; + memcpy(outbuf + 1, buffer, cnt); + + draw_spinner(remaining, size); + fflush(stdout); + res = send_command(fd, CMD_WRITEMEM, loads, 2, + NULL, 0, 1); + if (res < 0) + return -EIO; + } buffer += cnt; address += cnt; remaining -= cnt; -- cgit v1.2.1