fvp: Move TSP from Secure DRAM to Secure SRAM
authorSandrine Bailleux <sandrine.bailleux@arm.com>
Tue, 20 May 2014 16:28:25 +0000 (17:28 +0100)
committerSandrine Bailleux <sandrine.bailleux@arm.com>
Thu, 22 May 2014 16:30:58 +0000 (17:30 +0100)
The TSP used to execute from secure DRAM on the FVPs because there was
not enough space in Trusted SRAM to fit it in. Thanks to recent RAM
usage enhancements being implemented, we have made enough savings for
the TSP to execute in SRAM.

However, there is no contiguous free chunk of SRAM big enough to hold
the TSP. Therefore, the different bootloader images need to be moved
around to reduce memory fragmentation. This patch keeps the overall
memory layout (i.e. keeping BL1 R/W at the bottom, BL2 at the top and
BL3-1 in between) but moves the base addresses of all the bootloader
images in such a way that:
 - memory fragmentation is reduced enough to fit BL3-2 in;
 - new base addresses are suitable for release builds as well as debug
   ones;
 - each image has a few extra kilobytes for future growth.
   BL3-1 and BL3-2 are the images which received the biggest slice
   of the cake since they will most probably grow the most.

A few useful numbers for reference (valid at the time of this patch):
        |-----------------------|-------------------------------
        |  image size (debug)   |  extra space for the future
--------|-----------------------|-------------------------------
BL1 R/W |         20 KB         |            4 KB
BL2     |         44 KB         |            4 KB
BL3-1   |        108 KB         |           12 KB
BL3-2   |         56 KB         |            8 KB
--------|-----------------------|-------------------------------
Total   |        228 KB         |           28 KB       = 256 KB
--------|-----------------------|-------------------------------

Although on FVPs the TSP now executes from Trusted SRAM by default,
this patch keeps the option to execute it from Trusted DRAM. This is
controlled by the build configuration 'TSP_RAM_LOCATION'.

Fixes ARM-Software/tf-issues#81

Change-Id: Ifb9ef2befa9a2d5ac0813f7f79834df7af992b94

bl32/tsp/tsp.ld.S
plat/fvp/bl2_plat_setup.c
plat/fvp/platform.h
plat/fvp/platform.mk

index 797d8d7c13fa2c8e11493c57e65519645c4fa8e2..559ae3d3bc504ae208f307dc86587899ba709585 100644 (file)
@@ -113,7 +113,7 @@ SECTIONS
         __COHERENT_RAM_END__ = .;
     } >RAM
 
-    __BL2_END__ = .;
+    __BL32_END__ = .;
 
     __BSS_SIZE__ = SIZEOF(.bss);
     __COHERENT_RAM_UNALIGNED_SIZE__ =
index 672f096756d357783fc13e7d37fa95b0c6d11bf5..b945db98a0ac696f48f5544f9d9d1d8cd6152e3b 100644 (file)
@@ -98,11 +98,13 @@ bl31_params_t *bl2_plat_get_bl31_params(void)
 {
        bl2_to_bl31_params_mem_t *bl31_params_mem;
 
+#if TSP_RAM_LOCATION_ID == TSP_IN_TZDRAM
        /*
         * Ensure that the secure DRAM memory used for passing BL31 arguments
         * does not overlap with the BL32_BASE.
         */
        assert(BL32_BASE > PARAMS_BASE + sizeof(bl2_to_bl31_params_mem_t));
+#endif
 
        /*
         * Allocate the memory for all the arguments that needs to
@@ -265,8 +267,6 @@ void bl2_plat_get_bl32_meminfo(meminfo_t *bl32_meminfo)
 {
        /*
         * Populate the extents of memory available for loading BL32.
-        * TODO: We are temporarily executing BL2 from TZDRAM;
-        * will eventually move to Trusted SRAM
         */
        bl32_meminfo->total_base = BL32_BASE;
        bl32_meminfo->free_base = BL32_BASE;
index 07c79d9ffb2633de97866550375a9048e336b7a7..981bc98a955929e836eee01ad217593a4a4e4ebd 100644 (file)
 /*******************************************************************************
  * BL2 specific defines.
  ******************************************************************************/
-#define BL2_BASE                       0x0402D000
+#define BL2_BASE                       (TZRAM_BASE + TZRAM_SIZE - 0xc000)
 
 /*******************************************************************************
  * BL31 specific defines.
  ******************************************************************************/
-#define BL31_BASE                      0x0400C000
+#define BL31_BASE                      (TZRAM_BASE + 0x6000)
 
 /*******************************************************************************
  * BL32 specific defines.
  ******************************************************************************/
-#define TSP_SEC_MEM_BASE               TZDRAM_BASE
-#define TSP_SEC_MEM_SIZE               TZDRAM_SIZE
-#define BL32_BASE                      (TZDRAM_BASE + 0x2000)
-#define BL32_LIMIT                     (TZDRAM_BASE + (1 << 21))
+/*
+ * On FVP, the TSP can execute either from Trusted SRAM or Trusted DRAM.
+ */
+#define TSP_IN_TZRAM                   0
+#define TSP_IN_TZDRAM                  1
+
+#if TSP_RAM_LOCATION_ID == TSP_IN_TZRAM
+# define TSP_SEC_MEM_BASE              TZRAM_BASE
+# define TSP_SEC_MEM_SIZE              TZRAM_SIZE
+# define BL32_BASE                     (TZRAM_BASE + TZRAM_SIZE - 0x1c000)
+# define BL32_LIMIT                    BL2_BASE
+#elif TSP_RAM_LOCATION_ID == TSP_IN_TZDRAM
+# define TSP_SEC_MEM_BASE              TZDRAM_BASE
+# define TSP_SEC_MEM_SIZE              TZDRAM_SIZE
+# define BL32_BASE                     (TZDRAM_BASE + 0x2000)
+# define BL32_LIMIT                    (TZDRAM_BASE + (1 << 21))
+#else
+# error "Unsupported TSP_RAM_LOCATION_ID value"
+#endif
 
 /*******************************************************************************
  * Platform specific page table and MMU setup constants
index 4de001bcb5f3f86eb6f86baefe7aeb083945c0db..82bafed6f74d25e721bc67a12496d40ab06095a2 100644 (file)
 # POSSIBILITY OF SUCH DAMAGE.
 #
 
+# On FVP, the TSP can execute either from Trusted SRAM or Trusted DRAM.
+# Trusted SRAM is the default.
+TSP_RAM_LOCATION       :=      tsram
+
+ifeq (${TSP_RAM_LOCATION}, tsram)
+  TSP_RAM_LOCATION_ID := TSP_IN_TZRAM
+else ifeq (${TSP_RAM_LOCATION}, tdram)
+  TSP_RAM_LOCATION_ID := TSP_IN_TZDRAM
+else
+  $(error "Unsupported TSP_RAM_LOCATION value")
+endif
+
+# Process TSP_RAM_LOCATION_ID flag
+$(eval $(call add_define,TSP_RAM_LOCATION_ID))
+
 PLAT_INCLUDES          :=      -Iplat/fvp/include/
 
 PLAT_BL_COMMON_SOURCES :=      drivers/arm/pl011/pl011.c                       \