diff --git a/arch/arm/src/lc823450/Make.defs b/arch/arm/src/lc823450/Make.defs index 6fbf42aef2..d03f95acc6 100644 --- a/arch/arm/src/lc823450/Make.defs +++ b/arch/arm/src/lc823450/Make.defs @@ -63,7 +63,7 @@ CMN_CSRCS += up_ramvec_initialize.c up_ramvec_attach.c endif ifeq ($(CONFIG_BUILD_PROTECTED),y) -CMN_CSRCS += up_mpu.c up_task_start.c up_pthread_start.c +CMN_CSRCS += up_task_start.c up_pthread_start.c ifneq ($(CONFIG_DISABLE_SIGNALS),y) CMN_CSRCS += up_signal_dispatch.c CMN_UASRCS += up_signal_handler.S @@ -184,5 +184,9 @@ endif ifeq ($(CONFIG_BUILD_PROTECTED),y) CHIP_CSRCS += lc823450_userspace.c +endif + +ifeq ($(CONFIG_ARM_MPU),y) +CMN_CSRCS += up_mpu.c CHIP_CSRCS += lc823450_mpuinit2.c endif diff --git a/arch/arm/src/lc823450/lc823450_cpustart.c b/arch/arm/src/lc823450/lc823450_cpustart.c index 82f857e05c..d3aa51cced 100644 --- a/arch/arm/src/lc823450/lc823450_cpustart.c +++ b/arch/arm/src/lc823450/lc823450_cpustart.c @@ -60,6 +60,10 @@ #include "lc823450_syscontrol.h" +#if defined(CONFIG_BUILD_FLAT) && defined(CONFIG_ARM_MPU) +# include "lc823450_mpuinit2.h" +#endif + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -113,6 +117,13 @@ static void cpu1_boot(void) { putreg32((uint32_t)&_stext, NVIC_VECTAB); /* use CPU0 vectors */ +#if defined(CONFIG_BUILD_FLAT) && defined(CONFIG_ARM_MPU) + lc823450_mpuinitialize(); + + irq_attach(LC823450_IRQ_MEMFAULT, up_memfault, NULL); + up_enable_irq(LC823450_IRQ_MEMFAULT); +#endif + irq_attach(LC823450_IRQ_CTXM3_01, lc823450_pause_handler, NULL); up_enable_irq(LC823450_IRQ_CTXM3_01); } diff --git a/arch/arm/src/lc823450/lc823450_irq.c b/arch/arm/src/lc823450/lc823450_irq.c index 7faf0bded8..a2982c6549 100644 --- a/arch/arm/src/lc823450/lc823450_irq.c +++ b/arch/arm/src/lc823450/lc823450_irq.c @@ -547,7 +547,7 @@ void up_irqinitialize(void) * Fault handler. */ -#ifdef CONFIG_ARMV7M_MPU +#ifdef CONFIG_ARM_MPU irq_attach(LC823450_IRQ_MEMFAULT, up_memfault, NULL); up_enable_irq(LC823450_IRQ_MEMFAULT); #endif @@ -556,9 +556,6 @@ void up_irqinitialize(void) #ifdef CONFIG_DEBUG irq_attach(LC823450_IRQ_NMI, lc823450_nmi, NULL); -#ifndef CONFIG_ARMV7M_MPU - irq_attach(LC823450_IRQ_MEMFAULT, up_memfault, NULL); -#endif irq_attach(LC823450_IRQ_BUSFAULT, lc823450_busfault, NULL); irq_attach(LC823450_IRQ_USAGEFAULT, lc823450_usagefault, NULL); irq_attach(LC823450_IRQ_PENDSV, lc823450_pendsv, NULL); diff --git a/arch/arm/src/lc823450/lc823450_mpuinit2.c b/arch/arm/src/lc823450/lc823450_mpuinit2.c index 91eb170f06..04ff22d22e 100644 --- a/arch/arm/src/lc823450/lc823450_mpuinit2.c +++ b/arch/arm/src/lc823450/lc823450_mpuinit2.c @@ -46,9 +46,10 @@ #include #include "mpu.h" +#include "up_internal.h" #include "lc823450_mpuinit2.h" -#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_ARM_MPU) +#ifdef CONFIG_ARM_MPU /**************************************************************************** * Pre-processor Definitions @@ -85,6 +86,7 @@ void lc823450_mpuinitialize(void) { +#ifdef CONFIG_BUILD_PROTECTED uintptr_t datastart = MIN(USERSPACE->us_datastart, USERSPACE->us_bssstart); uintptr_t dataend = MAX(USERSPACE->us_dataend, USERSPACE->us_bssend); @@ -101,6 +103,19 @@ void lc823450_mpuinitialize(void) USERSPACE->us_textend - USERSPACE->us_textstart); mpu_user_intsram(datastart, dataend - datastart); +#endif + +#ifdef CONFIG_BUILD_FLAT + uint32_t size = (uint32_t)((uint32_t)&_eronly - (uint32_t)&_stext); + + /* 128KB align */ + + size = size & 0x20000; + + /* Protect text area in SRAM as privileged flash */ + + mpu_priv_flash((uintptr_t)&_stext, size); +#endif /* Then enable the MPU */ @@ -122,5 +137,5 @@ void lc823450_mpu_uheap(uintptr_t start, size_t size) mpu_user_intsram(start, size); } -#endif /* CONFIG_BUILD_PROTECTED && CONFIG_ARM_MPU */ +#endif /* CONFIG_ARM_MPU */ diff --git a/arch/arm/src/lc823450/lc823450_mpuinit2.h b/arch/arm/src/lc823450/lc823450_mpuinit2.h index 5252c31e21..8ae7d71a85 100644 --- a/arch/arm/src/lc823450/lc823450_mpuinit2.h +++ b/arch/arm/src/lc823450/lc823450_mpuinit2.h @@ -69,7 +69,7 @@ * ****************************************************************************/ -#ifdef CONFIG_BUILD_PROTECTED +#ifdef CONFIG_ARM_MPU void lc823450_mpuinitialize(void); #else # define lc823450_mpuinitialize() @@ -83,7 +83,7 @@ void lc823450_mpuinitialize(void); * ****************************************************************************/ -#ifdef CONFIG_BUILD_PROTECTED +#ifdef CONFIG_ARM_MPU void lc823450_mpu_uheap(uintptr_t start, size_t size); #else # define lc823450_mpu_uheap(start,size) diff --git a/arch/arm/src/lc823450/lc823450_start.c b/arch/arm/src/lc823450/lc823450_start.c index a424210eb3..a98d21ce89 100644 --- a/arch/arm/src/lc823450/lc823450_start.c +++ b/arch/arm/src/lc823450/lc823450_start.c @@ -351,6 +351,9 @@ void __start(void) #ifdef CONFIG_BUILD_PROTECTED lc823450_userspace(); +#endif +#if defined(CONFIG_BUILD_FLAT) && defined(CONFIG_ARM_MPU) + lc823450_mpuinitialize(); #endif showprogress('E');