xref: /rk3399_ARM-atf/bl2/bl2_image_load_v2.c (revision 1af540ef2a09797c3a22c40c340facd4b2f47c2f)
1 /*
2  * Copyright (c) 2016-2018, 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 #include "bl2_private.h"
18 
19 
20 /*******************************************************************************
21  * This function loads SCP_BL2/BL3x images and returns the ep_info for
22  * the next executable image.
23  ******************************************************************************/
24 entry_point_info_t *bl2_load_images(void)
25 {
26 	bl_params_t *bl2_to_next_bl_params;
27 	bl_load_info_t *bl2_load_info;
28 	const bl_load_info_node_t *bl2_node_info;
29 	int plat_setup_done = 0;
30 	int err;
31 
32 	/*
33 	 * Get information about the images to load.
34 	 */
35 	bl2_load_info = plat_get_bl_image_load_info();
36 	assert(bl2_load_info);
37 	assert(bl2_load_info->head);
38 	assert(bl2_load_info->h.type == PARAM_BL_LOAD_INFO);
39 	assert(bl2_load_info->h.version >= VERSION_2);
40 	bl2_node_info = bl2_load_info->head;
41 
42 	while (bl2_node_info) {
43 		/*
44 		 * Perform platform setup before loading the image,
45 		 * if indicated in the image attributes AND if NOT
46 		 * already done before.
47 		 */
48 		if (bl2_node_info->image_info->h.attr & IMAGE_ATTRIB_PLAT_SETUP) {
49 			if (plat_setup_done) {
50 				WARN("BL2: Platform setup already done!!\n");
51 			} else {
52 				INFO("BL2: Doing platform setup\n");
53 				bl2_platform_setup();
54 				plat_setup_done = 1;
55 			}
56 		}
57 
58 		err = bl2_plat_handle_pre_image_load(bl2_node_info->image_id);
59 		if (err) {
60 			ERROR("BL2: Failure in pre image load handling (%i)\n", err);
61 			plat_error_handler(err);
62 		}
63 
64 		if (!(bl2_node_info->image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) {
65 			INFO("BL2: Loading image id %d\n", bl2_node_info->image_id);
66 			err = load_auth_image(bl2_node_info->image_id,
67 				bl2_node_info->image_info);
68 			if (err) {
69 				ERROR("BL2: Failed to load image (%i)\n", err);
70 				plat_error_handler(err);
71 			}
72 		} else {
73 			INFO("BL2: Skip loading image id %d\n", bl2_node_info->image_id);
74 		}
75 
76 		/* Allow platform to handle image information. */
77 		err = bl2_plat_handle_post_image_load(bl2_node_info->image_id);
78 		if (err) {
79 			ERROR("BL2: Failure in post image load handling (%i)\n", err);
80 			plat_error_handler(err);
81 		}
82 
83 		/* Go to next image */
84 		bl2_node_info = bl2_node_info->next_load_info;
85 	}
86 
87 	/*
88 	 * Get information to pass to the next image.
89 	 */
90 	bl2_to_next_bl_params = plat_get_next_bl_params();
91 	assert(bl2_to_next_bl_params);
92 	assert(bl2_to_next_bl_params->head);
93 	assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS);
94 	assert(bl2_to_next_bl_params->h.version >= VERSION_2);
95 	assert(bl2_to_next_bl_params->head->ep_info);
96 
97 	/* Populate arg0 for the next BL image if not already provided */
98 	if (bl2_to_next_bl_params->head->ep_info->args.arg0 == (u_register_t)0)
99 		bl2_to_next_bl_params->head->ep_info->args.arg0 =
100 					(u_register_t)bl2_to_next_bl_params;
101 
102 	/* Flush the parameters to be passed to next image */
103 	plat_flush_next_bl_params();
104 
105 	return bl2_to_next_bl_params->head->ep_info;
106 }
107