diff options
author | scott worley <scott.worley@microchip.corp-partner.google.com> | 2018-05-01 08:50:37 -0400 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-05-18 20:08:16 -0700 |
commit | a91ca602150f1bf5c98b00ad4b75f33c7a9f3fc8 (patch) | |
tree | 778c2e75ffe538599ba522d8ad4db7f97d409934 | |
parent | 23947f1d3b79479efa11c7caffaa35cd4f314926 (diff) | |
download | chrome-ec-a91ca602150f1bf5c98b00ad4b75f33c7a9f3fc8.tar.gz |
flash: Fix offset bug in spi_flash_read
Observed VBOOT hash failure for EC_RW. Function
spi_flash_read with size > SPI_FLASH_MAX_READ_LEN
is incorrectly incrementing the offset. For example:
0, 0x100, 0x300, 0x600, all with read size = 256.
BUG=
BRANCH=any EC using SPI flash
TEST=Trigger VBOOT hash re-calculation using EC
console hash rw command. Second test program
SPI flash with known test pattern longer than
SPI_FLASH_MAX_READ_LEN and read using EC
console flashread.
Change-Id: I5fda47f132f64b12044b94663a19d889f1c2b32a
Reviewed-on: https://chromium-review.googlesource.com/1036258
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Scott Worley <scott.worley@microchip.corp-partner.google.com>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | common/spi_flash.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/common/spi_flash.c b/common/spi_flash.c index 2465a18830..70e3d89c49 100644 --- a/common/spi_flash.c +++ b/common/spi_flash.c @@ -151,16 +151,16 @@ int spi_flash_set_status(int reg1, int reg2) */ int spi_flash_read(uint8_t *buf_usr, unsigned int offset, unsigned int bytes) { - int i, read_size, ret; + int i, read_size, ret, spi_addr; uint8_t cmd[4]; if (offset + bytes > CONFIG_FLASH_SIZE) return EC_ERROR_INVAL; cmd[0] = SPI_FLASH_READ; for (i = 0; i < bytes; i += read_size) { - offset += i; - cmd[1] = (offset >> 16) & 0xFF; - cmd[2] = (offset >> 8) & 0xFF; - cmd[3] = offset & 0xFF; + spi_addr = offset + i; + cmd[1] = (spi_addr >> 16) & 0xFF; + cmd[2] = (spi_addr >> 8) & 0xFF; + cmd[3] = spi_addr & 0xFF; read_size = MIN((bytes - i), SPI_FLASH_MAX_READ_SIZE); ret = spi_transaction(SPI_FLASH_DEVICE, cmd, |