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> 34*dec840afSJuan 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 41*dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 42*dec840afSJuan Castillo 43*dec840afSJuan Castillo #ifdef BL32_BASE 44*dec840afSJuan Castillo static int bl32_cert_error; 45*dec840afSJuan Castillo #endif 46*dec840afSJuan Castillo 47*dec840afSJuan Castillo /* 48*dec840afSJuan Castillo * Load and authenticate the key and content certificates for a BL3-x image 49*dec840afSJuan Castillo * 50*dec840afSJuan Castillo * Parameters: 51*dec840afSJuan Castillo * key_cert_blob: key certificate blob id (see auth.h) 52*dec840afSJuan Castillo * key_cert_name: key certificate filename 53*dec840afSJuan Castillo * cont_cert_blob: content certificate blob id (see auth.h) 54*dec840afSJuan Castillo * cont_cert_name: content certificate filename 55*dec840afSJuan Castillo * mem_layout: Trusted SRAM memory layout 56*dec840afSJuan Castillo * load_addr: load the certificates at this address 57*dec840afSJuan Castillo * 58*dec840afSJuan Castillo * Return: 0 = success, Otherwise = error 59*dec840afSJuan Castillo */ 60*dec840afSJuan Castillo static int load_cert_bl3x(int key_cert_blob, const char *key_cert_name, 61*dec840afSJuan Castillo int cont_cert_blob, const char *cont_cert_name, 62*dec840afSJuan Castillo meminfo_t *mem_layout, uint64_t load_addr) 63*dec840afSJuan Castillo { 64*dec840afSJuan Castillo image_info_t image_info; 65*dec840afSJuan Castillo int err; 66*dec840afSJuan Castillo 67*dec840afSJuan Castillo /* Load Key certificate */ 68*dec840afSJuan Castillo image_info.h.version = VERSION_1; 69*dec840afSJuan Castillo err = load_image(mem_layout, key_cert_name, load_addr, &image_info, NULL); 70*dec840afSJuan Castillo if (err) { 71*dec840afSJuan Castillo ERROR("Cannot load %s.\n", key_cert_name); 72*dec840afSJuan Castillo return err; 73*dec840afSJuan Castillo } 74*dec840afSJuan Castillo 75*dec840afSJuan Castillo err = auth_verify_obj(key_cert_blob, image_info.image_base, 76*dec840afSJuan Castillo image_info.image_size); 77*dec840afSJuan Castillo if (err) { 78*dec840afSJuan Castillo ERROR("Invalid key certificate %s.\n", key_cert_name); 79*dec840afSJuan Castillo return err; 80*dec840afSJuan Castillo } 81*dec840afSJuan Castillo 82*dec840afSJuan Castillo /* Load Content certificate */ 83*dec840afSJuan Castillo image_info.h.version = VERSION_1; 84*dec840afSJuan Castillo err = load_image(mem_layout, cont_cert_name, load_addr, &image_info, NULL); 85*dec840afSJuan Castillo if (err) { 86*dec840afSJuan Castillo ERROR("Cannot load %s.\n", cont_cert_name); 87*dec840afSJuan Castillo return err; 88*dec840afSJuan Castillo } 89*dec840afSJuan Castillo 90*dec840afSJuan Castillo err = auth_verify_obj(cont_cert_blob, image_info.image_base, 91*dec840afSJuan Castillo image_info.image_size); 92*dec840afSJuan Castillo if (err) { 93*dec840afSJuan Castillo ERROR("Invalid content certificate %s.\n", cont_cert_name); 94*dec840afSJuan Castillo return err; 95*dec840afSJuan Castillo } 96*dec840afSJuan Castillo 97*dec840afSJuan Castillo return 0; 98*dec840afSJuan Castillo } 99*dec840afSJuan Castillo 100*dec840afSJuan Castillo /* 101*dec840afSJuan Castillo * Load and authenticate the Trusted Key certificate the key and content 102*dec840afSJuan Castillo * certificates for each of the BL3-x images. 103*dec840afSJuan Castillo * 104*dec840afSJuan Castillo * Return: 0 = success, Otherwise = error 105*dec840afSJuan Castillo */ 106*dec840afSJuan Castillo static int load_certs(void) 107*dec840afSJuan Castillo { 108*dec840afSJuan Castillo const uint64_t load_addr = BL31_BASE; 109*dec840afSJuan Castillo image_info_t image_info; 110*dec840afSJuan Castillo meminfo_t *mem_layout; 111*dec840afSJuan Castillo int err; 112*dec840afSJuan Castillo 113*dec840afSJuan Castillo /* Find out how much free trusted ram remains after BL2 load */ 114*dec840afSJuan Castillo mem_layout = bl2_plat_sec_mem_layout(); 115*dec840afSJuan Castillo 116*dec840afSJuan Castillo /* Load the Trusted Key certificate in the BL31 region */ 117*dec840afSJuan Castillo image_info.h.version = VERSION_1; 118*dec840afSJuan Castillo err = load_image(mem_layout, TRUSTED_KEY_CERT_NAME, load_addr, 119*dec840afSJuan Castillo &image_info, NULL); 120*dec840afSJuan Castillo if (err) { 121*dec840afSJuan Castillo ERROR("Failed to load Trusted Key certificate.\n"); 122*dec840afSJuan Castillo return err; 123*dec840afSJuan Castillo } 124*dec840afSJuan Castillo 125*dec840afSJuan Castillo /* Validate the certificate */ 126*dec840afSJuan Castillo err = auth_verify_obj(AUTH_TRUSTED_KEY_CERT, image_info.image_base, 127*dec840afSJuan Castillo image_info.image_size); 128*dec840afSJuan Castillo if (err) { 129*dec840afSJuan Castillo ERROR("Invalid Trusted Key certificate.\n"); 130*dec840afSJuan Castillo return err; 131*dec840afSJuan Castillo } 132*dec840afSJuan Castillo 133*dec840afSJuan Castillo /* Load and validate Key and Content certificates for BL3-x images */ 134*dec840afSJuan Castillo #ifdef BL30_BASE 135*dec840afSJuan Castillo err = load_cert_bl3x(AUTH_BL30_KEY_CERT, BL30_KEY_CERT_NAME, 136*dec840afSJuan Castillo AUTH_BL30_IMG_CERT, BL30_CERT_NAME, 137*dec840afSJuan Castillo mem_layout, load_addr); 138*dec840afSJuan Castillo if (err) { 139*dec840afSJuan Castillo ERROR("Failed to verify BL3-0 authenticity\n"); 140*dec840afSJuan Castillo return err; 141*dec840afSJuan Castillo } 142*dec840afSJuan Castillo #endif /* BL30_BASE */ 143*dec840afSJuan Castillo 144*dec840afSJuan Castillo err = load_cert_bl3x(AUTH_BL31_KEY_CERT, BL31_KEY_CERT_NAME, 145*dec840afSJuan Castillo AUTH_BL31_IMG_CERT, BL31_CERT_NAME, 146*dec840afSJuan Castillo mem_layout, load_addr); 147*dec840afSJuan Castillo if (err) { 148*dec840afSJuan Castillo ERROR("Failed to verify BL3-1 authenticity\n"); 149*dec840afSJuan Castillo return err; 150*dec840afSJuan Castillo } 151*dec840afSJuan Castillo 152*dec840afSJuan Castillo #ifdef BL32_BASE 153*dec840afSJuan Castillo /* BL3-2 image is optional, but keep the return value in case the 154*dec840afSJuan Castillo * image is present but the certificate is missing */ 155*dec840afSJuan Castillo err = load_cert_bl3x(AUTH_BL32_KEY_CERT, BL32_KEY_CERT_NAME, 156*dec840afSJuan Castillo AUTH_BL32_IMG_CERT, BL32_CERT_NAME, 157*dec840afSJuan Castillo mem_layout, load_addr); 158*dec840afSJuan Castillo if (err) { 159*dec840afSJuan Castillo WARN("Failed to verify BL3-2 authenticity\n"); 160*dec840afSJuan Castillo } 161*dec840afSJuan Castillo bl32_cert_error = err; 162*dec840afSJuan Castillo #endif /* BL32_BASE */ 163*dec840afSJuan Castillo 164*dec840afSJuan Castillo err = load_cert_bl3x(AUTH_BL33_KEY_CERT, BL33_KEY_CERT_NAME, 165*dec840afSJuan Castillo AUTH_BL33_IMG_CERT, BL33_CERT_NAME, 166*dec840afSJuan Castillo mem_layout, load_addr); 167*dec840afSJuan Castillo if (err) { 168*dec840afSJuan Castillo ERROR("Failed to verify BL3-3 authenticity\n"); 169*dec840afSJuan Castillo return err; 170*dec840afSJuan Castillo } 171*dec840afSJuan Castillo 172*dec840afSJuan Castillo return 0; 173*dec840afSJuan Castillo } 174*dec840afSJuan Castillo 175*dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 176*dec840afSJuan 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 20893d81d64SSandrine Bailleux if (e == 0) { 209*dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 210*dec840afSJuan Castillo e = auth_verify_obj(AUTH_BL30_IMG, 211*dec840afSJuan Castillo bl30_image_info.image_base, 212*dec840afSJuan Castillo bl30_image_info.image_size); 213*dec840afSJuan Castillo if (e) { 214*dec840afSJuan Castillo ERROR("Failed to authenticate BL3-0 image.\n"); 215*dec840afSJuan Castillo panic(); 216*dec840afSJuan Castillo } 217*dec840afSJuan Castillo 218*dec840afSJuan Castillo /* After working with data, invalidate the data cache */ 219*dec840afSJuan Castillo inv_dcache_range(bl30_image_info.image_base, 220*dec840afSJuan Castillo (size_t)bl30_image_info.image_size); 221*dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 222*dec840afSJuan Castillo 22393d81d64SSandrine Bailleux /* The subsequent handling of BL3-0 is platform specific */ 22493d81d64SSandrine Bailleux bl2_plat_handle_bl30(&bl30_image_info); 22593d81d64SSandrine Bailleux } 22693d81d64SSandrine Bailleux #endif /* BL30_BASE */ 22793d81d64SSandrine Bailleux 22893d81d64SSandrine Bailleux return e; 22993d81d64SSandrine Bailleux } 23029fb905dSVikram Kanigiri 23129fb905dSVikram Kanigiri /******************************************************************************* 23293d81d64SSandrine Bailleux * Load the BL3-1 image. 23393d81d64SSandrine Bailleux * The bl2_to_bl31_params and bl31_ep_info params will be updated with the 23493d81d64SSandrine Bailleux * relevant BL3-1 information. 23593d81d64SSandrine Bailleux * Return 0 on success, a negative error code otherwise. 2364f6ad66aSAchin Gupta ******************************************************************************/ 23793d81d64SSandrine Bailleux static int load_bl31(bl31_params_t *bl2_to_bl31_params, 23893d81d64SSandrine Bailleux entry_point_info_t *bl31_ep_info) 2394f6ad66aSAchin Gupta { 240fb037bfbSDan Handley meminfo_t *bl2_tzram_layout; 2414112bfa0SVikram Kanigiri int e; 2424f6ad66aSAchin Gupta 2436ad2e461SDan Handley INFO("BL2: Loading BL3-1\n"); 24493d81d64SSandrine Bailleux assert(bl2_to_bl31_params != NULL); 24593d81d64SSandrine Bailleux assert(bl31_ep_info != NULL); 2464f6ad66aSAchin Gupta 2474f6ad66aSAchin Gupta /* Find out how much free trusted ram remains after BL2 load */ 248ee12f6f7SSandrine Bailleux bl2_tzram_layout = bl2_plat_sec_mem_layout(); 2494f6ad66aSAchin Gupta 25093d81d64SSandrine Bailleux /* Set the X0 parameter to BL3-1 */ 25103462671SAndrew Thoelke bl31_ep_info->args.arg0 = (unsigned long)bl2_to_bl31_params; 25203462671SAndrew Thoelke 2538f55dfb4SSandrine Bailleux /* Load the BL3-1 image */ 2544112bfa0SVikram Kanigiri e = load_image(bl2_tzram_layout, 2554112bfa0SVikram Kanigiri BL31_IMAGE_NAME, 2564112bfa0SVikram Kanigiri BL31_BASE, 2574112bfa0SVikram Kanigiri bl2_to_bl31_params->bl31_image_info, 2584112bfa0SVikram Kanigiri bl31_ep_info); 2594f6ad66aSAchin Gupta 260*dec840afSJuan Castillo if (e == 0) { 261*dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 262*dec840afSJuan Castillo e = auth_verify_obj(AUTH_BL31_IMG, 263*dec840afSJuan Castillo bl2_to_bl31_params->bl31_image_info->image_base, 264*dec840afSJuan Castillo bl2_to_bl31_params->bl31_image_info->image_size); 265*dec840afSJuan Castillo if (e) { 266*dec840afSJuan Castillo ERROR("Failed to authenticate BL3-1 image.\n"); 267*dec840afSJuan Castillo panic(); 268*dec840afSJuan Castillo } 269*dec840afSJuan Castillo 270*dec840afSJuan Castillo /* After working with data, invalidate the data cache */ 271*dec840afSJuan Castillo inv_dcache_range(bl2_to_bl31_params->bl31_image_info->image_base, 272*dec840afSJuan Castillo (size_t)bl2_to_bl31_params->bl31_image_info->image_size); 273*dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 274*dec840afSJuan Castillo 2754112bfa0SVikram Kanigiri bl2_plat_set_bl31_ep_info(bl2_to_bl31_params->bl31_image_info, 2764112bfa0SVikram Kanigiri bl31_ep_info); 277*dec840afSJuan Castillo } 278a3050ed5SAchin Gupta 27993d81d64SSandrine Bailleux return e; 280561cd33eSHarry Liebel } 281e4d084eaSAchin Gupta 28293d81d64SSandrine Bailleux /******************************************************************************* 28393d81d64SSandrine Bailleux * Load the BL3-2 image if there's one. 28493d81d64SSandrine Bailleux * The bl2_to_bl31_params param will be updated with the relevant BL3-2 28593d81d64SSandrine Bailleux * information. 28693d81d64SSandrine Bailleux * If a platform does not want to attempt to load BL3-2 image it must leave 28793d81d64SSandrine Bailleux * BL32_BASE undefined. 28893d81d64SSandrine Bailleux * Return 0 on success or if there's no BL3-2 image to load, a negative error 28993d81d64SSandrine Bailleux * code otherwise. 29093d81d64SSandrine Bailleux ******************************************************************************/ 29193d81d64SSandrine Bailleux static int load_bl32(bl31_params_t *bl2_to_bl31_params) 29293d81d64SSandrine Bailleux { 29393d81d64SSandrine Bailleux int e = 0; 2941151c821SDan Handley #ifdef BL32_BASE 29593d81d64SSandrine Bailleux meminfo_t bl32_mem_info; 29693d81d64SSandrine Bailleux 2976ad2e461SDan Handley INFO("BL2: Loading BL3-2\n"); 29893d81d64SSandrine Bailleux assert(bl2_to_bl31_params != NULL); 29993d81d64SSandrine Bailleux 30029fb905dSVikram Kanigiri /* 30193d81d64SSandrine Bailleux * It is up to the platform to specify where BL3-2 should be loaded if 30293d81d64SSandrine Bailleux * it exists. It could create space in the secure sram or point to a 3031151c821SDan Handley * completely different memory. 30429fb905dSVikram Kanigiri */ 3056871c5d3SVikram Kanigiri bl2_plat_get_bl32_meminfo(&bl32_mem_info); 3066871c5d3SVikram Kanigiri e = load_image(&bl32_mem_info, 30729fb905dSVikram Kanigiri BL32_IMAGE_NAME, 3084112bfa0SVikram Kanigiri BL32_BASE, 3094112bfa0SVikram Kanigiri bl2_to_bl31_params->bl32_image_info, 3104112bfa0SVikram Kanigiri bl2_to_bl31_params->bl32_ep_info); 31129fb905dSVikram Kanigiri 31293d81d64SSandrine Bailleux if (e == 0) { 313*dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 314*dec840afSJuan Castillo /* Image is present. Check if there is a valid certificate */ 315*dec840afSJuan Castillo if (bl32_cert_error) { 316*dec840afSJuan Castillo ERROR("Failed to authenticate BL3-2 certificates.\n"); 317*dec840afSJuan Castillo panic(); 318*dec840afSJuan Castillo } 319*dec840afSJuan Castillo 320*dec840afSJuan Castillo e = auth_verify_obj(AUTH_BL32_IMG, 321*dec840afSJuan Castillo bl2_to_bl31_params->bl32_image_info->image_base, 322*dec840afSJuan Castillo bl2_to_bl31_params->bl32_image_info->image_size); 323*dec840afSJuan Castillo if (e) { 324*dec840afSJuan Castillo ERROR("Failed to authenticate BL3-2 image.\n"); 325*dec840afSJuan Castillo panic(); 326*dec840afSJuan Castillo } 327*dec840afSJuan Castillo /* After working with data, invalidate the data cache */ 328*dec840afSJuan Castillo inv_dcache_range(bl2_to_bl31_params->bl32_image_info->image_base, 329*dec840afSJuan Castillo (size_t)bl2_to_bl31_params->bl32_image_info->image_size); 330*dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 331*dec840afSJuan Castillo 3324112bfa0SVikram Kanigiri bl2_plat_set_bl32_ep_info( 3334112bfa0SVikram Kanigiri bl2_to_bl31_params->bl32_image_info, 3344112bfa0SVikram Kanigiri bl2_to_bl31_params->bl32_ep_info); 335a3050ed5SAchin Gupta } 3361151c821SDan Handley #endif /* BL32_BASE */ 3374112bfa0SVikram Kanigiri 33893d81d64SSandrine Bailleux return e; 33993d81d64SSandrine Bailleux } 34093d81d64SSandrine Bailleux 34193d81d64SSandrine Bailleux /******************************************************************************* 34293d81d64SSandrine Bailleux * Load the BL3-3 image. 34393d81d64SSandrine Bailleux * The bl2_to_bl31_params param will be updated with the relevant BL3-3 34493d81d64SSandrine Bailleux * information. 34593d81d64SSandrine Bailleux * Return 0 on success, a negative error code otherwise. 34693d81d64SSandrine Bailleux ******************************************************************************/ 34793d81d64SSandrine Bailleux static int load_bl33(bl31_params_t *bl2_to_bl31_params) 34893d81d64SSandrine Bailleux { 34993d81d64SSandrine Bailleux meminfo_t bl33_mem_info; 35093d81d64SSandrine Bailleux int e; 35193d81d64SSandrine Bailleux 3526ad2e461SDan Handley INFO("BL2: Loading BL3-3\n"); 35393d81d64SSandrine Bailleux assert(bl2_to_bl31_params != NULL); 35493d81d64SSandrine Bailleux 35593d81d64SSandrine Bailleux bl2_plat_get_bl33_meminfo(&bl33_mem_info); 35693d81d64SSandrine Bailleux 35793d81d64SSandrine Bailleux /* Load the BL3-3 image in non-secure memory provided by the platform */ 35893d81d64SSandrine Bailleux e = load_image(&bl33_mem_info, 35993d81d64SSandrine Bailleux BL33_IMAGE_NAME, 36093d81d64SSandrine Bailleux plat_get_ns_image_entrypoint(), 36193d81d64SSandrine Bailleux bl2_to_bl31_params->bl33_image_info, 36293d81d64SSandrine Bailleux bl2_to_bl31_params->bl33_ep_info); 36393d81d64SSandrine Bailleux 364*dec840afSJuan Castillo if (e == 0) { 365*dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 366*dec840afSJuan Castillo e = auth_verify_obj(AUTH_BL33_IMG, 367*dec840afSJuan Castillo bl2_to_bl31_params->bl33_image_info->image_base, 368*dec840afSJuan Castillo bl2_to_bl31_params->bl33_image_info->image_size); 369*dec840afSJuan Castillo if (e) { 370*dec840afSJuan Castillo ERROR("Failed to authenticate BL3-3 image.\n"); 371*dec840afSJuan Castillo panic(); 372*dec840afSJuan Castillo } 373*dec840afSJuan Castillo /* After working with data, invalidate the data cache */ 374*dec840afSJuan Castillo inv_dcache_range(bl2_to_bl31_params->bl33_image_info->image_base, 375*dec840afSJuan Castillo (size_t)bl2_to_bl31_params->bl33_image_info->image_size); 376*dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 377*dec840afSJuan Castillo 37893d81d64SSandrine Bailleux bl2_plat_set_bl33_ep_info(bl2_to_bl31_params->bl33_image_info, 37993d81d64SSandrine Bailleux bl2_to_bl31_params->bl33_ep_info); 380*dec840afSJuan Castillo } 38193d81d64SSandrine Bailleux 38293d81d64SSandrine Bailleux return e; 38393d81d64SSandrine Bailleux } 38493d81d64SSandrine Bailleux 38593d81d64SSandrine Bailleux /******************************************************************************* 38693d81d64SSandrine Bailleux * The only thing to do in BL2 is to load further images and pass control to 38793d81d64SSandrine Bailleux * BL3-1. The memory occupied by BL2 will be reclaimed by BL3-x stages. BL2 runs 38893d81d64SSandrine Bailleux * entirely in S-EL1. 38993d81d64SSandrine Bailleux ******************************************************************************/ 39093d81d64SSandrine Bailleux void bl2_main(void) 39193d81d64SSandrine Bailleux { 39293d81d64SSandrine Bailleux bl31_params_t *bl2_to_bl31_params; 39393d81d64SSandrine Bailleux entry_point_info_t *bl31_ep_info; 39493d81d64SSandrine Bailleux int e; 39593d81d64SSandrine Bailleux 3966ad2e461SDan Handley NOTICE("BL2: %s\n", version_string); 3976ad2e461SDan Handley NOTICE("BL2: %s\n", build_message); 3986ad2e461SDan Handley 39993d81d64SSandrine Bailleux /* Perform remaining generic architectural setup in S-EL1 */ 40093d81d64SSandrine Bailleux bl2_arch_setup(); 40193d81d64SSandrine Bailleux 402*dec840afSJuan Castillo #if TRUSTED_BOARD_BOOT 403*dec840afSJuan Castillo /* Initialize authentication module */ 404*dec840afSJuan Castillo auth_init(); 405*dec840afSJuan Castillo 406*dec840afSJuan Castillo /* Validate the certificates involved in the Chain of Trust */ 407*dec840afSJuan Castillo e = load_certs(); 408*dec840afSJuan Castillo if (e) { 409*dec840afSJuan Castillo ERROR("Chain of Trust invalid. Aborting...\n"); 410*dec840afSJuan Castillo panic(); 411*dec840afSJuan Castillo } 412*dec840afSJuan Castillo #endif /* TRUSTED_BOARD_BOOT */ 413*dec840afSJuan Castillo 41493d81d64SSandrine Bailleux /* 41593d81d64SSandrine Bailleux * Load the subsequent bootloader images 41693d81d64SSandrine Bailleux */ 41793d81d64SSandrine Bailleux e = load_bl30(); 41893d81d64SSandrine Bailleux if (e) { 41993d81d64SSandrine Bailleux ERROR("Failed to load BL3-0 (%i)\n", e); 42093d81d64SSandrine Bailleux panic(); 42193d81d64SSandrine Bailleux } 42293d81d64SSandrine Bailleux 423ef538c6fSJuan Castillo /* Perform platform setup in BL2 after loading BL3-0 */ 424ef538c6fSJuan Castillo bl2_platform_setup(); 425ef538c6fSJuan Castillo 42693d81d64SSandrine Bailleux /* 42793d81d64SSandrine Bailleux * Get a pointer to the memory the platform has set aside to pass 42893d81d64SSandrine Bailleux * information to BL3-1. 42993d81d64SSandrine Bailleux */ 43093d81d64SSandrine Bailleux bl2_to_bl31_params = bl2_plat_get_bl31_params(); 43193d81d64SSandrine Bailleux bl31_ep_info = bl2_plat_get_bl31_ep_info(); 43293d81d64SSandrine Bailleux 43393d81d64SSandrine Bailleux e = load_bl31(bl2_to_bl31_params, bl31_ep_info); 43493d81d64SSandrine Bailleux if (e) { 43593d81d64SSandrine Bailleux ERROR("Failed to load BL3-1 (%i)\n", e); 43693d81d64SSandrine Bailleux panic(); 43793d81d64SSandrine Bailleux } 43893d81d64SSandrine Bailleux 43993d81d64SSandrine Bailleux e = load_bl32(bl2_to_bl31_params); 44093d81d64SSandrine Bailleux if (e) 44193d81d64SSandrine Bailleux WARN("Failed to load BL3-2 (%i)\n", e); 44293d81d64SSandrine Bailleux 44393d81d64SSandrine Bailleux e = load_bl33(bl2_to_bl31_params); 44493d81d64SSandrine Bailleux if (e) { 44593d81d64SSandrine Bailleux ERROR("Failed to load BL3-3 (%i)\n", e); 44693d81d64SSandrine Bailleux panic(); 44793d81d64SSandrine Bailleux } 44893d81d64SSandrine Bailleux 44903462671SAndrew Thoelke /* Flush the params to be passed to memory */ 45003462671SAndrew Thoelke bl2_plat_flush_bl31_params(); 45103462671SAndrew Thoelke 4524f6ad66aSAchin Gupta /* 45393d81d64SSandrine Bailleux * Run BL3-1 via an SMC to BL1. Information on how to pass control to 45493d81d64SSandrine Bailleux * the BL3-2 (if present) and BL3-3 software images will be passed to 45593d81d64SSandrine Bailleux * BL3-1 as an argument. 4564f6ad66aSAchin Gupta */ 45703462671SAndrew Thoelke smc(RUN_IMAGE, (unsigned long)bl31_ep_info, 0, 0, 0, 0, 0, 0); 4584f6ad66aSAchin Gupta } 459