blob: dee3fc2d3a9bedfa03c5bc0ef84c1719a20a65bd [file] [log] [blame]
Yatharth Kochar51f76f62016-09-12 16:10:33 +01001/*
Yann Gautiera3bb76f2022-02-14 09:54:36 +01002 * Copyright (c) 2016-2022, 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
Yatharth Kochar51f76f62016-09-12 16:10:33 +01007#include <assert.h>
Yatharth Kochar51f76f62016-09-12 16:10:33 +01008#include <stdint.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <arch.h>
11#include <arch_helpers.h>
Yann Gautiera3bb76f2022-02-14 09:54:36 +010012#include "bl2_private.h"
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <common/bl_common.h>
14#include <common/debug.h>
15#include <common/desc_image_load.h>
16#include <drivers/auth/auth_mod.h>
17#include <plat/common/platform.h>
18
Yann Gautiera3bb76f2022-02-14 09:54:36 +010019#include <platform_def.h>
Yatharth Kochar51f76f62016-09-12 16:10:33 +010020
21/*******************************************************************************
22 * This function loads SCP_BL2/BL3x images and returns the ep_info for
23 * the next executable image.
24 ******************************************************************************/
Roberto Vargas02b2c2b2018-02-12 12:36:17 +000025struct entry_point_info *bl2_load_images(void)
Yatharth Kochar51f76f62016-09-12 16:10:33 +010026{
27 bl_params_t *bl2_to_next_bl_params;
28 bl_load_info_t *bl2_load_info;
29 const bl_load_info_node_t *bl2_node_info;
30 int plat_setup_done = 0;
31 int err;
32
33 /*
34 * Get information about the images to load.
35 */
36 bl2_load_info = plat_get_bl_image_load_info();
Zelaleme8dadb12020-02-05 14:12:39 -060037 assert(bl2_load_info != NULL);
38 assert(bl2_load_info->head != NULL);
Yatharth Kochar51f76f62016-09-12 16:10:33 +010039 assert(bl2_load_info->h.type == PARAM_BL_LOAD_INFO);
40 assert(bl2_load_info->h.version >= VERSION_2);
41 bl2_node_info = bl2_load_info->head;
42
Zelaleme8dadb12020-02-05 14:12:39 -060043 while (bl2_node_info != NULL) {
Yatharth Kochar51f76f62016-09-12 16:10:33 +010044 /*
45 * Perform platform setup before loading the image,
46 * if indicated in the image attributes AND if NOT
47 * already done before.
48 */
John Powella5c66362020-03-20 14:21:05 -050049 if ((bl2_node_info->image_info->h.attr &
50 IMAGE_ATTRIB_PLAT_SETUP) != 0U) {
51 if (plat_setup_done != 0) {
Yatharth Kochar51f76f62016-09-12 16:10:33 +010052 WARN("BL2: Platform setup already done!!\n");
53 } else {
54 INFO("BL2: Doing platform setup\n");
55 bl2_platform_setup();
56 plat_setup_done = 1;
57 }
58 }
59
Masahiro Yamada02a0d3d2018-02-01 16:45:51 +090060 err = bl2_plat_handle_pre_image_load(bl2_node_info->image_id);
John Powella5c66362020-03-20 14:21:05 -050061 if (err != 0) {
Masahiro Yamada02a0d3d2018-02-01 16:45:51 +090062 ERROR("BL2: Failure in pre image load handling (%i)\n", err);
63 plat_error_handler(err);
64 }
65
John Powella5c66362020-03-20 14:21:05 -050066 if ((bl2_node_info->image_info->h.attr &
67 IMAGE_ATTRIB_SKIP_LOADING) == 0U) {
Yann Gautiera3bb76f2022-02-14 09:54:36 +010068 INFO("BL2: Loading image id %u\n", bl2_node_info->image_id);
Yatharth Kochar51f76f62016-09-12 16:10:33 +010069 err = load_auth_image(bl2_node_info->image_id,
70 bl2_node_info->image_info);
John Powella5c66362020-03-20 14:21:05 -050071 if (err != 0) {
Yann Gautiera3bb76f2022-02-14 09:54:36 +010072 ERROR("BL2: Failed to load image id %u (%i)\n",
Sandrine Bailleuxe545a832020-02-03 15:58:16 +010073 bl2_node_info->image_id, err);
Yatharth Kochar51f76f62016-09-12 16:10:33 +010074 plat_error_handler(err);
75 }
76 } else {
Yann Gautiera3bb76f2022-02-14 09:54:36 +010077 INFO("BL2: Skip loading image id %u\n", bl2_node_info->image_id);
Yatharth Kochar51f76f62016-09-12 16:10:33 +010078 }
79
80 /* Allow platform to handle image information. */
81 err = bl2_plat_handle_post_image_load(bl2_node_info->image_id);
John Powella5c66362020-03-20 14:21:05 -050082 if (err != 0) {
Yatharth Kochar51f76f62016-09-12 16:10:33 +010083 ERROR("BL2: Failure in post image load handling (%i)\n", err);
84 plat_error_handler(err);
85 }
86
87 /* Go to next image */
88 bl2_node_info = bl2_node_info->next_load_info;
89 }
90
91 /*
92 * Get information to pass to the next image.
93 */
94 bl2_to_next_bl_params = plat_get_next_bl_params();
Zelaleme8dadb12020-02-05 14:12:39 -060095 assert(bl2_to_next_bl_params != NULL);
96 assert(bl2_to_next_bl_params->head != NULL);
Yatharth Kochar51f76f62016-09-12 16:10:33 +010097 assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS);
98 assert(bl2_to_next_bl_params->h.version >= VERSION_2);
Zelaleme8dadb12020-02-05 14:12:39 -060099 assert(bl2_to_next_bl_params->head->ep_info != NULL);
Dan Handley09c97c92017-04-18 14:46:23 +0100100
Etienne Carrieredc8bbb42018-02-05 10:42:42 +0100101 /* Populate arg0 for the next BL image if not already provided */
Etienne Carriere2b407d22018-02-06 10:58:21 +0100102 if (bl2_to_next_bl_params->head->ep_info->args.arg0 == (u_register_t)0)
Etienne Carrieredc8bbb42018-02-05 10:42:42 +0100103 bl2_to_next_bl_params->head->ep_info->args.arg0 =
104 (u_register_t)bl2_to_next_bl_params;
Yatharth Kochar51f76f62016-09-12 16:10:33 +0100105
106 /* Flush the parameters to be passed to next image */
107 plat_flush_next_bl_params();
108
109 return bl2_to_next_bl_params->head->ep_info;
110}