@@ -318,11 +318,20 @@ static int region_allocate_and_init(const u8_t index,
318
318
static int mpu_configure_region (const u8_t index ,
319
319
const struct k_mem_partition * new_region );
320
320
321
+ #if !defined(CONFIG_MPU_GAP_FILLING )
322
+ static int mpu_configure_regions (const struct k_mem_partition
323
+ * regions [], u8_t regions_num , u8_t start_reg_index ,
324
+ bool do_sanity_check );
325
+ #endif
326
+
321
327
/* This internal function programs a set of given MPU regions
322
328
* over a background memory area, optionally performing a
323
329
* sanity check of the memory regions to be programmed.
330
+ *
331
+ * The function performs a full partition of the background memory
332
+ * area, effectively, leaving no space in this area uncovered by MPU.
324
333
*/
325
- static int mpu_configure_regions (const struct k_mem_partition
334
+ static int mpu_configure_regions_and_partition (const struct k_mem_partition
326
335
* regions [], u8_t regions_num , u8_t start_reg_index ,
327
336
bool do_sanity_check )
328
337
{
@@ -472,7 +481,7 @@ static int mpu_configure_static_mpu_regions(const struct k_mem_partition
472
481
ARG_UNUSED (background_area_base );
473
482
ARG_UNUSED (background_area_end );
474
483
475
- mpu_reg_index = mpu_configure_regions (static_regions ,
484
+ mpu_reg_index = mpu_configure_regions_and_partition (static_regions ,
476
485
regions_num , mpu_reg_index , true);
477
486
478
487
static_regions_num = mpu_reg_index ;
@@ -539,6 +548,7 @@ static int mpu_configure_dynamic_mpu_regions(const struct k_mem_partition
539
548
ARM_MPU_ClrRegion (i );
540
549
}
541
550
551
+ #if defined(CONFIG_MPU_GAP_FILLING )
542
552
/* Reset MPU regions inside which dynamic memory regions may
543
553
* be programmed.
544
554
*/
@@ -551,10 +561,25 @@ static int mpu_configure_dynamic_mpu_regions(const struct k_mem_partition
551
561
* forming a full partition of the background area, specified by the
552
562
* given boundaries.
553
563
*/
564
+ mpu_reg_index = mpu_configure_regions_and_partition (dynamic_regions ,
565
+ regions_num , mpu_reg_index , true);
566
+ #else
567
+
568
+ /* We are going to skip the full partition of the background areas.
569
+ * So we can disable MPU regions inside which dynamic memroy regions
570
+ * may be programmed.
571
+ */
572
+ for (int i = 0 ; i < MPU_DYNAMIC_REGION_AREAS_NUM ; i ++ ) {
573
+ ARM_MPU_ClrRegion (dyn_reg_info [i ].index );
574
+ }
554
575
576
+ /* The dynamic regions are now programmed on top of
577
+ * existing SRAM region configuration.
578
+ */
555
579
mpu_reg_index = mpu_configure_regions (dynamic_regions ,
556
580
regions_num , mpu_reg_index , true);
557
581
582
+ #endif /* CONFIG_MPU_GAP_FILLING */
558
583
return mpu_reg_index ;
559
584
}
560
585
0 commit comments