Commit 60633799 authored by Sandrine Bailleux's avatar Sandrine Bailleux
Browse files

fvp: Properly detect the location of BL1 R/W data

There was already a rudimentary mechanism to detect whether BL1
R/W data was loaded at the top or bottom of memory. Basically,
 - either BL1 was loaded at the very end of the trusted RAM
 - in all other cases BL1 was considered sitting at the bottom of
   the memory and the memory usage structure was updated accordingly,
   potentially resulting in critical memory waste.
For instance, if BL1 R/W base address was set to
(TZRAM_END - 4096 - bl1_size), it would virtually occupy the whole
memory.

This patch improves the mechanism to detect the location of BL1
to avoid such scenarios.

Change-Id: I224a9edf0fe8d34208545d84b28b63f2bb830d03
parent 8f55dfb4
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <arch_helpers.h> #include <arch_helpers.h>
#include <assert.h> #include <assert.h>
#include <bl_common.h> #include <bl_common.h>
#include <debug.h>
#include <console.h> #include <console.h>
#include <mmio.h> #include <mmio.h>
#include <platform.h> #include <platform.h>
...@@ -69,34 +70,25 @@ meminfo_t *bl1_plat_sec_mem_layout(void) ...@@ -69,34 +70,25 @@ meminfo_t *bl1_plat_sec_mem_layout(void)
******************************************************************************/ ******************************************************************************/
void bl1_early_platform_setup(void) void bl1_early_platform_setup(void)
{ {
const unsigned long bl1_ram_base = BL1_RAM_BASE; const size_t bl1_size = BL1_RAM_LIMIT - BL1_RAM_BASE;
const unsigned long bl1_ram_limit = BL1_RAM_LIMIT;
const unsigned long tzram_limit = TZRAM_BASE + TZRAM_SIZE;
/* Initialize the console to provide early debug support */ /* Initialize the console to provide early debug support */
console_init(PL011_UART0_BASE); console_init(PL011_UART0_BASE);
/* /* Allow BL1 to see the whole Trusted RAM */
* Calculate how much ram is BL1 using & how much remains free.
* This also includes a rudimentary mechanism to detect whether
* the BL1 data is loaded at the top or bottom of memory.
* TODO: add support for discontigous chunks of free ram if
* needed. Might need dynamic memory allocation support
* et al.
*/
bl1_tzram_layout.total_base = TZRAM_BASE; bl1_tzram_layout.total_base = TZRAM_BASE;
bl1_tzram_layout.total_size = TZRAM_SIZE; bl1_tzram_layout.total_size = TZRAM_SIZE;
if (bl1_ram_limit == tzram_limit) { /* Calculate how much RAM BL1 is using and how much remains free */
/* BL1 has been loaded at the top of memory. */ bl1_tzram_layout.free_base = TZRAM_BASE;
bl1_tzram_layout.free_base = TZRAM_BASE; bl1_tzram_layout.free_size = TZRAM_SIZE;
bl1_tzram_layout.free_size = bl1_ram_base - TZRAM_BASE; reserve_mem(&bl1_tzram_layout.free_base,
} else { &bl1_tzram_layout.free_size,
/* BL1 has been loaded at the bottom of memory. */ BL1_RAM_BASE,
bl1_tzram_layout.free_base = bl1_ram_limit; bl1_size);
bl1_tzram_layout.free_size =
tzram_limit - bl1_ram_limit; INFO("BL1: 0x%lx - 0x%lx [size = %u]\n", BL1_RAM_BASE, BL1_RAM_LIMIT,
} bl1_size);
/* Initialize the platform config for future decision making */ /* Initialize the platform config for future decision making */
fvp_config_setup(); fvp_config_setup();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment