Skip to content

Commit a9b9085

Browse files
committed
arm-cortex-r82: Add MPU support
This commit introduces support for the Memory Protection Unit (MPU) to the ARM Cortex-R82 port. The MPU enhances system security by allowing the definition of memory regions with specific access permissions. The following changes have been made: - Added MPU configuration functions in `port.c` to set up memory regions and their attributes. - Updated `portASM.S` to include assembly routines for MPU and context switching with MPU support. - Created `mpu_wrappers_v2_asm.c` to provide assembly wrappers for MPU operations. - Updated `portmacro.h` to include MPU-related macros and definitions. - Modified `task.h` to include MPU-related task attributes. - Updated `CMakeLists.txt` to include the new MPU source file. - Enhanced the `README.md` with instructions on MPU configuration. Signed-off-by: Ahmed Ismail <Ahmed.Ismail@arm.com>
1 parent d33d04b commit a9b9085

9 files changed

Lines changed: 2983 additions & 385 deletions

File tree

.github/.cSpellWords.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ CANTX
7070
capitalisation
7171
cbmc
7272
CBMC
73+
cbnz
7374
cbor
7475
CBOR
7576
CCIE
@@ -108,6 +109,8 @@ CLKS
108109
CLKSOURCE
109110
CLKSTA
110111
CLRB
112+
clrex
113+
CLREX
111114
CLRF
112115
clrm
113116
CLRPSW
@@ -379,6 +382,7 @@ IFSR
379382
imajeff
380383
INACK
381384
INDF
385+
initialisations
382386
inpw
383387
INTE
384388
INTFRCH
@@ -652,18 +656,24 @@ PPUDR
652656
PPUER
653657
PPUSR
654658
ppux
659+
Prbar
660+
PRBAR
655661
PRCR
656662
PREA
657663
PREB
658664
PRIA
659665
Prioritised
660666
PRIS
661667
PRIVDEFENA
668+
Prlar
669+
PRLAR
662670
PROCDLY
663671
PRODH
664672
PRODL
665673
PROGE
666674
Prokic
675+
Prselr
676+
PRSELR
667677
prtmacro
668678
psha
669679
psplim
@@ -706,6 +716,7 @@ REENT
706716
REGA
707717
RELD
708718
Renesas
719+
restoreallgpregisters
709720
reta
710721
reti
711722
RETP
@@ -773,6 +784,8 @@ SCBR
773784
SCDR
774785
SCER
775786
SCSR
787+
Sctlr
788+
SCTLR
776789
SDCC
777790
SECU
778791
SENDA
@@ -930,6 +943,7 @@ UNSUB
930943
UNSUBACK
931944
unsubscriptions
932945
unsuspended
946+
unupdated
933947
UPAC
934948
URAD
935949
URAT

.github/scripts/kernel_checker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
r'.*portable/.*/ARM_CM4_MPU*',
120120
r'.*portable/.*/ARM_CM4F_MPU*',
121121
r'.*portable/.*/ARM_CR82*',
122+
r'.*include/task\.h$',
122123
]
123124

