summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-11-01 16:23:48 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-11-02 01:07:06 +0000
commit874effa445584c04909735b96e082cc9c5787883 (patch)
treed329b861cf1098e93ef6763dba9035b01d85d9cf
parent23ff7f6517ede8faa6fb257cb2740b7d22d153de (diff)
downloadchrome-ec-874effa445584c04909735b96e082cc9c5787883.tar.gz
lm4: Verify data buffer is aligned for flash writes
All the current data buffers *are* aligned, but we should check anyway just to avoid unpleasant surprises in the future. This matches what we do on STM32L. On STM32F, we copy a byte at a time so alignment of the source data doesn't matter. BUG=chrome-os-partner:9526 BRANCH=none TEST=manual flasherase 0x20000 0x1000 flashwrite 0x20000 0x200 -> succeeds flashwrite 0x20201 0x200 -> fails Change-Id: Id1a0fd8f6871e1fcdc3f55ec25eea40f33b5214c Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/175532 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r--chip/lm4/flash.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/chip/lm4/flash.c b/chip/lm4/flash.c
index d2d670c8ef..62e04ec8c9 100644
--- a/chip/lm4/flash.c
+++ b/chip/lm4/flash.c
@@ -96,6 +96,10 @@ int flash_physical_write(int offset, int size, const char *data)
if (all_protected)
return EC_ERROR_ACCESS_DENIED;
+ /* Fail if offset, size, and data aren't at least word-aligned */
+ if ((offset | size | (uint32_t)(uintptr_t)data) & 3)
+ return EC_ERROR_INVAL;
+
/* Get initial write buffer index and page */
LM4_FLASH_FMA = offset & ~(FLASH_FWB_BYTES - 1);
i = (offset >> 2) & (FLASH_FWB_WORDS - 1);