Skip to content

Commit 9526fbb

Browse files
author
Daniel Fedai Larsen
committed
Fix compile error and clean up
1 parent b7fc25c commit 9526fbb

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

arch.mk

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ ifeq ($(TARGET),imx_rt)
382382
-I$(MCUXPRESSO_DRIVERS) \
383383
-I$(MCUXPRESSO_DRIVERS)/drivers \
384384
-I$(MCUXPRESSO)/drivers \
385+
-I$(MCUXPRESSO)/drivers/cache/armv7-m7 \
385386
-I$(MCUXPRESSO)/drivers/common \
386387
-I$(MCUXPRESSO)/drivers/flexspi \
387388
-I$(MCUXPRESSO)/drivers/lpuart \
@@ -405,7 +406,8 @@ ifeq ($(TARGET),imx_rt)
405406
-I$(MCUXPRESSO)/utilities/debug_console
406407
OBJS+=\
407408
$(MCUXPRESSO_DRIVERS)/drivers/fsl_clock.o \
408-
$(MCUXPRESSO)/drivers/flexspi/fsl_flexspi.o
409+
$(MCUXPRESSO)/drivers/flexspi/fsl_flexspi.o \
410+
$(MCUXPRESSO)/drivers/cache/armv7-m7/fsl_cache.o
409411
ifeq ($(DEBUG_UART),1)
410412
OBJS+= $(MCUXPRESSO)/drivers/lpuart/fsl_lpuart.o
411413
endif
@@ -415,7 +417,8 @@ ifeq ($(TARGET),imx_rt)
415417
-I$(MCUXPRESSO_DRIVERS)/utilities/debug_console
416418
OBJS+=\
417419
$(MCUXPRESSO_DRIVERS)/drivers/fsl_clock.o \
418-
$(MCUXPRESSO_DRIVERS)/drivers/fsl_flexspi.o
420+
$(MCUXPRESSO_DRIVERS)/drivers/fsl_flexspi.o \
421+
$(MCUXPRESSO_DRIVERS)/drivers/fsl_cache.o
419422
ifeq ($(DEBUG_UART),1)
420423
OBJS+= $(MCUXPRESSO_DRIVERS)/drivers/fsl_lpuart.o
421424
endif

hal/imx_rt.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <target.h>
2727
#include "image.h"
2828
#include "printf.h"
29+
#include "fsl_cache.h"
2930
#include "fsl_common.h"
3031
#include "fsl_iomuxc.h"
3132
#include "fsl_nor_flash.h"
@@ -831,8 +832,6 @@ void hal_prepare_boot(void)
831832

832833
#endif /* __WOLFBOOT */
833834

834-
void DCACHE_InvalidateByRange(uint32_t address, uint32_t size_byte);
835-
836835
static int hal_flash_init(void)
837836
{
838837
#ifdef USE_GET_CONFIG
@@ -858,16 +857,24 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
858857
status_t status;
859858
uint32_t wbuf[CONFIG_FLASH_PAGE_SIZE / sizeof(uint32_t)];
860859
int i;
861-
asm volatile("cpsid i");
862860
hal_flash_init(); /* make sure g_bootloaderTree is set */
863861
#ifdef DEBUG_EXT_FLASH
864862
wolfBoot_printf("flash write: addr 0x%x, len %d\n",
865863
address - FLASH_BASE, len);
866864
#endif
865+
/**
866+
* Disable interrupts before accessing flash when using XIP
867+
* (note 4 p.279 in i.MX RT1060 Processor Reference Manual, Rev. 3, 07/2021)
868+
*/
869+
asm volatile("cpsid i");
867870
for (i = 0; i < len; i+= CONFIG_FLASH_PAGE_SIZE) {
868871
memcpy(wbuf, data + i, CONFIG_FLASH_PAGE_SIZE);
869872
status = g_bootloaderTree->flexSpiNorDriver->program(0, FLEXSPI_CONFIG,
870873
(address + i) - FLASH_BASE, wbuf);
874+
/**
875+
* Flash is memory mapped, so the address range must be invalidated in data cache
876+
* to ensure coherency between flash and cache
877+
*/
871878
DCACHE_InvalidateByRange(address + i, sizeof(wbuf));
872879
if (status != kStatus_Success)
873880
{
@@ -895,9 +902,17 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
895902
wolfBoot_printf("flash erase: addr 0x%x, len %d\n",
896903
address - FLASH_BASE, len);
897904
#endif
905+
/**
906+
* Disable interrupts before accessing flash when using XIP
907+
* (note 4 p.279 in i.MX RT1060 Processor Reference Manual, Rev. 3, 07/2021)
908+
*/
898909
asm volatile("cpsid i");
899910
status = g_bootloaderTree->flexSpiNorDriver->erase(0, FLEXSPI_CONFIG,
900911
address - FLASH_BASE, len);
912+
/**
913+
* Flash is memory mapped, so the address range must be invalidated in data cache
914+
* to ensure coherency between flash and cache
915+
*/
901916
DCACHE_InvalidateByRange(address, len);
902917
asm volatile("cpsie i");
903918
if (status != kStatus_Success)

0 commit comments

Comments
 (0)