xref: /rk3399_ARM-atf/bl2/bl2_image_load_v2.c (revision 3443a7027d78a9ccebc6940f0a69300ec7c1ed44)
142019bf4SYatharth Kochar /*
2466bb285SZelalem  * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved.
342019bf4SYatharth Kochar  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
542019bf4SYatharth Kochar  */
642019bf4SYatharth Kochar 
709d40e0eSAntonio Nino Diaz #include <assert.h>
809d40e0eSAntonio Nino Diaz #include <stdint.h>
909d40e0eSAntonio Nino Diaz 
1009d40e0eSAntonio Nino Diaz #include <platform_def.h>
1109d40e0eSAntonio Nino Diaz 
1242019bf4SYatharth Kochar #include <arch.h>
1342019bf4SYatharth Kochar #include <arch_helpers.h>
1409d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
1509d40e0eSAntonio Nino Diaz #include <common/debug.h>
1609d40e0eSAntonio Nino Diaz #include <common/desc_image_load.h>
1709d40e0eSAntonio Nino Diaz #include <drivers/auth/auth_mod.h>
1809d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
1942019bf4SYatharth Kochar 
2009d40e0eSAntonio Nino Diaz #include "bl2_private.h"
2142019bf4SYatharth Kochar 
2242019bf4SYatharth Kochar /*******************************************************************************
2342019bf4SYatharth Kochar  * This function loads SCP_BL2/BL3x images and returns the ep_info for
2442019bf4SYatharth Kochar  * the next executable image.
2542019bf4SYatharth Kochar  ******************************************************************************/
268cb47628SRoberto Vargas struct entry_point_info *bl2_load_images(void)
2742019bf4SYatharth Kochar {
2842019bf4SYatharth Kochar 	bl_params_t *bl2_to_next_bl_params;
2942019bf4SYatharth Kochar 	bl_load_info_t *bl2_load_info;
3042019bf4SYatharth Kochar 	const bl_load_info_node_t *bl2_node_info;
3142019bf4SYatharth Kochar 	int plat_setup_done = 0;
3242019bf4SYatharth Kochar 	int err;
3342019bf4SYatharth Kochar 
3442019bf4SYatharth Kochar 	/*
3542019bf4SYatharth Kochar 	 * Get information about the images to load.
3642019bf4SYatharth Kochar 	 */
3742019bf4SYatharth Kochar 	bl2_load_info = plat_get_bl_image_load_info();
38466bb285SZelalem 	assert(bl2_load_info != NULL);
39466bb285SZelalem 	assert(bl2_load_info->head != NULL);
4042019bf4SYatharth Kochar 	assert(bl2_load_info->h.type == PARAM_BL_LOAD_INFO);
4142019bf4SYatharth Kochar 	assert(bl2_load_info->h.version >= VERSION_2);
4242019bf4SYatharth Kochar 	bl2_node_info = bl2_load_info->head;
4342019bf4SYatharth Kochar 
44466bb285SZelalem 	while (bl2_node_info != NULL) {
4542019bf4SYatharth Kochar 		/*
4642019bf4SYatharth Kochar 		 * Perform platform setup before loading the image,
4742019bf4SYatharth Kochar 		 * if indicated in the image attributes AND if NOT
4842019bf4SYatharth Kochar 		 * already done before.
4942019bf4SYatharth Kochar 		 */
50*3443a702SJohn Powell 		if ((bl2_node_info->image_info->h.attr &
51*3443a702SJohn Powell 		    IMAGE_ATTRIB_PLAT_SETUP) != 0U) {
52*3443a702SJohn Powell 			if (plat_setup_done != 0) {
5342019bf4SYatharth Kochar 				WARN("BL2: Platform setup already done!!\n");
5442019bf4SYatharth Kochar 			} else {
5542019bf4SYatharth Kochar 				INFO("BL2: Doing platform setup\n");
5642019bf4SYatharth Kochar 				bl2_platform_setup();
5742019bf4SYatharth Kochar 				plat_setup_done = 1;
5842019bf4SYatharth Kochar 			}
5942019bf4SYatharth Kochar 		}
6042019bf4SYatharth Kochar 
61ba68ef55SMasahiro Yamada 		err = bl2_plat_handle_pre_image_load(bl2_node_info->image_id);
62*3443a702SJohn Powell 		if (err != 0) {
63ba68ef55SMasahiro Yamada 			ERROR("BL2: Failure in pre image load handling (%i)\n", err);
64ba68ef55SMasahiro Yamada 			plat_error_handler(err);
65ba68ef55SMasahiro Yamada 		}
66ba68ef55SMasahiro Yamada 
67*3443a702SJohn Powell 		if ((bl2_node_info->image_info->h.attr &
68*3443a702SJohn Powell 		    IMAGE_ATTRIB_SKIP_LOADING) == 0U) {
6942019bf4SYatharth Kochar 			INFO("BL2: Loading image id %d\n", bl2_node_info->image_id);
7042019bf4SYatharth Kochar 			err = load_auth_image(bl2_node_info->image_id,
7142019bf4SYatharth Kochar 				bl2_node_info->image_info);
72*3443a702SJohn Powell 			if (err != 0) {
73a416325bSSandrine Bailleux 				ERROR("BL2: Failed to load image id %d (%i)\n",
74a416325bSSandrine Bailleux 				      bl2_node_info->image_id, err);
7542019bf4SYatharth Kochar 				plat_error_handler(err);
7642019bf4SYatharth Kochar 			}
7742019bf4SYatharth Kochar 		} else {
7842019bf4SYatharth Kochar 			INFO("BL2: Skip loading image id %d\n", bl2_node_info->image_id);
7942019bf4SYatharth Kochar 		}
8042019bf4SYatharth Kochar 
8142019bf4SYatharth Kochar 		/* Allow platform to handle image information. */
8242019bf4SYatharth Kochar 		err = bl2_plat_handle_post_image_load(bl2_node_info->image_id);
83*3443a702SJohn Powell 		if (err != 0) {
8442019bf4SYatharth Kochar 			ERROR("BL2: Failure in post image load handling (%i)\n", err);
8542019bf4SYatharth Kochar 			plat_error_handler(err);
8642019bf4SYatharth Kochar 		}
8742019bf4SYatharth Kochar 
8842019bf4SYatharth Kochar 		/* Go to next image */
8942019bf4SYatharth Kochar 		bl2_node_info = bl2_node_info->next_load_info;
9042019bf4SYatharth Kochar 	}
9142019bf4SYatharth Kochar 
9242019bf4SYatharth Kochar 	/*
9342019bf4SYatharth Kochar 	 * Get information to pass to the next image.
9442019bf4SYatharth Kochar 	 */
9542019bf4SYatharth Kochar 	bl2_to_next_bl_params = plat_get_next_bl_params();
96466bb285SZelalem 	assert(bl2_to_next_bl_params != NULL);
97466bb285SZelalem 	assert(bl2_to_next_bl_params->head != NULL);
9842019bf4SYatharth Kochar 	assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS);
9942019bf4SYatharth Kochar 	assert(bl2_to_next_bl_params->h.version >= VERSION_2);
100466bb285SZelalem 	assert(bl2_to_next_bl_params->head->ep_info != NULL);
101c2a9ee63SDan Handley 
10210c66958SEtienne Carriere 	/* Populate arg0 for the next BL image if not already provided */
10395ae5b00SEtienne Carriere 	if (bl2_to_next_bl_params->head->ep_info->args.arg0 == (u_register_t)0)
10410c66958SEtienne Carriere 		bl2_to_next_bl_params->head->ep_info->args.arg0 =
10510c66958SEtienne Carriere 					(u_register_t)bl2_to_next_bl_params;
10642019bf4SYatharth Kochar 
10742019bf4SYatharth Kochar 	/* Flush the parameters to be passed to next image */
10842019bf4SYatharth Kochar 	plat_flush_next_bl_params();
10942019bf4SYatharth Kochar 
11042019bf4SYatharth Kochar 	return bl2_to_next_bl_params->head->ep_info;
11142019bf4SYatharth Kochar }
112