summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/main.c3
-rw-r--r--core/cortex-m/include/mpu.h10
-rw-r--r--core/cortex-m/mpu.c17
3 files changed, 26 insertions, 4 deletions
diff --git a/common/main.c b/common/main.c
index 3c60216aa2..7f1cbc265d 100644
--- a/common/main.c
+++ b/common/main.c
@@ -137,8 +137,7 @@ test_mockable __keep int main(void)
/* We wait to report the failure until here where we have console. */
if (mpu_pre_init_rv != EC_SUCCESS)
- /* TODO: Need real fix (chromium:1085868) */
- CPRINTS("MPU init failed");
+ panic("MPU init failed");
/* be less verbose if we boot for USB resume to meet spec timings */
if (!(system_get_reset_flags() & EC_RESET_FLAG_USB_RESUME)) {
diff --git a/core/cortex-m/include/mpu.h b/core/cortex-m/include/mpu.h
index 17539fa09e..81aefa6a75 100644
--- a/core/cortex-m/include/mpu.h
+++ b/core/cortex-m/include/mpu.h
@@ -12,6 +12,11 @@
#include "config.h" /* chips might override MPU attribute settings */
/*
+ * ARMv7-M SRAM region
+ */
+#define CORTEX_M_SRAM_BASE 0x20000000
+
+/*
* Region assignment. 7 as the highest, a higher index has a higher priority.
* For example, using 7 for .iram.text allows us to mark entire RAM XN except
* .iram.text, which is used for hibernation.
@@ -54,6 +59,11 @@ enum mpu_region {
#define MPU_CTRL_ENABLE BIT(0)
/*
+ * Minimum region size is 32 bytes, 5 bits of address space
+ */
+#define MPU_SIZE_BITS_MIN 5
+
+/*
* XN (execute never) bit. It's bit 12 if accessed by halfword.
* 0: XN off
* 1: XN on
diff --git a/core/cortex-m/mpu.c b/core/cortex-m/mpu.c
index 53fffaaaa5..e2a2a464e1 100644
--- a/core/cortex-m/mpu.c
+++ b/core/cortex-m/mpu.c
@@ -68,6 +68,9 @@ int mpu_update_region(uint8_t region, uint32_t addr, uint8_t size_bit,
if (region >= mpu_num_regions())
return -EC_ERROR_INVAL;
+ if (size_bit < MPU_SIZE_BITS_MIN)
+ return -EC_ERROR_INVAL;
+
asm volatile("isb; dsb;");
MPU_NUMBER = region;
@@ -341,9 +344,19 @@ int mpu_pre_init(void)
return EC_ERROR_UNIMPLEMENTED;
mpu_disable();
+
for (i = 0; i < num_mpu_regions; ++i) {
- rv = mpu_config_region(i, CONFIG_RAM_BASE, CONFIG_RAM_SIZE, 0,
- 0);
+ /*
+ * Disable all regions.
+ *
+ * We use the smallest possible size (32 bytes), but it
+ * doesn't really matter since the regions are disabled.
+ *
+ * Use the fixed SRAM region base to ensure base is aligned
+ * to the region size.
+ */
+ rv = mpu_update_region(i, CORTEX_M_SRAM_BASE, MPU_SIZE_BITS_MIN,
+ 0, 0, 0);
if (rv != EC_SUCCESS)
return rv;
}