Skip to content

Commit

Permalink
drivers/flash/soc_flash_mcux: adjust alignment logic
Browse files Browse the repository at this point in the history
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 <l.burelli@arduino.cc>
  • Loading branch information
pillo79 authored and mmahadevan108 committed Nov 7, 2024
1 parent 20cd3a3 commit 33def30
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/flash/soc_flash_mcux.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ static int flash_mcux_read(const struct device *dev, off_t offset,
/* Check id the ECC issue is due to the Flash being erased
* ("addr" and "len" must be word-aligned for this call).
*/
rc = FLASH_VerifyErase(&priv->config, ((addr + 0x3) & ~0x3), ((len + 0x3) & ~0x3));
rc = FLASH_VerifyErase(&priv->config,
ROUND_DOWN(addr, 4),
ROUND_DOWN(addr + len + 3, 4) - ROUND_DOWN(addr, 4));
if (rc == kStatus_FLASH_Success) {
rc = -ENODATA;
} else {
Expand Down

0 comments on commit 33def30

Please sign in to comment.