This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 5384299  hw: kinetis: Only allow aligned block erases
     new 4c5b1fa  Merge pull request #2523 from utzig/fix-qspi-block-erase
5384299 is described below

commit 5384299facac74b6213270cfc740d3db954a2f1c
Author: Fabio Utzig <ut...@apache.org>
AuthorDate: Thu Mar 11 09:38:48 2021 -0300

    hw: kinetis: Only allow aligned block erases
    
    This fixes an issue where an erase command with sizes larger or equal
    than a block erase (32K or 64K) could delete the whole block even when
    it was not aligned. A block erase command is accepted for any address
    inside the block, but if a flash area is not aligned to this block size,
    it will result in erasing data which are not part of the expected
    requested range. With this change the alignment must be valid when doing
    block erases.
    
    Signed-off-by: Fabio Utzig <ut...@apache.org>
---
 hw/mcu/nxp/kinetis/src/hal_qspi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/mcu/nxp/kinetis/src/hal_qspi.c 
b/hw/mcu/nxp/kinetis/src/hal_qspi.c
index d688283..cea45a3 100644
--- a/hw/mcu/nxp/kinetis/src/hal_qspi.c
+++ b/hw/mcu/nxp/kinetis/src/hal_qspi.c
@@ -320,10 +320,10 @@ nxp_qspi_erase(const struct hal_flash *dev,
         QSPI_ClearFifo(QuadSPI0, kQSPI_TxFifo);
         QSPI_SetIPCommandAddress(QuadSPI0, FSL_FEATURE_QSPI_AMBA_BASE + 
address);
         cmd_write_enable();
-        if (size >= SZ64K) {
+        if (size >= SZ64K && (address % SZ64K) == 0) {
             QSPI_ExecuteIPCommand(QuadSPI0, LUT_CMD_ERASE_BLOCK64K);
             erased_size = SZ64K;
-        } else if (size >= SZ32K) {
+        } else if (size >= SZ32K && (address % SZ32K) == 0) {
             QSPI_ExecuteIPCommand(QuadSPI0, LUT_CMD_ERASE_BLOCK32K);
             erased_size = SZ32K;
         } else {

Reply via email to