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 | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 34 | #include <auth.h> |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 35 | #include <bl_common.h> |
Dan Handley | 714a0d2 | 2014-04-09 13:13:04 +0100 | [diff] [blame] | 36 | #include <debug.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 37 | #include <platform.h> |
Dan Handley | ed6ff95 | 2014-05-14 17:44:19 +0100 | [diff] [blame] | 38 | #include <platform_def.h> |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 39 | #include <stdint.h> |
Dan Handley | bcd60ba | 2014-04-17 18:53:42 +0100 | [diff] [blame] | 40 | #include "bl2_private.h" |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 41 | |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 42 | #if TRUSTED_BOARD_BOOT |
| 43 | |
| 44 | #ifdef BL32_BASE |
| 45 | static int bl32_cert_error; |
| 46 | #endif |
| 47 | |
| 48 | /* |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 49 | * Load and authenticate the key and content certificates for a BL3-x image. |
| 50 | * The _blob values identify the authentication objects (an object may be seen |
| 51 | * as a single stage in the authentication process). See auth.h for the complete |
| 52 | * list of objects. The _id values are passed to the IO framework to identify |
| 53 | * the images to load. |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 54 | * |
| 55 | * Parameters: |
| 56 | * key_cert_blob: key certificate blob id (see auth.h) |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 57 | * key_cert_id: key certificate image identifier (for IO framework) |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 58 | * cont_cert_blob: content certificate blob id (see auth.h) |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 59 | * cont_cert_id: content certificate image identifier (for IO framework) |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 60 | * mem_layout: Trusted SRAM memory layout |
| 61 | * load_addr: load the certificates at this address |
| 62 | * |
| 63 | * Return: 0 = success, Otherwise = error |
| 64 | */ |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 65 | static int load_cert_bl3x(unsigned int key_cert_blob, unsigned int key_cert_id, |
| 66 | unsigned int cont_cert_blob, unsigned int cont_cert_id, |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 67 | meminfo_t *mem_layout, uint64_t load_addr) |
| 68 | { |
| 69 | image_info_t image_info; |
| 70 | int err; |
| 71 | |
| 72 | /* Load Key certificate */ |
| 73 | image_info.h.version = VERSION_1; |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 74 | err = load_image(mem_layout, key_cert_id, load_addr, &image_info, NULL); |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 75 | if (err) { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 76 | ERROR("Cannot load key certificate id=%u\n", key_cert_id); |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 77 | return err; |
| 78 | } |
| 79 | |
| 80 | err = auth_verify_obj(key_cert_blob, image_info.image_base, |
| 81 | image_info.image_size); |
| 82 | if (err) { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 83 | ERROR("Invalid key certificate id=%u\n", key_cert_id); |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 84 | return err; |
| 85 | } |
| 86 | |
| 87 | /* Load Content certificate */ |
| 88 | image_info.h.version = VERSION_1; |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 89 | err = load_image(mem_layout, cont_cert_id, load_addr, &image_info, NULL); |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 90 | if (err) { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 91 | ERROR("Cannot load content certificate id=%u\n", |
| 92 | cont_cert_id); |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 93 | return err; |
| 94 | } |
| 95 | |
| 96 | err = auth_verify_obj(cont_cert_blob, image_info.image_base, |
| 97 | image_info.image_size); |
| 98 | if (err) { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 99 | ERROR("Invalid content certificate id=%u\n", cont_cert_id); |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 100 | return err; |
| 101 | } |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | * Load and authenticate the Trusted Key certificate the key and content |
| 108 | * certificates for each of the BL3-x images. |
| 109 | * |
| 110 | * Return: 0 = success, Otherwise = error |
| 111 | */ |
| 112 | static int load_certs(void) |
| 113 | { |
| 114 | const uint64_t load_addr = BL31_BASE; |
| 115 | image_info_t image_info; |
| 116 | meminfo_t *mem_layout; |
| 117 | int err; |
| 118 | |
| 119 | /* Find out how much free trusted ram remains after BL2 load */ |
| 120 | mem_layout = bl2_plat_sec_mem_layout(); |
| 121 | |
| 122 | /* Load the Trusted Key certificate in the BL31 region */ |
| 123 | image_info.h.version = VERSION_1; |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 124 | err = load_image(mem_layout, TRUSTED_KEY_CERT_ID, load_addr, |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 125 | &image_info, NULL); |
| 126 | if (err) { |
| 127 | ERROR("Failed to load Trusted Key certificate.\n"); |
| 128 | return err; |
| 129 | } |
| 130 | |
| 131 | /* Validate the certificate */ |
| 132 | err = auth_verify_obj(AUTH_TRUSTED_KEY_CERT, image_info.image_base, |
| 133 | image_info.image_size); |
| 134 | if (err) { |
| 135 | ERROR("Invalid Trusted Key certificate.\n"); |
| 136 | return err; |
| 137 | } |
| 138 | |
| 139 | /* Load and validate Key and Content certificates for BL3-x images */ |
| 140 | #ifdef BL30_BASE |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 141 | err = load_cert_bl3x(AUTH_BL30_KEY_CERT, BL30_KEY_CERT_ID, |
| 142 | AUTH_BL30_IMG_CERT, BL30_CERT_ID, |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 143 | mem_layout, load_addr); |
| 144 | if (err) { |
| 145 | ERROR("Failed to verify BL3-0 authenticity\n"); |
| 146 | return err; |
| 147 | } |
| 148 | #endif /* BL30_BASE */ |
| 149 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 150 | err = load_cert_bl3x(AUTH_BL31_KEY_CERT, BL31_KEY_CERT_ID, |
| 151 | AUTH_BL31_IMG_CERT, BL31_CERT_ID, |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 152 | mem_layout, load_addr); |
| 153 | if (err) { |
| 154 | ERROR("Failed to verify BL3-1 authenticity\n"); |
| 155 | return err; |
| 156 | } |
| 157 | |
| 158 | #ifdef BL32_BASE |
| 159 | /* BL3-2 image is optional, but keep the return value in case the |
| 160 | * image is present but the certificate is missing */ |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 161 | err = load_cert_bl3x(AUTH_BL32_KEY_CERT, BL32_KEY_CERT_ID, |
| 162 | AUTH_BL32_IMG_CERT, BL32_CERT_ID, |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 163 | mem_layout, load_addr); |
| 164 | if (err) { |
| 165 | WARN("Failed to verify BL3-2 authenticity\n"); |
| 166 | } |
| 167 | bl32_cert_error = err; |
| 168 | #endif /* BL32_BASE */ |
| 169 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 170 | err = load_cert_bl3x(AUTH_BL33_KEY_CERT, BL33_KEY_CERT_ID, |
| 171 | AUTH_BL33_IMG_CERT, BL33_CERT_ID, |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 172 | mem_layout, load_addr); |
| 173 | if (err) { |
| 174 | ERROR("Failed to verify BL3-3 authenticity\n"); |
| 175 | return err; |
| 176 | } |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | #endif /* TRUSTED_BOARD_BOOT */ |
| 182 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 183 | /******************************************************************************* |
| 184 | * Load the BL3-0 image if there's one. |
| 185 | * If a platform does not want to attempt to load BL3-0 image it must leave |
| 186 | * BL30_BASE undefined. |
| 187 | * Return 0 on success or if there's no BL3-0 image to load, a negative error |
| 188 | * code otherwise. |
| 189 | ******************************************************************************/ |
| 190 | static int load_bl30(void) |
| 191 | { |
| 192 | int e = 0; |
| 193 | #ifdef BL30_BASE |
| 194 | meminfo_t bl30_mem_info; |
| 195 | image_info_t bl30_image_info; |
| 196 | |
| 197 | /* |
| 198 | * It is up to the platform to specify where BL3-0 should be loaded if |
| 199 | * it exists. It could create space in the secure sram or point to a |
| 200 | * completely different memory. |
| 201 | * |
| 202 | * The entry point information is not relevant in this case as the AP |
| 203 | * won't execute the BL3-0 image. |
| 204 | */ |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 205 | INFO("BL2: Loading BL3-0\n"); |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 206 | bl2_plat_get_bl30_meminfo(&bl30_mem_info); |
Juan Castillo | 4db9d15 | 2014-11-13 17:04:33 +0000 | [diff] [blame] | 207 | bl30_image_info.h.version = VERSION_1; |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 208 | e = load_image(&bl30_mem_info, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 209 | BL30_IMAGE_ID, |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 210 | BL30_BASE, |
| 211 | &bl30_image_info, |
| 212 | NULL); |
| 213 | |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 214 | if (e) |
| 215 | return e; |
| 216 | |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 217 | #if TRUSTED_BOARD_BOOT |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 218 | e = auth_verify_obj(AUTH_BL30_IMG, |
| 219 | bl30_image_info.image_base, |
| 220 | bl30_image_info.image_size); |
| 221 | if (e) { |
| 222 | ERROR("Failed to authenticate BL3-0 image.\n"); |
| 223 | return e; |
| 224 | } |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 225 | |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 226 | /* After working with data, invalidate the data cache */ |
| 227 | inv_dcache_range(bl30_image_info.image_base, |
| 228 | (size_t)bl30_image_info.image_size); |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 229 | #endif /* TRUSTED_BOARD_BOOT */ |
| 230 | |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 231 | /* The subsequent handling of BL3-0 is platform specific */ |
| 232 | e = bl2_plat_handle_bl30(&bl30_image_info); |
| 233 | if (e) { |
| 234 | ERROR("Failure in platform-specific handling of BL3-0 image.\n"); |
| 235 | return e; |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 236 | } |
| 237 | #endif /* BL30_BASE */ |
| 238 | |
| 239 | return e; |
| 240 | } |
Vikram Kanigiri | a3a5e4a | 2014-05-15 18:27:15 +0100 | [diff] [blame] | 241 | |
| 242 | /******************************************************************************* |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 243 | * Load the BL3-1 image. |
| 244 | * The bl2_to_bl31_params and bl31_ep_info params will be updated with the |
| 245 | * relevant BL3-1 information. |
| 246 | * Return 0 on success, a negative error code otherwise. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 247 | ******************************************************************************/ |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 248 | static int load_bl31(bl31_params_t *bl2_to_bl31_params, |
| 249 | entry_point_info_t *bl31_ep_info) |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 250 | { |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 251 | meminfo_t *bl2_tzram_layout; |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 252 | int e; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 253 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 254 | INFO("BL2: Loading BL3-1\n"); |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 255 | assert(bl2_to_bl31_params != NULL); |
| 256 | assert(bl31_ep_info != NULL); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 257 | |
| 258 | /* Find out how much free trusted ram remains after BL2 load */ |
Sandrine Bailleux | ee12f6f | 2013-11-28 14:55:58 +0000 | [diff] [blame] | 259 | bl2_tzram_layout = bl2_plat_sec_mem_layout(); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 260 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 261 | /* Set the X0 parameter to BL3-1 */ |
Andrew Thoelke | a55566d | 2014-05-28 22:22:55 +0100 | [diff] [blame] | 262 | bl31_ep_info->args.arg0 = (unsigned long)bl2_to_bl31_params; |
| 263 | |
Sandrine Bailleux | 467d057 | 2014-06-24 14:02:34 +0100 | [diff] [blame] | 264 | /* Load the BL3-1 image */ |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 265 | e = load_image(bl2_tzram_layout, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 266 | BL31_IMAGE_ID, |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 267 | BL31_BASE, |
| 268 | bl2_to_bl31_params->bl31_image_info, |
| 269 | bl31_ep_info); |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 270 | if (e) |
| 271 | return e; |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 272 | |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 273 | #if TRUSTED_BOARD_BOOT |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 274 | e = auth_verify_obj(AUTH_BL31_IMG, |
| 275 | bl2_to_bl31_params->bl31_image_info->image_base, |
| 276 | bl2_to_bl31_params->bl31_image_info->image_size); |
| 277 | if (e) { |
| 278 | ERROR("Failed to authenticate BL3-1 image.\n"); |
| 279 | return e; |
| 280 | } |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 281 | |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 282 | /* After working with data, invalidate the data cache */ |
| 283 | inv_dcache_range(bl2_to_bl31_params->bl31_image_info->image_base, |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 284 | (size_t)bl2_to_bl31_params->bl31_image_info->image_size); |
| 285 | #endif /* TRUSTED_BOARD_BOOT */ |
| 286 | |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 287 | bl2_plat_set_bl31_ep_info(bl2_to_bl31_params->bl31_image_info, |
| 288 | bl31_ep_info); |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 289 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 290 | return e; |
| 291 | } |
Vikram Kanigiri | da56743 | 2014-04-15 18:08:08 +0100 | [diff] [blame] | 292 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 293 | /******************************************************************************* |
| 294 | * Load the BL3-2 image if there's one. |
| 295 | * The bl2_to_bl31_params param will be updated with the relevant BL3-2 |
| 296 | * information. |
| 297 | * If a platform does not want to attempt to load BL3-2 image it must leave |
| 298 | * BL32_BASE undefined. |
| 299 | * Return 0 on success or if there's no BL3-2 image to load, a negative error |
| 300 | * code otherwise. |
| 301 | ******************************************************************************/ |
| 302 | static int load_bl32(bl31_params_t *bl2_to_bl31_params) |
| 303 | { |
| 304 | int e = 0; |
| 305 | #ifdef BL32_BASE |
| 306 | meminfo_t bl32_mem_info; |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 307 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 308 | INFO("BL2: Loading BL3-2\n"); |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 309 | assert(bl2_to_bl31_params != NULL); |
Dan Handley | 21a30ab | 2014-04-15 11:38:38 +0100 | [diff] [blame] | 310 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 311 | /* |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 312 | * It is up to the platform to specify where BL3-2 should be loaded if |
| 313 | * 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] | 314 | * completely different memory. |
Vikram Kanigiri | a3a5e4a | 2014-05-15 18:27:15 +0100 | [diff] [blame] | 315 | */ |
Vikram Kanigiri | d8c9d26 | 2014-05-16 18:48:12 +0100 | [diff] [blame] | 316 | bl2_plat_get_bl32_meminfo(&bl32_mem_info); |
Dan Handley | 21a30ab | 2014-04-15 11:38:38 +0100 | [diff] [blame] | 317 | e = load_image(&bl32_mem_info, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 318 | BL32_IMAGE_ID, |
Dan Handley | 21a30ab | 2014-04-15 11:38:38 +0100 | [diff] [blame] | 319 | BL32_BASE, |
| 320 | bl2_to_bl31_params->bl32_image_info, |
| 321 | bl2_to_bl31_params->bl32_ep_info); |
Vikram Kanigiri | a3a5e4a | 2014-05-15 18:27:15 +0100 | [diff] [blame] | 322 | |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 323 | if (e) |
| 324 | return e; |
| 325 | |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 326 | #if TRUSTED_BOARD_BOOT |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 327 | /* Image is present. Check if there is a valid certificate */ |
| 328 | if (bl32_cert_error) { |
| 329 | ERROR("Failed to authenticate BL3-2 certificates.\n"); |
| 330 | return bl32_cert_error; |
| 331 | } |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 332 | |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 333 | e = auth_verify_obj(AUTH_BL32_IMG, |
| 334 | bl2_to_bl31_params->bl32_image_info->image_base, |
| 335 | bl2_to_bl31_params->bl32_image_info->image_size); |
| 336 | if (e) { |
| 337 | ERROR("Failed to authenticate BL3-2 image.\n"); |
| 338 | return e; |
| 339 | } |
| 340 | /* After working with data, invalidate the data cache */ |
| 341 | inv_dcache_range(bl2_to_bl31_params->bl32_image_info->image_base, |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 342 | (size_t)bl2_to_bl31_params->bl32_image_info->image_size); |
| 343 | #endif /* TRUSTED_BOARD_BOOT */ |
| 344 | |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 345 | bl2_plat_set_bl32_ep_info( |
| 346 | bl2_to_bl31_params->bl32_image_info, |
| 347 | bl2_to_bl31_params->bl32_ep_info); |
Dan Handley | 21a30ab | 2014-04-15 11:38:38 +0100 | [diff] [blame] | 348 | #endif /* BL32_BASE */ |
Achin Gupta | a3050ed | 2014-02-19 17:52:35 +0000 | [diff] [blame] | 349 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 350 | return e; |
| 351 | } |
| 352 | |
| 353 | /******************************************************************************* |
| 354 | * Load the BL3-3 image. |
| 355 | * The bl2_to_bl31_params param will be updated with the relevant BL3-3 |
| 356 | * information. |
| 357 | * Return 0 on success, a negative error code otherwise. |
| 358 | ******************************************************************************/ |
| 359 | static int load_bl33(bl31_params_t *bl2_to_bl31_params) |
| 360 | { |
| 361 | meminfo_t bl33_mem_info; |
| 362 | int e; |
| 363 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 364 | INFO("BL2: Loading BL3-3\n"); |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 365 | assert(bl2_to_bl31_params != NULL); |
| 366 | |
| 367 | bl2_plat_get_bl33_meminfo(&bl33_mem_info); |
| 368 | |
| 369 | /* Load the BL3-3 image in non-secure memory provided by the platform */ |
| 370 | e = load_image(&bl33_mem_info, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 371 | BL33_IMAGE_ID, |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 372 | plat_get_ns_image_entrypoint(), |
| 373 | bl2_to_bl31_params->bl33_image_info, |
| 374 | bl2_to_bl31_params->bl33_ep_info); |
| 375 | |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 376 | if (e) |
| 377 | return e; |
| 378 | |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 379 | #if TRUSTED_BOARD_BOOT |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 380 | e = auth_verify_obj(AUTH_BL33_IMG, |
| 381 | bl2_to_bl31_params->bl33_image_info->image_base, |
| 382 | bl2_to_bl31_params->bl33_image_info->image_size); |
| 383 | if (e) { |
| 384 | ERROR("Failed to authenticate BL3-3 image.\n"); |
| 385 | return e; |
| 386 | } |
| 387 | /* After working with data, invalidate the data cache */ |
| 388 | inv_dcache_range(bl2_to_bl31_params->bl33_image_info->image_base, |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 389 | (size_t)bl2_to_bl31_params->bl33_image_info->image_size); |
| 390 | #endif /* TRUSTED_BOARD_BOOT */ |
| 391 | |
Sandrine Bailleux | aada44c | 2015-03-26 11:07:09 +0000 | [diff] [blame] | 392 | bl2_plat_set_bl33_ep_info(bl2_to_bl31_params->bl33_image_info, |
| 393 | bl2_to_bl31_params->bl33_ep_info); |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 394 | |
| 395 | return e; |
| 396 | } |
| 397 | |
| 398 | /******************************************************************************* |
| 399 | * The only thing to do in BL2 is to load further images and pass control to |
| 400 | * BL3-1. The memory occupied by BL2 will be reclaimed by BL3-x stages. BL2 runs |
| 401 | * entirely in S-EL1. |
| 402 | ******************************************************************************/ |
| 403 | void bl2_main(void) |
| 404 | { |
| 405 | bl31_params_t *bl2_to_bl31_params; |
| 406 | entry_point_info_t *bl31_ep_info; |
| 407 | int e; |
| 408 | |
Dan Handley | 91b624e | 2014-07-29 17:14:00 +0100 | [diff] [blame] | 409 | NOTICE("BL2: %s\n", version_string); |
| 410 | NOTICE("BL2: %s\n", build_message); |
| 411 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 412 | /* Perform remaining generic architectural setup in S-EL1 */ |
| 413 | bl2_arch_setup(); |
| 414 | |
Juan Castillo | 9246ab8 | 2015-01-28 16:46:57 +0000 | [diff] [blame] | 415 | #if TRUSTED_BOARD_BOOT |
| 416 | /* Initialize authentication module */ |
| 417 | auth_init(); |
| 418 | |
| 419 | /* Validate the certificates involved in the Chain of Trust */ |
| 420 | e = load_certs(); |
| 421 | if (e) { |
| 422 | ERROR("Chain of Trust invalid. Aborting...\n"); |
| 423 | panic(); |
| 424 | } |
| 425 | #endif /* TRUSTED_BOARD_BOOT */ |
| 426 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 427 | /* |
| 428 | * Load the subsequent bootloader images |
| 429 | */ |
| 430 | e = load_bl30(); |
| 431 | if (e) { |
| 432 | ERROR("Failed to load BL3-0 (%i)\n", e); |
| 433 | panic(); |
| 434 | } |
| 435 | |
Juan Castillo | 6b672f5 | 2014-09-04 14:43:09 +0100 | [diff] [blame] | 436 | /* Perform platform setup in BL2 after loading BL3-0 */ |
| 437 | bl2_platform_setup(); |
| 438 | |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 439 | /* |
| 440 | * Get a pointer to the memory the platform has set aside to pass |
| 441 | * information to BL3-1. |
| 442 | */ |
| 443 | bl2_to_bl31_params = bl2_plat_get_bl31_params(); |
| 444 | bl31_ep_info = bl2_plat_get_bl31_ep_info(); |
| 445 | |
| 446 | e = load_bl31(bl2_to_bl31_params, bl31_ep_info); |
| 447 | if (e) { |
| 448 | ERROR("Failed to load BL3-1 (%i)\n", e); |
| 449 | panic(); |
| 450 | } |
| 451 | |
| 452 | e = load_bl32(bl2_to_bl31_params); |
| 453 | if (e) |
| 454 | WARN("Failed to load BL3-2 (%i)\n", e); |
| 455 | |
| 456 | e = load_bl33(bl2_to_bl31_params); |
| 457 | if (e) { |
| 458 | ERROR("Failed to load BL3-3 (%i)\n", e); |
| 459 | panic(); |
| 460 | } |
| 461 | |
Andrew Thoelke | a55566d | 2014-05-28 22:22:55 +0100 | [diff] [blame] | 462 | /* Flush the params to be passed to memory */ |
| 463 | bl2_plat_flush_bl31_params(); |
| 464 | |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 465 | /* |
Sandrine Bailleux | f841ef0 | 2014-06-24 14:19:36 +0100 | [diff] [blame] | 466 | * Run BL3-1 via an SMC to BL1. Information on how to pass control to |
| 467 | * the BL3-2 (if present) and BL3-3 software images will be passed to |
| 468 | * BL3-1 as an argument. |
Achin Gupta | 4f6ad66 | 2013-10-25 09:08:21 +0100 | [diff] [blame] | 469 | */ |
Andrew Thoelke | a55566d | 2014-05-28 22:22:55 +0100 | [diff] [blame] | 470 | 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] | 471 | } |