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