From a09a27c2e819a1d7fbd2f9cdf72d09308ca3620e Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Tue, 13 Jun 2017 16:08:09 -0500 Subject: [PATCH] arm: nxp: mpu: Fix region descriptor 0 attributes Clearing fields in the region descriptor attributes doesn't always have the expected effect of revoking permissions. In the case of bus master supervisor mode fields (MxSM), setting to zero actually enables read, write, and execute access. When we reworked handling of region descriptor 0, we inadvertently enabled execution from RAM by clearing the MxSM fields and enabling the descriptor. This caused samples/mpu_test run to throw a usage fault instead of an MPU-triggered bus fault. Fix this by setting all the MxSM fields to 2'b11, which gives supervisor mode the same access as user mode. Signed-off-by: Maureen Helm --- arch/arm/soc/nxp_kinetis/k6x/nxp_mpu_regions.c | 2 +- include/arch/arm/cortex_m/mpu/nxp_mpu.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/arm/soc/nxp_kinetis/k6x/nxp_mpu_regions.c b/arch/arm/soc/nxp_kinetis/k6x/nxp_mpu_regions.c index 734b17b986624..16245d767700b 100644 --- a/arch/arm/soc/nxp_kinetis/k6x/nxp_mpu_regions.c +++ b/arch/arm/soc/nxp_kinetis/k6x/nxp_mpu_regions.c @@ -15,7 +15,7 @@ static struct nxp_mpu_region mpu_regions[] = { MPU_REGION_ENTRY("DEBUGGER_0", 0, 0xFFFFFFFF, - 0), + REGION_DEBUG_ATTR), /* Region 1 */ MPU_REGION_ENTRY("FLASH_0", CONFIG_FLASH_BASE_ADDRESS, diff --git a/include/arch/arm/cortex_m/mpu/nxp_mpu.h b/include/arch/arm/cortex_m/mpu/nxp_mpu.h index b451d8793856a..a4cb3895f5bcc 100644 --- a/include/arch/arm/cortex_m/mpu/nxp_mpu.h +++ b/include/arch/arm/cortex_m/mpu/nxp_mpu.h @@ -78,6 +78,9 @@ #define REGION_RO_ATTR (MPU_REGION_READ | \ MPU_REGION_SU) +#define REGION_DEBUG_ATTR MPU_REGION_SU + + /* Region definition data structure */ struct nxp_mpu_region { /* Region Base Address */