fast_spi: Copy mmio flash to cache when reading
The flash_rewrite operation modifies the contents read from flash_read
in place so copy the data to the cache before returning from
fast_spi_flash_read
BUG=b:124297157
TEST=Tested setting vendor data on arcada
BRANCH=none
Change-Id: I37dbd6fa3899322ce0b52dbd39c3ab9b68dca13c
Signed-off-by: Mathew King <mathewk@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1552021
Reviewed-by: Julius Werner <jwerner@chromium.org>
diff --git a/src/drivers/flash/fast_spi.c b/src/drivers/flash/fast_spi.c
index c758ec1..70ac858 100644
--- a/src/drivers/flash/fast_spi.c
+++ b/src/drivers/flash/fast_spi.c
@@ -155,12 +155,19 @@
assert(offset + size <= flash->rom_size);
/*
- * If the read is entirely within the memory map just return a pointer
- * within the memory mapped region
+ * If the read is entirely within the memory map just copy the data
+ *
+ * We can't just return the pointer because the flash_rewrite operation
+ * will modify this data
*/
- if (offset >= flash->mmio_offset && offset + size < flash->mmio_end)
- return (void *)(uintptr_t)(flash->mmio_address -
- flash->mmio_offset + offset);
+ if (offset >= flash->mmio_offset && offset + size < flash->mmio_end) {
+ uintptr_t mmio_address =
+ (uintptr_t)(flash->mmio_address -
+ flash->mmio_offset + offset);
+ memcpy(data, (void *)mmio_address, size);
+
+ return data;
+ }
while (size) {
size_t xfer_len = get_xfer_len(offset, size);