Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 1 | /* |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 5 | */ |
| 6 | #include <assert.h> |
| 7 | #include <debug.h> |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 8 | #include <firmware_image_package.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 9 | #include <io_driver.h> |
| 10 | #include <io_fip.h> |
| 11 | #include <io_memmap.h> |
| 12 | #include <io_storage.h> |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 13 | #include <plat_arm.h> |
| 14 | #include <platform.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 15 | #include <platform_def.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 16 | #include <string.h> |
Sandrine Bailleux | 7659a26 | 2016-07-05 09:55:03 +0100 | [diff] [blame] | 17 | #include <utils.h> |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 18 | |
| 19 | /* IO devices */ |
| 20 | static const io_dev_connector_t *fip_dev_con; |
| 21 | static uintptr_t fip_dev_handle; |
| 22 | static const io_dev_connector_t *memmap_dev_con; |
| 23 | static uintptr_t memmap_dev_handle; |
| 24 | |
| 25 | static const io_block_spec_t fip_block_spec = { |
| 26 | .offset = PLAT_ARM_FIP_BASE, |
| 27 | .length = PLAT_ARM_FIP_MAX_SIZE |
| 28 | }; |
| 29 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 30 | static const io_uuid_spec_t bl2_uuid_spec = { |
| 31 | .uuid = UUID_TRUSTED_BOOT_FIRMWARE_BL2, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 32 | }; |
| 33 | |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 34 | static const io_uuid_spec_t scp_bl2_uuid_spec = { |
| 35 | .uuid = UUID_SCP_FIRMWARE_SCP_BL2, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 38 | static const io_uuid_spec_t bl31_uuid_spec = { |
| 39 | .uuid = UUID_EL3_RUNTIME_FIRMWARE_BL31, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 42 | static const io_uuid_spec_t bl32_uuid_spec = { |
| 43 | .uuid = UUID_SECURE_PAYLOAD_BL32, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
Summer Qin | 8072678 | 2017-04-20 16:28:39 +0100 | [diff] [blame] | 46 | static const io_uuid_spec_t bl32_extra1_uuid_spec = { |
| 47 | .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1, |
| 48 | }; |
| 49 | |
| 50 | static const io_uuid_spec_t bl32_extra2_uuid_spec = { |
| 51 | .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2, |
| 52 | }; |
| 53 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 54 | static const io_uuid_spec_t bl33_uuid_spec = { |
| 55 | .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 58 | static const io_uuid_spec_t tb_fw_config_uuid_spec = { |
| 59 | .uuid = UUID_TB_FW_CONFIG, |
| 60 | }; |
| 61 | |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 62 | static const io_uuid_spec_t hw_config_uuid_spec = { |
| 63 | .uuid = UUID_HW_CONFIG, |
| 64 | }; |
| 65 | |
Soby Mathew | b681484 | 2018-04-04 09:40:32 +0100 | [diff] [blame] | 66 | static const io_uuid_spec_t soc_fw_config_uuid_spec = { |
| 67 | .uuid = UUID_SOC_FW_CONFIG, |
| 68 | }; |
| 69 | |
| 70 | static const io_uuid_spec_t tos_fw_config_uuid_spec = { |
| 71 | .uuid = UUID_TOS_FW_CONFIG, |
| 72 | }; |
| 73 | |
| 74 | static const io_uuid_spec_t nt_fw_config_uuid_spec = { |
| 75 | .uuid = UUID_NT_FW_CONFIG, |
| 76 | }; |
| 77 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 78 | #if TRUSTED_BOARD_BOOT |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 79 | static const io_uuid_spec_t tb_fw_cert_uuid_spec = { |
| 80 | .uuid = UUID_TRUSTED_BOOT_FW_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 83 | static const io_uuid_spec_t trusted_key_cert_uuid_spec = { |
| 84 | .uuid = UUID_TRUSTED_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 87 | static const io_uuid_spec_t scp_fw_key_cert_uuid_spec = { |
| 88 | .uuid = UUID_SCP_FW_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 91 | static const io_uuid_spec_t soc_fw_key_cert_uuid_spec = { |
| 92 | .uuid = UUID_SOC_FW_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 95 | static const io_uuid_spec_t tos_fw_key_cert_uuid_spec = { |
| 96 | .uuid = UUID_TRUSTED_OS_FW_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 99 | static const io_uuid_spec_t nt_fw_key_cert_uuid_spec = { |
| 100 | .uuid = UUID_NON_TRUSTED_FW_KEY_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 103 | static const io_uuid_spec_t scp_fw_cert_uuid_spec = { |
| 104 | .uuid = UUID_SCP_FW_CONTENT_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 107 | static const io_uuid_spec_t soc_fw_cert_uuid_spec = { |
| 108 | .uuid = UUID_SOC_FW_CONTENT_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 109 | }; |
| 110 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 111 | static const io_uuid_spec_t tos_fw_cert_uuid_spec = { |
| 112 | .uuid = UUID_TRUSTED_OS_FW_CONTENT_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 115 | static const io_uuid_spec_t nt_fw_cert_uuid_spec = { |
| 116 | .uuid = UUID_NON_TRUSTED_FW_CONTENT_CERT, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 117 | }; |
| 118 | #endif /* TRUSTED_BOARD_BOOT */ |
| 119 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 120 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 121 | static int open_fip(const uintptr_t spec); |
| 122 | static int open_memmap(const uintptr_t spec); |
| 123 | |
| 124 | struct plat_io_policy { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 125 | uintptr_t *dev_handle; |
| 126 | uintptr_t image_spec; |
| 127 | int (*check)(const uintptr_t spec); |
| 128 | }; |
| 129 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 130 | /* By default, ARM platforms load images from the FIP */ |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 131 | static const struct plat_io_policy policies[] = { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 132 | [FIP_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 133 | &memmap_dev_handle, |
| 134 | (uintptr_t)&fip_block_spec, |
| 135 | open_memmap |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 136 | }, |
| 137 | [BL2_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 138 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 139 | (uintptr_t)&bl2_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 140 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 141 | }, |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 142 | [SCP_BL2_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 143 | &fip_dev_handle, |
Juan Castillo | a72b647 | 2015-12-10 15:49:17 +0000 | [diff] [blame] | 144 | (uintptr_t)&scp_bl2_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 145 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 146 | }, |
| 147 | [BL31_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 148 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 149 | (uintptr_t)&bl31_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 150 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 151 | }, |
| 152 | [BL32_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 153 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 154 | (uintptr_t)&bl32_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 155 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 156 | }, |
Summer Qin | 8072678 | 2017-04-20 16:28:39 +0100 | [diff] [blame] | 157 | [BL32_EXTRA1_IMAGE_ID] = { |
| 158 | &fip_dev_handle, |
| 159 | (uintptr_t)&bl32_extra1_uuid_spec, |
| 160 | open_fip |
| 161 | }, |
| 162 | [BL32_EXTRA2_IMAGE_ID] = { |
| 163 | &fip_dev_handle, |
| 164 | (uintptr_t)&bl32_extra2_uuid_spec, |
| 165 | open_fip |
| 166 | }, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 167 | [BL33_IMAGE_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 168 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 169 | (uintptr_t)&bl33_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 170 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 171 | }, |
Soby Mathew | 7c6df5b | 2018-01-15 14:43:42 +0000 | [diff] [blame] | 172 | [TB_FW_CONFIG_ID] = { |
| 173 | &fip_dev_handle, |
| 174 | (uintptr_t)&tb_fw_config_uuid_spec, |
| 175 | open_fip |
| 176 | }, |
Soby Mathew | 96a1c6b | 2018-01-15 14:45:33 +0000 | [diff] [blame] | 177 | [HW_CONFIG_ID] = { |
| 178 | &fip_dev_handle, |
| 179 | (uintptr_t)&hw_config_uuid_spec, |
| 180 | open_fip |
| 181 | }, |
Soby Mathew | b681484 | 2018-04-04 09:40:32 +0100 | [diff] [blame] | 182 | [SOC_FW_CONFIG_ID] = { |
| 183 | &fip_dev_handle, |
| 184 | (uintptr_t)&soc_fw_config_uuid_spec, |
| 185 | open_fip |
| 186 | }, |
| 187 | [TOS_FW_CONFIG_ID] = { |
| 188 | &fip_dev_handle, |
| 189 | (uintptr_t)&tos_fw_config_uuid_spec, |
| 190 | open_fip |
| 191 | }, |
| 192 | [NT_FW_CONFIG_ID] = { |
| 193 | &fip_dev_handle, |
| 194 | (uintptr_t)&nt_fw_config_uuid_spec, |
| 195 | open_fip |
| 196 | }, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 197 | #if TRUSTED_BOARD_BOOT |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 198 | [TRUSTED_BOOT_FW_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 199 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 200 | (uintptr_t)&tb_fw_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 201 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 202 | }, |
| 203 | [TRUSTED_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 204 | &fip_dev_handle, |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 205 | (uintptr_t)&trusted_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 206 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 207 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 208 | [SCP_FW_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 209 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 210 | (uintptr_t)&scp_fw_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 211 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 212 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 213 | [SOC_FW_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 214 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 215 | (uintptr_t)&soc_fw_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 216 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 217 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 218 | [TRUSTED_OS_FW_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 219 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 220 | (uintptr_t)&tos_fw_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 221 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 222 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 223 | [NON_TRUSTED_FW_KEY_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 224 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 225 | (uintptr_t)&nt_fw_key_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 226 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 227 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 228 | [SCP_FW_CONTENT_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 229 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 230 | (uintptr_t)&scp_fw_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 231 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 232 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 233 | [SOC_FW_CONTENT_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 234 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 235 | (uintptr_t)&soc_fw_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 236 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 237 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 238 | [TRUSTED_OS_FW_CONTENT_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 239 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 240 | (uintptr_t)&tos_fw_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 241 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 242 | }, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 243 | [NON_TRUSTED_FW_CONTENT_CERT_ID] = { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 244 | &fip_dev_handle, |
Juan Castillo | be80120 | 2015-12-03 10:19:21 +0000 | [diff] [blame] | 245 | (uintptr_t)&nt_fw_cert_uuid_spec, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 246 | open_fip |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 247 | }, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 248 | #endif /* TRUSTED_BOARD_BOOT */ |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | |
| 252 | /* Weak definitions may be overridden in specific ARM standard platform */ |
| 253 | #pragma weak plat_arm_io_setup |
| 254 | #pragma weak plat_arm_get_alt_image_source |
| 255 | |
| 256 | |
| 257 | static int open_fip(const uintptr_t spec) |
| 258 | { |
| 259 | int result; |
| 260 | uintptr_t local_image_handle; |
| 261 | |
| 262 | /* See if a Firmware Image Package is available */ |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 263 | result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 264 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 265 | result = io_open(fip_dev_handle, spec, &local_image_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 266 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 267 | VERBOSE("Using FIP\n"); |
| 268 | io_close(local_image_handle); |
| 269 | } |
| 270 | } |
| 271 | return result; |
| 272 | } |
| 273 | |
| 274 | |
| 275 | static int open_memmap(const uintptr_t spec) |
| 276 | { |
| 277 | int result; |
| 278 | uintptr_t local_image_handle; |
| 279 | |
| 280 | result = io_dev_init(memmap_dev_handle, (uintptr_t)NULL); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 281 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 282 | result = io_open(memmap_dev_handle, spec, &local_image_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 283 | if (result == 0) { |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 284 | VERBOSE("Using Memmap\n"); |
| 285 | io_close(local_image_handle); |
| 286 | } |
| 287 | } |
| 288 | return result; |
| 289 | } |
| 290 | |
| 291 | |
| 292 | void arm_io_setup(void) |
| 293 | { |
| 294 | int io_result; |
| 295 | |
| 296 | io_result = register_io_dev_fip(&fip_dev_con); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 297 | assert(io_result == 0); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 298 | |
| 299 | io_result = register_io_dev_memmap(&memmap_dev_con); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 300 | assert(io_result == 0); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 301 | |
| 302 | /* Open connections to devices and cache the handles */ |
| 303 | io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL, |
| 304 | &fip_dev_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 305 | assert(io_result == 0); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 306 | |
| 307 | io_result = io_dev_open(memmap_dev_con, (uintptr_t)NULL, |
| 308 | &memmap_dev_handle); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 309 | assert(io_result == 0); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 310 | |
| 311 | /* Ignore improbable errors in release builds */ |
| 312 | (void)io_result; |
| 313 | } |
| 314 | |
| 315 | void plat_arm_io_setup(void) |
| 316 | { |
| 317 | arm_io_setup(); |
| 318 | } |
| 319 | |
| 320 | int plat_arm_get_alt_image_source( |
Soren Brinkmann | 46dd170 | 2016-01-14 10:11:05 -0800 | [diff] [blame] | 321 | unsigned int image_id __unused, |
| 322 | uintptr_t *dev_handle __unused, |
| 323 | uintptr_t *image_spec __unused) |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 324 | { |
| 325 | /* By default do not try an alternative */ |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 326 | return -ENOENT; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* Return an IO device handle and specification which can be used to access |
| 330 | * an image. Use this to enforce platform load policy */ |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 331 | int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle, |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 332 | uintptr_t *image_spec) |
| 333 | { |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 334 | int result; |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 335 | const struct plat_io_policy *policy; |
| 336 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 337 | assert(image_id < ARRAY_SIZE(policies)); |
| 338 | |
| 339 | policy = &policies[image_id]; |
| 340 | result = policy->check(policy->image_spec); |
Juan Castillo | 6e76206 | 2015-11-02 10:47:01 +0000 | [diff] [blame] | 341 | if (result == 0) { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 342 | *image_spec = policy->image_spec; |
| 343 | *dev_handle = *(policy->dev_handle); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 344 | } else { |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 345 | VERBOSE("Trying alternative IO\n"); |
| 346 | result = plat_arm_get_alt_image_source(image_id, dev_handle, |
| 347 | image_spec); |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 348 | } |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 349 | |
Dan Handley | 9df4804 | 2015-03-19 18:58:55 +0000 | [diff] [blame] | 350 | return result; |
| 351 | } |
Yatharth Kochar | 736a3bf | 2015-10-11 14:14:55 +0100 | [diff] [blame] | 352 | |
| 353 | /* |
| 354 | * See if a Firmware Image Package is available, |
| 355 | * by checking if TOC is valid or not. |
| 356 | */ |
| 357 | int arm_io_is_toc_valid(void) |
| 358 | { |
| 359 | int result; |
| 360 | |
| 361 | result = io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID); |
| 362 | |
| 363 | return (result == 0); |
| 364 | } |
| 365 | |