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