blob: 118bd26289b006e4ac422b63042349ca3f23aac8 [file] [log] [blame]
Soby Mathew7c6df5b2018-01-15 14:43:42 +00001/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Soby Mathew96a1c6b2018-01-15 14:45:33 +00007#include <arm_dyn_cfg_helpers.h>
Soby Mathew7c6df5b2018-01-15 14:43:42 +00008#include <assert.h>
9#include <debug.h>
10#include <desc_image_load.h>
Soby Mathewcc364842018-02-21 01:16:39 +000011#include <plat_arm.h>
Soby Mathew7c6df5b2018-01-15 14:43:42 +000012#include <platform.h>
13#include <platform_def.h>
14#include <string.h>
15#include <tbbr_img_def.h>
16
17#if LOAD_IMAGE_V2
18
Soby Mathew96a1c6b2018-01-15 14:45:33 +000019/* Variable to store the address to TB_FW_CONFIG passed from BL1 */
20static void *tb_fw_cfg_dtb;
21
Soby Mathew7c6df5b2018-01-15 14:43:42 +000022/*
23 * Helper function to load TB_FW_CONFIG and populate the load information to
24 * arg0 of BL2 entrypoint info.
25 */
26void arm_load_tb_fw_config(void)
27{
28 int err;
29 uintptr_t config_base = 0;
30 image_desc_t *image_desc;
31
32 image_desc_t arm_tb_fw_info = {
33 .image_id = TB_FW_CONFIG_ID,
34 SET_STATIC_PARAM_HEAD(image_info, PARAM_IMAGE_BINARY,
35 VERSION_2, image_info_t, 0),
36 .image_info.image_base = ARM_TB_FW_CONFIG_BASE,
37 .image_info.image_max_size = ARM_TB_FW_CONFIG_LIMIT - ARM_TB_FW_CONFIG_BASE,
38 };
39
40 VERBOSE("BL1: Loading TB_FW_CONFIG\n");
41 err = load_auth_image(TB_FW_CONFIG_ID, &arm_tb_fw_info.image_info);
Soby Mathewcc364842018-02-21 01:16:39 +000042 if (err != 0) {
Soby Mathew7c6df5b2018-01-15 14:43:42 +000043 /* Return if TB_FW_CONFIG is not loaded */
44 VERBOSE("Failed to load TB_FW_CONFIG\n");
45 return;
46 }
47
48 config_base = arm_tb_fw_info.image_info.image_base;
49
50 /* The BL2 ep_info arg0 is modified to point to TB_FW_CONFIG */
51 image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
Soby Mathewcc364842018-02-21 01:16:39 +000052 assert(image_desc != NULL);
Soby Mathew7c6df5b2018-01-15 14:43:42 +000053 image_desc->ep_info.args.arg0 = config_base;
54
55 INFO("BL1: TB_FW_CONFIG loaded at address = %p\n",
56 (void *) config_base);
Soby Mathew45e39e22018-03-26 15:16:46 +010057
58#if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH)
59 int tb_fw_node;
60 uint32_t disable_auth = 0;
61
62 err = arm_dyn_tb_fw_cfg_init((void *)config_base, &tb_fw_node);
63 if (err < 0) {
John Tsichritzis116d78a2018-06-15 11:43:02 +010064 ERROR("Invalid TB_FW_CONFIG loaded\n");
65 panic();
Soby Mathew45e39e22018-03-26 15:16:46 +010066 }
67
68 err = arm_dyn_get_disable_auth((void *)config_base, tb_fw_node, &disable_auth);
69 if (err < 0)
70 return;
71
72 if (disable_auth == 1)
73 dyn_disable_auth();
74#endif
Soby Mathew7c6df5b2018-01-15 14:43:42 +000075}
76
Soby Mathew96a1c6b2018-01-15 14:45:33 +000077/*
78 * BL2 utility function to set the address of TB_FW_CONFIG passed from BL1.
79 */
80void arm_bl2_set_tb_cfg_addr(void *dtb)
81{
Soby Mathewcc364842018-02-21 01:16:39 +000082 assert(dtb != NULL);
Soby Mathew96a1c6b2018-01-15 14:45:33 +000083 tb_fw_cfg_dtb = dtb;
84}
85
86/*
87 * BL2 utility function to initialize dynamic configuration specified by
Soby Mathewb6814842018-04-04 09:40:32 +010088 * TB_FW_CONFIG. Populate the bl_mem_params_node_t of other FW_CONFIGs if
89 * specified in TB_FW_CONFIG.
Soby Mathew96a1c6b2018-01-15 14:45:33 +000090 */
91void arm_bl2_dyn_cfg_init(void)
92{
Soby Mathewb6814842018-04-04 09:40:32 +010093 int err = 0, tb_fw_node;
94 unsigned int i;
95 bl_mem_params_node_t *cfg_mem_params = NULL;
96 uint64_t image_base;
97 uint32_t image_size;
98 const unsigned int config_ids[] = {
99 HW_CONFIG_ID,
100 SOC_FW_CONFIG_ID,
101 NT_FW_CONFIG_ID,
102#ifdef SPD_tspd
103 /* Currently tos_fw_config is only present for TSP */
104 TOS_FW_CONFIG_ID
105#endif
106 };
Soby Mathew96a1c6b2018-01-15 14:45:33 +0000107
108 if (tb_fw_cfg_dtb == NULL) {
109 VERBOSE("No TB_FW_CONFIG specified\n");
110 return;
111 }
112
113 err = arm_dyn_tb_fw_cfg_init((void *)tb_fw_cfg_dtb, &tb_fw_node);
114 if (err < 0) {
115 ERROR("Invalid TB_FW_CONFIG passed from BL1\n");
116 panic();
117 }
118
Soby Mathewb6814842018-04-04 09:40:32 +0100119 /* Iterate through all the fw config IDs */
120 for (i = 0; i < ARRAY_SIZE(config_ids); i++) {
121 /* Get the config load address and size from TB_FW_CONFIG */
122 cfg_mem_params = get_bl_mem_params_node(config_ids[i]);
123 if (cfg_mem_params == NULL) {
124 VERBOSE("Couldn't find HW_CONFIG in bl_mem_params_node\n");
125 continue;
126 }
Soby Mathew96a1c6b2018-01-15 14:45:33 +0000127
Soby Mathewb6814842018-04-04 09:40:32 +0100128 err = arm_dyn_get_config_load_info((void *)tb_fw_cfg_dtb, tb_fw_node,
129 config_ids[i], &image_base, &image_size);
130 if (err < 0) {
131 VERBOSE("Couldn't find config_id %d load info in TB_FW_CONFIG\n",
132 config_ids[i]);
133 continue;
134 }
135
136 /*
137 * Do some runtime checks on the load addresses of soc_fw_config,
138 * tos_fw_config, nt_fw_config. This is not a comprehensive check
139 * of all invalid addresses but to prevent trivial porting errors.
140 */
141 if (config_ids[i] != HW_CONFIG_ID) {
Soby Mathew96a1c6b2018-01-15 14:45:33 +0000142
Soby Mathewb6814842018-04-04 09:40:32 +0100143 if (check_uptr_overflow(image_base, image_size) != 0)
144 continue;
145
Soby Mathewaf14b462018-06-01 16:53:38 +0100146 /* Ensure the configs don't overlap with BL31 */
147 if ((image_base > BL31_BASE) || ((image_base + image_size) > BL31_BASE))
Soby Mathewb6814842018-04-04 09:40:32 +0100148 continue;
149
150 /* Ensure the configs are loaded in a valid address */
151 if (image_base < ARM_BL_RAM_BASE)
152 continue;
153#ifdef BL32_BASE
154 /*
155 * If BL32 is present, ensure that the configs don't
156 * overlap with it.
157 */
158 if (image_base >= BL32_BASE && image_base <= BL32_LIMIT)
159 continue;
160#endif
161 }
162
163
164 cfg_mem_params->image_info.image_base = (uintptr_t)image_base;
165 cfg_mem_params->image_info.image_max_size = image_size;
166
167 /* Remove the IMAGE_ATTRIB_SKIP_LOADING attribute from HW_CONFIG node */
168 cfg_mem_params->image_info.h.attr &= ~IMAGE_ATTRIB_SKIP_LOADING;
169 }
Soby Mathew45e39e22018-03-26 15:16:46 +0100170
171#if TRUSTED_BOARD_BOOT && defined(DYN_DISABLE_AUTH)
172 uint32_t disable_auth = 0;
173
174 err = arm_dyn_get_disable_auth((void *)tb_fw_cfg_dtb, tb_fw_node,
175 &disable_auth);
176 if (err < 0)
177 return;
178
179 if (disable_auth == 1)
180 dyn_disable_auth();
181#endif
Soby Mathew96a1c6b2018-01-15 14:45:33 +0000182}
183
Soby Mathew7c6df5b2018-01-15 14:43:42 +0000184#endif /* LOAD_IMAGE_V2 */