summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chip/mec1322/flash.c16
-rw-r--r--common/spi_flash.c30
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;
}
/**