blob: 0f40785d4cb7831d5318623e9e9bc908950e2ee1 [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>
Roberto Vargas2ca18d92018-02-12 12:36:17 +000017#include "bl2_private.h"
Yatharth Kochar51f76f62016-09-12 16:10:33 +010018
19
20/*******************************************************************************
21 * This function loads SCP_BL2/BL3x images and returns the ep_info for
22 * the next executable image.
23 ******************************************************************************/
Roberto Vargas02b2c2b2018-02-12 12:36:17 +000024struct entry_point_info *bl2_load_images(void)
Yatharth Kochar51f76f62016-09-12 16:10:33 +010025{
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
Masahiro Yamada02a0d3d2018-02-01 16:45:51 +090058 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
Yatharth Kochar51f76f62016-09-12 16:10:33 +010064 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);
Dan Handley09c97c92017-04-18 14:46:23 +010095 assert(bl2_to_next_bl_params->head->ep_info);
96
Etienne Carrieredc8bbb42018-02-05 10:42:42 +010097 /* Populate arg0 for the next BL image if not already provided */
Etienne Carriere2b407d22018-02-06 10:58:21 +010098 if (bl2_to_next_bl_params->head->ep_info->args.arg0 == (u_register_t)0)
Etienne Carrieredc8bbb42018-02-05 10:42:42 +010099 bl2_to_next_bl_params->head->ep_info->args.arg0 =
100 (u_register_t)bl2_to_next_bl_params;
Yatharth Kochar51f76f62016-09-12 16:10:33 +0100101
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}