Skip to content

Commit 777c6c4

Browse files
masayuki2009davids5
authored andcommitted
arch: imxrt: Fix imxrt for CONFIG_BUILD_PROTECTED=y
Summary: - Fix imxrt_allocateheap.c for CONFIG_BUILD_PROTECTED=y - Call mpu_reset() in imxrt_mpuinit.c Impact: - CONFIG_BUILD_PROTECTED=y only Testing: - Tested with imxrt1060-evk:knsh (will be updated later) Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
1 parent 1cc6e4b commit 777c6c4

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

arch/arm/src/imxrt/imxrt_allocateheap.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include <arch/imxrt/chip.h>
3838

39+
#include "mpu.h"
3940
#include "arm_internal.h"
4041
#include "hardware/imxrt_memorymap.h"
4142
#include "imxrt_mpuinit.h"
@@ -309,14 +310,30 @@ void up_allocate_heap(void **heap_start, size_t *heap_size)
309310
uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend +
310311
CONFIG_MM_KERNEL_HEAPSIZE;
311312
size_t usize = PRIMARY_RAM_END - ubase;
313+
int log2;
312314

313315
DEBUGASSERT(ubase < (uintptr_t)PRIMARY_RAM_END);
314316

317+
/* Adjust that size to account for MPU alignment requirements.
318+
* NOTE that there is an implicit assumption that the PRIMARY_RAM_END
319+
* is aligned to the MPU requirement.
320+
*/
321+
322+
log2 = (int)mpu_log2regionfloor(usize);
323+
DEBUGASSERT((PRIMARY_RAM_END & ((1 << log2) - 1)) == 0);
324+
325+
usize = (1 << log2);
326+
ubase = PRIMARY_RAM_END - usize;
327+
315328
/* Return the user-space heap settings */
316329

317330
board_autoled_on(LED_HEAPALLOCATE);
318331
*heap_start = (void *)ubase;
319332
*heap_size = usize;
333+
334+
/* Allow user-mode access to the user heap memory */
335+
336+
imxrt_mpu_uheap((uintptr_t)ubase, usize);
320337
#else
321338

322339
/* Return the heap settings */
@@ -348,8 +365,21 @@ void up_allocate_kheap(void **heap_start, size_t *heap_size)
348365

349366
uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend +
350367
CONFIG_MM_KERNEL_HEAPSIZE;
368+
size_t usize = PRIMARY_RAM_END - ubase;
369+
int log2;
351370
DEBUGASSERT(ubase < (uintptr_t)PRIMARY_RAM_END);
352371

372+
/* Adjust that size to account for MPU alignment requirements.
373+
* NOTE that there is an implicit assumption that the CONFIG_RAM_END
374+
* is aligned to the MPU requirement.
375+
*/
376+
377+
log2 = (int)mpu_log2regionfloor(usize);
378+
DEBUGASSERT((PRIMARY_RAM_END & ((1 << log2) - 1)) == 0);
379+
380+
usize = (1 << log2);
381+
ubase = PRIMARY_RAM_END - usize;
382+
353383
/* Return the kernel heap settings (i.e., the part of the heap region
354384
* that was not dedicated to the user heap).
355385
*/

arch/arm/src/imxrt/imxrt_mpuinit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ void imxrt_mpu_initialize(void)
9191

9292
mpu_showtype();
9393

94+
/* Reset MPU if enabled */
95+
96+
mpu_reset();
97+
9498
#ifdef CONFIG_ARMV7M_DCACHE
9599
/* Memory barrier */
96100

0 commit comments

Comments
 (0)