14f6ad66aSAchin Gupta /* 2e83b0cadSDan Handley * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. 34f6ad66aSAchin Gupta * 44f6ad66aSAchin Gupta * Redistribution and use in source and binary forms, with or without 54f6ad66aSAchin Gupta * modification, are permitted provided that the following conditions are met: 64f6ad66aSAchin Gupta * 74f6ad66aSAchin Gupta * Redistributions of source code must retain the above copyright notice, this 84f6ad66aSAchin Gupta * list of conditions and the following disclaimer. 94f6ad66aSAchin Gupta * 104f6ad66aSAchin Gupta * Redistributions in binary form must reproduce the above copyright notice, 114f6ad66aSAchin Gupta * this list of conditions and the following disclaimer in the documentation 124f6ad66aSAchin Gupta * and/or other materials provided with the distribution. 134f6ad66aSAchin Gupta * 144f6ad66aSAchin Gupta * Neither the name of ARM nor the names of its contributors may be used 154f6ad66aSAchin Gupta * to endorse or promote products derived from this software without specific 164f6ad66aSAchin Gupta * prior written permission. 174f6ad66aSAchin Gupta * 184f6ad66aSAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 194f6ad66aSAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 204f6ad66aSAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 214f6ad66aSAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 224f6ad66aSAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 234f6ad66aSAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 244f6ad66aSAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 254f6ad66aSAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 264f6ad66aSAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 274f6ad66aSAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 284f6ad66aSAchin Gupta * POSSIBILITY OF SUCH DAMAGE. 294f6ad66aSAchin Gupta */ 304f6ad66aSAchin Gupta 3197043ac9SDan Handley #include <arch.h> 324f6ad66aSAchin Gupta #include <arch_helpers.h> 3397043ac9SDan Handley #include <assert.h> 34dec840afSJuan Castillo #include <auth.h> 354f6ad66aSAchin Gupta #include <bl_common.h> 3635e98e55SDan Handley #include <debug.h> 3797043ac9SDan Handley #include <platform.h> 385f0cdb05SDan Handley #include <platform_def.h> 395b827a8fSDan Handley #include "bl2_private.h" 404f6ad66aSAchin Gupta 41dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 42dec840afSJuan Castillo 43dec840afSJuan Castillo #ifdef BL32_BASE 44dec840afSJuan Castillo static int bl32_cert_error; 45dec840afSJuan Castillo #endif 46dec840afSJuan Castillo 47dec840afSJuan Castillo /* 48dec840afSJuan Castillo * Load and authenticate the key and content certificates for a BL3-x image 49dec840afSJuan Castillo * 50dec840afSJuan Castillo * Parameters: 51dec840afSJuan Castillo * key_cert_blob: key certificate blob id (see auth.h) 52dec840afSJuan Castillo * key_cert_name: key certificate filename 53dec840afSJuan Castillo * cont_cert_blob: content certificate blob id (see auth.h) 54dec840afSJuan Castillo * cont_cert_name: content certificate filename 55dec840afSJuan Castillo * mem_layout: Trusted SRAM memory layout 56dec840afSJuan Castillo * load_addr: load the certificates at this address 57dec840afSJuan Castillo * 58dec840afSJuan Castillo * Return: 0 = success, Otherwise = error 59dec840afSJuan Castillo */ 60dec840afSJuan Castillo static int load_cert_bl3x(int key_cert_blob, const char *key_cert_name, 61dec840afSJuan Castillo int cont_cert_blob, const char *cont_cert_name, 62dec840afSJuan Castillo meminfo_t *mem_layout, uint64_t load_addr) 63dec840afSJuan Castillo { 64dec840afSJuan Castillo image_info_t image_info; 65dec840afSJuan Castillo int err; 66dec840afSJuan Castillo 67dec840afSJuan Castillo /* Load Key certificate */ 68dec840afSJuan Castillo image_info.h.version = VERSION_1; 69dec840afSJuan Castillo err = load_image(mem_layout, key_cert_name, load_addr, &image_info, NULL); 70dec840afSJuan Castillo if (err) { 71dec840afSJuan Castillo ERROR("Cannot load %s.\n", key_cert_name); 72dec840afSJuan Castillo return err; 73dec840afSJuan Castillo } 74dec840afSJuan Castillo 75dec840afSJuan Castillo err = auth_verify_obj(key_cert_blob, image_info.image_base, 76dec840afSJuan Castillo image_info.image_size); 77dec840afSJuan Castillo if (err) { 78dec840afSJuan Castillo ERROR("Invalid key certificate %s.\n", key_cert_name); 79dec840afSJuan Castillo return err; 80dec840afSJuan Castillo } 81dec840afSJuan Castillo 82dec840afSJuan Castillo /* Load Content certificate */ 83dec840afSJuan Castillo image_info.h.version = VERSION_1; 84dec840afSJuan Castillo err = load_image(mem_layout, cont_cert_name, load_addr, &image_info, NULL); 85dec840afSJuan Castillo if (err) { 86dec840afSJuan Castillo ERROR("Cannot load %s.\n", cont_cert_name); 87dec840afSJuan Castillo return err; 88dec840afSJuan Castillo } 89dec840afSJuan Castillo 90dec840afSJuan Castillo err = auth_verify_obj(cont_cert_blob, image_info.image_base, 91dec840afSJuan Castillo image_info.image_size); 92dec840afSJuan Castillo if (err) { 93dec840afSJuan Castillo ERROR("Invalid content certificate %s.\n", cont_cert_name); 94dec840afSJuan Castillo return err; 95dec840afSJuan Castillo } 96dec840afSJuan Castillo 97dec840afSJuan Castillo return 0; 98dec840afSJuan Castillo } 99dec840afSJuan Castillo 100dec840afSJuan Castillo /* 101dec840afSJuan Castillo * Load and authenticate the Trusted Key certificate the key and content 102dec840afSJuan Castillo * certificates for each of the BL3-x images. 103dec840afSJuan Castillo * 104dec840afSJuan Castillo * Return: 0 = success, Otherwise = error 105dec840afSJuan Castillo */ 106dec840afSJuan Castillo static int load_certs(void) 107dec840afSJuan Castillo { 108dec840afSJuan Castillo const uint64_t load_addr = BL31_BASE; 109dec840afSJuan Castillo image_info_t image_info; 110dec840afSJuan Castillo meminfo_t *mem_layout; 111dec840afSJuan Castillo int err; 112dec840afSJuan Castillo 113dec840afSJuan Castillo /* Find out how much free trusted ram remains after BL2 load */ 114dec840afSJuan Castillo mem_layout = bl2_plat_sec_mem_layout(); 115dec840afSJuan Castillo 116dec840afSJuan Castillo /* Load the Trusted Key certificate in the BL31 region */ 117dec840afSJuan Castillo image_info.h.version = VERSION_1; 118dec840afSJuan Castillo err = load_image(mem_layout, TRUSTED_KEY_CERT_NAME, load_addr, 119dec840afSJuan Castillo &image_info, NULL); 120dec840afSJuan Castillo if (err) { 121dec840afSJuan Castillo ERROR("Failed to load Trusted Key certificate.\n"); 122dec840afSJuan Castillo return err; 123dec840afSJuan Castillo } 124dec840afSJuan Castillo 125dec840afSJuan Castillo /* Validate the certificate */ 126dec840afSJuan Castillo err = auth_verify_obj(AUTH_TRUSTED_KEY_CERT, image_info.image_base, 127dec840afSJuan Castillo image_info.image_size); 128dec840afSJuan Castillo if (err) { 129dec840afSJuan Castillo ERROR("Invalid Trusted Key certificate.\n"); 130dec840afSJuan Castillo return err; 131dec840afSJuan Castillo } 132dec840afSJuan Castillo 133dec840afSJuan Castillo /* Load and validate Key and Content certificates for BL3-x images */ 134dec840afSJuan Castillo #ifdef BL30_BASE 135dec840afSJuan Castillo err = load_cert_bl3x(AUTH_BL30_KEY_CERT, BL30_KEY_CERT_NAME, 136dec840afSJuan Castillo AUTH_BL30_IMG_CERT, BL30_CERT_NAME, 137dec840afSJuan Castillo mem_layout, load_addr); 138dec840afSJuan Castillo if (err) { 139dec840afSJuan Castillo ERROR("Failed to verify BL3-0 authenticity\n"); 140dec840afSJuan Castillo return err; 141dec840afSJuan Castillo } 142dec840afSJuan Castillo #endif /* BL30_BASE */ 143dec840afSJuan Castillo 144dec840afSJuan Castillo err = load_cert_bl3x(AUTH_BL31_KEY_CERT, BL31_KEY_CERT_NAME, 145dec840afSJuan Castillo AUTH_BL31_IMG_CERT, BL31_CERT_NAME, 146dec840afSJuan Castillo mem_layout, load_addr); 147dec840afSJuan Castillo if (err) { 148dec840afSJuan Castillo ERROR("Failed to verify BL3-1 authenticity\n"); 149dec840afSJuan Castillo return err; 150dec840afSJuan Castillo } 151dec840afSJuan Castillo 152dec840afSJuan Castillo #ifdef BL32_BASE 153dec840afSJuan Castillo /* BL3-2 image is optional, but keep the return value in case the 154dec840afSJuan Castillo * image is present but the certificate is missing */ 155dec840afSJuan Castillo err = load_cert_bl3x(AUTH_BL32_KEY_CERT, BL32_KEY_CERT_NAME, 156dec840afSJuan Castillo AUTH_BL32_IMG_CERT, BL32_CERT_NAME, 157dec840afSJuan Castillo mem_layout, load_addr); 158dec840afSJuan Castillo if (err) { 159dec840afSJuan Castillo WARN("Failed to verify BL3-2 authenticity\n"); 160dec840afSJuan Castillo } 161dec840afSJuan Castillo bl32_cert_error = err; 162dec840afSJuan Castillo #endif /* BL32_BASE */ 163dec840afSJuan Castillo 164dec840afSJuan Castillo err = load_cert_bl3x(AUTH_BL33_KEY_CERT, BL33_KEY_CERT_NAME, 165dec840afSJuan Castillo AUTH_BL33_IMG_CERT, BL33_CERT_NAME, 166dec840afSJuan Castillo mem_layout, load_addr); 167dec840afSJuan Castillo if (err) { 168dec840afSJuan Castillo ERROR("Failed to verify BL3-3 authenticity\n"); 169dec840afSJuan Castillo return err; 170dec840afSJuan Castillo } 171dec840afSJuan Castillo 172dec840afSJuan Castillo return 0; 173dec840afSJuan Castillo } 174dec840afSJuan Castillo 175dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 176dec840afSJuan Castillo 17793d81d64SSandrine Bailleux /******************************************************************************* 17893d81d64SSandrine Bailleux * Load the BL3-0 image if there's one. 17993d81d64SSandrine Bailleux * If a platform does not want to attempt to load BL3-0 image it must leave 18093d81d64SSandrine Bailleux * BL30_BASE undefined. 18193d81d64SSandrine Bailleux * Return 0 on success or if there's no BL3-0 image to load, a negative error 18293d81d64SSandrine Bailleux * code otherwise. 18393d81d64SSandrine Bailleux ******************************************************************************/ 18493d81d64SSandrine Bailleux static int load_bl30(void) 18593d81d64SSandrine Bailleux { 18693d81d64SSandrine Bailleux int e = 0; 18793d81d64SSandrine Bailleux #ifdef BL30_BASE 18893d81d64SSandrine Bailleux meminfo_t bl30_mem_info; 18993d81d64SSandrine Bailleux image_info_t bl30_image_info; 19093d81d64SSandrine Bailleux 19193d81d64SSandrine Bailleux /* 19293d81d64SSandrine Bailleux * It is up to the platform to specify where BL3-0 should be loaded if 19393d81d64SSandrine Bailleux * it exists. It could create space in the secure sram or point to a 19493d81d64SSandrine Bailleux * completely different memory. 19593d81d64SSandrine Bailleux * 19693d81d64SSandrine Bailleux * The entry point information is not relevant in this case as the AP 19793d81d64SSandrine Bailleux * won't execute the BL3-0 image. 19893d81d64SSandrine Bailleux */ 1996ad2e461SDan Handley INFO("BL2: Loading BL3-0\n"); 20093d81d64SSandrine Bailleux bl2_plat_get_bl30_meminfo(&bl30_mem_info); 20192de3565SJuan Castillo bl30_image_info.h.version = VERSION_1; 20293d81d64SSandrine Bailleux e = load_image(&bl30_mem_info, 20393d81d64SSandrine Bailleux BL30_IMAGE_NAME, 20493d81d64SSandrine Bailleux BL30_BASE, 20593d81d64SSandrine Bailleux &bl30_image_info, 20693d81d64SSandrine Bailleux NULL); 20793d81d64SSandrine Bailleux 208*bcb79b90SSandrine Bailleux if (e) 209*bcb79b90SSandrine Bailleux return e; 210*bcb79b90SSandrine Bailleux 211dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 212dec840afSJuan Castillo e = auth_verify_obj(AUTH_BL30_IMG, 213dec840afSJuan Castillo bl30_image_info.image_base, 214dec840afSJuan Castillo bl30_image_info.image_size); 215dec840afSJuan Castillo if (e) { 216dec840afSJuan Castillo ERROR("Failed to authenticate BL3-0 image.\n"); 217*bcb79b90SSandrine Bailleux return e; 218dec840afSJuan Castillo } 219dec840afSJuan Castillo 220dec840afSJuan Castillo /* After working with data, invalidate the data cache */ 221dec840afSJuan Castillo inv_dcache_range(bl30_image_info.image_base, 222dec840afSJuan Castillo (size_t)bl30_image_info.image_size); 223dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 224dec840afSJuan Castillo 22593d81d64SSandrine Bailleux /* The subsequent handling of BL3-0 is platform specific */ 226*bcb79b90SSandrine Bailleux e = bl2_plat_handle_bl30(&bl30_image_info); 227*bcb79b90SSandrine Bailleux if (e) { 228*bcb79b90SSandrine Bailleux ERROR("Failure in platform-specific handling of BL3-0 image.\n"); 229*bcb79b90SSandrine Bailleux return e; 23093d81d64SSandrine Bailleux } 23193d81d64SSandrine Bailleux #endif /* BL30_BASE */ 23293d81d64SSandrine Bailleux 23393d81d64SSandrine Bailleux return e; 23493d81d64SSandrine Bailleux } 23529fb905dSVikram Kanigiri 23629fb905dSVikram Kanigiri /******************************************************************************* 23793d81d64SSandrine Bailleux * Load the BL3-1 image. 23893d81d64SSandrine Bailleux * The bl2_to_bl31_params and bl31_ep_info params will be updated with the 23993d81d64SSandrine Bailleux * relevant BL3-1 information. 24093d81d64SSandrine Bailleux * Return 0 on success, a negative error code otherwise. 2414f6ad66aSAchin Gupta ******************************************************************************/ 24293d81d64SSandrine Bailleux static int load_bl31(bl31_params_t *bl2_to_bl31_params, 24393d81d64SSandrine Bailleux entry_point_info_t *bl31_ep_info) 2444f6ad66aSAchin Gupta { 245fb037bfbSDan Handley meminfo_t *bl2_tzram_layout; 2464112bfa0SVikram Kanigiri int e; 2474f6ad66aSAchin Gupta 2486ad2e461SDan Handley INFO("BL2: Loading BL3-1\n"); 24993d81d64SSandrine Bailleux assert(bl2_to_bl31_params != NULL); 25093d81d64SSandrine Bailleux assert(bl31_ep_info != NULL); 2514f6ad66aSAchin Gupta 2524f6ad66aSAchin Gupta /* Find out how much free trusted ram remains after BL2 load */ 253ee12f6f7SSandrine Bailleux bl2_tzram_layout = bl2_plat_sec_mem_layout(); 2544f6ad66aSAchin Gupta 25593d81d64SSandrine Bailleux /* Set the X0 parameter to BL3-1 */ 25603462671SAndrew Thoelke bl31_ep_info->args.arg0 = (unsigned long)bl2_to_bl31_params; 25703462671SAndrew Thoelke 2588f55dfb4SSandrine Bailleux /* Load the BL3-1 image */ 2594112bfa0SVikram Kanigiri e = load_image(bl2_tzram_layout, 2604112bfa0SVikram Kanigiri BL31_IMAGE_NAME, 2614112bfa0SVikram Kanigiri BL31_BASE, 2624112bfa0SVikram Kanigiri bl2_to_bl31_params->bl31_image_info, 2634112bfa0SVikram Kanigiri bl31_ep_info); 264*bcb79b90SSandrine Bailleux if (e) 265*bcb79b90SSandrine Bailleux return e; 2664f6ad66aSAchin Gupta 267dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 268dec840afSJuan Castillo e = auth_verify_obj(AUTH_BL31_IMG, 269dec840afSJuan Castillo bl2_to_bl31_params->bl31_image_info->image_base, 270dec840afSJuan Castillo bl2_to_bl31_params->bl31_image_info->image_size); 271dec840afSJuan Castillo if (e) { 272dec840afSJuan Castillo ERROR("Failed to authenticate BL3-1 image.\n"); 273*bcb79b90SSandrine Bailleux return e; 274dec840afSJuan Castillo } 275dec840afSJuan Castillo 276dec840afSJuan Castillo /* After working with data, invalidate the data cache */ 277dec840afSJuan Castillo inv_dcache_range(bl2_to_bl31_params->bl31_image_info->image_base, 278dec840afSJuan Castillo (size_t)bl2_to_bl31_params->bl31_image_info->image_size); 279dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 280dec840afSJuan Castillo 2814112bfa0SVikram Kanigiri bl2_plat_set_bl31_ep_info(bl2_to_bl31_params->bl31_image_info, 2824112bfa0SVikram Kanigiri bl31_ep_info); 283a3050ed5SAchin Gupta 28493d81d64SSandrine Bailleux return e; 285561cd33eSHarry Liebel } 286e4d084eaSAchin Gupta 28793d81d64SSandrine Bailleux /******************************************************************************* 28893d81d64SSandrine Bailleux * Load the BL3-2 image if there's one. 28993d81d64SSandrine Bailleux * The bl2_to_bl31_params param will be updated with the relevant BL3-2 29093d81d64SSandrine Bailleux * information. 29193d81d64SSandrine Bailleux * If a platform does not want to attempt to load BL3-2 image it must leave 29293d81d64SSandrine Bailleux * BL32_BASE undefined. 29393d81d64SSandrine Bailleux * Return 0 on success or if there's no BL3-2 image to load, a negative error 29493d81d64SSandrine Bailleux * code otherwise. 29593d81d64SSandrine Bailleux ******************************************************************************/ 29693d81d64SSandrine Bailleux static int load_bl32(bl31_params_t *bl2_to_bl31_params) 29793d81d64SSandrine Bailleux { 29893d81d64SSandrine Bailleux int e = 0; 2991151c821SDan Handley #ifdef BL32_BASE 30093d81d64SSandrine Bailleux meminfo_t bl32_mem_info; 30193d81d64SSandrine Bailleux 3026ad2e461SDan Handley INFO("BL2: Loading BL3-2\n"); 30393d81d64SSandrine Bailleux assert(bl2_to_bl31_params != NULL); 30493d81d64SSandrine Bailleux 30529fb905dSVikram Kanigiri /* 30693d81d64SSandrine Bailleux * It is up to the platform to specify where BL3-2 should be loaded if 30793d81d64SSandrine Bailleux * it exists. It could create space in the secure sram or point to a 3081151c821SDan Handley * completely different memory. 30929fb905dSVikram Kanigiri */ 3106871c5d3SVikram Kanigiri bl2_plat_get_bl32_meminfo(&bl32_mem_info); 3116871c5d3SVikram Kanigiri e = load_image(&bl32_mem_info, 31229fb905dSVikram Kanigiri BL32_IMAGE_NAME, 3134112bfa0SVikram Kanigiri BL32_BASE, 3144112bfa0SVikram Kanigiri bl2_to_bl31_params->bl32_image_info, 3154112bfa0SVikram Kanigiri bl2_to_bl31_params->bl32_ep_info); 31629fb905dSVikram Kanigiri 317*bcb79b90SSandrine Bailleux if (e) 318*bcb79b90SSandrine Bailleux return e; 319*bcb79b90SSandrine Bailleux 320dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 321dec840afSJuan Castillo /* Image is present. Check if there is a valid certificate */ 322dec840afSJuan Castillo if (bl32_cert_error) { 323dec840afSJuan Castillo ERROR("Failed to authenticate BL3-2 certificates.\n"); 324*bcb79b90SSandrine Bailleux return bl32_cert_error; 325dec840afSJuan Castillo } 326dec840afSJuan Castillo 327dec840afSJuan Castillo e = auth_verify_obj(AUTH_BL32_IMG, 328dec840afSJuan Castillo bl2_to_bl31_params->bl32_image_info->image_base, 329dec840afSJuan Castillo bl2_to_bl31_params->bl32_image_info->image_size); 330dec840afSJuan Castillo if (e) { 331dec840afSJuan Castillo ERROR("Failed to authenticate BL3-2 image.\n"); 332*bcb79b90SSandrine Bailleux return e; 333dec840afSJuan Castillo } 334dec840afSJuan Castillo /* After working with data, invalidate the data cache */ 335dec840afSJuan Castillo inv_dcache_range(bl2_to_bl31_params->bl32_image_info->image_base, 336dec840afSJuan Castillo (size_t)bl2_to_bl31_params->bl32_image_info->image_size); 337dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 338dec840afSJuan Castillo 3394112bfa0SVikram Kanigiri bl2_plat_set_bl32_ep_info( 3404112bfa0SVikram Kanigiri bl2_to_bl31_params->bl32_image_info, 3414112bfa0SVikram Kanigiri bl2_to_bl31_params->bl32_ep_info); 3421151c821SDan Handley #endif /* BL32_BASE */ 3434112bfa0SVikram Kanigiri 34493d81d64SSandrine Bailleux return e; 34593d81d64SSandrine Bailleux } 34693d81d64SSandrine Bailleux 34793d81d64SSandrine Bailleux /******************************************************************************* 34893d81d64SSandrine Bailleux * Load the BL3-3 image. 34993d81d64SSandrine Bailleux * The bl2_to_bl31_params param will be updated with the relevant BL3-3 35093d81d64SSandrine Bailleux * information. 35193d81d64SSandrine Bailleux * Return 0 on success, a negative error code otherwise. 35293d81d64SSandrine Bailleux ******************************************************************************/ 35393d81d64SSandrine Bailleux static int load_bl33(bl31_params_t *bl2_to_bl31_params) 35493d81d64SSandrine Bailleux { 35593d81d64SSandrine Bailleux meminfo_t bl33_mem_info; 35693d81d64SSandrine Bailleux int e; 35793d81d64SSandrine Bailleux 3586ad2e461SDan Handley INFO("BL2: Loading BL3-3\n"); 35993d81d64SSandrine Bailleux assert(bl2_to_bl31_params != NULL); 36093d81d64SSandrine Bailleux 36193d81d64SSandrine Bailleux bl2_plat_get_bl33_meminfo(&bl33_mem_info); 36293d81d64SSandrine Bailleux 36393d81d64SSandrine Bailleux /* Load the BL3-3 image in non-secure memory provided by the platform */ 36493d81d64SSandrine Bailleux e = load_image(&bl33_mem_info, 36593d81d64SSandrine Bailleux BL33_IMAGE_NAME, 36693d81d64SSandrine Bailleux plat_get_ns_image_entrypoint(), 36793d81d64SSandrine Bailleux bl2_to_bl31_params->bl33_image_info, 36893d81d64SSandrine Bailleux bl2_to_bl31_params->bl33_ep_info); 36993d81d64SSandrine Bailleux 370*bcb79b90SSandrine Bailleux if (e) 371*bcb79b90SSandrine Bailleux return e; 372*bcb79b90SSandrine Bailleux 373dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 374dec840afSJuan Castillo e = auth_verify_obj(AUTH_BL33_IMG, 375dec840afSJuan Castillo bl2_to_bl31_params->bl33_image_info->image_base, 376dec840afSJuan Castillo bl2_to_bl31_params->bl33_image_info->image_size); 377dec840afSJuan Castillo if (e) { 378dec840afSJuan Castillo ERROR("Failed to authenticate BL3-3 image.\n"); 379*bcb79b90SSandrine Bailleux return e; 380dec840afSJuan Castillo } 381dec840afSJuan Castillo /* After working with data, invalidate the data cache */ 382dec840afSJuan Castillo inv_dcache_range(bl2_to_bl31_params->bl33_image_info->image_base, 383dec840afSJuan Castillo (size_t)bl2_to_bl31_params->bl33_image_info->image_size); 384dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 385dec840afSJuan Castillo 38693d81d64SSandrine Bailleux bl2_plat_set_bl33_ep_info(bl2_to_bl31_params->bl33_image_info, 38793d81d64SSandrine Bailleux bl2_to_bl31_params->bl33_ep_info); 38893d81d64SSandrine Bailleux 38993d81d64SSandrine Bailleux return e; 39093d81d64SSandrine Bailleux } 39193d81d64SSandrine Bailleux 39293d81d64SSandrine Bailleux /******************************************************************************* 39393d81d64SSandrine Bailleux * The only thing to do in BL2 is to load further images and pass control to 39493d81d64SSandrine Bailleux * BL3-1. The memory occupied by BL2 will be reclaimed by BL3-x stages. BL2 runs 39593d81d64SSandrine Bailleux * entirely in S-EL1. 39693d81d64SSandrine Bailleux ******************************************************************************/ 39793d81d64SSandrine Bailleux void bl2_main(void) 39893d81d64SSandrine Bailleux { 39993d81d64SSandrine Bailleux bl31_params_t *bl2_to_bl31_params; 40093d81d64SSandrine Bailleux entry_point_info_t *bl31_ep_info; 40193d81d64SSandrine Bailleux int e; 40293d81d64SSandrine Bailleux 4036ad2e461SDan Handley NOTICE("BL2: %s\n", version_string); 4046ad2e461SDan Handley NOTICE("BL2: %s\n", build_message); 4056ad2e461SDan Handley 40693d81d64SSandrine Bailleux /* Perform remaining generic architectural setup in S-EL1 */ 40793d81d64SSandrine Bailleux bl2_arch_setup(); 40893d81d64SSandrine Bailleux 409dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 410dec840afSJuan Castillo /* Initialize authentication module */ 411dec840afSJuan Castillo auth_init(); 412dec840afSJuan Castillo 413dec840afSJuan Castillo /* Validate the certificates involved in the Chain of Trust */ 414dec840afSJuan Castillo e = load_certs(); 415dec840afSJuan Castillo if (e) { 416dec840afSJuan Castillo ERROR("Chain of Trust invalid. Aborting...\n"); 417dec840afSJuan Castillo panic(); 418dec840afSJuan Castillo } 419dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 420dec840afSJuan Castillo 42193d81d64SSandrine Bailleux /* 42293d81d64SSandrine Bailleux * Load the subsequent bootloader images 42393d81d64SSandrine Bailleux */ 42493d81d64SSandrine Bailleux e = load_bl30(); 42593d81d64SSandrine Bailleux if (e) { 42693d81d64SSandrine Bailleux ERROR("Failed to load BL3-0 (%i)\n", e); 42793d81d64SSandrine Bailleux panic(); 42893d81d64SSandrine Bailleux } 42993d81d64SSandrine Bailleux 430ef538c6fSJuan Castillo /* Perform platform setup in BL2 after loading BL3-0 */ 431ef538c6fSJuan Castillo bl2_platform_setup(); 432ef538c6fSJuan Castillo 43393d81d64SSandrine Bailleux /* 43493d81d64SSandrine Bailleux * Get a pointer to the memory the platform has set aside to pass 43593d81d64SSandrine Bailleux * information to BL3-1. 43693d81d64SSandrine Bailleux */ 43793d81d64SSandrine Bailleux bl2_to_bl31_params = bl2_plat_get_bl31_params(); 43893d81d64SSandrine Bailleux bl31_ep_info = bl2_plat_get_bl31_ep_info(); 43993d81d64SSandrine Bailleux 44093d81d64SSandrine Bailleux e = load_bl31(bl2_to_bl31_params, bl31_ep_info); 44193d81d64SSandrine Bailleux if (e) { 44293d81d64SSandrine Bailleux ERROR("Failed to load BL3-1 (%i)\n", e); 44393d81d64SSandrine Bailleux panic(); 44493d81d64SSandrine Bailleux } 44593d81d64SSandrine Bailleux 44693d81d64SSandrine Bailleux e = load_bl32(bl2_to_bl31_params); 44793d81d64SSandrine Bailleux if (e) 44893d81d64SSandrine Bailleux WARN("Failed to load BL3-2 (%i)\n", e); 44993d81d64SSandrine Bailleux 45093d81d64SSandrine Bailleux e = load_bl33(bl2_to_bl31_params); 45193d81d64SSandrine Bailleux if (e) { 45293d81d64SSandrine Bailleux ERROR("Failed to load BL3-3 (%i)\n", e); 45393d81d64SSandrine Bailleux panic(); 45493d81d64SSandrine Bailleux } 45593d81d64SSandrine Bailleux 45603462671SAndrew Thoelke /* Flush the params to be passed to memory */ 45703462671SAndrew Thoelke bl2_plat_flush_bl31_params(); 45803462671SAndrew Thoelke 4594f6ad66aSAchin Gupta /* 46093d81d64SSandrine Bailleux * Run BL3-1 via an SMC to BL1. Information on how to pass control to 46193d81d64SSandrine Bailleux * the BL3-2 (if present) and BL3-3 software images will be passed to 46293d81d64SSandrine Bailleux * BL3-1 as an argument. 4634f6ad66aSAchin Gupta */ 46403462671SAndrew Thoelke smc(RUN_IMAGE, (unsigned long)bl31_ep_info, 0, 0, 0, 0, 0, 0); 4654f6ad66aSAchin Gupta } 466