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 <l.burelli@arduino.cc>
This commit is contained in:
Luca Burelli 2024-11-05 11:30:37 +01:00 committed by Mahesh Mahadevan
parent 20cd3a3f09
commit 33def3036a
1 changed files with 3 additions and 1 deletions

View File

@ -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 {