1 /* 2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <arch.h> 8 #include <arch_helpers.h> 9 #include <assert.h> 10 #include <auth_mod.h> 11 #include <bl_common.h> 12 #include <debug.h> 13 #include <desc_image_load.h> 14 #include <platform.h> 15 #include <platform_def.h> 16 #include <stdint.h> 17 18 19 /******************************************************************************* 20 * This function loads SCP_BL2/BL3x images and returns the ep_info for 21 * the next executable image. 22 ******************************************************************************/ bl2_load_images(void)23entry_point_info_t *bl2_load_images(void) 24 { 25 bl_params_t *bl2_to_next_bl_params; 26 bl_load_info_t *bl2_load_info; 27 const bl_load_info_node_t *bl2_node_info; 28 int plat_setup_done = 0; 29 int err; 30 31 /* 32 * Get information about the images to load. 33 */ 34 bl2_load_info = plat_get_bl_image_load_info(); 35 assert(bl2_load_info); 36 assert(bl2_load_info->head); 37 assert(bl2_load_info->h.type == PARAM_BL_LOAD_INFO); 38 assert(bl2_load_info->h.version >= VERSION_2); 39 bl2_node_info = bl2_load_info->head; 40 41 while (bl2_node_info) { 42 /* 43 * Perform platform setup before loading the image, 44 * if indicated in the image attributes AND if NOT 45 * already done before. 46 */ 47 if (bl2_node_info->image_info->h.attr & IMAGE_ATTRIB_PLAT_SETUP) { 48 if (plat_setup_done) { 49 WARN("BL2: Platform setup already done!!\n"); 50 } else { 51 INFO("BL2: Doing platform setup\n"); 52 bl2_platform_setup(); 53 plat_setup_done = 1; 54 } 55 } 56 57 if (!(bl2_node_info->image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) { 58 INFO("BL2: Loading image id %d\n", bl2_node_info->image_id); 59 err = load_auth_image(bl2_node_info->image_id, 60 bl2_node_info->image_info); 61 if (err) { 62 ERROR("BL2: Failed to load image (%i)\n", err); 63 plat_error_handler(err); 64 } 65 } else { 66 INFO("BL2: Skip loading image id %d\n", bl2_node_info->image_id); 67 } 68 69 /* Allow platform to handle image information. */ 70 err = bl2_plat_handle_post_image_load(bl2_node_info->image_id); 71 if (err) { 72 ERROR("BL2: Failure in post image load handling (%i)\n", err); 73 plat_error_handler(err); 74 } 75 76 /* Go to next image */ 77 bl2_node_info = bl2_node_info->next_load_info; 78 } 79 80 /* 81 * Get information to pass to the next image. 82 */ 83 bl2_to_next_bl_params = plat_get_next_bl_params(); 84 assert(bl2_to_next_bl_params); 85 assert(bl2_to_next_bl_params->head); 86 assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS); 87 assert(bl2_to_next_bl_params->h.version >= VERSION_2); 88 assert(bl2_to_next_bl_params->head->ep_info); 89 90 /* Populate arg0 for the next BL image */ 91 bl2_to_next_bl_params->head->ep_info->args.arg0 = (u_register_t)bl2_to_next_bl_params; 92 93 /* Flush the parameters to be passed to next image */ 94 plat_flush_next_bl_params(); 95 96 return bl2_to_next_bl_params->head->ep_info; 97 } 98