Skip to content

Commit 3ddfef0

Browse files
nandojvetomi-font
authored andcommitted
[zep fromtree] platform: stm: CMSIS_Driver: Fix stale pFlash state
IS_FLASH_SECURE_OPERATION() reads pFlash.ProcedureOnGoing which is only set inside HAL_FLASH_Program()/HAL_FLASHEx_Erase(), after the unlock call. On boot pFlash is zero-initialized, so IS_FLASH_SECURE_OPERATION() always returns true (secure), causing HAL_FLASH_Unlock_SEC() to be called even for non-secure flash regions. The subsequent HAL erase/write then uses the NSCR register which is still locked, failing with HAL_ERROR and triggering an MCUboot swap panic on image index 1. Replace IS_FLASH_SECURE_OPERATION() with is_range_secure() in the lock/unlock paths, matching the existing pattern used for write_type and EraseInit.TypeErase selection in the same functions. Change-Id: I31ab30bbf4b50212c859d4dbbb7a8c3c62c45fae Signed-off-by: BUDKE Gerson Fernando <gerson.budke@leica-geosystems.com> (cherry picked from commit e3ee916)
1 parent 3a128df commit 3ddfef0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

‎platform/ext/target/stm/common/hal/CMSIS_Driver/low_level_flash.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ static int32_t Flash_ProgramData(uint32_t addr,
569569
stm32_icache_disable();
570570
#endif /* TFM_ICACHE_ENABLE */
571571

572-
if (IS_FLASH_SECURE_OPERATION()) {
572+
if (is_range_secure(&ARM_FLASH0_DEV, addr, cnt)) {
573573
HAL_FLASH_Unlock_SEC();
574574
} else {
575575
HAL_FLASH_Unlock_NS();
@@ -603,7 +603,7 @@ static int32_t Flash_ProgramData(uint32_t addr,
603603

604604
ARM_FLASH0_STATUS.busy = DRIVER_STATUS_IDLE;
605605

606-
if (IS_FLASH_SECURE_OPERATION()) {
606+
if (is_range_secure(&ARM_FLASH0_DEV, addr, cnt)) {
607607
HAL_FLASH_Lock_SEC();
608608
} else {
609609
HAL_FLASH_Lock_NS();
@@ -711,15 +711,15 @@ static int32_t Flash_EraseSector(uint32_t addr)
711711
#endif /* TFM_ICACHE_ENABLE */
712712

713713
ARM_FLASH0_STATUS.error = DRIVER_STATUS_NO_ERROR;
714-
if (IS_FLASH_SECURE_OPERATION()) {
714+
if (is_range_secure(&ARM_FLASH0_DEV, addr, 4)) {
715715
HAL_FLASH_Unlock_SEC();
716716
} else {
717717
HAL_FLASH_Unlock_NS();
718718
}
719719
ARM_FLASH0_STATUS.busy = DRIVER_STATUS_BUSY;
720720
err = HAL_FLASHEx_Erase(&EraseInit, &pageError);
721721
ARM_FLASH0_STATUS.busy = DRIVER_STATUS_IDLE;
722-
if (IS_FLASH_SECURE_OPERATION()) {
722+
if (is_range_secure(&ARM_FLASH0_DEV, addr, 4)) {
723723
HAL_FLASH_Lock_SEC();
724724
} else {
725725
HAL_FLASH_Lock_NS();

0 commit comments

Comments
 (0)