summaryrefslogtreecommitdiffstats
path: root/bsps/arm
diff options
context:
space:
mode:
authorChristian Mauderer <christian.mauderer@embedded-brains.de>2022-12-09 10:20:17 +0100
committerChristian Mauderer <christian.mauderer@embedded-brains.de>2022-12-15 09:20:52 +0100
commit7b968a2eb4358f958e4be3aedf462e250ba1749b (patch)
tree7db2d0bf9301ca019372ffeffc179ec00779527e /bsps/arm
parentbsps/atsam: Fix unidirectional SPI transfers (diff)
downloadrtems-7b968a2eb4358f958e4be3aedf462e250ba1749b.tar.bz2
bsps/atsam: Add NULL pointer protection
Diffstat (limited to 'bsps/arm')
-rw-r--r--bsps/arm/atsam/README6
-rw-r--r--bsps/arm/atsam/contrib/libraries/libboard/source/board_lowlevel.c17
-rw-r--r--bsps/arm/atsam/include/bsp.h4
-rw-r--r--bsps/arm/atsam/include/libchip/include/mpu.h1
-rw-r--r--bsps/arm/atsam/start/bspstarthooks.c2
5 files changed, 28 insertions, 2 deletions
diff --git a/bsps/arm/atsam/README b/bsps/arm/atsam/README
index 2ebaa726c8..47aa11d2c0 100644
--- a/bsps/arm/atsam/README
+++ b/bsps/arm/atsam/README
@@ -59,9 +59,13 @@ Use ATSAM_CONSOLE_DEVICE_INDEX=XYZ to set the device index for /dev/console
Use ATSAM_CONSOLE_USE_INTERRUPTS=XYZ to set the use interrupt driven mode for
console devices (used by default).
-Use ATSAM_MEMORY_TCM_SIZE=XYZ to set the size of tightly coupled memories (TCM)
+Use ATSAM_MEMORY_NULL_SIZE=XYZ to set the size of NULL pointer protection area
in bytes (default 0x00000000).
+Use ATSAM_MEMORY_TCM_SIZE=XYZ to set the size of tightly coupled memories (TCM)
+in bytes (default 0x00000000). Note: ITCM is reduced by the
+ATSAM_MEMORY_NULL_SIZE.
+
Use ATSAM_MEMORY_INTFLASH_SIZE=XYZ to set the size of internal flash in bytes
(default is derived from chip variant).
diff --git a/bsps/arm/atsam/contrib/libraries/libboard/source/board_lowlevel.c b/bsps/arm/atsam/contrib/libraries/libboard/source/board_lowlevel.c
index cbdf41ba73..a2dd595fb5 100644
--- a/bsps/arm/atsam/contrib/libraries/libboard/source/board_lowlevel.c
+++ b/bsps/arm/atsam/contrib/libraries/libboard/source/board_lowlevel.c
@@ -347,6 +347,23 @@ void _SetupMemoryRegion(void)
SCB->SHCSR |= (SCB_SHCSR_MEMFAULTENA_Msk | SCB_SHCSR_BUSFAULTENA_Msk
| SCB_SHCSR_USGFAULTENA_Msk);
+#ifdef __rtems__
+ dwRegionBaseAddr =
+ ((uintptr_t)atsam_memory_null_begin) |
+ MPU_REGION_VALID |
+ MPU_NULL_REGION;
+ if (atsam_memory_null_begin != atsam_memory_itcm_end) {
+ dwRegionAttr =
+ MPU_AP_NO_ACCESS |
+ MPU_REGION_EXECUTE_NEVER |
+ MPU_CalMPURegionSize((uintptr_t)atsam_memory_null_size) |
+ MPU_REGION_ENABLE;
+ } else {
+ dwRegionAttr = MPU_REGION_DISABLE;
+ }
+ MPU_SetRegion(dwRegionBaseAddr, dwRegionAttr);
+#endif /* __rtems__ */
+
/* Enable the MPU region */
#ifndef __rtems__
MPU_Enable(MPU_ENABLE | MPU_PRIVDEFENA);
diff --git a/bsps/arm/atsam/include/bsp.h b/bsps/arm/atsam/include/bsp.h
index 8fe98be364..0bca3d2c22 100644
--- a/bsps/arm/atsam/include/bsp.h
+++ b/bsps/arm/atsam/include/bsp.h
@@ -89,6 +89,10 @@ typedef struct {
uint8_t phy_addr;
} if_atsam_config;
+extern char atsam_memory_null_begin[];
+extern char atsam_memory_null_end[];
+extern char atsam_memory_null_size[];
+
extern char atsam_memory_dtcm_begin[];
extern char atsam_memory_dtcm_end[];
extern char atsam_memory_dtcm_size[];
diff --git a/bsps/arm/atsam/include/libchip/include/mpu.h b/bsps/arm/atsam/include/libchip/include/mpu.h
index a5d00a681b..034ba58474 100644
--- a/bsps/arm/atsam/include/libchip/include/mpu.h
+++ b/bsps/arm/atsam/include/libchip/include/mpu.h
@@ -56,6 +56,7 @@
#endif
#define MPU_SYSTEM_REGION (12)
#ifdef __rtems__
+#define MPU_NULL_REGION (13)
/* Reserve the region with highest priority for user applications */
#define MPU_USER_DEFINED_REGION (15)
#endif /* __rtems__ */
diff --git a/bsps/arm/atsam/start/bspstarthooks.c b/bsps/arm/atsam/start/bspstarthooks.c
index 516b86228d..2be2fc050b 100644
--- a/bsps/arm/atsam/start/bspstarthooks.c
+++ b/bsps/arm/atsam/start/bspstarthooks.c
@@ -106,7 +106,7 @@ static void configure_tcm(void)
uintptr_t tcm_size;
uint32_t itcmcr_sz;
- tcm_size = (uintptr_t) atsam_memory_itcm_size;
+ tcm_size = (uintptr_t) atsam_memory_dtcm_size;
itcmcr_sz = (SCB->ITCMCR & SCB_ITCMCR_SZ_Msk) >> SCB_ITCMCR_SZ_Pos;
if (tcm_setup_and_check_if_do_efc_config(tcm_size, itcmcr_sz)) {