blob: 6ebc467ed61764eaaa4e0fda254a23ca52d57ac5 [file] [log] [blame]
Louis Mayencourtbadcac82019-10-24 15:18:46 +01001/*
2 * Copyright (c) 2019-2020, ARM Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8
9#include <common/debug.h>
10#include <common/fdt_wrappers.h>
11#include <drivers/io/io_storage.h>
12#include <lib/object_pool.h>
13#include <libfdt.h>
14#include <tools_share/firmware_image_package.h>
15
16#include <plat/arm/common/arm_fconf_getter.h>
17#include <plat/arm/common/arm_fconf_io_storage.h>
18#include <platform_def.h>
19
20const io_block_spec_t fip_block_spec = {
21 .offset = PLAT_ARM_FIP_BASE,
22 .length = PLAT_ARM_FIP_MAX_SIZE
23};
24
25const io_uuid_spec_t arm_uuid_spec[MAX_NUMBER_IDS] = {
26 [BL2_IMAGE_ID] = {UUID_TRUSTED_BOOT_FIRMWARE_BL2},
27 [TB_FW_CONFIG_ID] = {UUID_TB_FW_CONFIG},
Louis Mayencourt6b232d92020-02-28 16:57:30 +000028#if !ARM_IO_IN_DTB
29 [SCP_BL2_IMAGE_ID] = {UUID_SCP_FIRMWARE_SCP_BL2},
30 [BL31_IMAGE_ID] = {UUID_EL3_RUNTIME_FIRMWARE_BL31},
31 [BL32_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32},
32 [BL32_EXTRA1_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32_EXTRA1},
33 [BL32_EXTRA2_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32_EXTRA2},
34 [BL33_IMAGE_ID] = {UUID_NON_TRUSTED_FIRMWARE_BL33},
35 [HW_CONFIG_ID] = {UUID_HW_CONFIG},
36 [SOC_FW_CONFIG_ID] = {UUID_SOC_FW_CONFIG},
37 [TOS_FW_CONFIG_ID] = {UUID_TOS_FW_CONFIG},
38 [NT_FW_CONFIG_ID] = {UUID_NT_FW_CONFIG},
39#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +010040#if TRUSTED_BOARD_BOOT
41 [TRUSTED_BOOT_FW_CERT_ID] = {UUID_TRUSTED_BOOT_FW_CERT},
Louis Mayencourt6b232d92020-02-28 16:57:30 +000042#if !ARM_IO_IN_DTB
43 [TRUSTED_KEY_CERT_ID] = {UUID_TRUSTED_KEY_CERT},
44 [SCP_FW_KEY_CERT_ID] = {UUID_SCP_FW_KEY_CERT},
45 [SOC_FW_KEY_CERT_ID] = {UUID_SOC_FW_KEY_CERT},
46 [TRUSTED_OS_FW_KEY_CERT_ID] = {UUID_TRUSTED_OS_FW_KEY_CERT},
47 [NON_TRUSTED_FW_KEY_CERT_ID] = {UUID_NON_TRUSTED_FW_KEY_CERT},
48 [SCP_FW_CONTENT_CERT_ID] = {UUID_SCP_FW_CONTENT_CERT},
49 [SOC_FW_CONTENT_CERT_ID] = {UUID_SOC_FW_CONTENT_CERT},
50 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {UUID_TRUSTED_OS_FW_CONTENT_CERT},
51 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {UUID_NON_TRUSTED_FW_CONTENT_CERT},
52#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +010053#endif /* TRUSTED_BOARD_BOOT */
54};
55
56/* By default, ARM platforms load images from the FIP */
57struct plat_io_policy policies[MAX_NUMBER_IDS] = {
58 [FIP_IMAGE_ID] = {
59 &memmap_dev_handle,
60 (uintptr_t)&fip_block_spec,
61 open_memmap
62 },
63 [BL2_IMAGE_ID] = {
64 &fip_dev_handle,
65 (uintptr_t)&arm_uuid_spec[BL2_IMAGE_ID],
66 open_fip
67 },
68 [TB_FW_CONFIG_ID] = {
69 &fip_dev_handle,
70 (uintptr_t)&arm_uuid_spec[TB_FW_CONFIG_ID],
71 open_fip
72 },
Louis Mayencourt6b232d92020-02-28 16:57:30 +000073#if !ARM_IO_IN_DTB
74 [SCP_BL2_IMAGE_ID] = {
75 &fip_dev_handle,
76 (uintptr_t)&arm_uuid_spec[SCP_BL2_IMAGE_ID],
77 open_fip
78 },
79 [BL31_IMAGE_ID] = {
80 &fip_dev_handle,
81 (uintptr_t)&arm_uuid_spec[BL31_IMAGE_ID],
82 open_fip
83 },
84 [BL32_IMAGE_ID] = {
85 &fip_dev_handle,
86 (uintptr_t)&arm_uuid_spec[BL32_IMAGE_ID],
87 open_fip
88 },
89 [BL32_EXTRA1_IMAGE_ID] = {
90 &fip_dev_handle,
91 (uintptr_t)&arm_uuid_spec[BL32_EXTRA1_IMAGE_ID],
92 open_fip
93 },
94 [BL32_EXTRA2_IMAGE_ID] = {
95 &fip_dev_handle,
96 (uintptr_t)&arm_uuid_spec[BL32_EXTRA2_IMAGE_ID],
97 open_fip
98 },
99 [BL33_IMAGE_ID] = {
100 &fip_dev_handle,
101 (uintptr_t)&arm_uuid_spec[BL33_IMAGE_ID],
102 open_fip
103 },
104 [HW_CONFIG_ID] = {
105 &fip_dev_handle,
106 (uintptr_t)&arm_uuid_spec[HW_CONFIG_ID],
107 open_fip
108 },
109 [SOC_FW_CONFIG_ID] = {
110 &fip_dev_handle,
111 (uintptr_t)&arm_uuid_spec[SOC_FW_CONFIG_ID],
112 open_fip
113 },
114 [TOS_FW_CONFIG_ID] = {
115 &fip_dev_handle,
116 (uintptr_t)&arm_uuid_spec[TOS_FW_CONFIG_ID],
117 open_fip
118 },
119 [NT_FW_CONFIG_ID] = {
120 &fip_dev_handle,
121 (uintptr_t)&arm_uuid_spec[NT_FW_CONFIG_ID],
122 open_fip
123 },
124#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100125#if TRUSTED_BOARD_BOOT
126 [TRUSTED_BOOT_FW_CERT_ID] = {
127 &fip_dev_handle,
128 (uintptr_t)&arm_uuid_spec[TRUSTED_BOOT_FW_CERT_ID],
129 open_fip
130 },
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000131#if !ARM_IO_IN_DTB
132 [TRUSTED_KEY_CERT_ID] = {
133 &fip_dev_handle,
134 (uintptr_t)&arm_uuid_spec[TRUSTED_KEY_CERT_ID],
135 open_fip
136 },
137 [SCP_FW_KEY_CERT_ID] = {
138 &fip_dev_handle,
139 (uintptr_t)&arm_uuid_spec[SCP_FW_KEY_CERT_ID],
140 open_fip
141 },
142 [SOC_FW_KEY_CERT_ID] = {
143 &fip_dev_handle,
144 (uintptr_t)&arm_uuid_spec[SOC_FW_KEY_CERT_ID],
145 open_fip
146 },
147 [TRUSTED_OS_FW_KEY_CERT_ID] = {
148 &fip_dev_handle,
149 (uintptr_t)&arm_uuid_spec[TRUSTED_OS_FW_KEY_CERT_ID],
150 open_fip
151 },
152 [NON_TRUSTED_FW_KEY_CERT_ID] = {
153 &fip_dev_handle,
154 (uintptr_t)&arm_uuid_spec[NON_TRUSTED_FW_KEY_CERT_ID],
155 open_fip
156 },
157 [SCP_FW_CONTENT_CERT_ID] = {
158 &fip_dev_handle,
159 (uintptr_t)&arm_uuid_spec[SCP_FW_CONTENT_CERT_ID],
160 open_fip
161 },
162 [SOC_FW_CONTENT_CERT_ID] = {
163 &fip_dev_handle,
164 (uintptr_t)&arm_uuid_spec[SOC_FW_CONTENT_CERT_ID],
165 open_fip
166 },
167 [TRUSTED_OS_FW_CONTENT_CERT_ID] = {
168 &fip_dev_handle,
169 (uintptr_t)&arm_uuid_spec[TRUSTED_OS_FW_CONTENT_CERT_ID],
170 open_fip
171 },
172 [NON_TRUSTED_FW_CONTENT_CERT_ID] = {
173 &fip_dev_handle,
174 (uintptr_t)&arm_uuid_spec[NON_TRUSTED_FW_CONTENT_CERT_ID],
175 open_fip
176 },
177#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100178#endif /* TRUSTED_BOARD_BOOT */
179};
180
181#ifdef IMAGE_BL2
182
183#if TRUSTED_BOARD_BOOT
Louis Mayencourt2711cc82020-02-24 14:37:25 +0000184#define FCONF_ARM_IO_UUID_NUMBER U(19)
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100185#else
Louis Mayencourt2711cc82020-02-24 14:37:25 +0000186#define FCONF_ARM_IO_UUID_NUMBER U(10)
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100187#endif
188
189static io_uuid_spec_t fconf_arm_uuids[FCONF_ARM_IO_UUID_NUMBER];
190static OBJECT_POOL_ARRAY(fconf_arm_uuids_pool, fconf_arm_uuids);
191
192struct policies_load_info {
193 unsigned int image_id;
194 const char *name;
195};
196
197/* image id to property name table */
198static const struct policies_load_info load_info[FCONF_ARM_IO_UUID_NUMBER] = {
199 {SCP_BL2_IMAGE_ID, "scp_bl2_uuid"},
200 {BL31_IMAGE_ID, "bl31_uuid"},
201 {BL32_IMAGE_ID, "bl32_uuid"},
202 {BL32_EXTRA1_IMAGE_ID, "bl32_extra1_uuid"},
203 {BL32_EXTRA2_IMAGE_ID, "bl32_extra2_uuid"},
204 {BL33_IMAGE_ID, "bl33_uuid"},
205 {HW_CONFIG_ID, "hw_cfg_uuid"},
206 {SOC_FW_CONFIG_ID, "soc_fw_cfg_uuid"},
207 {TOS_FW_CONFIG_ID, "tos_fw_cfg_uuid"},
208 {NT_FW_CONFIG_ID, "nt_fw_cfg_uuid"},
209#if TRUSTED_BOARD_BOOT
210 {TRUSTED_KEY_CERT_ID, "t_key_cert_uuid"},
211 {SCP_FW_KEY_CERT_ID, "scp_fw_key_uuid"},
212 {SOC_FW_KEY_CERT_ID, "soc_fw_key_uuid"},
213 {TRUSTED_OS_FW_KEY_CERT_ID, "tos_fw_key_cert_uuid"},
214 {NON_TRUSTED_FW_KEY_CERT_ID, "nt_fw_key_cert_uuid"},
215 {SCP_FW_CONTENT_CERT_ID, "scp_fw_content_cert_uuid"},
216 {SOC_FW_CONTENT_CERT_ID, "soc_fw_content_cert_uuid"},
217 {TRUSTED_OS_FW_CONTENT_CERT_ID, "tos_fw_content_cert_uuid"},
218 {NON_TRUSTED_FW_CONTENT_CERT_ID, "nt_fw_content_cert_uuid"},
219#endif /* TRUSTED_BOARD_BOOT */
220};
221
222int fconf_populate_arm_io_policies(uintptr_t config)
223{
224 int err, node;
225 unsigned int i;
226
227 union uuid_helper_t uuid_helper;
228 io_uuid_spec_t *uuid_ptr;
229
230 /* As libfdt uses void *, we can't avoid this cast */
231 const void *dtb = (void *)config;
232
233 /* Assert the node offset point to "arm,io-fip-handle" compatible property */
234 const char *compatible_str = "arm,io-fip-handle";
235 node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
236 if (node < 0) {
237 ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str);
238 return node;
239 }
240
241 /* Locate the uuid cells and read the value for all the load info uuid */
242 for (i = 0; i < FCONF_ARM_IO_UUID_NUMBER; i++) {
243 uuid_ptr = pool_alloc(&fconf_arm_uuids_pool);
244 err = fdtw_read_array(dtb, node, load_info[i].name, 4, &uuid_helper.word);
245 if (err < 0) {
246 WARN("FCONF: Read cell failed for %s\n", load_info[i].name);
247 return err;
248 }
249
250 VERBOSE("FCONF: arm-io_policies.%s cell found with value = 0x%x 0x%x 0x%x 0x%x\n",
251 load_info[i].name,
252 uuid_helper.word[0], uuid_helper.word[1],
253 uuid_helper.word[2], uuid_helper.word[3]);
254
255 uuid_ptr->uuid = uuid_helper.uuid_struct;
256 policies[load_info[i].image_id].image_spec = (uintptr_t)uuid_ptr;
257 policies[load_info[i].image_id].dev_handle = &fip_dev_handle;
258 policies[load_info[i].image_id].check = open_fip;
259 }
260 return 0;
261}
262
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000263#if ARM_IO_IN_DTB
Madhukar Pappireddy81519692019-12-06 15:46:42 -0600264FCONF_REGISTER_POPULATOR(TB_FW, arm_io, fconf_populate_arm_io_policies);
Louis Mayencourt6b232d92020-02-28 16:57:30 +0000265#endif /* ARM_IO_IN_DTB */
Louis Mayencourtbadcac82019-10-24 15:18:46 +0100266
267#endif /* IMAGE_BL2 */