blob: ed7f1f5a5945c396829591ddd9e66f60ce94316b [file] [log] [blame]
Yatharth Kocharf9a0f162016-09-13 17:07:57 +01001/*
Manish Pandey1fa6ecb2020-02-25 11:38:19 +00002 * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved.
Yatharth Kocharf9a0f162016-09-13 17:07:57 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Yatharth Kocharf9a0f162016-09-13 17:07:57 +01005 */
6
Sathees Balya90950092018-11-15 14:22:30 +00007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008#include <common/bl_common.h>
9#include <common/desc_image_load.h>
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000010#if defined(SPD_spmd)
11#include <plat/arm/common/fconf_arm_sp_getter.h>
12#endif
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000013#include <plat/arm/common/plat_arm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <plat/common/platform.h>
15
Yatharth Kocharf9a0f162016-09-13 17:07:57 +010016#pragma weak plat_flush_next_bl_params
17#pragma weak plat_get_bl_image_load_info
18#pragma weak plat_get_next_bl_params
19
Sathees Balya90950092018-11-15 14:22:30 +000020static bl_params_t *next_bl_params_cpy_ptr;
Yatharth Kocharf9a0f162016-09-13 17:07:57 +010021
22/*******************************************************************************
23 * This function flushes the data structures so that they are visible
24 * in memory for the next BL image.
25 ******************************************************************************/
26void plat_flush_next_bl_params(void)
27{
Sathees Balya90950092018-11-15 14:22:30 +000028 assert(next_bl_params_cpy_ptr != NULL);
29
30 flush_bl_params_desc_args(bl_mem_params_desc_ptr,
31 bl_mem_params_desc_num,
32 next_bl_params_cpy_ptr);
Yatharth Kocharf9a0f162016-09-13 17:07:57 +010033}
34
Olivier Deprez042db532020-03-19 09:27:11 +010035#if defined(SPD_spmd) && SPMD_SPM_AT_SEL2
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000036/*******************************************************************************
37 * This function appends Secure Partitions to list of loadable images.
38 ******************************************************************************/
Olivier Deprez042db532020-03-19 09:27:11 +010039static void plat_add_sp_images_load_info(struct bl_load_info *load_info)
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000040{
41 bl_load_info_node_t *node_info = load_info->head;
42 unsigned int index = 0;
43
44 if (sp_mem_params_descs[index].image_id == 0) {
45 ERROR("No Secure Partition Image available\n");
46 return;
47 }
48
49 /* Traverse through the bl images list */
50 do {
51 node_info = node_info->next_load_info;
52 } while (node_info->next_load_info != NULL);
53
54 for (; index < MAX_SP_IDS; index++) {
55 /* Populate the image information */
56 node_info->image_id = sp_mem_params_descs[index].image_id;
57 node_info->image_info = &sp_mem_params_descs[index].image_info;
58
59 if ((index + 1U) == MAX_SP_IDS) {
60 INFO("Reached Max number of SPs\n");
61 return;
62 }
63
64 if (sp_mem_params_descs[index + 1U].image_id == 0) {
65 return;
66 }
67
68 node_info->next_load_info =
69 &sp_mem_params_descs[index + 1U].load_node_mem;
70 node_info = node_info->next_load_info;
71
72 }
73}
74#endif
75
Yatharth Kocharf9a0f162016-09-13 17:07:57 +010076/*******************************************************************************
77 * This function returns the list of loadable images.
78 ******************************************************************************/
Sandrine Bailleuxb3b6e222018-07-11 12:44:22 +020079struct bl_load_info *plat_get_bl_image_load_info(void)
Yatharth Kocharf9a0f162016-09-13 17:07:57 +010080{
Olivier Deprez042db532020-03-19 09:27:11 +010081#if defined(SPD_spmd) && SPMD_SPM_AT_SEL2
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000082 bl_load_info_t *bl_load_info;
83
84 bl_load_info = get_bl_load_info_from_mem_params_desc();
85 plat_add_sp_images_load_info(bl_load_info);
86
87 return bl_load_info;
88#else
Yatharth Kocharf9a0f162016-09-13 17:07:57 +010089 return get_bl_load_info_from_mem_params_desc();
Manish Pandey1fa6ecb2020-02-25 11:38:19 +000090#endif
Yatharth Kocharf9a0f162016-09-13 17:07:57 +010091}
92
93/*******************************************************************************
Sathees Balya90950092018-11-15 14:22:30 +000094 * ARM helper function to return the list of executable images.Since the default
95 * descriptors are allocated within BL2 RW memory, this prevents BL31/BL32
96 * overlay of BL2 memory. Hence this function also copies the descriptors to a
97 * pre-allocated memory indicated by ARM_BL2_MEM_DESC_BASE.
Yatharth Kocharf9a0f162016-09-13 17:07:57 +010098 ******************************************************************************/
Sathees Balya90950092018-11-15 14:22:30 +000099struct bl_params *arm_get_next_bl_params(void)
Yatharth Kocharf9a0f162016-09-13 17:07:57 +0100100{
Sathees Balya90950092018-11-15 14:22:30 +0000101 bl_mem_params_node_t *bl2_mem_params_descs_cpy
102 = (bl_mem_params_node_t *)ARM_BL2_MEM_DESC_BASE;
103 const bl_params_t *next_bl_params;
104
105 next_bl_params_cpy_ptr =
106 (bl_params_t *)(ARM_BL2_MEM_DESC_BASE +
107 (bl_mem_params_desc_num * sizeof(bl_mem_params_node_t)));
108
109 /*
110 * Copy the memory descriptors to ARM_BL2_MEM_DESC_BASE area.
111 */
112 (void) memcpy(bl2_mem_params_descs_cpy, bl_mem_params_desc_ptr,
113 (bl_mem_params_desc_num * sizeof(bl_mem_params_node_t)));
Soby Mathew96a1c6b2018-01-15 14:45:33 +0000114
Sathees Balya90950092018-11-15 14:22:30 +0000115 /*
116 * Modify the global 'bl_mem_params_desc_ptr' to point to the
117 * copied location.
118 */
119 bl_mem_params_desc_ptr = bl2_mem_params_descs_cpy;
120
121 next_bl_params = get_next_bl_params_from_mem_params_desc();
122 assert(next_bl_params != NULL);
123
124 /*
125 * Copy 'next_bl_params' to the reserved location after the copied
126 * memory descriptors.
127 */
128 (void) memcpy(next_bl_params_cpy_ptr, next_bl_params,
129 (sizeof(bl_params_t)));
130
131 populate_next_bl_params_config(next_bl_params_cpy_ptr);
132
133 return next_bl_params_cpy_ptr;
Yatharth Kocharf9a0f162016-09-13 17:07:57 +0100134}
Sathees Balya90950092018-11-15 14:22:30 +0000135
136/*******************************************************************************
137 * This function returns the list of executable images
138 ******************************************************************************/
139struct bl_params *plat_get_next_bl_params(void)
140{
141 return arm_get_next_bl_params();
142}
143