Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 1 | /* |
Dan Handley | e83b0ca | 2014-01-14 18:17:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 31 | #include <arch.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 32 | #include <arch_helpers.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 33 | #include <assert.h> |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 34 | #include <auth_mod.h> |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 35 | #include <bl1.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 36 | #include <bl_common.h> |
Dan Handley | 714a0d2 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 37 | #include <debug.h> |
Juan Castillo | ec813f5 | 2015-10-01 18:37:40 +0100 | [diff] [blame] | 38 | #include <errno.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 39 | #include <platform.h> |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 40 | #include <platform_def.h> |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 41 | #include <stdint.h> |
Dan Handley | bcd60ba | 2014-04-17 18:53:42 +0100 | [diff] [blame] | 42 | #include "bl2_private.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 43 | |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 44 | /* |
| 45 | * Check for platforms that use obsolete image terminology |
| 46 | */ |
| 47 | #ifdef BL30_BASE |
| 48 | # error "BL30_BASE platform define no longer used - please use SCP_BL2_BASE" |
| 49 | #endif |
| 50 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 51 | /******************************************************************************* |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 52 | * Load the SCP_BL2 image if there's one. |
| 53 | * If a platform does not want to attempt to load SCP_BL2 image it must leave |
| 54 | * SCP_BL2_BASE undefined. |
| 55 | * Return 0 on success or if there's no SCP_BL2 image to load, a negative error |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 56 | * code otherwise. |
| 57 | ******************************************************************************/ |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 58 | static int load_scp_bl2(void) |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 59 | { |
| 60 | int e = 0; |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 61 | #ifdef SCP_BL2_BASE |
| 62 | meminfo_t scp_bl2_mem_info; |
| 63 | image_info_t scp_bl2_image_info; |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 64 | |
| 65 | /* |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 66 | * It is up to the platform to specify where SCP_BL2 should be loaded if |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 67 | * it exists. It could create space in the secure sram or point to a |
| 68 | * completely different memory. |
| 69 | * |
| 70 | * The entry point information is not relevant in this case as the AP |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 71 | * won't execute the SCP_BL2 image. |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 72 | */ |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 73 | INFO("BL2: Loading SCP_BL2\n"); |
| 74 | bl2_plat_get_scp_bl2_meminfo(&scp_bl2_mem_info); |
| 75 | scp_bl2_image_info.h.version = VERSION_1; |
| 76 | e = load_auth_image(&scp_bl2_mem_info, |
| 77 | SCP_BL2_IMAGE_ID, |
| 78 | SCP_BL2_BASE, |
| 79 | &scp_bl2_image_info, |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 80 | NULL); |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 81 | |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 82 | if (e == 0) { |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 83 | /* The subsequent handling of SCP_BL2 is platform specific */ |
| 84 | e = bl2_plat_handle_scp_bl2(&scp_bl2_image_info); |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 85 | if (e) { |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 86 | ERROR("Failure in platform-specific handling of SCP_BL2 image.\n"); |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 87 | } |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 88 | } |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 89 | #endif /* SCP_BL2_BASE */ |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 90 | |
| 91 | return e; |
| 92 | } |
Vikram Kanigiri | a3a5e4a | 2014-05-15 18:27:15 +0100 | [diff] [blame] | 93 | |
Sandrine Bailleux | 03897bb | 2015-11-26 16:31:34 +0000 | [diff] [blame] | 94 | #ifndef EL3_PAYLOAD_BASE |
Vikram Kanigiri | a3a5e4a | 2014-05-15 18:27:15 +0100 | [diff] [blame] | 95 | /******************************************************************************* |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 96 | * Load the BL31 image. |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 97 | * The bl2_to_bl31_params and bl31_ep_info params will be updated with the |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 98 | * relevant BL31 information. |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 99 | * Return 0 on success, a negative error code otherwise. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 100 | ******************************************************************************/ |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 101 | static int load_bl31(bl31_params_t *bl2_to_bl31_params, |
| 102 | entry_point_info_t *bl31_ep_info) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 103 | { |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 104 | meminfo_t *bl2_tzram_layout; |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 105 | int e; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 106 | |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 107 | INFO("BL2: Loading BL31\n"); |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 108 | assert(bl2_to_bl31_params != NULL); |
| 109 | assert(bl31_ep_info != NULL); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 110 | |
| 111 | /* Find out how much free trusted ram remains after BL2 load */ |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 112 | bl2_tzram_layout = bl2_plat_sec_mem_layout(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 113 | |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 114 | /* Set the X0 parameter to BL31 */ |
Andrew Thoelke | a55566d | 2014-05-28 22:22:55 +0100 | [diff] [blame] | 115 | bl31_ep_info->args.arg0 = (unsigned long)bl2_to_bl31_params; |
| 116 | |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 117 | /* Load the BL31 image */ |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 118 | e = load_auth_image(bl2_tzram_layout, |
| 119 | BL31_IMAGE_ID, |
| 120 | BL31_BASE, |
| 121 | bl2_to_bl31_params->bl31_image_info, |
| 122 | bl31_ep_info); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 123 | |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 124 | if (e == 0) { |
| 125 | bl2_plat_set_bl31_ep_info(bl2_to_bl31_params->bl31_image_info, |
| 126 | bl31_ep_info); |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 127 | } |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 128 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 129 | return e; |
| 130 | } |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 131 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 132 | /******************************************************************************* |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 133 | * Load the BL32 image if there's one. |
| 134 | * The bl2_to_bl31_params param will be updated with the relevant BL32 |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 135 | * information. |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 136 | * If a platform does not want to attempt to load BL32 image it must leave |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 137 | * BL32_BASE undefined. |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 138 | * Return 0 on success or if there's no BL32 image to load, a negative error |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 139 | * code otherwise. |
| 140 | ******************************************************************************/ |
| 141 | static int load_bl32(bl31_params_t *bl2_to_bl31_params) |
| 142 | { |
| 143 | int e = 0; |
| 144 | #ifdef BL32_BASE |
| 145 | meminfo_t bl32_mem_info; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 146 | |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 147 | INFO("BL2: Loading BL32\n"); |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 148 | assert(bl2_to_bl31_params != NULL); |
Dan Handley | 21a30ab | 2014-04-15 11:38:38 +0100 | [diff] [blame] | 149 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 150 | /* |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 151 | * It is up to the platform to specify where BL32 should be loaded if |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 152 | * it exists. It could create space in the secure sram or point to a |
Dan Handley | 21a30ab | 2014-04-15 11:38:38 +0100 | [diff] [blame] | 153 | * completely different memory. |
Vikram Kanigiri | a3a5e4a | 2014-05-15 18:27:15 +0100 | [diff] [blame] | 154 | */ |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 155 | bl2_plat_get_bl32_meminfo(&bl32_mem_info); |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 156 | e = load_auth_image(&bl32_mem_info, |
| 157 | BL32_IMAGE_ID, |
| 158 | BL32_BASE, |
| 159 | bl2_to_bl31_params->bl32_image_info, |
| 160 | bl2_to_bl31_params->bl32_ep_info); |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 161 | |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 162 | if (e == 0) { |
| 163 | bl2_plat_set_bl32_ep_info( |
| 164 | bl2_to_bl31_params->bl32_image_info, |
| 165 | bl2_to_bl31_params->bl32_ep_info); |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 166 | } |
Dan Handley | 21a30ab | 2014-04-15 11:38:38 +0100 | [diff] [blame] | 167 | #endif /* BL32_BASE */ |
Achin Gupta | a3050ed | 2014-02-19 17:52:35 +0000 | [diff] [blame] | 168 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 169 | return e; |
| 170 | } |
| 171 | |
Antonio Nino Diaz | 2b8277b | 2016-04-06 17:31:57 +0100 | [diff] [blame] | 172 | #ifndef PRELOADED_BL33_BASE |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 173 | /******************************************************************************* |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 174 | * Load the BL33 image. |
| 175 | * The bl2_to_bl31_params param will be updated with the relevant BL33 |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 176 | * information. |
| 177 | * Return 0 on success, a negative error code otherwise. |
| 178 | ******************************************************************************/ |
| 179 | static int load_bl33(bl31_params_t *bl2_to_bl31_params) |
| 180 | { |
| 181 | meminfo_t bl33_mem_info; |
| 182 | int e; |
| 183 | |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 184 | INFO("BL2: Loading BL33\n"); |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 185 | assert(bl2_to_bl31_params != NULL); |
| 186 | |
| 187 | bl2_plat_get_bl33_meminfo(&bl33_mem_info); |
| 188 | |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 189 | /* Load the BL33 image in non-secure memory provided by the platform */ |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 190 | e = load_auth_image(&bl33_mem_info, |
| 191 | BL33_IMAGE_ID, |
| 192 | plat_get_ns_image_entrypoint(), |
| 193 | bl2_to_bl31_params->bl33_image_info, |
| 194 | bl2_to_bl31_params->bl33_ep_info); |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 195 | |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 196 | if (e == 0) { |
| 197 | bl2_plat_set_bl33_ep_info(bl2_to_bl31_params->bl33_image_info, |
| 198 | bl2_to_bl31_params->bl33_ep_info); |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 199 | } |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 200 | |
| 201 | return e; |
| 202 | } |
Antonio Nino Diaz | 2b8277b | 2016-04-06 17:31:57 +0100 | [diff] [blame] | 203 | #endif /* PRELOADED_BL33_BASE */ |
Antonio Nino Diaz | faf573a | 2016-02-15 14:53:10 +0000 | [diff] [blame] | 204 | |
Sandrine Bailleux | 03897bb | 2015-11-26 16:31:34 +0000 | [diff] [blame] | 205 | #endif /* EL3_PAYLOAD_BASE */ |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 206 | |
| 207 | /******************************************************************************* |
| 208 | * The only thing to do in BL2 is to load further images and pass control to |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 209 | * BL31. The memory occupied by BL2 will be reclaimed by BL3x stages. BL2 runs |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 210 | * entirely in S-EL1. |
| 211 | ******************************************************************************/ |
| 212 | void bl2_main(void) |
| 213 | { |
| 214 | bl31_params_t *bl2_to_bl31_params; |
| 215 | entry_point_info_t *bl31_ep_info; |
| 216 | int e; |
| 217 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 218 | NOTICE("BL2: %s\n", version_string); |
| 219 | NOTICE("BL2: %s\n", build_message); |
| 220 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 221 | /* Perform remaining generic architectural setup in S-EL1 */ |
| 222 | bl2_arch_setup(); |
| 223 | |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 224 | #if TRUSTED_BOARD_BOOT |
| 225 | /* Initialize authentication module */ |
Juan Castillo | a08a5e7 | 2015-05-19 11:54:12 +0100 | [diff] [blame] | 226 | auth_mod_init(); |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 227 | #endif /* TRUSTED_BOARD_BOOT */ |
| 228 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 229 | /* |
| 230 | * Load the subsequent bootloader images |
| 231 | */ |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 232 | e = load_scp_bl2(); |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 233 | if (e) { |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 234 | ERROR("Failed to load SCP_BL2 (%i)\n", e); |
Juan Castillo | 26ae583 | 2015-09-25 15:41:14 +0100 | [diff] [blame] | 235 | plat_error_handler(e); |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 236 | } |
| 237 | |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 238 | /* Perform platform setup in BL2 after loading SCP_BL2 */ |
Juan Castillo | 6b672f5 | 2014-09-04 14:43:09 +0100 | [diff] [blame] | 239 | bl2_platform_setup(); |
| 240 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 241 | /* |
| 242 | * Get a pointer to the memory the platform has set aside to pass |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 243 | * information to BL31. |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 244 | */ |
| 245 | bl2_to_bl31_params = bl2_plat_get_bl31_params(); |
| 246 | bl31_ep_info = bl2_plat_get_bl31_ep_info(); |
| 247 | |
Sandrine Bailleux | 03897bb | 2015-11-26 16:31:34 +0000 | [diff] [blame] | 248 | #ifdef EL3_PAYLOAD_BASE |
| 249 | /* |
| 250 | * In the case of an EL3 payload, we don't need to load any further |
| 251 | * images. Just update the BL31 entrypoint info structure to make BL1 |
| 252 | * jump to the EL3 payload. |
| 253 | * The pointer to the memory the platform has set aside to pass |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 254 | * information to BL31 in the normal boot flow is reused here, even |
Sandrine Bailleux | 03897bb | 2015-11-26 16:31:34 +0000 | [diff] [blame] | 255 | * though only a fraction of the information contained in the |
| 256 | * bl31_params_t structure makes sense in the context of EL3 payloads. |
| 257 | * This will be refined in the future. |
| 258 | */ |
Antonio Nino Diaz | faf573a | 2016-02-15 14:53:10 +0000 | [diff] [blame] | 259 | INFO("BL2: Populating the entrypoint info for the EL3 payload\n"); |
Sandrine Bailleux | 03897bb | 2015-11-26 16:31:34 +0000 | [diff] [blame] | 260 | bl31_ep_info->pc = EL3_PAYLOAD_BASE; |
| 261 | bl31_ep_info->args.arg0 = (unsigned long) bl2_to_bl31_params; |
| 262 | bl2_plat_set_bl31_ep_info(NULL, bl31_ep_info); |
| 263 | #else |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 264 | e = load_bl31(bl2_to_bl31_params, bl31_ep_info); |
| 265 | if (e) { |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 266 | ERROR("Failed to load BL31 (%i)\n", e); |
Juan Castillo | 26ae583 | 2015-09-25 15:41:14 +0100 | [diff] [blame] | 267 | plat_error_handler(e); |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | e = load_bl32(bl2_to_bl31_params); |
Juan Castillo | 97dbcf1 | 2015-08-17 10:43:27 +0100 | [diff] [blame] | 271 | if (e) { |
Juan Castillo | ec813f5 | 2015-10-01 18:37:40 +0100 | [diff] [blame] | 272 | if (e == -EAUTH) { |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 273 | ERROR("Failed to authenticate BL32\n"); |
Juan Castillo | 26ae583 | 2015-09-25 15:41:14 +0100 | [diff] [blame] | 274 | plat_error_handler(e); |
Juan Castillo | 97dbcf1 | 2015-08-17 10:43:27 +0100 | [diff] [blame] | 275 | } else { |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 276 | WARN("Failed to load BL32 (%i)\n", e); |
Juan Castillo | 97dbcf1 | 2015-08-17 10:43:27 +0100 | [diff] [blame] | 277 | } |
| 278 | } |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 279 | |
Antonio Nino Diaz | 2b8277b | 2016-04-06 17:31:57 +0100 | [diff] [blame] | 280 | #ifdef PRELOADED_BL33_BASE |
Antonio Nino Diaz | faf573a | 2016-02-15 14:53:10 +0000 | [diff] [blame] | 281 | /* |
| 282 | * In this case, don't load the BL33 image as it's already loaded in |
| 283 | * memory. Update BL33 entrypoint information. |
| 284 | */ |
| 285 | INFO("BL2: Populating the entrypoint info for the preloaded BL33\n"); |
Antonio Nino Diaz | 2b8277b | 2016-04-06 17:31:57 +0100 | [diff] [blame] | 286 | bl2_to_bl31_params->bl33_ep_info->pc = PRELOADED_BL33_BASE; |
Antonio Nino Diaz | faf573a | 2016-02-15 14:53:10 +0000 | [diff] [blame] | 287 | bl2_plat_set_bl33_ep_info(NULL, bl2_to_bl31_params->bl33_ep_info); |
| 288 | #else |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 289 | e = load_bl33(bl2_to_bl31_params); |
| 290 | if (e) { |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 291 | ERROR("Failed to load BL33 (%i)\n", e); |
Juan Castillo | 26ae583 | 2015-09-25 15:41:14 +0100 | [diff] [blame] | 292 | plat_error_handler(e); |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 293 | } |
Antonio Nino Diaz | 2b8277b | 2016-04-06 17:31:57 +0100 | [diff] [blame] | 294 | #endif /* PRELOADED_BL33_BASE */ |
Antonio Nino Diaz | faf573a | 2016-02-15 14:53:10 +0000 | [diff] [blame] | 295 | |
Sandrine Bailleux | 03897bb | 2015-11-26 16:31:34 +0000 | [diff] [blame] | 296 | #endif /* EL3_PAYLOAD_BASE */ |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 297 | |
Andrew Thoelke | a55566d | 2014-05-28 22:22:55 +0100 | [diff] [blame] | 298 | /* Flush the params to be passed to memory */ |
| 299 | bl2_plat_flush_bl31_params(); |
| 300 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 301 | /* |
Juan Castillo | 7d19941 | 2015-12-14 09:35:25 +0000 | [diff] [blame] | 302 | * Run BL31 via an SMC to BL1. Information on how to pass control to |
| 303 | * the BL32 (if present) and BL33 software images will be passed to |
| 304 | * BL31 as an argument. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 305 | */ |
Yatharth Kochar | 71c9a5e | 2015-10-10 19:06:53 +0100 | [diff] [blame] | 306 | smc(BL1_SMC_RUN_IMAGE, (unsigned long)bl31_ep_info, 0, 0, 0, 0, 0, 0); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 307 | } |