Skip to content

Commit b7fc25c

Browse files
author
Daniel Fedai Larsen
committed
Invalidate cache after flash_write/erase and disable+enable IRQs
1 parent 918fdc5 commit b7fc25c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

hal/imx_rt.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,8 @@ void hal_prepare_boot(void)
831831

832832
#endif /* __WOLFBOOT */
833833

834+
void DCACHE_InvalidateByRange(uint32_t address, uint32_t size_byte);
835+
834836
static int hal_flash_init(void)
835837
{
836838
#ifdef USE_GET_CONFIG
@@ -856,6 +858,7 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
856858
status_t status;
857859
uint32_t wbuf[CONFIG_FLASH_PAGE_SIZE / sizeof(uint32_t)];
858860
int i;
861+
asm volatile("cpsid i");
859862
hal_flash_init(); /* make sure g_bootloaderTree is set */
860863
#ifdef DEBUG_EXT_FLASH
861864
wolfBoot_printf("flash write: addr 0x%x, len %d\n",
@@ -865,9 +868,14 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
865868
memcpy(wbuf, data + i, CONFIG_FLASH_PAGE_SIZE);
866869
status = g_bootloaderTree->flexSpiNorDriver->program(0, FLEXSPI_CONFIG,
867870
(address + i) - FLASH_BASE, wbuf);
871+
DCACHE_InvalidateByRange(address + i, sizeof(wbuf));
868872
if (status != kStatus_Success)
873+
{
874+
asm volatile("cpsie i");
869875
return -1;
876+
}
870877
}
878+
asm volatile("cpsie i");
871879
return 0;
872880
}
873881

@@ -887,8 +895,11 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
887895
wolfBoot_printf("flash erase: addr 0x%x, len %d\n",
888896
address - FLASH_BASE, len);
889897
#endif
898+
asm volatile("cpsid i");
890899
status = g_bootloaderTree->flexSpiNorDriver->erase(0, FLEXSPI_CONFIG,
891900
address - FLASH_BASE, len);
901+
DCACHE_InvalidateByRange(address, len);
902+
asm volatile("cpsie i");
892903
if (status != kStatus_Success)
893904
return -1;
894905
return 0;

0 commit comments

Comments
 (0)