Page MenuHomePhabricator

Fix BL2 scatter file
Open, Needs TriagePublic

Description

Proposal comes from Mark Horvath:

The maximum size of the region ER_DATA is set to BL2_DATA_SIZE which is usually equals to the size of the available RAM. But not just the ER_DATA region have to be placed into RAM but also the BOOT_DATA, the heap and the MSP stack.

In addition if the TFM_MULTI_CORE_TOPOLOGY macro is set then the BOOT_DATA is not placed at the start of the RAM in TF-M but after unprivileged data.

So I would recommend to use the same check like in tfm_common_s.sct and adjust BOOT_DATA start:

--- a/platform/ext/target/musca_b1/Device/Source/armclang/musca_bl2.sct
+++ b/platform/ext/target/musca_b1/Device/Source/armclang/musca_bl2.sct
@@ -24,10 +24,10 @@ LR_CODE BL2_CODE_START {
         * (+RO)
     }

-    TFM_SHARED_DATA BL2_DATA_START ALIGN 32 EMPTY BOOT_TFM_SHARED_DATA_SIZE {
+    TFM_SHARED_DATA BOOT_TFM_SHARED_DATA_BASE ALIGN 32 EMPTY BOOT_TFM_SHARED_DATA_SIZE {
     }

-    ER_DATA +0 BL2_DATA_SIZE {
+    ER_DATA +0 {
         * (+ZI +RW)
     }

@@ -37,4 +37,15 @@ LR_CODE BL2_CODE_START {

     ARM_LIB_HEAP +0 ALIGN 8 EMPTY BL2_HEAP_SIZE {
     }
+
+    /* This empty, zero long execution region is here to mark the limit address
+     * of the last execution region that is allocated in SRAM.
+     */
+    SRAM_WATERMARK +0 EMPTY 0x0 {
+    }
+
+    /* Make sure that the sections allocated in the SRAM does not exceed the
+     * size of the SRAM available.
+     */
+    ScatterAssert(ImageLimit(SRAM_WATERMARK) <= BL2_DATA_START + BL2_DATA_SIZE)
}

Commit: https://review.trustedfirmware.org/c/trusted-firmware-m/+/4212

Event Timeline

tamasban created this task.Thu, May 14, 7:36 AM

As I saw the memory limit issue also present in the non-secure scatter files.

The memory limit issue could also be fixed by:

ARM_LIB_HEAP (BL2_DATA_START + BL2_DATA_SIZE) ALIGN 8 EMPTY -BL2_HEAP_SIZE

Anyhow I would recommend the original proposal as it easier to understand. (Even if it is causing a linker warning because of the empty region.)

BalintMatyi updated the task description. (Show Details)Tue, May 26, 12:31 PM