diff --git a/plat/juno/bl2_plat_setup.c b/plat/juno/bl2_plat_setup.c index 28fac8023eb7edab55e102f99b136782fb419b36..20dfc298e0073e4a05ac103e0d31c09e833ed270 100644 --- a/plat/juno/bl2_plat_setup.c +++ b/plat/juno/bl2_plat_setup.c @@ -28,11 +28,15 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include <stdio.h> +#include <string.h> #include <assert.h> #include <arch_helpers.h> #include <platform.h> #include <bl2.h> #include <bl_common.h> +#include <scp_bootloader.h> +#include <debug.h> /******************************************************************************* * Declarations of linker defined symbols which will help us find the layout @@ -102,6 +106,54 @@ void bl2_early_platform_setup(meminfo *mem_layout, bl2_tzram_layout.next = 0; } +/******************************************************************************* + * Load BL3-0 into Trusted RAM, then transfer it using the SCP Download + * protocol. The image is loaded into RAM in the same place that BL3-1 will be + * loaded later so here, we copy the RAM layout structure and use it to load + * the image into. When this function exits, the RAM layout remains untouched + * so the BL2 can load BL3-1 as normal. + ******************************************************************************/ +static int load_bl30(void) +{ + meminfo *bl2_tzram_layout; + meminfo tzram_layout; + meminfo *tmp_tzram_layout = &tzram_layout; + unsigned long bl30_base; + unsigned int image_len; + unsigned int bl2_load, bl30_load; + int ret = -1; + + /* Find out how much free trusted ram remains after BL2 load */ + bl2_tzram_layout = bl2_plat_sec_mem_layout(); + + /* copy the TZRAM layout and use it */ + memcpy(tmp_tzram_layout, bl2_tzram_layout, sizeof(meminfo)); + + /* Work out where to load BL3-0 before transferring to SCP */ + bl2_load = tmp_tzram_layout->attr & LOAD_MASK; + assert((bl2_load == TOP_LOAD) || (bl2_load == BOT_LOAD)); + bl30_load = (bl2_load == TOP_LOAD) ? BOT_LOAD : TOP_LOAD; + + /* Load the BL3-0 image */ + bl30_base = load_image(tmp_tzram_layout, BL30_IMAGE_NAME, + bl30_load, BL30_BASE); + + if (bl30_base != 0) { + image_len = image_size(BL30_IMAGE_NAME); + INFO("BL2: BL3-0 loaded at 0x%lx, len=%d (0x%x)\n\r", bl30_base, + image_len, image_len); + flush_dcache_range(bl30_base, image_len); + ret = scp_bootloader_transfer((void *)bl30_base, image_len); + } + + if (ret == 0) + INFO("BL2: BL3-0 loaded and transferred to SCP\n\r"); + else + ERROR("BL2: BL3-0 load and transfer failure\n\r"); + + return ret; +} + /******************************************************************************* * Perform platform specific setup, i.e. initialize the IO layer, load BL3-0 * image and initialise the memory location to use for passing arguments to @@ -112,6 +164,10 @@ void bl2_platform_setup() /* Initialise the IO layer and register platform IO devices */ io_setup(); + /* Load BL3-0 */ + if (load_bl30() != 0) + panic(); + /* Populate the extents of memory available for loading BL3-3 */ bl2_to_bl31_args.bl33_meminfo.total_base = DRAM_BASE; bl2_to_bl31_args.bl33_meminfo.total_size = DRAM_SIZE; diff --git a/plat/juno/plat_io_storage.c b/plat/juno/plat_io_storage.c index ad16ca670ffc5ee48adf6b07c29af901155e5bd8..6f2d881273c2f71a7ceaa020f771ccbe4cc0b3c5 100644 --- a/plat/juno/plat_io_storage.c +++ b/plat/juno/plat_io_storage.c @@ -58,6 +58,11 @@ static io_file_spec bl2_file_spec = { .mode = FOPEN_MODE_R }; +static io_file_spec bl30_file_spec = { + .path = BL30_IMAGE_NAME, + .mode = FOPEN_MODE_R +}; + static io_file_spec bl31_file_spec = { .path = BL31_IMAGE_NAME, .mode = FOPEN_MODE_R @@ -81,6 +86,7 @@ typedef struct { static plat_io_policy policies[] = { { FIP_IMAGE_NAME, &memmap_dev_handle, &fip_block_spec, open_memmap }, { BL2_IMAGE_NAME, &fip_dev_handle, &bl2_file_spec, open_fip }, + { BL30_IMAGE_NAME, &fip_dev_handle, &bl30_file_spec, open_fip }, { BL31_IMAGE_NAME, &fip_dev_handle, &bl31_file_spec, open_fip }, { BL33_IMAGE_NAME, &fip_dev_handle, &bl33_file_spec, open_fip }, {0, 0, 0} diff --git a/plat/juno/platform.h b/plat/juno/platform.h index 1b902ea5f9861e785b62868c6c25f0881531fd1a..1730532e4126c7308b2239c41f04ccf08ac51825 100644 --- a/plat/juno/platform.h +++ b/plat/juno/platform.h @@ -54,6 +54,9 @@ /* Trusted Boot Firmware BL2 */ #define BL2_IMAGE_NAME "bl2.bin" +/* SCP Firmware BL3-0 */ +#define BL30_IMAGE_NAME "bl30.bin" + /* EL3 Runtime Firmware BL3-1 */ #define BL31_IMAGE_NAME "bl31.bin" @@ -155,6 +158,13 @@ ******************************************************************************/ #define BL31_BASE 0x0400C000 +/******************************************************************************* + * BL3-0 specific defines. + * BL3-0 is loaded to the same place as BL3-1. Once BL3-0 is transferred to the + * SCP, it is discarded and BL3-1 is loaded over the top. + ******************************************************************************/ +#define BL30_BASE BL31_BASE + /******************************************************************************* * Platform specific page table and MMU setup constants ******************************************************************************/