mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
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>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user