Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 1 | /* |
Zelalem | e8dadb1 | 2020-02-05 14:12:39 -0600 | [diff] [blame] | 2 | * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved. |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 7 | #include <assert.h> |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 8 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
| 10 | #include <platform_def.h> |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 11 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | #include <arch.h> |
| 13 | #include <arch_helpers.h> |
| 14 | #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> |
| 19 | |
| 20 | #include "bl2_private.h" |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 21 | |
| 22 | /******************************************************************************* |
| 23 | * This function loads SCP_BL2/BL3x images and returns the ep_info for |
| 24 | * the next executable image. |
| 25 | ******************************************************************************/ |
Roberto Vargas | 02b2c2b | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 26 | struct entry_point_info *bl2_load_images(void) |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 27 | { |
| 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(); |
Zelalem | e8dadb1 | 2020-02-05 14:12:39 -0600 | [diff] [blame] | 38 | assert(bl2_load_info != NULL); |
| 39 | assert(bl2_load_info->head != NULL); |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 40 | 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 | |
Zelalem | e8dadb1 | 2020-02-05 14:12:39 -0600 | [diff] [blame] | 44 | while (bl2_node_info != NULL) { |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 45 | /* |
| 46 | * Perform platform setup before loading the image, |
| 47 | * if indicated in the image attributes AND if NOT |
| 48 | * already done before. |
| 49 | */ |
| 50 | if (bl2_node_info->image_info->h.attr & IMAGE_ATTRIB_PLAT_SETUP) { |
| 51 | if (plat_setup_done) { |
| 52 | 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 Yamada | 02a0d3d | 2018-02-01 16:45:51 +0900 | [diff] [blame] | 60 | err = bl2_plat_handle_pre_image_load(bl2_node_info->image_id); |
| 61 | if (err) { |
| 62 | ERROR("BL2: Failure in pre image load handling (%i)\n", err); |
| 63 | plat_error_handler(err); |
| 64 | } |
| 65 | |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 66 | if (!(bl2_node_info->image_info->h.attr & IMAGE_ATTRIB_SKIP_LOADING)) { |
| 67 | INFO("BL2: Loading image id %d\n", bl2_node_info->image_id); |
| 68 | err = load_auth_image(bl2_node_info->image_id, |
| 69 | bl2_node_info->image_info); |
| 70 | if (err) { |
Sandrine Bailleux | e545a83 | 2020-02-03 15:58:16 +0100 | [diff] [blame] | 71 | ERROR("BL2: Failed to load image id %d (%i)\n", |
| 72 | bl2_node_info->image_id, err); |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 73 | plat_error_handler(err); |
| 74 | } |
| 75 | } else { |
| 76 | INFO("BL2: Skip loading image id %d\n", bl2_node_info->image_id); |
| 77 | } |
| 78 | |
| 79 | /* Allow platform to handle image information. */ |
| 80 | err = bl2_plat_handle_post_image_load(bl2_node_info->image_id); |
| 81 | if (err) { |
| 82 | ERROR("BL2: Failure in post image load handling (%i)\n", err); |
| 83 | plat_error_handler(err); |
| 84 | } |
| 85 | |
| 86 | /* Go to next image */ |
| 87 | bl2_node_info = bl2_node_info->next_load_info; |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * Get information to pass to the next image. |
| 92 | */ |
| 93 | bl2_to_next_bl_params = plat_get_next_bl_params(); |
Zelalem | e8dadb1 | 2020-02-05 14:12:39 -0600 | [diff] [blame] | 94 | assert(bl2_to_next_bl_params != NULL); |
| 95 | assert(bl2_to_next_bl_params->head != NULL); |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 96 | assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS); |
| 97 | assert(bl2_to_next_bl_params->h.version >= VERSION_2); |
Zelalem | e8dadb1 | 2020-02-05 14:12:39 -0600 | [diff] [blame] | 98 | assert(bl2_to_next_bl_params->head->ep_info != NULL); |
Dan Handley | 09c97c9 | 2017-04-18 14:46:23 +0100 | [diff] [blame] | 99 | |
Etienne Carriere | dc8bbb4 | 2018-02-05 10:42:42 +0100 | [diff] [blame] | 100 | /* Populate arg0 for the next BL image if not already provided */ |
Etienne Carriere | 2b407d2 | 2018-02-06 10:58:21 +0100 | [diff] [blame] | 101 | if (bl2_to_next_bl_params->head->ep_info->args.arg0 == (u_register_t)0) |
Etienne Carriere | dc8bbb4 | 2018-02-05 10:42:42 +0100 | [diff] [blame] | 102 | bl2_to_next_bl_params->head->ep_info->args.arg0 = |
| 103 | (u_register_t)bl2_to_next_bl_params; |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 104 | |
| 105 | /* Flush the parameters to be passed to next image */ |
| 106 | plat_flush_next_bl_params(); |
| 107 | |
| 108 | return bl2_to_next_bl_params->head->ep_info; |
| 109 | } |