blob: 2baa29abac8c00acfe009e719f54e68d5abff36b [file] [log] [blame]
Yatharth Kochara65be2f2015-10-09 18:06:13 +01001/*
Alexei Fedorov71707b12020-07-13 14:06:47 +01002 * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
Yatharth Kochara65be2f2015-10-09 18:06:13 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Yatharth Kochara65be2f2015-10-09 18:06:13 +01005 */
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +01006
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +01007#include <assert.h>
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +01008#include <errno.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
Yatharth Kochara65be2f2015-10-09 18:06:13 +010010#include <platform_def.h>
11
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <arch_helpers.h>
13#include <bl1/bl1.h>
14#include <common/bl_common.h>
15#include <common/debug.h>
16#include <plat/common/platform.h>
17
Yatharth Kochara65be2f2015-10-09 18:06:13 +010018/*
19 * The following platform functions are weakly defined. They
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010020 * are default implementations that allow BL1 to compile in
Yatharth Kochara65be2f2015-10-09 18:06:13 +010021 * absence of real definitions. The Platforms may override
22 * with more complex definitions.
23 */
24#pragma weak bl1_plat_get_next_image_id
25#pragma weak bl1_plat_set_ep_info
26#pragma weak bl1_plat_get_image_desc
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010027#pragma weak bl1_plat_fwu_done
Soby Mathew2f38ce32018-02-08 17:45:12 +000028#pragma weak bl1_plat_handle_pre_image_load
29#pragma weak bl1_plat_handle_post_image_load
Alexei Fedorov71707b12020-07-13 14:06:47 +010030#if MEASURED_BOOT
31#pragma weak bl1_plat_set_bl2_hash
32#endif
Yatharth Kochara65be2f2015-10-09 18:06:13 +010033
34unsigned int bl1_plat_get_next_image_id(void)
35{
36 /* BL2 load will be done by default. */
37 return BL2_IMAGE_ID;
38}
39
40void bl1_plat_set_ep_info(unsigned int image_id,
Sandrine Bailleuxb3b6e222018-07-11 12:44:22 +020041 struct entry_point_info *ep_info)
Yatharth Kochara65be2f2015-10-09 18:06:13 +010042{
43
44}
45
Soby Mathew2f38ce32018-02-08 17:45:12 +000046int bl1_plat_handle_pre_image_load(unsigned int image_id)
47{
48 return 0;
49}
50
Yatharth Kochara65be2f2015-10-09 18:06:13 +010051/*
52 * Following is the default definition that always
53 * returns BL2 image details.
54 */
Sandrine Bailleuxb3b6e222018-07-11 12:44:22 +020055struct image_desc *bl1_plat_get_image_desc(unsigned int image_id)
Yatharth Kochara65be2f2015-10-09 18:06:13 +010056{
57 static image_desc_t bl2_img_desc = BL2_IMAGE_DESC;
58 return &bl2_img_desc;
59}
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010060
Dan Handley89f8f332015-12-15 14:28:24 +000061__dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010062{
63 while (1)
64 wfi();
65}
66
67/*
68 * The Platforms must override with real definition.
69 */
70#pragma weak bl1_plat_mem_check
71
72int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size,
73 unsigned int flags)
74{
75 assert(0);
76 return -ENOMEM;
77}
Soby Mathew6e16a332018-01-10 12:51:34 +000078
79/*
80 * Default implementation for bl1_plat_handle_post_image_load(). This function
81 * populates the default arguments to BL2. The BL2 memory layout structure
82 * is allocated and the calculated layout is populated in arg1 to BL2.
83 */
84int bl1_plat_handle_post_image_load(unsigned int image_id)
85{
86 meminfo_t *bl2_tzram_layout;
87 meminfo_t *bl1_tzram_layout;
88 image_desc_t *image_desc;
89 entry_point_info_t *ep_info;
90
91 if (image_id != BL2_IMAGE_ID)
92 return 0;
93
94 /* Get the image descriptor */
95 image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
Soby Mathewcc364842018-02-21 01:16:39 +000096 assert(image_desc != NULL);
Soby Mathew6e16a332018-01-10 12:51:34 +000097
98 /* Get the entry point info */
99 ep_info = &image_desc->ep_info;
100
101 /* Find out how much free trusted ram remains after BL1 load */
102 bl1_tzram_layout = bl1_plat_sec_mem_layout();
103
104 /*
105 * Create a new layout of memory for BL2 as seen by BL1 i.e.
106 * tell it the amount of total and free memory available.
107 * This layout is created at the first free address visible
108 * to BL2. BL2 will read the memory layout before using its
109 * memory for other purposes.
110 */
Soby Mathew6e16a332018-01-10 12:51:34 +0000111 bl2_tzram_layout = (meminfo_t *) bl1_tzram_layout->total_base;
Soby Mathew6e16a332018-01-10 12:51:34 +0000112
Soby Mathew6e16a332018-01-10 12:51:34 +0000113 bl1_calc_bl2_mem_layout(bl1_tzram_layout, bl2_tzram_layout);
Soby Mathew6e16a332018-01-10 12:51:34 +0000114
115 ep_info->args.arg1 = (uintptr_t)bl2_tzram_layout;
116
117 VERBOSE("BL1: BL2 memory layout address = %p\n",
118 (void *) bl2_tzram_layout);
119 return 0;
120}
Alexei Fedorov71707b12020-07-13 14:06:47 +0100121
122#if MEASURED_BOOT
123/*
124 * Calculates and writes BL2 hash data to TB_FW_CONFIG DTB.
125 */
126void bl1_plat_set_bl2_hash(const image_desc_t *image_desc)
127{
128}
129#endif