summaryrefslogtreecommitdiff
path: root/src/drivers/spi/spansion.c
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2016-12-17 13:16:07 -0600
committerAaron Durbin <adurbin@chromium.org>2016-12-19 22:34:52 +0100
commit41f669023953b3d032078ffc17d80944880d1db7 (patch)
treeed5243a97c69a8d55c5fb7bd748fa158d36008a4 /src/drivers/spi/spansion.c
parent06cd903566b57af4698089de4a67dd49bf7e56ed (diff)
downloadcoreboot-41f669023953b3d032078ffc17d80944880d1db7.tar.xz
drivers/spi: fix flash writes at page boundaries
There was an assumption that all SPI controllers could consume a full page of data to write. However, that assumption doesn't hold when spi_crop_chunk() indicates sizes smaller than page size. If the requested offset isn't page aligned from the start then writes will fail corrupting data since a page boundary isn't honored. The spansion driver needed quite a bit more work to honor the spi_crop_chunk() result. It now mimics the other driver's code. Also, needed to add spi_crop_chunk() to marvell/bg4cd SoC to make google/cosmos build. SPI obviously doesn't work on that platform, but it fixes the build error. Change-Id: I93e24a5a717adcee45a017c164bd960f4592ad50 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/17910 Tested-by: build bot (Jenkins) Reviewed-by: Matt DeVillier <matt.devillier@gmail.com> Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Diffstat (limited to 'src/drivers/spi/spansion.c')
-rw-r--r--src/drivers/spi/spansion.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/drivers/spi/spansion.c b/src/drivers/spi/spansion.c
index 091f7ae460..7f57d21e14 100644
--- a/src/drivers/spi/spansion.c
+++ b/src/drivers/spi/spansion.c
@@ -205,7 +205,6 @@ static int spansion_write(const struct spi_flash *flash, u32 offset, size_t len,
const void *buf)
{
struct spansion_spi_flash *spsn = to_spansion_spi_flash(flash);
- unsigned long page_addr;
unsigned long byte_addr;
unsigned long page_size;
size_t chunk_len;
@@ -214,16 +213,16 @@ static int spansion_write(const struct spi_flash *flash, u32 offset, size_t len,
u8 cmd[4];
page_size = spsn->params->page_size;
- page_addr = offset / page_size;
- byte_addr = offset % page_size;
for (actual = 0; actual < len; actual += chunk_len) {
+ byte_addr = offset % page_size;
chunk_len = min(len - actual, page_size - byte_addr);
+ chunk_len = spi_crop_chunk(sizeof(cmd), chunk_len);
cmd[0] = CMD_S25FLXX_PP;
- cmd[1] = page_addr >> 8;
- cmd[2] = page_addr;
- cmd[3] = byte_addr;
+ cmd[1] = (offset >> 16) & 0xff;
+ cmd[2] = (offset >> 8) & 0xff;
+ cmd[3] = offset & 0xff;
#if CONFIG_DEBUG_SPI_FLASH
printk(BIOS_SPEW, "PP: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x }"
@@ -248,8 +247,7 @@ static int spansion_write(const struct spi_flash *flash, u32 offset, size_t len,
if (ret)
break;
- page_addr++;
- byte_addr = 0;
+ offset += chunk_len;
}
#if CONFIG_DEBUG_SPI_FLASH