17baff11fSYatharth Kochar /* 2101d01e2SSoby Mathew * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. 37baff11fSYatharth Kochar * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 57baff11fSYatharth Kochar */ 648bfb88eSYatharth Kochar 748bfb88eSYatharth Kochar #include <arch_helpers.h> 848bfb88eSYatharth Kochar #include <assert.h> 97baff11fSYatharth Kochar #include <bl_common.h> 10101d01e2SSoby Mathew #include <bl1.h> 117baff11fSYatharth Kochar #include <debug.h> 1248bfb88eSYatharth Kochar #include <errno.h> 13566034fcSSoby Mathew #include <platform.h> 147baff11fSYatharth Kochar #include <platform_def.h> 157baff11fSYatharth Kochar 167baff11fSYatharth Kochar /* 177baff11fSYatharth Kochar * The following platform functions are weakly defined. They 1848bfb88eSYatharth Kochar * are default implementations that allow BL1 to compile in 197baff11fSYatharth Kochar * absence of real definitions. The Platforms may override 207baff11fSYatharth Kochar * with more complex definitions. 217baff11fSYatharth Kochar */ 227baff11fSYatharth Kochar #pragma weak bl1_plat_get_next_image_id 237baff11fSYatharth Kochar #pragma weak bl1_plat_set_ep_info 247baff11fSYatharth Kochar #pragma weak bl1_plat_get_image_desc 2548bfb88eSYatharth Kochar #pragma weak bl1_plat_fwu_done 26566034fcSSoby Mathew #pragma weak bl1_plat_handle_pre_image_load 27566034fcSSoby Mathew #pragma weak bl1_plat_handle_post_image_load 287baff11fSYatharth Kochar 297baff11fSYatharth Kochar 307baff11fSYatharth Kochar unsigned int bl1_plat_get_next_image_id(void) 317baff11fSYatharth Kochar { 327baff11fSYatharth Kochar /* BL2 load will be done by default. */ 337baff11fSYatharth Kochar return BL2_IMAGE_ID; 347baff11fSYatharth Kochar } 357baff11fSYatharth Kochar 367baff11fSYatharth Kochar void bl1_plat_set_ep_info(unsigned int image_id, 377baff11fSYatharth Kochar entry_point_info_t *ep_info) 387baff11fSYatharth Kochar { 397baff11fSYatharth Kochar 407baff11fSYatharth Kochar } 417baff11fSYatharth Kochar 42566034fcSSoby Mathew int bl1_plat_handle_pre_image_load(unsigned int image_id) 43566034fcSSoby Mathew { 44566034fcSSoby Mathew return 0; 45566034fcSSoby Mathew } 46566034fcSSoby Mathew 477baff11fSYatharth Kochar /* 487baff11fSYatharth Kochar * Following is the default definition that always 497baff11fSYatharth Kochar * returns BL2 image details. 507baff11fSYatharth Kochar */ 517baff11fSYatharth Kochar image_desc_t *bl1_plat_get_image_desc(unsigned int image_id) 527baff11fSYatharth Kochar { 537baff11fSYatharth Kochar static image_desc_t bl2_img_desc = BL2_IMAGE_DESC; 547baff11fSYatharth Kochar return &bl2_img_desc; 557baff11fSYatharth Kochar } 5648bfb88eSYatharth Kochar 571f37b944SDan Handley __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved) 5848bfb88eSYatharth Kochar { 5948bfb88eSYatharth Kochar while (1) 6048bfb88eSYatharth Kochar wfi(); 6148bfb88eSYatharth Kochar } 6248bfb88eSYatharth Kochar 6348bfb88eSYatharth Kochar /* 6448bfb88eSYatharth Kochar * The Platforms must override with real definition. 6548bfb88eSYatharth Kochar */ 6648bfb88eSYatharth Kochar #pragma weak bl1_plat_mem_check 6748bfb88eSYatharth Kochar 6848bfb88eSYatharth Kochar int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size, 6948bfb88eSYatharth Kochar unsigned int flags) 7048bfb88eSYatharth Kochar { 7148bfb88eSYatharth Kochar assert(0); 7248bfb88eSYatharth Kochar return -ENOMEM; 7348bfb88eSYatharth Kochar } 74101d01e2SSoby Mathew 75101d01e2SSoby Mathew /* 76101d01e2SSoby Mathew * Default implementation for bl1_plat_handle_post_image_load(). This function 77101d01e2SSoby Mathew * populates the default arguments to BL2. The BL2 memory layout structure 78101d01e2SSoby Mathew * is allocated and the calculated layout is populated in arg1 to BL2. 79101d01e2SSoby Mathew */ 80101d01e2SSoby Mathew int bl1_plat_handle_post_image_load(unsigned int image_id) 81101d01e2SSoby Mathew { 82101d01e2SSoby Mathew meminfo_t *bl2_tzram_layout; 83101d01e2SSoby Mathew meminfo_t *bl1_tzram_layout; 84101d01e2SSoby Mathew image_desc_t *image_desc; 85101d01e2SSoby Mathew entry_point_info_t *ep_info; 86101d01e2SSoby Mathew 87101d01e2SSoby Mathew if (image_id != BL2_IMAGE_ID) 88101d01e2SSoby Mathew return 0; 89101d01e2SSoby Mathew 90101d01e2SSoby Mathew /* Get the image descriptor */ 91101d01e2SSoby Mathew image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); 92*da5f2745SSoby Mathew assert(image_desc != NULL); 93101d01e2SSoby Mathew 94101d01e2SSoby Mathew /* Get the entry point info */ 95101d01e2SSoby Mathew ep_info = &image_desc->ep_info; 96101d01e2SSoby Mathew 97101d01e2SSoby Mathew /* Find out how much free trusted ram remains after BL1 load */ 98101d01e2SSoby Mathew bl1_tzram_layout = bl1_plat_sec_mem_layout(); 99101d01e2SSoby Mathew 100101d01e2SSoby Mathew /* 101101d01e2SSoby Mathew * Create a new layout of memory for BL2 as seen by BL1 i.e. 102101d01e2SSoby Mathew * tell it the amount of total and free memory available. 103101d01e2SSoby Mathew * This layout is created at the first free address visible 104101d01e2SSoby Mathew * to BL2. BL2 will read the memory layout before using its 105101d01e2SSoby Mathew * memory for other purposes. 106101d01e2SSoby Mathew */ 107101d01e2SSoby Mathew #if LOAD_IMAGE_V2 108101d01e2SSoby Mathew bl2_tzram_layout = (meminfo_t *) bl1_tzram_layout->total_base; 109101d01e2SSoby Mathew #else 110101d01e2SSoby Mathew bl2_tzram_layout = (meminfo_t *) bl1_tzram_layout->free_base; 111101d01e2SSoby Mathew #endif /* LOAD_IMAGE_V2 */ 112101d01e2SSoby Mathew 113101d01e2SSoby Mathew #if !ERROR_DEPRECATED 114101d01e2SSoby Mathew bl1_init_bl2_mem_layout(bl1_tzram_layout, bl2_tzram_layout); 115101d01e2SSoby Mathew #else 116101d01e2SSoby Mathew bl1_calc_bl2_mem_layout(bl1_tzram_layout, bl2_tzram_layout); 117101d01e2SSoby Mathew #endif 118101d01e2SSoby Mathew 119101d01e2SSoby Mathew ep_info->args.arg1 = (uintptr_t)bl2_tzram_layout; 120101d01e2SSoby Mathew 121101d01e2SSoby Mathew VERBOSE("BL1: BL2 memory layout address = %p\n", 122101d01e2SSoby Mathew (void *) bl2_tzram_layout); 123101d01e2SSoby Mathew return 0; 124101d01e2SSoby Mathew } 125