Skip to content

Commit 3926134

Browse files
danieldegrassecarlescufi
authored andcommitted
arch: arm: mpu: Make XN bit conditional on CONFIG_XIP for RAM region
Make the execute never (XN) bit conditonal on CONFIG_XIP for the RAM MPU region attribute. This is required because when CONFIG_XIP is not set, the entire image will be linked into SRAM. In this case, SRAM must be executable. Signed-off-by: Daniel DeGrasse <[email protected]>
1 parent 654aa9b commit 3926134

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

include/zephyr/arch/arm/aarch32/mpu/arm_mpu_v7m.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,15 @@
110110
#define REGION_4G REGION_SIZE(4GB)
111111

112112
/* Some helper defines for common regions */
113+
114+
/* On Cortex-M, we can only set the XN bit when CONFIG_XIP=y. When
115+
* CONFIG_XIP=n, the entire image will be linked to SRAM, so we need to keep
116+
* the SRAM region XN bit clear or the application code will not be executable.
117+
*/
113118
#define REGION_RAM_ATTR(size) \
114119
{ \
115120
(NORMAL_OUTER_INNER_WRITE_BACK_WRITE_READ_ALLOCATE_NON_SHAREABLE | \
116-
MPU_RASR_XN_Msk | size | P_RW_U_NA_Msk) \
121+
IF_ENABLED(CONFIG_XIP, (MPU_RASR_XN_Msk |)) size | P_RW_U_NA_Msk) \
117122
}
118123
#define REGION_RAM_NOCACHE_ATTR(size) \
119124
{ \

include/zephyr/arch/arm/aarch32/mpu/arm_mpu_v8.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,14 @@
245245
.r_limit = limit - 1, \
246246
}
247247
#else
248+
249+
/* On Cortex-M, we can only set the XN bit when CONFIG_XIP=y. When
250+
* CONFIG_XIP=n, the entire image will be linked to SRAM, so we need to keep
251+
* the SRAM region XN bit clear or the application code will not be executable.
252+
*/
248253
#define REGION_RAM_ATTR(base, size) \
249254
{\
250-
.rbar = NOT_EXEC | \
255+
.rbar = IF_ENABLED(CONFIG_XIP, (NOT_EXEC |)) \
251256
P_RW_U_NA_Msk | NON_SHAREABLE_Msk, /* AP, XN, SH */ \
252257
/* Cache-ability */ \
253258
.mair_idx = MPU_MAIR_INDEX_SRAM, \

0 commit comments

Comments
 (0)