blob: 4b1f233495fcf6cf54629ae42724a37670e006ff [file] [log] [blame]
Yatharth Kochara65be2f2015-10-09 18:06:13 +01001/*
Soby Mathew6e16a332018-01-10 12:51:34 +00002 * Copyright (c) 2015-2018, 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
7#include <arch_helpers.h>
8#include <assert.h>
Yatharth Kochara65be2f2015-10-09 18:06:13 +01009#include <bl_common.h>
Soby Mathew6e16a332018-01-10 12:51:34 +000010#include <bl1.h>
Yatharth Kochara65be2f2015-10-09 18:06:13 +010011#include <debug.h>
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010012#include <errno.h>
Soby Mathew2f38ce32018-02-08 17:45:12 +000013#include <platform.h>
Yatharth Kochara65be2f2015-10-09 18:06:13 +010014#include <platform_def.h>
15
16/*
17 * The following platform functions are weakly defined. They
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010018 * are default implementations that allow BL1 to compile in
Yatharth Kochara65be2f2015-10-09 18:06:13 +010019 * absence of real definitions. The Platforms may override
20 * with more complex definitions.
21 */
22#pragma weak bl1_plat_get_next_image_id
23#pragma weak bl1_plat_set_ep_info
24#pragma weak bl1_plat_get_image_desc
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010025#pragma weak bl1_plat_fwu_done
Soby Mathew2f38ce32018-02-08 17:45:12 +000026#pragma weak bl1_plat_handle_pre_image_load
27#pragma weak bl1_plat_handle_post_image_load
Yatharth Kochara65be2f2015-10-09 18:06:13 +010028
29
30unsigned int bl1_plat_get_next_image_id(void)
31{
32 /* BL2 load will be done by default. */
33 return BL2_IMAGE_ID;
34}
35
36void bl1_plat_set_ep_info(unsigned int image_id,
37 entry_point_info_t *ep_info)
38{
39
40}
41
Soby Mathew2f38ce32018-02-08 17:45:12 +000042int bl1_plat_handle_pre_image_load(unsigned int image_id)
43{
44 return 0;
45}
46
Yatharth Kochara65be2f2015-10-09 18:06:13 +010047/*
48 * Following is the default definition that always
49 * returns BL2 image details.
50 */
51image_desc_t *bl1_plat_get_image_desc(unsigned int image_id)
52{
53 static image_desc_t bl2_img_desc = BL2_IMAGE_DESC;
54 return &bl2_img_desc;
55}
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010056
Dan Handley89f8f332015-12-15 14:28:24 +000057__dead2 void bl1_plat_fwu_done(void *client_cookie, void *reserved)
Yatharth Kochar71c9a5e2015-10-10 19:06:53 +010058{
59 while (1)
60 wfi();
61}
62
63/*
64 * The Platforms must override with real definition.
65 */
66#pragma weak bl1_plat_mem_check
67
68int bl1_plat_mem_check(uintptr_t mem_base, unsigned int mem_size,
69 unsigned int flags)
70{
71 assert(0);
72 return -ENOMEM;
73}
Soby Mathew6e16a332018-01-10 12:51:34 +000074
75/*
76 * Default implementation for bl1_plat_handle_post_image_load(). This function
77 * populates the default arguments to BL2. The BL2 memory layout structure
78 * is allocated and the calculated layout is populated in arg1 to BL2.
79 */
80int bl1_plat_handle_post_image_load(unsigned int image_id)
81{
82 meminfo_t *bl2_tzram_layout;
83 meminfo_t *bl1_tzram_layout;
84 image_desc_t *image_desc;
85 entry_point_info_t *ep_info;
86
87 if (image_id != BL2_IMAGE_ID)
88 return 0;
89
90 /* Get the image descriptor */
91 image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
Soby Mathewcc364842018-02-21 01:16:39 +000092 assert(image_desc != NULL);
Soby Mathew6e16a332018-01-10 12:51:34 +000093
94 /* Get the entry point info */
95 ep_info = &image_desc->ep_info;
96
97 /* Find out how much free trusted ram remains after BL1 load */
98 bl1_tzram_layout = bl1_plat_sec_mem_layout();
99
100 /*
101 * Create a new layout of memory for BL2 as seen by BL1 i.e.
102 * tell it the amount of total and free memory available.
103 * This layout is created at the first free address visible
104 * to BL2. BL2 will read the memory layout before using its
105 * memory for other purposes.
106 */
107#if LOAD_IMAGE_V2
108 bl2_tzram_layout = (meminfo_t *) bl1_tzram_layout->total_base;
109#else
110 bl2_tzram_layout = (meminfo_t *) bl1_tzram_layout->free_base;
111#endif /* LOAD_IMAGE_V2 */
112
113#if !ERROR_DEPRECATED
114 bl1_init_bl2_mem_layout(bl1_tzram_layout, bl2_tzram_layout);
115#else
116 bl1_calc_bl2_mem_layout(bl1_tzram_layout, bl2_tzram_layout);
117#endif
118
119 ep_info->args.arg1 = (uintptr_t)bl2_tzram_layout;
120
121 VERBOSE("BL1: BL2 memory layout address = %p\n",
122 (void *) bl2_tzram_layout);
123 return 0;
124}