Skip to content

Commit 14f63ba

Browse files
committed
drivers/flash/soc_flash_mcux: adjust alignment logic
The current alignment logic does not work as expected if given unaligned values, resulting in a skip of the first word. The length also has to take into account the starting address: for example, asking for 2 bytes at offset 3 should actually check 8 bytes. This patch adjusts the logic so that it always includes the first and the last word of the input area. Signed-off-by: Luca Burelli <[email protected]>
1 parent 9d78c65 commit 14f63ba

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/flash/soc_flash_mcux.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ static int flash_mcux_read(const struct device *dev, off_t offset,
221221
/* Check id the ECC issue is due to the Flash being erased
222222
* ("addr" and "len" must be word-aligned for this call).
223223
*/
224-
rc = FLASH_VerifyErase(&priv->config, ((addr + 0x3) & ~0x3), ((len + 0x3) & ~0x3));
224+
rc = FLASH_VerifyErase(&priv->config,
225+
ROUND_DOWN(addr, 4),
226+
ROUND_DOWN(addr + len + 3, 4) - ROUND_DOWN(addr, 4));
225227
if (rc == kStatus_FLASH_Success) {
226228
rc = -ENODATA;
227229
} else {

0 commit comments

Comments
 (0)