drivers: flash: mcux flexspi nor: Fix write on arbitrary offset
If a write offset isn't a multiple of the nor page size, and the length is too large to fit within a single page, it could wrap around in that page. Tested on i.MX RT1064 internal flash using NVS settings Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
This commit is contained in:
parent
dea03d4c2d
commit
aedc51aca8
2 changed files with 10 additions and 2 deletions
|
@ -335,7 +335,11 @@ static int flash_flexspi_nor_write(const struct device *dev, off_t offset,
|
||||||
}
|
}
|
||||||
|
|
||||||
while (len) {
|
while (len) {
|
||||||
i = MIN(SPI_NOR_PAGE_SIZE, len);
|
/* If the offset isn't a multiple of the NOR page size, we first need
|
||||||
|
* to write the remaining part that fits, otherwise the write could
|
||||||
|
* be wrapped around within the same page
|
||||||
|
*/
|
||||||
|
i = MIN(SPI_NOR_PAGE_SIZE - (offset % SPI_NOR_PAGE_SIZE), len);
|
||||||
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_NOR_WRITE_BUFFER
|
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_NOR_WRITE_BUFFER
|
||||||
memcpy(nor_write_buf, src, i);
|
memcpy(nor_write_buf, src, i);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -349,7 +349,11 @@ static int flash_flexspi_nor_write(const struct device *dev, off_t offset,
|
||||||
}
|
}
|
||||||
|
|
||||||
while (len) {
|
while (len) {
|
||||||
i = MIN(SPI_NOR_PAGE_SIZE, len);
|
/* If the offset isn't a multiple of the NOR page size, we first need
|
||||||
|
* to write the remaining part that fits, otherwise the write could
|
||||||
|
* be wrapped around within the same page
|
||||||
|
*/
|
||||||
|
i = MIN(SPI_NOR_PAGE_SIZE - (offset % SPI_NOR_PAGE_SIZE), len);
|
||||||
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_NOR_WRITE_BUFFER
|
#ifdef CONFIG_FLASH_MCUX_FLEXSPI_NOR_WRITE_BUFFER
|
||||||
memcpy(nor_write_buf, src, i);
|
memcpy(nor_write_buf, src, i);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue