Skip to content

Commit d6b5023

Browse files
mmahadevan108ioannisg
authored andcommitted
arch: arm: Setup Static MPU regions earlier in boot flow
Setup the static MPU regions before PRE_KERNEL_1 and PRE_KERNEL_2 functions are invoked. This will setup the MPU for SRAM regions in case code relocated to SRAM is invoked from any of these functions. Signed-off-by: Mahesh Mahadevan <[email protected]>
1 parent 1b36c6c commit d6b5023

File tree

4 files changed

+14
-27
lines changed

4 files changed

+14
-27
lines changed

arch/arm/core/aarch32/cortex_m/mpu/arm_mpu.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void arm_core_mpu_configure_dynamic_mpu_regions(const struct z_arm_mpu_partition
302302
* This function provides the default configuration mechanism for the Memory
303303
* Protection Unit (MPU).
304304
*/
305-
static int arm_mpu_init(const struct device *arg)
305+
int z_arm_mpu_init(void)
306306
{
307307
uint32_t r_index;
308308

@@ -416,8 +416,6 @@ static int arm_mpu_init(const struct device *arg)
416416
NUM_MPU_REGIONS,
417417
"Invalid number of MPU regions\n");
418418
#endif /* CORTEX_M0PLUS || CPU_CORTEX_M3 || CPU_CORTEX_M4 */
419+
419420
return 0;
420421
}
421-
422-
SYS_INIT(arm_mpu_init, PRE_KERNEL_1,
423-
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);

arch/arm/core/aarch32/cortex_m/mpu/nxp_mpu.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,8 @@ void arm_core_mpu_configure_dynamic_mpu_regions(
601601
* This function provides the default configuration mechanism for the Memory
602602
* Protection Unit (MPU).
603603
*/
604-
static int nxp_mpu_init(const struct device *arg)
604+
int z_arm_mpu_init(void)
605605
{
606-
ARG_UNUSED(arg);
607-
608606
uint32_t r_index;
609607

610608
if (mpu_config.num_regions > get_num_regions()) {
@@ -640,15 +638,5 @@ static int nxp_mpu_init(const struct device *arg)
640638

641639
arm_core_mpu_enable();
642640

643-
644641
return 0;
645642
}
646-
647-
#if defined(CONFIG_LOG)
648-
/* To have logging the driver needs to be initialized later */
649-
SYS_INIT(nxp_mpu_init, PRE_KERNEL_2,
650-
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
651-
#else
652-
SYS_INIT(nxp_mpu_init, PRE_KERNEL_1,
653-
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
654-
#endif

arch/arm/core/aarch32/thread.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -484,16 +484,6 @@ static void z_arm_prepare_switch_to_main(void)
484484
__ISB();
485485
#endif /* CONFIG_FPU_SHARING */
486486
#endif /* CONFIG_FPU */
487-
488-
#ifdef CONFIG_ARM_MPU
489-
/* Configure static memory map. This will program MPU regions,
490-
* to set up access permissions for fixed memory sections, such
491-
* as Application Memory or No-Cacheable SRAM area.
492-
*
493-
* This function is invoked once, upon system initialization.
494-
*/
495-
z_arm_configure_static_mpu_regions();
496-
#endif
497487
}
498488

499489
void arch_switch_to_main_thread(struct k_thread *main_thread, char *stack_ptr,

arch/arm/include/aarch32/kernel_arch_func.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern void z_arm_cpu_idle_init(void);
3333
#ifdef CONFIG_ARM_MPU
3434
extern void z_arm_configure_static_mpu_regions(void);
3535
extern void z_arm_configure_dynamic_mpu_regions(struct k_thread *thread);
36+
extern int z_arm_mpu_init(void);
3637
#endif /* CONFIG_ARM_MPU */
3738

3839
static ALWAYS_INLINE void arch_kernel_init(void)
@@ -42,6 +43,16 @@ static ALWAYS_INLINE void arch_kernel_init(void)
4243
z_arm_fault_init();
4344
z_arm_cpu_idle_init();
4445
z_arm_clear_faults();
46+
#if defined(CONFIG_ARM_MPU)
47+
z_arm_mpu_init();
48+
/* Configure static memory map. This will program MPU regions,
49+
* to set up access permissions for fixed memory sections, such
50+
* as Application Memory or No-Cacheable SRAM area.
51+
*
52+
* This function is invoked once, upon system initialization.
53+
*/
54+
z_arm_configure_static_mpu_regions();
55+
#endif
4556
}
4657

4758
static ALWAYS_INLINE void

0 commit comments

Comments
 (0)