2 * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
10 #include <platform_def.h>
13 #include <arch_helpers.h>
14 #include <common/bl_common.h>
15 #include <common/debug.h>
16 #include <common/desc_image_load.h>
17 #include <drivers/auth/auth_mod.h>
18 #include <plat/common/platform.h>
20 #include "bl2_private.h"
22 /*******************************************************************************
23 * This function loads SCP_BL2/BL3x images and returns the ep_info for
24 * the next executable image.
25 ******************************************************************************/
26 struct entry_point_info
*bl2_load_images(void)
28 bl_params_t
*bl2_to_next_bl_params
;
29 bl_load_info_t
*bl2_load_info
;
30 const bl_load_info_node_t
*bl2_node_info
;
31 int plat_setup_done
= 0;
35 * Get information about the images to load.
37 bl2_load_info
= plat_get_bl_image_load_info();
38 assert(bl2_load_info
);
39 assert(bl2_load_info
->head
);
40 assert(bl2_load_info
->h
.type
== PARAM_BL_LOAD_INFO
);
41 assert(bl2_load_info
->h
.version
>= VERSION_2
);
42 bl2_node_info
= bl2_load_info
->head
;
44 while (bl2_node_info
) {
46 * Perform platform setup before loading the image,
47 * if indicated in the image attributes AND if NOT
48 * already done before.
50 if (bl2_node_info
->image_info
->h
.attr
& IMAGE_ATTRIB_PLAT_SETUP
) {
51 if (plat_setup_done
) {
52 WARN("BL2: Platform setup already done!!\n");
54 INFO("BL2: Doing platform setup\n");
60 err
= bl2_plat_handle_pre_image_load(bl2_node_info
->image_id
);
62 ERROR("BL2: Failure in pre image load handling (%i)\n", err
);
63 plat_error_handler(err
);
66 if (!(bl2_node_info
->image_info
->h
.attr
& IMAGE_ATTRIB_SKIP_LOADING
)) {
67 INFO("BL2: Loading image id %d\n", bl2_node_info
->image_id
);
68 err
= load_auth_image(bl2_node_info
->image_id
,
69 bl2_node_info
->image_info
);
71 ERROR("BL2: Failed to load image (%i)\n", err
);
72 plat_error_handler(err
);
75 INFO("BL2: Skip loading image id %d\n", bl2_node_info
->image_id
);
78 /* Allow platform to handle image information. */
79 err
= bl2_plat_handle_post_image_load(bl2_node_info
->image_id
);
81 ERROR("BL2: Failure in post image load handling (%i)\n", err
);
82 plat_error_handler(err
);
85 /* Go to next image */
86 bl2_node_info
= bl2_node_info
->next_load_info
;
90 * Get information to pass to the next image.
92 bl2_to_next_bl_params
= plat_get_next_bl_params();
93 assert(bl2_to_next_bl_params
);
94 assert(bl2_to_next_bl_params
->head
);
95 assert(bl2_to_next_bl_params
->h
.type
== PARAM_BL_PARAMS
);
96 assert(bl2_to_next_bl_params
->h
.version
>= VERSION_2
);
97 assert(bl2_to_next_bl_params
->head
->ep_info
);
99 /* Populate arg0 for the next BL image if not already provided */
100 if (bl2_to_next_bl_params
->head
->ep_info
->args
.arg0
== (u_register_t
)0)
101 bl2_to_next_bl_params
->head
->ep_info
->args
.arg0
=
102 (u_register_t
)bl2_to_next_bl_params
;
104 /* Flush the parameters to be passed to next image */
105 plat_flush_next_bl_params();
107 return bl2_to_next_bl_params
->head
->ep_info
;