Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | const io_block_spec_t fip_block_spec = { |
| 21 | .offset = PLAT_ARM_FIP_BASE, |
| 22 | .length = PLAT_ARM_FIP_MAX_SIZE |
| 23 | }; |
| 24 | |
| 25 | const 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 Mayencourt | 244027d | 2020-06-11 21:15:15 +0100 | [diff] [blame] | 28 | [FW_CONFIG_ID] = {UUID_FW_CONFIG}, |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 29 | #if !ARM_IO_IN_DTB |
| 30 | [SCP_BL2_IMAGE_ID] = {UUID_SCP_FIRMWARE_SCP_BL2}, |
| 31 | [BL31_IMAGE_ID] = {UUID_EL3_RUNTIME_FIRMWARE_BL31}, |
| 32 | [BL32_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32}, |
| 33 | [BL32_EXTRA1_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32_EXTRA1}, |
| 34 | [BL32_EXTRA2_IMAGE_ID] = {UUID_SECURE_PAYLOAD_BL32_EXTRA2}, |
| 35 | [BL33_IMAGE_ID] = {UUID_NON_TRUSTED_FIRMWARE_BL33}, |
| 36 | [HW_CONFIG_ID] = {UUID_HW_CONFIG}, |
| 37 | [SOC_FW_CONFIG_ID] = {UUID_SOC_FW_CONFIG}, |
| 38 | [TOS_FW_CONFIG_ID] = {UUID_TOS_FW_CONFIG}, |
| 39 | [NT_FW_CONFIG_ID] = {UUID_NT_FW_CONFIG}, |
| 40 | #endif /* ARM_IO_IN_DTB */ |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 41 | #if TRUSTED_BOARD_BOOT |
| 42 | [TRUSTED_BOOT_FW_CERT_ID] = {UUID_TRUSTED_BOOT_FW_CERT}, |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 43 | #if !ARM_IO_IN_DTB |
| 44 | [TRUSTED_KEY_CERT_ID] = {UUID_TRUSTED_KEY_CERT}, |
| 45 | [SCP_FW_KEY_CERT_ID] = {UUID_SCP_FW_KEY_CERT}, |
| 46 | [SOC_FW_KEY_CERT_ID] = {UUID_SOC_FW_KEY_CERT}, |
| 47 | [TRUSTED_OS_FW_KEY_CERT_ID] = {UUID_TRUSTED_OS_FW_KEY_CERT}, |
| 48 | [NON_TRUSTED_FW_KEY_CERT_ID] = {UUID_NON_TRUSTED_FW_KEY_CERT}, |
| 49 | [SCP_FW_CONTENT_CERT_ID] = {UUID_SCP_FW_CONTENT_CERT}, |
| 50 | [SOC_FW_CONTENT_CERT_ID] = {UUID_SOC_FW_CONTENT_CERT}, |
| 51 | [TRUSTED_OS_FW_CONTENT_CERT_ID] = {UUID_TRUSTED_OS_FW_CONTENT_CERT}, |
| 52 | [NON_TRUSTED_FW_CONTENT_CERT_ID] = {UUID_NON_TRUSTED_FW_CONTENT_CERT}, |
Manish Pandey | 5f8e1a0 | 2020-05-27 22:40:10 +0100 | [diff] [blame] | 53 | #if defined(SPD_spmd) |
Manish Pandey | d07d017 | 2020-07-23 16:54:30 +0100 | [diff] [blame] | 54 | [SIP_SP_CONTENT_CERT_ID] = {UUID_SIP_SECURE_PARTITION_CONTENT_CERT}, |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 55 | [PLAT_SP_CONTENT_CERT_ID] = {UUID_PLAT_SECURE_PARTITION_CONTENT_CERT}, |
Manish Pandey | 5f8e1a0 | 2020-05-27 22:40:10 +0100 | [diff] [blame] | 56 | #endif |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 57 | #endif /* ARM_IO_IN_DTB */ |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 58 | #endif /* TRUSTED_BOARD_BOOT */ |
| 59 | }; |
| 60 | |
| 61 | /* By default, ARM platforms load images from the FIP */ |
| 62 | struct plat_io_policy policies[MAX_NUMBER_IDS] = { |
| 63 | [FIP_IMAGE_ID] = { |
| 64 | &memmap_dev_handle, |
| 65 | (uintptr_t)&fip_block_spec, |
| 66 | open_memmap |
| 67 | }, |
| 68 | [BL2_IMAGE_ID] = { |
| 69 | &fip_dev_handle, |
| 70 | (uintptr_t)&arm_uuid_spec[BL2_IMAGE_ID], |
| 71 | open_fip |
| 72 | }, |
| 73 | [TB_FW_CONFIG_ID] = { |
| 74 | &fip_dev_handle, |
| 75 | (uintptr_t)&arm_uuid_spec[TB_FW_CONFIG_ID], |
| 76 | open_fip |
| 77 | }, |
Louis Mayencourt | 244027d | 2020-06-11 21:15:15 +0100 | [diff] [blame] | 78 | [FW_CONFIG_ID] = { |
| 79 | &fip_dev_handle, |
| 80 | (uintptr_t)&arm_uuid_spec[FW_CONFIG_ID], |
| 81 | open_fip |
| 82 | }, |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 83 | #if !ARM_IO_IN_DTB |
| 84 | [SCP_BL2_IMAGE_ID] = { |
| 85 | &fip_dev_handle, |
| 86 | (uintptr_t)&arm_uuid_spec[SCP_BL2_IMAGE_ID], |
| 87 | open_fip |
| 88 | }, |
| 89 | [BL31_IMAGE_ID] = { |
| 90 | &fip_dev_handle, |
| 91 | (uintptr_t)&arm_uuid_spec[BL31_IMAGE_ID], |
| 92 | open_fip |
| 93 | }, |
| 94 | [BL32_IMAGE_ID] = { |
| 95 | &fip_dev_handle, |
| 96 | (uintptr_t)&arm_uuid_spec[BL32_IMAGE_ID], |
| 97 | open_fip |
| 98 | }, |
| 99 | [BL32_EXTRA1_IMAGE_ID] = { |
| 100 | &fip_dev_handle, |
| 101 | (uintptr_t)&arm_uuid_spec[BL32_EXTRA1_IMAGE_ID], |
| 102 | open_fip |
| 103 | }, |
| 104 | [BL32_EXTRA2_IMAGE_ID] = { |
| 105 | &fip_dev_handle, |
| 106 | (uintptr_t)&arm_uuid_spec[BL32_EXTRA2_IMAGE_ID], |
| 107 | open_fip |
| 108 | }, |
| 109 | [BL33_IMAGE_ID] = { |
| 110 | &fip_dev_handle, |
| 111 | (uintptr_t)&arm_uuid_spec[BL33_IMAGE_ID], |
| 112 | open_fip |
| 113 | }, |
| 114 | [HW_CONFIG_ID] = { |
| 115 | &fip_dev_handle, |
| 116 | (uintptr_t)&arm_uuid_spec[HW_CONFIG_ID], |
| 117 | open_fip |
| 118 | }, |
| 119 | [SOC_FW_CONFIG_ID] = { |
| 120 | &fip_dev_handle, |
| 121 | (uintptr_t)&arm_uuid_spec[SOC_FW_CONFIG_ID], |
| 122 | open_fip |
| 123 | }, |
| 124 | [TOS_FW_CONFIG_ID] = { |
| 125 | &fip_dev_handle, |
| 126 | (uintptr_t)&arm_uuid_spec[TOS_FW_CONFIG_ID], |
| 127 | open_fip |
| 128 | }, |
| 129 | [NT_FW_CONFIG_ID] = { |
| 130 | &fip_dev_handle, |
| 131 | (uintptr_t)&arm_uuid_spec[NT_FW_CONFIG_ID], |
| 132 | open_fip |
| 133 | }, |
| 134 | #endif /* ARM_IO_IN_DTB */ |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 135 | #if TRUSTED_BOARD_BOOT |
| 136 | [TRUSTED_BOOT_FW_CERT_ID] = { |
| 137 | &fip_dev_handle, |
| 138 | (uintptr_t)&arm_uuid_spec[TRUSTED_BOOT_FW_CERT_ID], |
| 139 | open_fip |
| 140 | }, |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 141 | #if !ARM_IO_IN_DTB |
| 142 | [TRUSTED_KEY_CERT_ID] = { |
| 143 | &fip_dev_handle, |
| 144 | (uintptr_t)&arm_uuid_spec[TRUSTED_KEY_CERT_ID], |
| 145 | open_fip |
| 146 | }, |
| 147 | [SCP_FW_KEY_CERT_ID] = { |
| 148 | &fip_dev_handle, |
| 149 | (uintptr_t)&arm_uuid_spec[SCP_FW_KEY_CERT_ID], |
| 150 | open_fip |
| 151 | }, |
| 152 | [SOC_FW_KEY_CERT_ID] = { |
| 153 | &fip_dev_handle, |
| 154 | (uintptr_t)&arm_uuid_spec[SOC_FW_KEY_CERT_ID], |
| 155 | open_fip |
| 156 | }, |
| 157 | [TRUSTED_OS_FW_KEY_CERT_ID] = { |
| 158 | &fip_dev_handle, |
| 159 | (uintptr_t)&arm_uuid_spec[TRUSTED_OS_FW_KEY_CERT_ID], |
| 160 | open_fip |
| 161 | }, |
| 162 | [NON_TRUSTED_FW_KEY_CERT_ID] = { |
| 163 | &fip_dev_handle, |
| 164 | (uintptr_t)&arm_uuid_spec[NON_TRUSTED_FW_KEY_CERT_ID], |
| 165 | open_fip |
| 166 | }, |
| 167 | [SCP_FW_CONTENT_CERT_ID] = { |
| 168 | &fip_dev_handle, |
| 169 | (uintptr_t)&arm_uuid_spec[SCP_FW_CONTENT_CERT_ID], |
| 170 | open_fip |
| 171 | }, |
| 172 | [SOC_FW_CONTENT_CERT_ID] = { |
| 173 | &fip_dev_handle, |
| 174 | (uintptr_t)&arm_uuid_spec[SOC_FW_CONTENT_CERT_ID], |
| 175 | open_fip |
| 176 | }, |
| 177 | [TRUSTED_OS_FW_CONTENT_CERT_ID] = { |
| 178 | &fip_dev_handle, |
| 179 | (uintptr_t)&arm_uuid_spec[TRUSTED_OS_FW_CONTENT_CERT_ID], |
| 180 | open_fip |
| 181 | }, |
| 182 | [NON_TRUSTED_FW_CONTENT_CERT_ID] = { |
| 183 | &fip_dev_handle, |
| 184 | (uintptr_t)&arm_uuid_spec[NON_TRUSTED_FW_CONTENT_CERT_ID], |
| 185 | open_fip |
| 186 | }, |
Manish Pandey | 5f8e1a0 | 2020-05-27 22:40:10 +0100 | [diff] [blame] | 187 | #if defined(SPD_spmd) |
Manish Pandey | d07d017 | 2020-07-23 16:54:30 +0100 | [diff] [blame] | 188 | [SIP_SP_CONTENT_CERT_ID] = { |
Manish Pandey | 5f8e1a0 | 2020-05-27 22:40:10 +0100 | [diff] [blame] | 189 | &fip_dev_handle, |
Manish Pandey | d07d017 | 2020-07-23 16:54:30 +0100 | [diff] [blame] | 190 | (uintptr_t)&arm_uuid_spec[SIP_SP_CONTENT_CERT_ID], |
Manish Pandey | 5f8e1a0 | 2020-05-27 22:40:10 +0100 | [diff] [blame] | 191 | open_fip |
| 192 | }, |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 193 | [PLAT_SP_CONTENT_CERT_ID] = { |
| 194 | &fip_dev_handle, |
| 195 | (uintptr_t)&arm_uuid_spec[PLAT_SP_CONTENT_CERT_ID], |
| 196 | open_fip |
| 197 | }, |
Manish Pandey | 5f8e1a0 | 2020-05-27 22:40:10 +0100 | [diff] [blame] | 198 | #endif |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 199 | #endif /* ARM_IO_IN_DTB */ |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 200 | #endif /* TRUSTED_BOARD_BOOT */ |
| 201 | }; |
| 202 | |
| 203 | #ifdef IMAGE_BL2 |
| 204 | |
| 205 | #if TRUSTED_BOARD_BOOT |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 206 | #define FCONF_ARM_IO_UUID_NUMBER U(21) |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 207 | #else |
Louis Mayencourt | 2711cc8 | 2020-02-24 14:37:25 +0000 | [diff] [blame] | 208 | #define FCONF_ARM_IO_UUID_NUMBER U(10) |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 209 | #endif |
| 210 | |
| 211 | static io_uuid_spec_t fconf_arm_uuids[FCONF_ARM_IO_UUID_NUMBER]; |
| 212 | static OBJECT_POOL_ARRAY(fconf_arm_uuids_pool, fconf_arm_uuids); |
| 213 | |
| 214 | struct policies_load_info { |
| 215 | unsigned int image_id; |
| 216 | const char *name; |
| 217 | }; |
| 218 | |
| 219 | /* image id to property name table */ |
| 220 | static const struct policies_load_info load_info[FCONF_ARM_IO_UUID_NUMBER] = { |
| 221 | {SCP_BL2_IMAGE_ID, "scp_bl2_uuid"}, |
| 222 | {BL31_IMAGE_ID, "bl31_uuid"}, |
| 223 | {BL32_IMAGE_ID, "bl32_uuid"}, |
| 224 | {BL32_EXTRA1_IMAGE_ID, "bl32_extra1_uuid"}, |
| 225 | {BL32_EXTRA2_IMAGE_ID, "bl32_extra2_uuid"}, |
| 226 | {BL33_IMAGE_ID, "bl33_uuid"}, |
| 227 | {HW_CONFIG_ID, "hw_cfg_uuid"}, |
| 228 | {SOC_FW_CONFIG_ID, "soc_fw_cfg_uuid"}, |
| 229 | {TOS_FW_CONFIG_ID, "tos_fw_cfg_uuid"}, |
| 230 | {NT_FW_CONFIG_ID, "nt_fw_cfg_uuid"}, |
| 231 | #if TRUSTED_BOARD_BOOT |
| 232 | {TRUSTED_KEY_CERT_ID, "t_key_cert_uuid"}, |
| 233 | {SCP_FW_KEY_CERT_ID, "scp_fw_key_uuid"}, |
| 234 | {SOC_FW_KEY_CERT_ID, "soc_fw_key_uuid"}, |
| 235 | {TRUSTED_OS_FW_KEY_CERT_ID, "tos_fw_key_cert_uuid"}, |
| 236 | {NON_TRUSTED_FW_KEY_CERT_ID, "nt_fw_key_cert_uuid"}, |
| 237 | {SCP_FW_CONTENT_CERT_ID, "scp_fw_content_cert_uuid"}, |
| 238 | {SOC_FW_CONTENT_CERT_ID, "soc_fw_content_cert_uuid"}, |
| 239 | {TRUSTED_OS_FW_CONTENT_CERT_ID, "tos_fw_content_cert_uuid"}, |
| 240 | {NON_TRUSTED_FW_CONTENT_CERT_ID, "nt_fw_content_cert_uuid"}, |
Manish Pandey | 5f8e1a0 | 2020-05-27 22:40:10 +0100 | [diff] [blame] | 241 | #if defined(SPD_spmd) |
Manish Pandey | d07d017 | 2020-07-23 16:54:30 +0100 | [diff] [blame] | 242 | {SIP_SP_CONTENT_CERT_ID, "sip_sp_content_cert_uuid"}, |
Manish Pandey | aff8075 | 2020-07-31 16:15:16 +0100 | [diff] [blame] | 243 | {PLAT_SP_CONTENT_CERT_ID, "plat_sp_content_cert_uuid"}, |
Manish Pandey | 5f8e1a0 | 2020-05-27 22:40:10 +0100 | [diff] [blame] | 244 | #endif |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 245 | #endif /* TRUSTED_BOARD_BOOT */ |
| 246 | }; |
| 247 | |
| 248 | int fconf_populate_arm_io_policies(uintptr_t config) |
| 249 | { |
| 250 | int err, node; |
| 251 | unsigned int i; |
| 252 | |
| 253 | union uuid_helper_t uuid_helper; |
| 254 | io_uuid_spec_t *uuid_ptr; |
| 255 | |
| 256 | /* As libfdt uses void *, we can't avoid this cast */ |
| 257 | const void *dtb = (void *)config; |
| 258 | |
| 259 | /* Assert the node offset point to "arm,io-fip-handle" compatible property */ |
| 260 | const char *compatible_str = "arm,io-fip-handle"; |
| 261 | node = fdt_node_offset_by_compatible(dtb, -1, compatible_str); |
| 262 | if (node < 0) { |
| 263 | ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str); |
| 264 | return node; |
| 265 | } |
| 266 | |
| 267 | /* Locate the uuid cells and read the value for all the load info uuid */ |
| 268 | for (i = 0; i < FCONF_ARM_IO_UUID_NUMBER; i++) { |
| 269 | uuid_ptr = pool_alloc(&fconf_arm_uuids_pool); |
Andre Przywara | 6cf6a1b | 2020-03-30 23:21:13 +0100 | [diff] [blame] | 270 | err = fdt_read_uint32_array(dtb, node, load_info[i].name, |
| 271 | 4, uuid_helper.word); |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 272 | if (err < 0) { |
| 273 | WARN("FCONF: Read cell failed for %s\n", load_info[i].name); |
| 274 | return err; |
| 275 | } |
| 276 | |
| 277 | VERBOSE("FCONF: arm-io_policies.%s cell found with value = 0x%x 0x%x 0x%x 0x%x\n", |
| 278 | load_info[i].name, |
| 279 | uuid_helper.word[0], uuid_helper.word[1], |
| 280 | uuid_helper.word[2], uuid_helper.word[3]); |
| 281 | |
| 282 | uuid_ptr->uuid = uuid_helper.uuid_struct; |
| 283 | policies[load_info[i].image_id].image_spec = (uintptr_t)uuid_ptr; |
| 284 | policies[load_info[i].image_id].dev_handle = &fip_dev_handle; |
| 285 | policies[load_info[i].image_id].check = open_fip; |
| 286 | } |
| 287 | return 0; |
| 288 | } |
| 289 | |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 290 | #if ARM_IO_IN_DTB |
Madhukar Pappireddy | 8151969 | 2019-12-06 15:46:42 -0600 | [diff] [blame] | 291 | FCONF_REGISTER_POPULATOR(TB_FW, arm_io, fconf_populate_arm_io_policies); |
Louis Mayencourt | 6b232d9 | 2020-02-28 16:57:30 +0000 | [diff] [blame] | 292 | #endif /* ARM_IO_IN_DTB */ |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 293 | |
| 294 | #endif /* IMAGE_BL2 */ |