| From ca7696bca357cfd71a34582c65a7c7c08828b6dc Mon Sep 17 00:00:00 2001 |
| From: Bence Balogh <bence.balogh@arm.com> |
| Date: Mon, 18 Dec 2023 14:00:14 +0100 |
| Subject: [PATCH 2/2] platform: corstone1000: Cover S_DATA with MPU |
| |
| The S_DATA has to be covered with MPU regions to override the |
| other MPU regions with smaller RNR values. |
| |
| Change-Id: I45fec65f51241939314941e25d287e6fdc82777c |
| Signed-off-by: Bence Balogh <bence.balogh@arm.com> |
| Upstream-Status: Submitted [https://review.trustedfirmware.org/c/TF-M/trusted-firmware-m/+/25583] |
| |
| --- |
| .../target/arm/corstone1000/CMakeLists.txt | 8 +++++++ |
| .../arm/corstone1000/tfm_hal_isolation.c | 22 +++++++++++++++++++ |
| 2 files changed, 30 insertions(+) |
| |
| diff --git a/platform/ext/target/arm/corstone1000/CMakeLists.txt b/platform/ext/target/arm/corstone1000/CMakeLists.txt |
| index 8817f514c..541504368 100644 |
| --- a/platform/ext/target/arm/corstone1000/CMakeLists.txt |
| +++ b/platform/ext/target/arm/corstone1000/CMakeLists.txt |
| @@ -40,6 +40,14 @@ target_compile_definitions(platform_region_defs |
| INTERFACE |
| TFM_LINKER_APP_ROT_LINKER_DATA_ALIGNMENT=0x2000 |
| TFM_LINKER_SP_META_PTR_ALIGNMENT=0x100 |
| + |
| + # The RAM MPU Region block sizes are calculated manually. The RAM has to be covered |
| + # with the MPU regions. These regions also have to be the power of 2 and |
| + # the start addresses have to be aligned to these sizes. The sizes can be calculated |
| + # from the S_DATA_START and S_DATA_SIZE defines. |
| + RAM_MPU_REGION_BLOCK_1_SIZE=0x4000 |
| + RAM_MPU_REGION_BLOCK_2_SIZE=0x20000 |
| + |
| ) |
| #========================= Platform common defs ===============================# |
| |
| diff --git a/platform/ext/target/arm/corstone1000/tfm_hal_isolation.c b/platform/ext/target/arm/corstone1000/tfm_hal_isolation.c |
| index 98e795dde..39b19c535 100644 |
| --- a/platform/ext/target/arm/corstone1000/tfm_hal_isolation.c |
| +++ b/platform/ext/target/arm/corstone1000/tfm_hal_isolation.c |
| @@ -15,6 +15,7 @@ |
| #include "mpu_config.h" |
| #include "mmio_defs.h" |
| #include "flash_layout.h" |
| +#include "region_defs.h" |
| |
| #define PROT_BOUNDARY_VAL \ |
| ((1U << HANDLE_ATTR_PRIV_POS) & HANDLE_ATTR_PRIV_MASK) |
| @@ -132,6 +133,27 @@ enum tfm_hal_status_t tfm_hal_set_up_static_boundaries( |
| |
| #endif |
| |
| + /* Set the RAM attributes. It is needed because the first region overlaps the whole |
| + * SRAM and it has to be overridden. |
| + * The RAM_MPU_REGION_BLOCK_1_SIZE and RAM_MPU_REGION_BLOCK_2_SIZE are calculated manually |
| + * and added to the platform_region_defs compile definitions. |
| + */ |
| + base = S_DATA_START; |
| + limit = S_DATA_START + RAM_MPU_REGION_BLOCK_1_SIZE; |
| + ret = configure_mpu(rnr++, base, limit, |
| + XN_EXEC_NOT_OK, AP_RW_PRIV_UNPRIV); |
| + if (ret != TFM_HAL_SUCCESS) { |
| + return ret; |
| + } |
| + |
| + base = S_DATA_START + RAM_MPU_REGION_BLOCK_1_SIZE; |
| + limit = S_DATA_START + RAM_MPU_REGION_BLOCK_1_SIZE + RAM_MPU_REGION_BLOCK_2_SIZE; |
| + ret = configure_mpu(rnr++, base, limit, |
| + XN_EXEC_NOT_OK, AP_RW_PRIV_UNPRIV); |
| + if (ret != TFM_HAL_SUCCESS) { |
| + return ret; |
| + } |
| + |
| arm_mpu_enable(); |
| |
| #endif /* CONFIG_TFM_ENABLE_MEMORY_PROTECT */ |