124125
KERNEL_HEADER = [

include/task.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
33
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
* Copyright 2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
45
*
56
* SPDX-License-Identifier: MIT
67
*
@@ -68,18 +69,21 @@
6869
#if defined( portARMV8M_MINOR_VERSION ) && ( portARMV8M_MINOR_VERSION >= 1 )
6970
#define tskMPU_REGION_PRIVILEGED_EXECUTE_NEVER ( 1U << 5U )
7071
#endif /* portARMV8M_MINOR_VERSION >= 1 */
72+
#define tskMPU_REGION_NON_SHAREABLE ( 1U << 6U )
73+
#define tskMPU_REGION_OUTER_SHAREABLE ( 1U << 7U )
74+
#define tskMPU_REGION_INNER_SHAREABLE ( 1U << 8U )
7175

7276
/* MPU region permissions stored in MPU settings to
7377
* authorize access requests. */
74-
#define tskMPU_READ_PERMISSION ( 1U << 0U )
75-
#define tskMPU_WRITE_PERMISSION ( 1U << 1U )
78+
#define tskMPU_READ_PERMISSION ( 1U << 0U )
79+
#define tskMPU_WRITE_PERMISSION ( 1U << 1U )
7680

7781
/* The direct to task notification feature used to have only a single notification
7882
* per task. Now there is an array of notifications per task that is dimensioned by
7983
* configTASK_NOTIFICATION_ARRAY_ENTRIES. For backward compatibility, any use of the
8084
* original direct to task notification defaults to using the first index in the
8185
* array. */
82-
#define tskDEFAULT_INDEX_TO_NOTIFY ( 0 )
86+
#define tskDEFAULT_INDEX_TO_NOTIFY ( 0 )
8387

8488
/**
8589
* task. h

portable/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ add_library(freertos_kernel_port OBJECT
243243
# ARMv8-R ports for GCC
244244
$<$<STREQUAL:${FREERTOS_PORT},GCC_ARM_CR82>:
245245
GCC/ARM_CR82/port.c
246-
GCC/ARM_CR82/portASM.S>
246+
GCC/ARM_CR82/portASM.S
247+
GCC/ARM_CR82/mpu_wrappers_v2_asm.c>
247248

248249
# ARMv4T ARM7TDMI ports for GCC
249250
$<$<STREQUAL:${FREERTOS_PORT},GCC_ARM7_AT91FR40008>:
@@ -822,6 +823,7 @@ if( FREERTOS_PORT MATCHES "GCC_ARM_CM(3|4)_MPU" OR
822823
FREERTOS_PORT MATCHES "GCC_ARM_CM(23|33|52|55|85)_NTZ_NONSECURE" OR
823824
FREERTOS_PORT MATCHES "GCC_ARM_CM(23|33|52|55|85)_NONSECURE" OR
824825
FREERTOS_PORT MATCHES "GCC_ARM_CM(33|52|55|85)_TFM" OR
826+
FREERTOS_PORT MATCHES "GCC_ARM_CR82" OR
825827
FREERTOS_PORT MATCHES "IAR_ARM_CM(23|33|52|55|85)_NTZ_NONSECURE" OR
826828
FREERTOS_PORT MATCHES "IAR_ARM_CM(23|33|52|55|85)_NONSECURE" OR
827829
FREERTOS_PORT MATCHES "IAR_ARM_CM(33|52|55|85)_TFM"

portable/GCC/ARM_CR82/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ The port is supported and tested on the following toolchains:
1818
- The port does not perform cache maintenance for shared buffers.
1919
- If your hardware or model doesn't support full cache coherency, you must handle cache clean/invalidate operations, memory attributes, and any additional barriers in your BSP/application (especially around shared-memory regions).
2020

21+
# MPU Support
22+
23+
- This port supports the FreeRTOS MPU on both single-core and SMP (multi-core) configurations. Enable via `configENABLE_MPU = 1`; the port programs MPU regions per task on each active core.
24+
25+
- Minimum MPU granularity and alignment: 64 bytes. Ensure any user‑defined region base and size are 64‑byte aligned.
26+
2127
# SMP Multicore Bring-up
2228

2329
For SMP systems using this port, the application only needs to start the scheduler on the primary core and issue an SVC from each secondary core once they are online. The kernel coordinates the rest and ensures all cores are properly managed.
@@ -39,4 +45,4 @@ Secondary core flow (to be done in each core’s reset handler):
3945
2. Wait for the primary core's signal that shared initialization is complete (i.e., `ucPrimaryCoreInitDoneFlag` set to 1).
4046
3. Update `VBAR_EL1` from the boot vector table to the FreeRTOS vector table.
4147
4. Initialize the GIC redistributor and enable SGIs so interrupts from the primary core are receivable; signal the primary that this secondary is online and ready by setting the its flag in the `ucSecondaryCoresReadyFlags` array.
42-
5. Issue an SVC with immediate value `106` to enter `FreeRTOS_SWI_Handler`, which will call `vPortRestoreContext()` based on the SVC number to start scheduling on this core.
48+
5. Issue an SVC with immediate value `106` (i.e., `portSVC_START_FIRST_TASK`) to enter `FreeRTOS_SWI_Handler`, which will call `vPortRestoreContext()` based on the SVC number to start scheduling on this core.

0 commit comments

Comments
 (0)