Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 1 | /* |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved. |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | #include <string.h> |
| 9 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 10 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | |
| 12 | #include <arch_helpers.h> |
| 13 | #include <common/debug.h> |
| 14 | #include <drivers/io/io_block.h> |
| 15 | #include <drivers/io/io_driver.h> |
| 16 | #include <drivers/io/io_dummy.h> |
| 17 | #include <drivers/io/io_storage.h> |
| 18 | #include <drivers/mmc.h> |
| 19 | #include <drivers/partition/partition.h> |
| 20 | #include <drivers/st/io_mmc.h> |
| 21 | #include <drivers/st/io_stm32image.h> |
| 22 | #include <drivers/st/stm32_sdmmc2.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 23 | #include <lib/mmio.h> |
| 24 | #include <lib/utils.h> |
| 25 | #include <plat/common/platform.h> |
| 26 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 27 | /* IO devices */ |
| 28 | static const io_dev_connector_t *dummy_dev_con; |
| 29 | static uintptr_t dummy_dev_handle; |
| 30 | static uintptr_t dummy_dev_spec; |
| 31 | |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 32 | static uintptr_t image_dev_handle; |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 33 | static uintptr_t storage_dev_handle; |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 34 | |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 35 | #if STM32MP_SDMMC || STM32MP_EMMC |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 36 | static io_block_spec_t gpt_block_spec = { |
| 37 | .offset = 0, |
| 38 | .length = 34 * MMC_BLOCK_SIZE, /* Size of GPT table */ |
| 39 | }; |
| 40 | |
Yann Gautier | f9af3bc | 2018-11-09 15:57:18 +0100 | [diff] [blame] | 41 | static uint32_t block_buffer[MMC_BLOCK_SIZE] __aligned(MMC_BLOCK_SIZE); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 42 | |
| 43 | static const io_block_dev_spec_t mmc_block_dev_spec = { |
| 44 | /* It's used as temp buffer in block driver */ |
| 45 | .buffer = { |
| 46 | .offset = (size_t)&block_buffer, |
| 47 | .length = MMC_BLOCK_SIZE, |
| 48 | }, |
| 49 | .ops = { |
| 50 | .read = mmc_read_blocks, |
| 51 | .write = NULL, |
| 52 | }, |
| 53 | .block_size = MMC_BLOCK_SIZE, |
| 54 | }; |
| 55 | |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 56 | static const io_dev_connector_t *mmc_dev_con; |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 57 | #endif /* STM32MP_SDMMC || STM32MP_EMMC */ |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 58 | |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 59 | #ifdef AARCH32_SP_OPTEE |
| 60 | static const struct stm32image_part_info optee_header_partition_spec = { |
| 61 | .name = OPTEE_HEADER_IMAGE_NAME, |
| 62 | .binary_type = OPTEE_HEADER_BINARY_TYPE, |
| 63 | }; |
| 64 | |
| 65 | static const struct stm32image_part_info optee_pager_partition_spec = { |
| 66 | .name = OPTEE_PAGER_IMAGE_NAME, |
| 67 | .binary_type = OPTEE_PAGER_BINARY_TYPE, |
| 68 | }; |
| 69 | |
| 70 | static const struct stm32image_part_info optee_paged_partition_spec = { |
| 71 | .name = OPTEE_PAGED_IMAGE_NAME, |
| 72 | .binary_type = OPTEE_PAGED_BINARY_TYPE, |
| 73 | }; |
| 74 | #else |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 75 | static const io_block_spec_t bl32_block_spec = { |
| 76 | .offset = BL32_BASE, |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 77 | .length = STM32MP_BL32_SIZE |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 78 | }; |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 79 | #endif |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 80 | |
| 81 | static const io_block_spec_t bl2_block_spec = { |
| 82 | .offset = BL2_BASE, |
Yann Gautier | a2e2a30 | 2019-02-14 11:13:39 +0100 | [diff] [blame] | 83 | .length = STM32MP_BL2_SIZE, |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 84 | }; |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 85 | |
| 86 | static const struct stm32image_part_info bl33_partition_spec = { |
| 87 | .name = BL33_IMAGE_NAME, |
| 88 | .binary_type = BL33_BINARY_TYPE, |
| 89 | }; |
| 90 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 91 | enum { |
| 92 | IMG_IDX_BL33, |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 93 | #ifdef AARCH32_SP_OPTEE |
| 94 | IMG_IDX_OPTEE_HEADER, |
| 95 | IMG_IDX_OPTEE_PAGER, |
| 96 | IMG_IDX_OPTEE_PAGED, |
| 97 | #endif |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 98 | IMG_IDX_NUM |
| 99 | }; |
| 100 | |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 101 | static struct stm32image_device_info stm32image_dev_info_spec __unused = { |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 102 | .lba_size = MMC_BLOCK_SIZE, |
| 103 | .part_info[IMG_IDX_BL33] = { |
| 104 | .name = BL33_IMAGE_NAME, |
| 105 | .binary_type = BL33_BINARY_TYPE, |
| 106 | }, |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 107 | #ifdef AARCH32_SP_OPTEE |
| 108 | .part_info[IMG_IDX_OPTEE_HEADER] = { |
| 109 | .name = OPTEE_HEADER_IMAGE_NAME, |
| 110 | .binary_type = OPTEE_HEADER_BINARY_TYPE, |
| 111 | }, |
| 112 | .part_info[IMG_IDX_OPTEE_PAGER] = { |
| 113 | .name = OPTEE_PAGER_IMAGE_NAME, |
| 114 | .binary_type = OPTEE_PAGER_BINARY_TYPE, |
| 115 | }, |
| 116 | .part_info[IMG_IDX_OPTEE_PAGED] = { |
| 117 | .name = OPTEE_PAGED_IMAGE_NAME, |
| 118 | .binary_type = OPTEE_PAGED_BINARY_TYPE, |
| 119 | }, |
| 120 | #endif |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 121 | }; |
| 122 | |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 123 | static io_block_spec_t stm32image_block_spec = { |
| 124 | .offset = 0, |
| 125 | .length = 0, |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 126 | }; |
| 127 | |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 128 | static const io_dev_connector_t *stm32image_dev_con __unused; |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 129 | |
| 130 | static int open_dummy(const uintptr_t spec); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 131 | static int open_image(const uintptr_t spec); |
| 132 | static int open_storage(const uintptr_t spec); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 133 | |
| 134 | struct plat_io_policy { |
| 135 | uintptr_t *dev_handle; |
| 136 | uintptr_t image_spec; |
| 137 | int (*check)(const uintptr_t spec); |
| 138 | }; |
| 139 | |
| 140 | static const struct plat_io_policy policies[] = { |
| 141 | [BL2_IMAGE_ID] = { |
| 142 | .dev_handle = &dummy_dev_handle, |
| 143 | .image_spec = (uintptr_t)&bl2_block_spec, |
| 144 | .check = open_dummy |
| 145 | }, |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 146 | #ifdef AARCH32_SP_OPTEE |
| 147 | [BL32_IMAGE_ID] = { |
| 148 | .dev_handle = &image_dev_handle, |
| 149 | .image_spec = (uintptr_t)&optee_header_partition_spec, |
| 150 | .check = open_image |
| 151 | }, |
| 152 | [BL32_EXTRA1_IMAGE_ID] = { |
| 153 | .dev_handle = &image_dev_handle, |
| 154 | .image_spec = (uintptr_t)&optee_pager_partition_spec, |
| 155 | .check = open_image |
| 156 | }, |
| 157 | [BL32_EXTRA2_IMAGE_ID] = { |
| 158 | .dev_handle = &image_dev_handle, |
| 159 | .image_spec = (uintptr_t)&optee_paged_partition_spec, |
| 160 | .check = open_image |
| 161 | }, |
| 162 | #else |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 163 | [BL32_IMAGE_ID] = { |
| 164 | .dev_handle = &dummy_dev_handle, |
| 165 | .image_spec = (uintptr_t)&bl32_block_spec, |
| 166 | .check = open_dummy |
| 167 | }, |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 168 | #endif |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 169 | [BL33_IMAGE_ID] = { |
| 170 | .dev_handle = &image_dev_handle, |
| 171 | .image_spec = (uintptr_t)&bl33_partition_spec, |
| 172 | .check = open_image |
| 173 | }, |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 174 | #if STM32MP_SDMMC || STM32MP_EMMC |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 175 | [GPT_IMAGE_ID] = { |
| 176 | .dev_handle = &storage_dev_handle, |
| 177 | .image_spec = (uintptr_t)&gpt_block_spec, |
| 178 | .check = open_storage |
| 179 | }, |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 180 | #endif |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 181 | [STM32_IMAGE_ID] = { |
| 182 | .dev_handle = &storage_dev_handle, |
| 183 | .image_spec = (uintptr_t)&stm32image_block_spec, |
| 184 | .check = open_storage |
| 185 | } |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | static int open_dummy(const uintptr_t spec) |
| 189 | { |
| 190 | return io_dev_init(dummy_dev_handle, 0); |
| 191 | } |
| 192 | |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 193 | static int open_image(const uintptr_t spec) |
| 194 | { |
| 195 | return io_dev_init(image_dev_handle, 0); |
| 196 | } |
| 197 | |
| 198 | static int open_storage(const uintptr_t spec) |
| 199 | { |
| 200 | return io_dev_init(storage_dev_handle, 0); |
| 201 | } |
| 202 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 203 | static void print_boot_device(boot_api_context_t *boot_context) |
| 204 | { |
| 205 | switch (boot_context->boot_interface_selected) { |
| 206 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD: |
| 207 | INFO("Using SDMMC\n"); |
| 208 | break; |
| 209 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC: |
| 210 | INFO("Using EMMC\n"); |
| 211 | break; |
| 212 | default: |
| 213 | ERROR("Boot interface not found\n"); |
| 214 | panic(); |
| 215 | break; |
| 216 | } |
| 217 | |
| 218 | if (boot_context->boot_interface_instance != 0U) { |
| 219 | INFO(" Instance %d\n", boot_context->boot_interface_instance); |
| 220 | } |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 221 | } |
| 222 | |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 223 | #if STM32MP_SDMMC || STM32MP_EMMC |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 224 | static void boot_mmc(enum mmc_device_type mmc_dev_type, |
| 225 | uint16_t boot_interface_instance) |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 226 | { |
| 227 | int io_result __unused; |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 228 | uint8_t idx; |
| 229 | struct stm32image_part_info *part; |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 230 | struct stm32_sdmmc2_params params; |
| 231 | struct mmc_device_info device_info; |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 232 | const partition_entry_t *entry; |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 233 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 234 | zeromem(&device_info, sizeof(struct mmc_device_info)); |
| 235 | zeromem(¶ms, sizeof(struct stm32_sdmmc2_params)); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 236 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 237 | device_info.mmc_dev_type = mmc_dev_type; |
| 238 | |
| 239 | switch (boot_interface_instance) { |
| 240 | case 1: |
| 241 | params.reg_base = STM32MP_SDMMC1_BASE; |
| 242 | break; |
| 243 | case 2: |
| 244 | params.reg_base = STM32MP_SDMMC2_BASE; |
| 245 | break; |
| 246 | case 3: |
| 247 | params.reg_base = STM32MP_SDMMC3_BASE; |
| 248 | break; |
| 249 | default: |
| 250 | WARN("SDMMC instance not found, using default\n"); |
| 251 | if (mmc_dev_type == MMC_IS_SD) { |
| 252 | params.reg_base = STM32MP_SDMMC1_BASE; |
| 253 | } else { |
| 254 | params.reg_base = STM32MP_SDMMC2_BASE; |
| 255 | } |
| 256 | break; |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 257 | } |
| 258 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 259 | params.device_info = &device_info; |
| 260 | if (stm32_sdmmc2_mmc_init(¶ms) != 0) { |
| 261 | ERROR("SDMMC%u init failed\n", boot_interface_instance); |
| 262 | panic(); |
| 263 | } |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 264 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 265 | /* Open MMC as a block device to read GPT table */ |
| 266 | io_result = register_io_dev_block(&mmc_dev_con); |
| 267 | if (io_result != 0) { |
| 268 | panic(); |
| 269 | } |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 270 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 271 | io_result = io_dev_open(mmc_dev_con, (uintptr_t)&mmc_block_dev_spec, |
| 272 | &storage_dev_handle); |
| 273 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 274 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 275 | partition_init(GPT_IMAGE_ID); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 276 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 277 | io_result = io_dev_close(storage_dev_handle); |
| 278 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 279 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 280 | stm32image_dev_info_spec.device_size = |
| 281 | stm32_sdmmc2_mmc_get_device_size(); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 282 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 283 | for (idx = 0U; idx < IMG_IDX_NUM; idx++) { |
| 284 | part = &stm32image_dev_info_spec.part_info[idx]; |
| 285 | entry = get_partition_entry(part->name); |
| 286 | if (entry == NULL) { |
| 287 | ERROR("Partition %s not found\n", part->name); |
Yann Gautier | 03f0468 | 2018-11-29 15:44:04 +0100 | [diff] [blame] | 288 | panic(); |
| 289 | } |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 290 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 291 | part->part_offset = entry->start; |
| 292 | part->bkp_offset = 0U; |
| 293 | } |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 294 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 295 | /* |
| 296 | * Re-open MMC with io_mmc, for better perfs compared to |
| 297 | * io_block. |
| 298 | */ |
| 299 | io_result = register_io_dev_mmc(&mmc_dev_con); |
| 300 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 301 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 302 | io_result = io_dev_open(mmc_dev_con, 0, &storage_dev_handle); |
| 303 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 304 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 305 | io_result = register_io_dev_stm32image(&stm32image_dev_con); |
| 306 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 307 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 308 | io_result = io_dev_open(stm32image_dev_con, |
| 309 | (uintptr_t)&stm32image_dev_info_spec, |
| 310 | &image_dev_handle); |
| 311 | assert(io_result == 0); |
| 312 | } |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 313 | #endif /* STM32MP_SDMMC || STM32MP_EMMC */ |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 314 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 315 | void stm32mp_io_setup(void) |
| 316 | { |
| 317 | int io_result __unused; |
| 318 | boot_api_context_t *boot_context = |
| 319 | (boot_api_context_t *)stm32mp_get_boot_ctx_address(); |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 320 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 321 | print_boot_device(boot_context); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 322 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 323 | if ((boot_context->boot_partition_used_toboot == 1U) || |
| 324 | (boot_context->boot_partition_used_toboot == 2U)) { |
| 325 | INFO("Boot used partition fsbl%d\n", |
| 326 | boot_context->boot_partition_used_toboot); |
| 327 | } |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 328 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 329 | io_result = register_io_dev_dummy(&dummy_dev_con); |
| 330 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 331 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 332 | io_result = io_dev_open(dummy_dev_con, dummy_dev_spec, |
| 333 | &dummy_dev_handle); |
| 334 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 335 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 336 | switch (boot_context->boot_interface_selected) { |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 337 | #if STM32MP_SDMMC |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 338 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD: |
| 339 | dmbsy(); |
| 340 | boot_mmc(MMC_IS_SD, boot_context->boot_interface_instance); |
| 341 | break; |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 342 | #endif |
| 343 | #if STM32MP_EMMC |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 344 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC: |
| 345 | dmbsy(); |
| 346 | boot_mmc(MMC_IS_EMMC, boot_context->boot_interface_instance); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 347 | break; |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 348 | #endif |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 349 | |
| 350 | default: |
| 351 | ERROR("Boot interface %d not supported\n", |
| 352 | boot_context->boot_interface_selected); |
| 353 | break; |
| 354 | } |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /* |
| 358 | * Return an IO device handle and specification which can be used to access |
| 359 | * an image. Use this to enforce platform load policy. |
| 360 | */ |
| 361 | int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle, |
| 362 | uintptr_t *image_spec) |
| 363 | { |
| 364 | int rc; |
| 365 | const struct plat_io_policy *policy; |
| 366 | |
| 367 | assert(image_id < ARRAY_SIZE(policies)); |
| 368 | |
| 369 | policy = &policies[image_id]; |
| 370 | rc = policy->check(policy->image_spec); |
| 371 | if (rc == 0) { |
| 372 | *image_spec = policy->image_spec; |
| 373 | *dev_handle = *(policy->dev_handle); |
| 374 | } |
| 375 | |
| 376 | return rc; |
| 377 | } |