Skip to content

Commit 3cca1ec

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 <[email protected]>
1 parent 7d6890e commit 3cca1ec

File tree

8 files changed

+2973
-385
lines changed

8 files changed

+2973
-385
lines changed

.github/.cSpellWords.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ CANTX
6969
capitalisation
7070
cbmc
7171
CBMC
72+
cbnz
7273
cbor
7374
CBOR
7475
CCIE
@@ -107,6 +108,8 @@ CLKS
107108
CLKSOURCE
108109
CLKSTA
109110
CLRB
111+
clrex
112+
CLREX
110113
CLRF
111114
clrm
112115
CLRPSW
@@ -378,6 +381,7 @@ IFSR
378381
imajeff
379382
INACK
380383
INDF
384+
initialisations
381385
inpw
382386
INTE
383387
INTFRCH
@@ -651,18 +655,24 @@ PPUDR
651655
PPUER
652656
PPUSR
653657
ppux
658+
Prbar
659+
PRBAR
654660
PRCR
655661
PREA
656662
PREB
657663
PRIA
658664
Prioritised
659665
PRIS
660666
PRIVDEFENA
667+
Prlar
668+
PRLAR
661669
PROCDLY
662670
PRODH
663671
PRODL
664672
PROGE
665673
Prokic
674+
Prselr
675+
PRSELR
666676
prtmacro
667677
psha
668678
psplim
@@ -705,6 +715,7 @@ REENT
705715
REGA
706716
RELD
707717
Renesas
718+
restoreallgpregisters
708719
reta
709720
reti
710721
RETP
@@ -772,6 +783,8 @@ SCBR
772783
SCDR
773784
SCER
774785
SCSR
786+
Sctlr
787+
SCTLR
775788
SDCC
776789
SECU
777790
SENDA
@@ -929,6 +942,7 @@ UNSUB
929942
UNSUBACK
930943
unsubscriptions
931944
unsuspended
945+
unupdated
932946
UPAC
933947
URAD
934948
URAT

include/task.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,21 @@
6868
#if defined( portARMV8M_MINOR_VERSION ) && ( portARMV8M_MINOR_VERSION >= 1 )
6969
#define tskMPU_REGION_PRIVILEGED_EXECUTE_NEVER ( 1U << 5U )
7070
#endif /* portARMV8M_MINOR_VERSION >= 1 */
71+
#define tskMPU_REGION_NON_SHAREABLE ( 1U << 6U )
72+
#define tskMPU_REGION_OUTER_SHAREABLE ( 1U << 7U )
73+
#define tskMPU_REGION_INNER_SHAREABLE ( 1U << 8U )
7174

7275
/* MPU region permissions stored in MPU settings to
7376
* authorize access requests. */
74-
#define tskMPU_READ_PERMISSION ( 1U << 0U )
75-
#define tskMPU_WRITE_PERMISSION ( 1U << 1U )
77+
#define tskMPU_READ_PERMISSION ( 1U << 0U )
78+
#define tskMPU_WRITE_PERMISSION ( 1U << 1U )
7679

7780
/* The direct to task notification feature used to have only a single notification
7881
* per task. Now there is an array of notifications per task that is dimensioned by
7982
* configTASK_NOTIFICATION_ARRAY_ENTRIES. For backward compatibility, any use of the
8083
* original direct to task notification defaults to using the first index in the
8184
* array. */
82-
#define tskDEFAULT_INDEX_TO_NOTIFY ( 0 )
85+
#define tskDEFAULT_INDEX_TO_NOTIFY ( 0 )
8386

8487
/**
8588
* 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)