diff options
author | philipchen <philipchen@google.com> | 2016-10-02 16:54:02 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-10-05 20:58:37 -0700 |
commit | 84db5ed037158f091f3bcd1b10bb06d527eff781 (patch) | |
tree | 4ce36806eb69fdc92246a604b8723f734e28aebf | |
parent | 3afd683d683f482f003405c721800e3ba2ccb637 (diff) | |
download | chrome-ec-84db5ed037158f091f3bcd1b10bb06d527eff781.tar.gz |
Enable spi_flash_read to read > SPI_FLASH_MAX_READ_SIZE
BUG=chromium:542789
BRANCH=none
TEST=make buildall
Change-Id: I55bf5bdb09b10be1c522ea4d843690abcc45abb2
Reviewed-on: https://chromium-review.googlesource.com/391867
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r-- | chip/mec1322/flash.c | 16 | ||||
-rw-r--r-- | common/spi_flash.c | 30 |
2 files changed, 22 insertions, 24 deletions
diff --git a/chip/mec1322/flash.c b/chip/mec1322/flash.c index e1cbc3c589..1564b93b48 100644 --- a/chip/mec1322/flash.c +++ b/chip/mec1322/flash.c @@ -36,21 +36,7 @@ struct flash_wp_state { */ int flash_physical_read(int offset, int size, char *data) { - int ret = EC_SUCCESS; - int i, read_size; - - for (i = 0; i < size; i += read_size) { - read_size = MIN((size - i), SPI_FLASH_MAX_READ_SIZE); - ret = spi_flash_read((uint8_t *)(data + i), - offset + i, - read_size); - if (ret != EC_SUCCESS) - break; - /* yield so other tasks get a chance to wake up */ - msleep(1); - } - - return ret; + return spi_flash_read(data, offset, size); } /** diff --git a/common/spi_flash.c b/common/spi_flash.c index c49215a3f4..b9ba3538ac 100644 --- a/common/spi_flash.c +++ b/common/spi_flash.c @@ -143,23 +143,35 @@ int spi_flash_set_status(int reg1, int reg2) /** * Returns the content of SPI flash * - * @param buf Buffer to write flash contents + * @param buf_usr Buffer to write flash contents * @param offset Flash offset to start reading from - * @param bytes Number of bytes to read. Limited by receive buffer to 256. + * @param bytes Number of bytes to read. * * @return EC_SUCCESS, or non-zero if any error. */ int spi_flash_read(uint8_t *buf_usr, unsigned int offset, unsigned int bytes) { - uint8_t cmd[4] = {SPI_FLASH_READ, - (offset >> 16) & 0xFF, - (offset >> 8) & 0xFF, - offset & 0xFF}; - + int i, read_size, ret; + uint8_t cmd[4]; if (offset + bytes > CONFIG_FLASH_SIZE) return EC_ERROR_INVAL; - - return spi_transaction(SPI_FLASH_DEVICE, cmd, 4, buf_usr, bytes); + 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; + read_size = MIN((bytes - i), SPI_FLASH_MAX_READ_SIZE); + ret = spi_transaction(SPI_FLASH_DEVICE, + cmd, + 4, + buf_usr + i, + read_size); + if (ret != EC_SUCCESS) + break; + msleep(1); + } + return ret; } /** |