xref: /rk3399_ARM-atf/bl2/bl2_image_load_v2.c (revision e4c77db9c80d87009611a3079454877e6ce45a04)
142019bf4SYatharth Kochar /*
2*e4c77db9SYann Gautier  * Copyright (c) 2016-2022, 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 
1042019bf4SYatharth Kochar #include <arch.h>
1142019bf4SYatharth Kochar #include <arch_helpers.h>
12*e4c77db9SYann Gautier #include "bl2_private.h"
1309d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
1409d40e0eSAntonio Nino Diaz #include <common/debug.h>
1509d40e0eSAntonio Nino Diaz #include <common/desc_image_load.h>
1609d40e0eSAntonio Nino Diaz #include <drivers/auth/auth_mod.h>
1709d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
1842019bf4SYatharth Kochar 
19*e4c77db9SYann Gautier #include <platform_def.h>
2042019bf4SYatharth Kochar 
2142019bf4SYatharth Kochar /*******************************************************************************
2242019bf4SYatharth Kochar  * This function loads SCP_BL2/BL3x images and returns the ep_info for
2342019bf4SYatharth Kochar  * the next executable image.
2442019bf4SYatharth Kochar  ******************************************************************************/
258cb47628SRoberto Vargas struct entry_point_info *bl2_load_images(void)
2642019bf4SYatharth Kochar {
2742019bf4SYatharth Kochar 	bl_params_t *bl2_to_next_bl_params;
2842019bf4SYatharth Kochar 	bl_load_info_t *bl2_load_info;
2942019bf4SYatharth Kochar 	const bl_load_info_node_t *bl2_node_info;
3042019bf4SYatharth Kochar 	int plat_setup_done = 0;
3142019bf4SYatharth Kochar 	int err;
3242019bf4SYatharth Kochar 
3342019bf4SYatharth Kochar 	/*
3442019bf4SYatharth Kochar 	 * Get information about the images to load.
3542019bf4SYatharth Kochar 	 */
3642019bf4SYatharth Kochar 	bl2_load_info = plat_get_bl_image_load_info();
37466bb285SZelalem 	assert(bl2_load_info != NULL);
38466bb285SZelalem 	assert(bl2_load_info->head != NULL);
3942019bf4SYatharth Kochar 	assert(bl2_load_info->h.type == PARAM_BL_LOAD_INFO);
4042019bf4SYatharth Kochar 	assert(bl2_load_info->h.version >= VERSION_2);
4142019bf4SYatharth Kochar 	bl2_node_info = bl2_load_info->head;
4242019bf4SYatharth Kochar 
43466bb285SZelalem 	while (bl2_node_info != NULL) {
4442019bf4SYatharth Kochar 		/*
4542019bf4SYatharth Kochar 		 * Perform platform setup before loading the image,
4642019bf4SYatharth Kochar 		 * if indicated in the image attributes AND if NOT
4742019bf4SYatharth Kochar 		 * already done before.
4842019bf4SYatharth Kochar 		 */
493443a702SJohn Powell 		if ((bl2_node_info->image_info->h.attr &
503443a702SJohn Powell 		    IMAGE_ATTRIB_PLAT_SETUP) != 0U) {
513443a702SJohn Powell 			if (plat_setup_done != 0) {
5242019bf4SYatharth Kochar 				WARN("BL2: Platform setup already done!!\n");
5342019bf4SYatharth Kochar 			} else {
5442019bf4SYatharth Kochar 				INFO("BL2: Doing platform setup\n");
5542019bf4SYatharth Kochar 				bl2_platform_setup();
5642019bf4SYatharth Kochar 				plat_setup_done = 1;
5742019bf4SYatharth Kochar 			}
5842019bf4SYatharth Kochar 		}
5942019bf4SYatharth Kochar 
60ba68ef55SMasahiro Yamada 		err = bl2_plat_handle_pre_image_load(bl2_node_info->image_id);
613443a702SJohn Powell 		if (err != 0) {
62ba68ef55SMasahiro Yamada 			ERROR("BL2: Failure in pre image load handling (%i)\n", err);
63ba68ef55SMasahiro Yamada 			plat_error_handler(err);
64ba68ef55SMasahiro Yamada 		}
65ba68ef55SMasahiro Yamada 
663443a702SJohn Powell 		if ((bl2_node_info->image_info->h.attr &
673443a702SJohn Powell 		    IMAGE_ATTRIB_SKIP_LOADING) == 0U) {
68*e4c77db9SYann Gautier 			INFO("BL2: Loading image id %u\n", bl2_node_info->image_id);
6942019bf4SYatharth Kochar 			err = load_auth_image(bl2_node_info->image_id,
7042019bf4SYatharth Kochar 				bl2_node_info->image_info);
713443a702SJohn Powell 			if (err != 0) {
72*e4c77db9SYann Gautier 				ERROR("BL2: Failed to load image id %u (%i)\n",
73a416325bSSandrine Bailleux 				      bl2_node_info->image_id, err);
7442019bf4SYatharth Kochar 				plat_error_handler(err);
7542019bf4SYatharth Kochar 			}
7642019bf4SYatharth Kochar 		} else {
77*e4c77db9SYann Gautier 			INFO("BL2: Skip loading image id %u\n", bl2_node_info->image_id);
7842019bf4SYatharth Kochar 		}
7942019bf4SYatharth Kochar 
8042019bf4SYatharth Kochar 		/* Allow platform to handle image information. */
8142019bf4SYatharth Kochar 		err = bl2_plat_handle_post_image_load(bl2_node_info->image_id);
823443a702SJohn Powell 		if (err != 0) {
8342019bf4SYatharth Kochar 			ERROR("BL2: Failure in post image load handling (%i)\n", err);
8442019bf4SYatharth Kochar 			plat_error_handler(err);
8542019bf4SYatharth Kochar 		}
8642019bf4SYatharth Kochar 
8742019bf4SYatharth Kochar 		/* Go to next image */
8842019bf4SYatharth Kochar 		bl2_node_info = bl2_node_info->next_load_info;
8942019bf4SYatharth Kochar 	}
9042019bf4SYatharth Kochar 
9142019bf4SYatharth Kochar 	/*
9242019bf4SYatharth Kochar 	 * Get information to pass to the next image.
9342019bf4SYatharth Kochar 	 */
9442019bf4SYatharth Kochar 	bl2_to_next_bl_params = plat_get_next_bl_params();
95466bb285SZelalem 	assert(bl2_to_next_bl_params != NULL);
96466bb285SZelalem 	assert(bl2_to_next_bl_params->head != NULL);
9742019bf4SYatharth Kochar 	assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS);
9842019bf4SYatharth Kochar 	assert(bl2_to_next_bl_params->h.version >= VERSION_2);
99466bb285SZelalem 	assert(bl2_to_next_bl_params->head->ep_info != NULL);
100c2a9ee63SDan Handley 
10110c66958SEtienne Carriere 	/* Populate arg0 for the next BL image if not already provided */
10295ae5b00SEtienne Carriere 	if (bl2_to_next_bl_params->head->ep_info->args.arg0 == (u_register_t)0)
10310c66958SEtienne Carriere 		bl2_to_next_bl_params->head->ep_info->args.arg0 =
10410c66958SEtienne Carriere 					(u_register_t)bl2_to_next_bl_params;
10542019bf4SYatharth Kochar 
10642019bf4SYatharth Kochar 	/* Flush the parameters to be passed to next image */
10742019bf4SYatharth Kochar 	plat_flush_next_bl_params();
10842019bf4SYatharth Kochar 
10942019bf4SYatharth Kochar 	return bl2_to_next_bl_params->head->ep_info;
11042019bf4SYatharth Kochar }
111