|
36 | 36 |
|
37 | 37 | #include <arch/imxrt/chip.h>
|
38 | 38 |
|
| 39 | +#include "mpu.h" |
39 | 40 | #include "arm_internal.h"
|
40 | 41 | #include "hardware/imxrt_memorymap.h"
|
41 | 42 | #include "imxrt_mpuinit.h"
|
@@ -309,14 +310,30 @@ void up_allocate_heap(void **heap_start, size_t *heap_size)
|
309 | 310 | uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend +
|
310 | 311 | CONFIG_MM_KERNEL_HEAPSIZE;
|
311 | 312 | size_t usize = PRIMARY_RAM_END - ubase;
|
| 313 | + int log2; |
312 | 314 |
|
313 | 315 | DEBUGASSERT(ubase < (uintptr_t)PRIMARY_RAM_END);
|
314 | 316 |
|
| 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 | + |
315 | 328 | /* Return the user-space heap settings */
|
316 | 329 |
|
317 | 330 | board_autoled_on(LED_HEAPALLOCATE);
|
318 | 331 | *heap_start = (void *)ubase;
|
319 | 332 | *heap_size = usize;
|
| 333 | + |
| 334 | + /* Allow user-mode access to the user heap memory */ |
| 335 | + |
| 336 | + imxrt_mpu_uheap((uintptr_t)ubase, usize); |
320 | 337 | #else
|
321 | 338 |
|
322 | 339 | /* Return the heap settings */
|
@@ -348,8 +365,21 @@ void up_allocate_kheap(void **heap_start, size_t *heap_size)
|
348 | 365 |
|
349 | 366 | uintptr_t ubase = (uintptr_t)USERSPACE->us_bssend +
|
350 | 367 | CONFIG_MM_KERNEL_HEAPSIZE;
|
| 368 | + size_t usize = PRIMARY_RAM_END - ubase; |
| 369 | + int log2; |
351 | 370 | DEBUGASSERT(ubase < (uintptr_t)PRIMARY_RAM_END);
|
352 | 371 |
|
| 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 | + |
353 | 383 | /* Return the kernel heap settings (i.e., the part of the heap region
|
354 | 384 | * that was not dedicated to the user heap).
|
355 | 385 | */
|
|
0 commit comments