From 41f669023953b3d032078ffc17d80944880d1db7 Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Sat, 17 Dec 2016 13:16:07 -0600 Subject: drivers/spi: fix flash writes at page boundaries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-on: https://review.coreboot.org/17910 Tested-by: build bot (Jenkins) Reviewed-by: Matt DeVillier Reviewed-by: Kyösti Mälkki --- src/drivers/spi/sst.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/drivers/spi/sst.c') diff --git a/src/drivers/spi/sst.c b/src/drivers/spi/sst.c index 70999a6652..e5714540ff 100644 --- a/src/drivers/spi/sst.c +++ b/src/drivers/spi/sst.c @@ -171,7 +171,6 @@ static int sst_write_256(const struct spi_flash *flash, u32 offset, size_t len, u8 cmd[4]; page_size = 256; - byte_addr = offset % page_size; /* If the data is not word aligned, write out leading single byte */ actual = offset % 2; @@ -193,6 +192,7 @@ static int sst_write_256(const struct spi_flash *flash, u32 offset, size_t len, cmd[3] = offset; 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); @@ -224,7 +224,6 @@ static int sst_write_256(const struct spi_flash *flash, u32 offset, size_t len, break; offset += chunk_len; - byte_addr = 0; } done: -- cgit v1.2.3