xref: /rk3399_ARM-atf/bl2/bl2_image_load_v2.c (revision 42019bf4e93a111984af9dc44608d8d5203a3b1d)
1*42019bf4SYatharth Kochar /*
2*42019bf4SYatharth Kochar  * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3*42019bf4SYatharth Kochar  *
4*42019bf4SYatharth Kochar  * Redistribution and use in source and binary forms, with or without
5*42019bf4SYatharth Kochar  * modification, are permitted provided that the following conditions are met:
6*42019bf4SYatharth Kochar  *
7*42019bf4SYatharth Kochar  * Redistributions of source code must retain the above copyright notice, this
8*42019bf4SYatharth Kochar  * list of conditions and the following disclaimer.
9*42019bf4SYatharth Kochar  *
10*42019bf4SYatharth Kochar  * Redistributions in binary form must reproduce the above copyright notice,
11*42019bf4SYatharth Kochar  * this list of conditions and the following disclaimer in the documentation
12*42019bf4SYatharth Kochar  * and/or other materials provided with the distribution.
13*42019bf4SYatharth Kochar  *
14*42019bf4SYatharth Kochar  * Neither the name of ARM nor the names of its contributors may be used
15*42019bf4SYatharth Kochar  * to endorse or promote products derived from this software without specific
16*42019bf4SYatharth Kochar  * prior written permission.
17*42019bf4SYatharth Kochar  *
18*42019bf4SYatharth Kochar  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*42019bf4SYatharth Kochar  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*42019bf4SYatharth Kochar  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*42019bf4SYatharth Kochar  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*42019bf4SYatharth Kochar  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*42019bf4SYatharth Kochar  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*42019bf4SYatharth Kochar  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*42019bf4SYatharth Kochar  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*42019bf4SYatharth Kochar  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*42019bf4SYatharth Kochar  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*42019bf4SYatharth Kochar  * POSSIBILITY OF SUCH DAMAGE.
29*42019bf4SYatharth Kochar  */
30*42019bf4SYatharth Kochar 
31*42019bf4SYatharth Kochar #include <arch.h>
32*42019bf4SYatharth Kochar #include <arch_helpers.h>
33*42019bf4SYatharth Kochar #include <assert.h>
34*42019bf4SYatharth Kochar #include <auth_mod.h>
35*42019bf4SYatharth Kochar #include <bl_common.h>
36*42019bf4SYatharth Kochar #include <debug.h>
37*42019bf4SYatharth Kochar #include <desc_image_load.h>
38*42019bf4SYatharth Kochar #include <platform.h>
39*42019bf4SYatharth Kochar #include <platform_def.h>
40*42019bf4SYatharth Kochar #include <stdint.h>
41*42019bf4SYatharth Kochar 
42*42019bf4SYatharth Kochar 
43*42019bf4SYatharth Kochar /*******************************************************************************
44*42019bf4SYatharth Kochar  * This function loads SCP_BL2/BL3x images and returns the ep_info for
45*42019bf4SYatharth Kochar  * the next executable image.
46*42019bf4SYatharth Kochar  ******************************************************************************/
47*42019bf4SYatharth Kochar entry_point_info_t *bl2_load_images(void)
48*42019bf4SYatharth Kochar {
49*42019bf4SYatharth Kochar 	bl_params_t *bl2_to_next_bl_params;
50*42019bf4SYatharth Kochar 	bl_load_info_t *bl2_load_info;
51*42019bf4SYatharth Kochar 	const bl_load_info_node_t *bl2_node_info;
52*42019bf4SYatharth Kochar 	int plat_setup_done = 0;
53*42019bf4SYatharth Kochar 	int err;
54*42019bf4SYatharth Kochar 
55*42019bf4SYatharth Kochar 	/*
56*42019bf4SYatharth Kochar 	 * Get information about the images to load.
57*42019bf4SYatharth Kochar 	 */
58*42019bf4SYatharth Kochar 	bl2_load_info = plat_get_bl_image_load_info();
59*42019bf4SYatharth Kochar 	assert(bl2_load_info);
60*42019bf4SYatharth Kochar 	assert(bl2_load_info->head);
61*42019bf4SYatharth Kochar 	assert(bl2_load_info->h.type == PARAM_BL_LOAD_INFO);
62*42019bf4SYatharth Kochar 	assert(bl2_load_info->h.version >= VERSION_2);
63*42019bf4SYatharth Kochar 	bl2_node_info = bl2_load_info->head;
64*42019bf4SYatharth Kochar 
65*42019bf4SYatharth Kochar 	while (bl2_node_info) {
66*42019bf4SYatharth Kochar 		/*
67*42019bf4SYatharth Kochar 		 * Perform platform setup before loading the image,
68*42019bf4SYatharth Kochar 		 * if indicated in the image attributes AND if NOT
69*42019bf4SYatharth Kochar 		 * already done before.
70*42019bf4SYatharth Kochar 		 */
71*42019bf4SYatharth Kochar 		if (bl2_node_info->image_info->h.attr & IMAGE_ATTRIB_PLAT_SETUP) {
72*42019bf4SYatharth Kochar 			if (plat_setup_done) {
73*42019bf4SYatharth Kochar 				WARN("BL2: Platform setup already done!!\n");
74*42019bf4SYatharth Kochar 			} else {
75*42019bf4SYatharth Kochar 				INFO("BL2: Doing platform setup\n");
76*42019bf4SYatharth Kochar 				bl2_platform_setup();
77*42019bf4SYatharth Kochar 				plat_setup_done = 1;
78*42019bf4SYatharth Kochar 			}
79*42019bf4SYatharth Kochar 		}
80*42019bf4SYatharth Kochar 
81*42019bf4SYatharth Kochar 		if (!(bl2_node_info->image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) {
82*42019bf4SYatharth Kochar 			INFO("BL2: Loading image id %d\n", bl2_node_info->image_id);
83*42019bf4SYatharth Kochar 			err = load_auth_image(bl2_node_info->image_id,
84*42019bf4SYatharth Kochar 				bl2_node_info->image_info);
85*42019bf4SYatharth Kochar 			if (err) {
86*42019bf4SYatharth Kochar 				ERROR("BL2: Failed to load image (%i)\n", err);
87*42019bf4SYatharth Kochar 				plat_error_handler(err);
88*42019bf4SYatharth Kochar 			}
89*42019bf4SYatharth Kochar 		} else {
90*42019bf4SYatharth Kochar 			INFO("BL2: Skip loading image id %d\n", bl2_node_info->image_id);
91*42019bf4SYatharth Kochar 		}
92*42019bf4SYatharth Kochar 
93*42019bf4SYatharth Kochar 		/* Allow platform to handle image information. */
94*42019bf4SYatharth Kochar 		err = bl2_plat_handle_post_image_load(bl2_node_info->image_id);
95*42019bf4SYatharth Kochar 		if (err) {
96*42019bf4SYatharth Kochar 			ERROR("BL2: Failure in post image load handling (%i)\n", err);
97*42019bf4SYatharth Kochar 			plat_error_handler(err);
98*42019bf4SYatharth Kochar 		}
99*42019bf4SYatharth Kochar 
100*42019bf4SYatharth Kochar 		/* Go to next image */
101*42019bf4SYatharth Kochar 		bl2_node_info = bl2_node_info->next_load_info;
102*42019bf4SYatharth Kochar 	}
103*42019bf4SYatharth Kochar 
104*42019bf4SYatharth Kochar 	/*
105*42019bf4SYatharth Kochar 	 * Get information to pass to the next image.
106*42019bf4SYatharth Kochar 	 */
107*42019bf4SYatharth Kochar 	bl2_to_next_bl_params = plat_get_next_bl_params();
108*42019bf4SYatharth Kochar 	assert(bl2_to_next_bl_params);
109*42019bf4SYatharth Kochar 	assert(bl2_to_next_bl_params->head);
110*42019bf4SYatharth Kochar 	assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS);
111*42019bf4SYatharth Kochar 	assert(bl2_to_next_bl_params->h.version >= VERSION_2);
112*42019bf4SYatharth Kochar 
113*42019bf4SYatharth Kochar 	/* Flush the parameters to be passed to next image */
114*42019bf4SYatharth Kochar 	plat_flush_next_bl_params();
115*42019bf4SYatharth Kochar 
116*42019bf4SYatharth Kochar 	return bl2_to_next_bl_params->head->ep_info;
117*42019bf4SYatharth Kochar }
118