diff --git a/hal/max32666.c b/hal/max32666.c index 859ece302d..a8fbaf117c 100644 --- a/hal/max32666.c +++ b/hal/max32666.c @@ -105,8 +105,9 @@ static void RAMFUNCTION icc_disable(void) static void RAMFUNCTION icc_enable(void) { - /* Invalidate and re-enable cache */ + /* Invalidate cache, wait for completion, then re-enable */ ICC0_INVALIDATE = 1; + while (!(ICC0_CTRL & ICC_CTRL_RDY)) {} ICC0_CTRL |= ICC_CTRL_EN; while (!(ICC0_CTRL & ICC_CTRL_RDY)) {} } @@ -325,6 +326,14 @@ void hal_init(void) FLC0_CLKDIV = FLC_CLKDIV_VALUE; FLC1_CLKDIV = FLC_CLKDIV_VALUE; + /* Point VTOR at our vector table so faults hit our handlers */ + *(volatile uint32_t *)0xE000ED08 = 0x10000000; + + /* Disable the ICC read buffer via TME before enabling the cache */ + TME_CTRL = 1; + SIR_TRIM_ICC = SIR_TRIM_ICC_RB_DIS; + TME_CTRL = 0; + /* Enable instruction cache */ icc_enable(); diff --git a/hal/max32666.h b/hal/max32666.h index 94f1d734fb..d5fe8d2b2a 100644 --- a/hal/max32666.h +++ b/hal/max32666.h @@ -170,6 +170,11 @@ #define ICC_CTRL_EN (1UL << 0) /* Cache enable */ #define ICC_CTRL_RDY (1UL << 16) /* Cache ready */ +/* Test mode / trim registers */ +#define TME_CTRL (*(volatile uint32_t *)0x40000C00UL) +#define SIR_TRIM_ICC (*(volatile uint32_t *)0x4000040CUL) +#define SIR_TRIM_ICC_RB_DIS (1UL << 6) /* Read buffer disable */ + /* ============== WDT - Watchdog Timer ============== */ /* MSDK: wdt_regs.h */ #define WDT0_BASE 0x40003000UL diff --git a/src/libwolfboot.c b/src/libwolfboot.c index 62fa63e55c..0ac7bd1154 100644 --- a/src/libwolfboot.c +++ b/src/libwolfboot.c @@ -178,7 +178,8 @@ int wolfBoot_initialize_encryption(void) #undef WOLFBOOT_FIXED_PARTITIONS #endif -#if defined(EXT_FLASH) && !defined(WOLFBOOT_NO_PARTITIONS) +#if defined(EXT_FLASH) && !defined(WOLFBOOT_NO_PARTITIONS) && \ + !defined(CUSTOM_PARTITION_TRAILER) static uint32_t ext_cache; #endif diff --git a/src/update_flash.c b/src/update_flash.c index 0cfeaab62e..f40129d855 100644 --- a/src/update_flash.c +++ b/src/update_flash.c @@ -914,6 +914,9 @@ static int RAMFUNCTION wolfBoot_update(int fallback_allowed) int fallback_image = 0; #ifndef DISABLE_BACKUP int rollback_needed = 0; +#ifdef CUSTOM_PARTITION_TRAILER + (void)rollback_needed; +#endif int bootStateRet = -1; uint8_t bootState = 0; #endif @@ -1444,7 +1447,7 @@ void RAMFUNCTION wolfBoot_start(void) int bootRet; #ifndef WOLFBOOT_SELF_UPDATE_MONOLITHIC int updateRet; -#ifndef DISABLE_BACKUP +#if !defined(DISABLE_BACKUP) && !defined(CUSTOM_PARTITION_TRAILER) int resumedFinalErase; #endif uint8_t bootState;