xref: /rk3399_ARM-atf/bl2/bl2_image_load_v2.c (revision c2a9ee6383b71af2d0dae7b0c578e987bcf35695)
142019bf4SYatharth Kochar /*
242019bf4SYatharth Kochar  * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
342019bf4SYatharth Kochar  *
442019bf4SYatharth Kochar  * Redistribution and use in source and binary forms, with or without
542019bf4SYatharth Kochar  * modification, are permitted provided that the following conditions are met:
642019bf4SYatharth Kochar  *
742019bf4SYatharth Kochar  * Redistributions of source code must retain the above copyright notice, this
842019bf4SYatharth Kochar  * list of conditions and the following disclaimer.
942019bf4SYatharth Kochar  *
1042019bf4SYatharth Kochar  * Redistributions in binary form must reproduce the above copyright notice,
1142019bf4SYatharth Kochar  * this list of conditions and the following disclaimer in the documentation
1242019bf4SYatharth Kochar  * and/or other materials provided with the distribution.
1342019bf4SYatharth Kochar  *
1442019bf4SYatharth Kochar  * Neither the name of ARM nor the names of its contributors may be used
1542019bf4SYatharth Kochar  * to endorse or promote products derived from this software without specific
1642019bf4SYatharth Kochar  * prior written permission.
1742019bf4SYatharth Kochar  *
1842019bf4SYatharth Kochar  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1942019bf4SYatharth Kochar  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2042019bf4SYatharth Kochar  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2142019bf4SYatharth Kochar  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2242019bf4SYatharth Kochar  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2342019bf4SYatharth Kochar  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2442019bf4SYatharth Kochar  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2542019bf4SYatharth Kochar  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2642019bf4SYatharth Kochar  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2742019bf4SYatharth Kochar  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2842019bf4SYatharth Kochar  * POSSIBILITY OF SUCH DAMAGE.
2942019bf4SYatharth Kochar  */
3042019bf4SYatharth Kochar 
3142019bf4SYatharth Kochar #include <arch.h>
3242019bf4SYatharth Kochar #include <arch_helpers.h>
3342019bf4SYatharth Kochar #include <assert.h>
3442019bf4SYatharth Kochar #include <auth_mod.h>
3542019bf4SYatharth Kochar #include <bl_common.h>
3642019bf4SYatharth Kochar #include <debug.h>
3742019bf4SYatharth Kochar #include <desc_image_load.h>
3842019bf4SYatharth Kochar #include <platform.h>
3942019bf4SYatharth Kochar #include <platform_def.h>
4042019bf4SYatharth Kochar #include <stdint.h>
4142019bf4SYatharth Kochar 
4242019bf4SYatharth Kochar 
4342019bf4SYatharth Kochar /*******************************************************************************
4442019bf4SYatharth Kochar  * This function loads SCP_BL2/BL3x images and returns the ep_info for
4542019bf4SYatharth Kochar  * the next executable image.
4642019bf4SYatharth Kochar  ******************************************************************************/
4742019bf4SYatharth Kochar entry_point_info_t *bl2_load_images(void)
4842019bf4SYatharth Kochar {
4942019bf4SYatharth Kochar 	bl_params_t *bl2_to_next_bl_params;
5042019bf4SYatharth Kochar 	bl_load_info_t *bl2_load_info;
5142019bf4SYatharth Kochar 	const bl_load_info_node_t *bl2_node_info;
5242019bf4SYatharth Kochar 	int plat_setup_done = 0;
5342019bf4SYatharth Kochar 	int err;
5442019bf4SYatharth Kochar 
5542019bf4SYatharth Kochar 	/*
5642019bf4SYatharth Kochar 	 * Get information about the images to load.
5742019bf4SYatharth Kochar 	 */
5842019bf4SYatharth Kochar 	bl2_load_info = plat_get_bl_image_load_info();
5942019bf4SYatharth Kochar 	assert(bl2_load_info);
6042019bf4SYatharth Kochar 	assert(bl2_load_info->head);
6142019bf4SYatharth Kochar 	assert(bl2_load_info->h.type == PARAM_BL_LOAD_INFO);
6242019bf4SYatharth Kochar 	assert(bl2_load_info->h.version >= VERSION_2);
6342019bf4SYatharth Kochar 	bl2_node_info = bl2_load_info->head;
6442019bf4SYatharth Kochar 
6542019bf4SYatharth Kochar 	while (bl2_node_info) {
6642019bf4SYatharth Kochar 		/*
6742019bf4SYatharth Kochar 		 * Perform platform setup before loading the image,
6842019bf4SYatharth Kochar 		 * if indicated in the image attributes AND if NOT
6942019bf4SYatharth Kochar 		 * already done before.
7042019bf4SYatharth Kochar 		 */
7142019bf4SYatharth Kochar 		if (bl2_node_info->image_info->h.attr & IMAGE_ATTRIB_PLAT_SETUP) {
7242019bf4SYatharth Kochar 			if (plat_setup_done) {
7342019bf4SYatharth Kochar 				WARN("BL2: Platform setup already done!!\n");
7442019bf4SYatharth Kochar 			} else {
7542019bf4SYatharth Kochar 				INFO("BL2: Doing platform setup\n");
7642019bf4SYatharth Kochar 				bl2_platform_setup();
7742019bf4SYatharth Kochar 				plat_setup_done = 1;
7842019bf4SYatharth Kochar 			}
7942019bf4SYatharth Kochar 		}
8042019bf4SYatharth Kochar 
8142019bf4SYatharth Kochar 		if (!(bl2_node_info->image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) {
8242019bf4SYatharth Kochar 			INFO("BL2: Loading image id %d\n", bl2_node_info->image_id);
8342019bf4SYatharth Kochar 			err = load_auth_image(bl2_node_info->image_id,
8442019bf4SYatharth Kochar 				bl2_node_info->image_info);
8542019bf4SYatharth Kochar 			if (err) {
8642019bf4SYatharth Kochar 				ERROR("BL2: Failed to load image (%i)\n", err);
8742019bf4SYatharth Kochar 				plat_error_handler(err);
8842019bf4SYatharth Kochar 			}
8942019bf4SYatharth Kochar 		} else {
9042019bf4SYatharth Kochar 			INFO("BL2: Skip loading image id %d\n", bl2_node_info->image_id);
9142019bf4SYatharth Kochar 		}
9242019bf4SYatharth Kochar 
9342019bf4SYatharth Kochar 		/* Allow platform to handle image information. */
9442019bf4SYatharth Kochar 		err = bl2_plat_handle_post_image_load(bl2_node_info->image_id);
9542019bf4SYatharth Kochar 		if (err) {
9642019bf4SYatharth Kochar 			ERROR("BL2: Failure in post image load handling (%i)\n", err);
9742019bf4SYatharth Kochar 			plat_error_handler(err);
9842019bf4SYatharth Kochar 		}
9942019bf4SYatharth Kochar 
10042019bf4SYatharth Kochar 		/* Go to next image */
10142019bf4SYatharth Kochar 		bl2_node_info = bl2_node_info->next_load_info;
10242019bf4SYatharth Kochar 	}
10342019bf4SYatharth Kochar 
10442019bf4SYatharth Kochar 	/*
10542019bf4SYatharth Kochar 	 * Get information to pass to the next image.
10642019bf4SYatharth Kochar 	 */
10742019bf4SYatharth Kochar 	bl2_to_next_bl_params = plat_get_next_bl_params();
10842019bf4SYatharth Kochar 	assert(bl2_to_next_bl_params);
10942019bf4SYatharth Kochar 	assert(bl2_to_next_bl_params->head);
11042019bf4SYatharth Kochar 	assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS);
11142019bf4SYatharth Kochar 	assert(bl2_to_next_bl_params->h.version >= VERSION_2);
112*c2a9ee63SDan Handley 	assert(bl2_to_next_bl_params->head->ep_info);
113*c2a9ee63SDan Handley 
114*c2a9ee63SDan Handley 	/* Populate arg0 for the next BL image */
115*c2a9ee63SDan Handley 	bl2_to_next_bl_params->head->ep_info->args.arg0 = (u_register_t)bl2_to_next_bl_params;
11642019bf4SYatharth Kochar 
11742019bf4SYatharth Kochar 	/* Flush the parameters to be passed to next image */
11842019bf4SYatharth Kochar 	plat_flush_next_bl_params();
11942019bf4SYatharth Kochar 
12042019bf4SYatharth Kochar 	return bl2_to_next_bl_params->head->ep_info;
12142019bf4SYatharth Kochar }
122