Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions hal/mcxa.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
/* Flash driver */
#include "fsl_romapi.h"

#include "hal/armv8m_tz.h"

#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) && !defined(NONSECURE_APP))
# define TZ_SECURE() (1)
#else
# define TZ_SECURE() (0)
#endif

/*!< Core clock frequency: 96000000Hz */
#define BOARD_BOOTCLOCKFRO96M_CORE_CLOCK 96000000UL

Expand Down Expand Up @@ -61,8 +69,32 @@ void hal_init(void)
FLASH_Init(&pflash);
}

#ifdef TZEN
static void mcxa_configure_sau(void)
{
/* Disable SAU */
SAU_CTRL = 0;

/* Configure SAU regions - adjust addresses based on MCXA memory map */
sau_init_region(0, 0x00000000, 0x0003FFFF, 1); /* Secure flash */
sau_init_region(1, 0x00040000, 0x0007FFFF, 0); /* Non-secure flash */
sau_init_region(2, 0x20000000, 0x2001FFFF, 1); /* Secure RAM */
sau_init_region(3, 0x20020000, 0x2003FFFF, 0); /* Non-secure RAM */
sau_init_region(4, 0x40000000, 0x5FFFFFFF, 0); /* Non-secure peripherals */

/* Enable SAU */
SAU_CTRL = SAU_INIT_CTRL_ENABLE;

/* Enable securefault handler */
SCB_SHCSR |= SCB_SHCSR_SECUREFAULT_EN;
}
#endif

void hal_prepare_boot(void)
{
#ifdef TZEN
mcxa_configure_sau();
#endif
}

#endif /* __WOLFBOOT */
Expand All @@ -76,6 +108,10 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};

#if TZ_SECURE()
/* Add TrustZone-specific handling if needed */
#endif

while (len > 0) {
if ((len < 16) || address & 0x0F) {
uint8_t aligned_qword[16];
Expand Down Expand Up @@ -118,6 +154,10 @@ void RAMFUNCTION hal_flash_lock(void)

int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
{
#if TZ_SECURE()
/* Add TrustZone-specific handling if needed */
#endif

while ((address % 4) != 0)
address --;
if (FLASH_EraseSector(&pflash, address, len, kFLASH_ApiEraseKey) != kStatus_Success)
Expand Down
42 changes: 41 additions & 1 deletion hal/mcxw.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
#include "fsl_flash_api.h"
#include "fsl_ccm32k.h"

#include "hal/armv8m_tz.h"

#if (defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) && !defined(NONSECURE_APP))
# define TZ_SECURE() (1)
#else
# define TZ_SECURE() (0)
#endif

#define FLASH FMU0

/*!< Core clock frequency: 48000000Hz */
Expand All @@ -61,9 +69,32 @@ void __assert_func(const char *a, int b, const char *c, const char *d)
}


void hal_prepare_boot(void)
#ifdef TZEN
static void mcxw_configure_sau(void)
{
/* Disable SAU */
SAU_CTRL = 0;

/* Configure SAU regions - adjust addresses based on MCXW memory map */
sau_init_region(0, 0x00000000, 0x0003FFFF, 1); /* Secure flash */
sau_init_region(1, 0x00040000, 0x0007FFFF, 0); /* Non-secure flash */
sau_init_region(2, 0x20000000, 0x2001FFFF, 1); /* Secure RAM */
sau_init_region(3, 0x20020000, 0x2003FFFF, 0); /* Non-secure RAM */
sau_init_region(4, 0x40000000, 0x5FFFFFFF, 0); /* Non-secure peripherals */

/* Enable SAU */
SAU_CTRL = SAU_INIT_CTRL_ENABLE;

/* Enable securefault handler */
SCB_SHCSR |= SCB_SHCSR_SECUREFAULT_EN;
}
#endif

void hal_prepare_boot(void)
{
#ifdef TZEN
mcxw_configure_sau();
#endif
}

#endif
Expand Down Expand Up @@ -91,6 +122,10 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
0xFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
};

#if TZ_SECURE()
/* Add TrustZone-specific handling if needed */
#endif

while (len > 0) {
if ((len < (int)flash_word_size) || (address & (flash_word_size - 1))) {
uint32_t aligned_qword[4];
Expand Down Expand Up @@ -144,6 +179,11 @@ void RAMFUNCTION hal_flash_lock(void)
int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
{
status_t result;

#if TZ_SECURE()
/* Add TrustZone-specific handling if needed */
#endif

if (address % pflash_sector_size)
address -= address % pflash_sector_size;
while (len > 0) {
Expand Down
12 changes: 9 additions & 3 deletions test-app/app_mcxw.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,22 @@ void main(void)
gpio_portA_init(20);

hal_init();
if (bootVer == 1) {

/* Check if we're in testing mode after an update */
if (wolfBoot_get_partition_state(PART_BOOT, NULL) == IMG_STATE_TESTING) {
/* Mark update successful */
wolfBoot_success();
/* Green LED ON, GPIOA port A pin 19 */
GPIO_PinWrite(GPIOA, 19, 0);
}
else if (bootVer == 1) {
/* Blue LED ON, GPIOA port A pin 20 */
GPIO_PinWrite(GPIOA, 20, 0);
wolfBoot_update_trigger();
}
else {
/* Green LED ON, GPIOA port A pin 19 */
GPIO_PinWrite(GPIOA, 19, 0);
/* mark boot successful */
wolfBoot_success();
}

/* busy wait */
Expand Down
Loading