Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 1 | /* |
Masahiro Yamada | 02a0d3d | 2018-02-01 16:45:51 +0900 | [diff] [blame] | 2 | * Copyright (c) 2016-2018, 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 | |
| 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 Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 17 | #include "bl2_private.h" |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 18 | |
| 19 | |
| 20 | /******************************************************************************* |
| 21 | * This function loads SCP_BL2/BL3x images and returns the ep_info for |
| 22 | * the next executable image. |
| 23 | ******************************************************************************/ |
| 24 | entry_point_info_t *bl2_load_images(void) |
| 25 | { |
| 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 Yamada | 02a0d3d | 2018-02-01 16:45:51 +0900 | [diff] [blame] | 58 | 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 Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 64 | 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 Handley | 09c97c9 | 2017-04-18 14:46:23 +0100 | [diff] [blame] | 95 | assert(bl2_to_next_bl_params->head->ep_info); |
| 96 | |
Etienne Carriere | dc8bbb4 | 2018-02-05 10:42:42 +0100 | [diff] [blame] | 97 | /* Populate arg0 for the next BL image if not already provided */ |
Etienne Carriere | 2b407d2 | 2018-02-06 10:58:21 +0100 | [diff] [blame] | 98 | 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] | 99 | bl2_to_next_bl_params->head->ep_info->args.arg0 = |
| 100 | (u_register_t)bl2_to_next_bl_params; |
Yatharth Kochar | 51f76f6 | 2016-09-12 16:10:33 +0100 | [diff] [blame] | 101 | |
| 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 | } |