bsps/atsam: Add NULL pointer protection

This commit is contained in:
Christian Mauderer
2022-12-09 10:20:17 +01:00
parent 26050b5fb4
commit 7b968a2eb4
9 changed files with 55 additions and 4 deletions

View File

@@ -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).

View File

@@ -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);

View File

@@ -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[];

View File

@@ -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__ */

View File

@@ -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)) {