blob: 6517703d87893b52e1447e3b3d12fe36e6892ef2 [file] [log] [blame]
Yatharth Kochar51f76f62016-09-12 16:10:33 +01001/*
2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Yatharth Kochar51f76f62016-09-12 16:10:33 +01005 */
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
18
19/*******************************************************************************
20 * This function loads SCP_BL2/BL3x images and returns the ep_info for
21 * the next executable image.
22 ******************************************************************************/
23entry_point_info_t *bl2_load_images(void)
24{
25 bl_params_t *bl2_to_next_bl_params;
26 bl_load_info_t *bl2_load_info;
27 const bl_load_info_node_t *bl2_node_info;
28 int plat_setup_done = 0;
29 int err;
30
31 /*
32 * Get information about the images to load.
33 */
34 bl2_load_info = plat_get_bl_image_load_info();
35 assert(bl2_load_info);
36 assert(bl2_load_info->head);
37 assert(bl2_load_info->h.type == PARAM_BL_LOAD_INFO);
38 assert(bl2_load_info->h.version >= VERSION_2);
39 bl2_node_info = bl2_load_info->head;
40
41 while (bl2_node_info) {
42 /*
43 * Perform platform setup before loading the image,
44 * if indicated in the image attributes AND if NOT
45 * already done before.
46 */
47 if (bl2_node_info->image_info->h.attr & IMAGE_ATTRIB_PLAT_SETUP) {
48 if (plat_setup_done) {
49 WARN("BL2: Platform setup already done!!\n");
50 } else {
51 INFO("BL2: Doing platform setup\n");
52 bl2_platform_setup();
53 plat_setup_done = 1;
54 }
55 }
56
57 if (!(bl2_node_info->image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) {
58 INFO("BL2: Loading image id %d\n", bl2_node_info->image_id);
59 err = load_auth_image(bl2_node_info->image_id,
60 bl2_node_info->image_info);
61 if (err) {
62 ERROR("BL2: Failed to load image (%i)\n", err);
63 plat_error_handler(err);
64 }
65 } else {
66 INFO("BL2: Skip loading image id %d\n", bl2_node_info->image_id);
67 }
68
69 /* Allow platform to handle image information. */
70 err = bl2_plat_handle_post_image_load(bl2_node_info->image_id);
71 if (err) {
72 ERROR("BL2: Failure in post image load handling (%i)\n", err);
73 plat_error_handler(err);
74 }
75
76 /* Go to next image */
77 bl2_node_info = bl2_node_info->next_load_info;
78 }
79
80 /*
81 * Get information to pass to the next image.
82 */
83 bl2_to_next_bl_params = plat_get_next_bl_params();
84 assert(bl2_to_next_bl_params);
85 assert(bl2_to_next_bl_params->head);
86 assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS);
87 assert(bl2_to_next_bl_params->h.version >= VERSION_2);
Dan Handley09c97c92017-04-18 14:46:23 +010088 assert(bl2_to_next_bl_params->head->ep_info);
89
90 /* Populate arg0 for the next BL image */
91 bl2_to_next_bl_params->head->ep_info->args.arg0 = (u_register_t)bl2_to_next_bl_params;
Yatharth Kochar51f76f62016-09-12 16:10:33 +010092
93 /* Flush the parameters to be passed to next image */
94 plat_flush_next_bl_params();
95
96 return bl2_to_next_bl_params->head->ep_info;
97}