blob: ebbad45e04a36c08b918e649cd11b5d05a1bc385 [file] [log] [blame]
Yatharth Kochar51f76f62016-09-12 16:10:33 +01001/*
Masahiro Yamada02a0d3d2018-02-01 16:45:51 +09002 * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
Yatharth Kochar51f76f62016-09-12 16:10:33 +01003 *
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
Masahiro Yamada02a0d3d2018-02-01 16:45:51 +090057 err = bl2_plat_handle_pre_image_load(bl2_node_info->image_id);
58 if (err) {
59 ERROR("BL2: Failure in pre image load handling (%i)\n", err);
60 plat_error_handler(err);
61 }
62
Yatharth Kochar51f76f62016-09-12 16:10:33 +010063 if (!(bl2_node_info->image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) {
64 INFO("BL2: Loading image id %d\n", bl2_node_info->image_id);
65 err = load_auth_image(bl2_node_info->image_id,
66 bl2_node_info->image_info);
67 if (err) {
68 ERROR("BL2: Failed to load image (%i)\n", err);
69 plat_error_handler(err);
70 }
71 } else {
72 INFO("BL2: Skip loading image id %d\n", bl2_node_info->image_id);
73 }
74
75 /* Allow platform to handle image information. */
76 err = bl2_plat_handle_post_image_load(bl2_node_info->image_id);
77 if (err) {
78 ERROR("BL2: Failure in post image load handling (%i)\n", err);
79 plat_error_handler(err);
80 }
81
82 /* Go to next image */
83 bl2_node_info = bl2_node_info->next_load_info;
84 }
85
86 /*
87 * Get information to pass to the next image.
88 */
89 bl2_to_next_bl_params = plat_get_next_bl_params();
90 assert(bl2_to_next_bl_params);
91 assert(bl2_to_next_bl_params->head);
92 assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS);
93 assert(bl2_to_next_bl_params->h.version >= VERSION_2);
Dan Handley09c97c92017-04-18 14:46:23 +010094 assert(bl2_to_next_bl_params->head->ep_info);
95
96 /* Populate arg0 for the next BL image */
97 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 +010098
99 /* Flush the parameters to be passed to next image */
100 plat_flush_next_bl_params();
101
102 return bl2_to_next_bl_params->head->ep_info;
103}