17baff11fSYatharth Kochar /* 23f498b0dSAlexei Fedorov * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved. 37baff11fSYatharth Kochar * 482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause 57baff11fSYatharth Kochar */ 648bfb88eSYatharth Kochar 748bfb88eSYatharth Kochar #include <assert.h> 848bfb88eSYatharth Kochar #include <errno.h> 909d40e0eSAntonio Nino Diaz 107baff11fSYatharth Kochar #include <platform_def.h> 117baff11fSYatharth Kochar 1209d40e0eSAntonio Nino Diaz #include <arch_helpers.h> 1309d40e0eSAntonio Nino Diaz #include <bl1/bl1.h> 1409d40e0eSAntonio Nino Diaz #include <common/bl_common.h> 1509d40e0eSAntonio Nino Diaz #include <common/debug.h> 1609d40e0eSAntonio Nino Diaz #include <plat/common/platform.h> 1709d40e0eSAntonio Nino Diaz 187baff11fSYatharth Kochar /* 197baff11fSYatharth Kochar * The following platform functions are weakly defined. They 2048bfb88eSYatharth Kochar * are default implementations that allow BL1 to compile in 217baff11fSYatharth Kochar * absence of real definitions. The Platforms may override 227baff11fSYatharth Kochar * with more complex definitions. 237baff11fSYatharth Kochar */ 247baff11fSYatharth Kochar #pragma weak bl1_plat_get_next_image_id 257baff11fSYatharth Kochar #pragma weak bl1_plat_set_ep_info 267baff11fSYatharth Kochar #pragma weak bl1_plat_get_image_desc 2748bfb88eSYatharth Kochar #pragma weak bl1_plat_fwu_done 28566034fcSSoby Mathew #pragma weak bl1_plat_handle_pre_image_load 29566034fcSSoby Mathew #pragma weak bl1_plat_handle_post_image_load 303f498b0dSAlexei Fedorov #if MEASURED_BOOT 313f498b0dSAlexei Fedorov #pragma weak bl1_plat_set_bl2_hash 323f498b0dSAlexei Fedorov #endif 337baff11fSYatharth Kochar 347baff11fSYatharth Kochar unsigned int bl1_plat_get_next_image_id(void) 357baff11fSYatharth Kochar { 367baff11fSYatharth Kochar /* BL2 load will be done by default. */ 377baff11fSYatharth Kochar return BL2_IMAGE_ID; 387baff11fSYatharth Kochar } 397baff11fSYatharth Kochar 407baff11fSYatharth Kochar void bl1_plat_set_ep_info(unsigned int image_id, 416c77e749SSandrine Bailleux struct entry_point_info *ep_info) 427baff11fSYatharth Kochar { 437baff11fSYatharth Kochar 447baff11fSYatharth Kochar } 457baff11fSYatharth Kochar 46566034fcSSoby Mathew int bl1_plat_handle_pre_image_load(unsigned int image_id) 47566034fcSSoby Mathew { 48566034fcSSoby Mathew return 0; 49566034fcSSoby Mathew } 50566034fcSSoby Mathew 517baff11fSYatharth Kochar /* 527baff11fSYatharth Kochar * Following is the default definition that always 537baff11fSYatharth Kochar * returns BL2 image details. 547baff11fSYatharth Kochar */ 556c77e749SSandrine Bailleux struct image_desc *bl1_plat_get_image_desc(unsigned int image_id) 567baff11fSYatharth Kochar { 577baff11fSYatharth Kochar static image_desc_t bl2_img_desc = BL2_IMAGE_DESC; 587baff11fSYatharth Kochar return &bl2_img_desc; 597baff11fSYatharth Kochar } 6048bfb88eSYatharth Kochar 611f37b944SDan Handley __dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved) 6248bfb88eSYatharth Kochar { 63*92069086SJimmy Brisson while (true) 6448bfb88eSYatharth Kochar wfi(); 6548bfb88eSYatharth Kochar } 6648bfb88eSYatharth Kochar 6748bfb88eSYatharth Kochar /* 6848bfb88eSYatharth Kochar * The Platforms must override with real definition. 6948bfb88eSYatharth Kochar */ 7048bfb88eSYatharth Kochar #pragma weak bl1_plat_mem_check 7148bfb88eSYatharth Kochar 7248bfb88eSYatharth Kochar int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size, 7348bfb88eSYatharth Kochar unsigned int flags) 7448bfb88eSYatharth Kochar { 7548bfb88eSYatharth Kochar assert(0); 7648bfb88eSYatharth Kochar return -ENOMEM; 7748bfb88eSYatharth Kochar } 78101d01e2SSoby Mathew 79101d01e2SSoby Mathew /* 80101d01e2SSoby Mathew * Default implementation for bl1_plat_handle_post_image_load(). This function 81101d01e2SSoby Mathew * populates the default arguments to BL2. The BL2 memory layout structure 82101d01e2SSoby Mathew * is allocated and the calculated layout is populated in arg1 to BL2. 83101d01e2SSoby Mathew */ 84101d01e2SSoby Mathew int bl1_plat_handle_post_image_load(unsigned int image_id) 85101d01e2SSoby Mathew { 86d74c6b83SJimmy Brisson meminfo_t *bl2_secram_layout; 87d74c6b83SJimmy Brisson meminfo_t *bl1_secram_layout; 88101d01e2SSoby Mathew image_desc_t *image_desc; 89101d01e2SSoby Mathew entry_point_info_t *ep_info; 90101d01e2SSoby Mathew 91101d01e2SSoby Mathew if (image_id != BL2_IMAGE_ID) 92101d01e2SSoby Mathew return 0; 93101d01e2SSoby Mathew 94101d01e2SSoby Mathew /* Get the image descriptor */ 95101d01e2SSoby Mathew image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); 96da5f2745SSoby Mathew assert(image_desc != NULL); 97101d01e2SSoby Mathew 98101d01e2SSoby Mathew /* Get the entry point info */ 99101d01e2SSoby Mathew ep_info = &image_desc->ep_info; 100101d01e2SSoby Mathew 101101d01e2SSoby Mathew /* Find out how much free trusted ram remains after BL1 load */ 102d74c6b83SJimmy Brisson bl1_secram_layout = bl1_plat_sec_mem_layout(); 103101d01e2SSoby Mathew 104101d01e2SSoby Mathew /* 105101d01e2SSoby Mathew * Create a new layout of memory for BL2 as seen by BL1 i.e. 106101d01e2SSoby Mathew * tell it the amount of total and free memory available. 107101d01e2SSoby Mathew * This layout is created at the first free address visible 108101d01e2SSoby Mathew * to BL2. BL2 will read the memory layout before using its 109101d01e2SSoby Mathew * memory for other purposes. 110101d01e2SSoby Mathew */ 111d74c6b83SJimmy Brisson bl2_secram_layout = (meminfo_t *) bl1_secram_layout->total_base; 112101d01e2SSoby Mathew 113d74c6b83SJimmy Brisson bl1_calc_bl2_mem_layout(bl1_secram_layout, bl2_secram_layout); 114101d01e2SSoby Mathew 115d74c6b83SJimmy Brisson ep_info->args.arg1 = (uintptr_t)bl2_secram_layout; 116101d01e2SSoby Mathew 117101d01e2SSoby Mathew VERBOSE("BL1: BL2 memory layout address = %p\n", 118d74c6b83SJimmy Brisson (void *) bl2_secram_layout); 119101d01e2SSoby Mathew return 0; 120101d01e2SSoby Mathew } 1213f498b0dSAlexei Fedorov 1223f498b0dSAlexei Fedorov #if MEASURED_BOOT 1233f498b0dSAlexei Fedorov /* 1243f498b0dSAlexei Fedorov * Calculates and writes BL2 hash data to TB_FW_CONFIG DTB. 1253f498b0dSAlexei Fedorov */ 1263f498b0dSAlexei Fedorov void bl1_plat_set_bl2_hash(const image_desc_t *image_desc) 1273f498b0dSAlexei Fedorov { 1283f498b0dSAlexei Fedorov } 1293f498b0dSAlexei Fedorov #endif 130