blob: 48c9beca6c55da56f3d7d120d262184bcee6bc37 [file] [log] [blame]
Yatharth Kochar42019bf2016-09-12 16:10:33 +01001/*
Zelalem466bb282020-02-05 14:12:39 -06002 * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved.
Yatharth Kochar42019bf2016-09-12 16:10:33 +01003 *
dp-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Yatharth Kochar42019bf2016-09-12 16:10:33 +01005 */
6
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +00007#include <assert.h>
8#include <stdint.h>
9
10#include <platform_def.h>
11
Yatharth Kochar42019bf2016-09-12 16:10:33 +010012#include <arch.h>
13#include <arch_helpers.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000014#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>
Yatharth Kochar42019bf2016-09-12 16:10:33 +010019
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000020#include "bl2_private.h"
Yatharth Kochar42019bf2016-09-12 16:10:33 +010021
22/*******************************************************************************
23 * This function loads SCP_BL2/BL3x images and returns the ep_info for
24 * the next executable image.
25 ******************************************************************************/
Roberto Vargas8cb47622018-02-12 12:36:17 +000026struct entry_point_info *bl2_load_images(void)
Yatharth Kochar42019bf2016-09-12 16:10:33 +010027{
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;
32 int err;
33
34 /*
35 * Get information about the images to load.
36 */
37 bl2_load_info = plat_get_bl_image_load_info();
Zelalem466bb282020-02-05 14:12:39 -060038 assert(bl2_load_info != NULL);
39 assert(bl2_load_info->head != NULL);
Yatharth Kochar42019bf2016-09-12 16:10:33 +010040 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;
43
Zelalem466bb282020-02-05 14:12:39 -060044 while (bl2_node_info != NULL) {
Yatharth Kochar42019bf2016-09-12 16:10:33 +010045 /*
46 * Perform platform setup before loading the image,
47 * if indicated in the image attributes AND if NOT
48 * already done before.
49 */
John Powell3443a702020-03-20 14:21:05 -050050 if ((bl2_node_info->image_info->h.attr &
51 IMAGE_ATTRIB_PLAT_SETUP) != 0U) {
52 if (plat_setup_done != 0) {
Yatharth Kochar42019bf2016-09-12 16:10:33 +010053 WARN("BL2: Platform setup already done!!\n");
54 } else {
55 INFO("BL2: Doing platform setup\n");
56 bl2_platform_setup();
57 plat_setup_done = 1;
58 }
59 }
60
Masahiro Yamadaba68ef52018-02-01 16:45:51 +090061 err = bl2_plat_handle_pre_image_load(bl2_node_info->image_id);
John Powell3443a702020-03-20 14:21:05 -050062 if (err != 0) {
Masahiro Yamadaba68ef52018-02-01 16:45:51 +090063 ERROR("BL2: Failure in pre image load handling (%i)\n", err);
64 plat_error_handler(err);
65 }
66
John Powell3443a702020-03-20 14:21:05 -050067 if ((bl2_node_info->image_info->h.attr &
68 IMAGE_ATTRIB_SKIP_LOADING) == 0U) {
Yatharth Kochar42019bf2016-09-12 16:10:33 +010069 INFO("BL2: Loading image id %d\n", bl2_node_info->image_id);
70 err = load_auth_image(bl2_node_info->image_id,
71 bl2_node_info->image_info);
John Powell3443a702020-03-20 14:21:05 -050072 if (err != 0) {
Sandrine Bailleuxa4163252020-02-03 15:58:16 +010073 ERROR("BL2: Failed to load image id %d (%i)\n",
74 bl2_node_info->image_id, err);
Yatharth Kochar42019bf2016-09-12 16:10:33 +010075 plat_error_handler(err);
76 }
77 } else {
78 INFO("BL2: Skip loading image id %d\n", bl2_node_info->image_id);
79 }
80
81 /* Allow platform to handle image information. */
82 err = bl2_plat_handle_post_image_load(bl2_node_info->image_id);
John Powell3443a702020-03-20 14:21:05 -050083 if (err != 0) {
Yatharth Kochar42019bf2016-09-12 16:10:33 +010084 ERROR("BL2: Failure in post image load handling (%i)\n", err);
85 plat_error_handler(err);
86 }
87
88 /* Go to next image */
89 bl2_node_info = bl2_node_info->next_load_info;
90 }
91
92 /*
93 * Get information to pass to the next image.
94 */
95 bl2_to_next_bl_params = plat_get_next_bl_params();
Zelalem466bb282020-02-05 14:12:39 -060096 assert(bl2_to_next_bl_params != NULL);
97 assert(bl2_to_next_bl_params->head != NULL);
Yatharth Kochar42019bf2016-09-12 16:10:33 +010098 assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS);
99 assert(bl2_to_next_bl_params->h.version >= VERSION_2);
Zelalem466bb282020-02-05 14:12:39 -0600100 assert(bl2_to_next_bl_params->head->ep_info != NULL);
Dan Handleyc2a9ee62017-04-18 14:46:23 +0100101
Etienne Carriere10c66952018-02-05 10:42:42 +0100102 /* Populate arg0 for the next BL image if not already provided */
Etienne Carriere95ae5b02018-02-06 10:58:21 +0100103 if (bl2_to_next_bl_params->head->ep_info->args.arg0 == (u_register_t)0)
Etienne Carriere10c66952018-02-05 10:42:42 +0100104 bl2_to_next_bl_params->head->ep_info->args.arg0 =
105 (u_register_t)bl2_to_next_bl_params;
Yatharth Kochar42019bf2016-09-12 16:10:33 +0100106
107 /* Flush the parameters to be passed to next image */
108 plat_flush_next_bl_params();
109
110 return bl2_to_next_bl_params->head->ep_info;
111}