Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 1 | /* |
Yann Gautier | ac22dd5 | 2021-03-22 14:22:14 +0100 | [diff] [blame] | 2 | * Copyright (c) 2015-2021, 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 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <arch_helpers.h> |
| 11 | #include <common/debug.h> |
Yann Gautier | a3bd8d1 | 2021-06-18 11:33:26 +0200 | [diff] [blame] | 12 | #include <common/desc_image_load.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 13 | #include <drivers/io/io_block.h> |
| 14 | #include <drivers/io/io_driver.h> |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 15 | #include <drivers/io/io_fip.h> |
Lionel Debieve | 402a46b | 2019-11-04 12:28:15 +0100 | [diff] [blame] | 16 | #include <drivers/io/io_mtd.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 17 | #include <drivers/io/io_storage.h> |
| 18 | #include <drivers/mmc.h> |
| 19 | #include <drivers/partition/partition.h> |
Lionel Debieve | 402a46b | 2019-11-04 12:28:15 +0100 | [diff] [blame] | 20 | #include <drivers/raw_nand.h> |
Lionel Debieve | 186b046 | 2019-09-24 18:30:12 +0200 | [diff] [blame] | 21 | #include <drivers/spi_nand.h> |
Lionel Debieve | cb0dbc4 | 2019-09-25 09:11:31 +0200 | [diff] [blame] | 22 | #include <drivers/spi_nor.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 23 | #include <drivers/st/io_mmc.h> |
Lionel Debieve | 402a46b | 2019-11-04 12:28:15 +0100 | [diff] [blame] | 24 | #include <drivers/st/stm32_fmc2_nand.h> |
Lionel Debieve | 186b046 | 2019-09-24 18:30:12 +0200 | [diff] [blame] | 25 | #include <drivers/st/stm32_qspi.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 26 | #include <drivers/st/stm32_sdmmc2.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 27 | #include <lib/mmio.h> |
| 28 | #include <lib/utils.h> |
| 29 | #include <plat/common/platform.h> |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 30 | #include <tools_share/firmware_image_package.h> |
| 31 | |
| 32 | #include <platform_def.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 33 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 34 | /* IO devices */ |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 35 | uintptr_t fip_dev_handle; |
| 36 | uintptr_t storage_dev_handle; |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 37 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 38 | static const io_dev_connector_t *fip_dev_con; |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 39 | |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 40 | #if STM32MP_SDMMC || STM32MP_EMMC |
Yann Gautier | ac22dd5 | 2021-03-22 14:22:14 +0100 | [diff] [blame] | 41 | static struct mmc_device_info mmc_info; |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 42 | static io_block_spec_t gpt_block_spec = { |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 43 | .offset = 0U, |
| 44 | .length = 34U * MMC_BLOCK_SIZE, /* Size of GPT table */ |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
Yann Gautier | f9af3bc | 2018-11-09 15:57:18 +0100 | [diff] [blame] | 47 | static uint32_t block_buffer[MMC_BLOCK_SIZE] __aligned(MMC_BLOCK_SIZE); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 48 | |
Yann Gautier | a3bd8d1 | 2021-06-18 11:33:26 +0200 | [diff] [blame] | 49 | static io_block_dev_spec_t mmc_block_dev_spec = { |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 50 | /* It's used as temp buffer in block driver */ |
| 51 | .buffer = { |
| 52 | .offset = (size_t)&block_buffer, |
| 53 | .length = MMC_BLOCK_SIZE, |
| 54 | }, |
| 55 | .ops = { |
| 56 | .read = mmc_read_blocks, |
| 57 | .write = NULL, |
| 58 | }, |
| 59 | .block_size = MMC_BLOCK_SIZE, |
| 60 | }; |
Vyacheslav Yurkov | e43a080 | 2021-06-04 10:10:51 +0200 | [diff] [blame] | 61 | |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 62 | static const io_dev_connector_t *mmc_dev_con; |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 63 | #endif /* STM32MP_SDMMC || STM32MP_EMMC */ |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 64 | |
Lionel Debieve | cb0dbc4 | 2019-09-25 09:11:31 +0200 | [diff] [blame] | 65 | #if STM32MP_SPI_NOR |
| 66 | static io_mtd_dev_spec_t spi_nor_dev_spec = { |
| 67 | .ops = { |
| 68 | .init = spi_nor_init, |
| 69 | .read = spi_nor_read, |
| 70 | }, |
| 71 | }; |
| 72 | #endif |
| 73 | |
Lionel Debieve | 402a46b | 2019-11-04 12:28:15 +0100 | [diff] [blame] | 74 | #if STM32MP_RAW_NAND |
| 75 | static io_mtd_dev_spec_t nand_dev_spec = { |
| 76 | .ops = { |
| 77 | .init = nand_raw_init, |
| 78 | .read = nand_read, |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 79 | .seek = nand_seek_bb |
Lionel Debieve | 402a46b | 2019-11-04 12:28:15 +0100 | [diff] [blame] | 80 | }, |
| 81 | }; |
| 82 | |
| 83 | static const io_dev_connector_t *nand_dev_con; |
| 84 | #endif |
| 85 | |
Lionel Debieve | 186b046 | 2019-09-24 18:30:12 +0200 | [diff] [blame] | 86 | #if STM32MP_SPI_NAND |
| 87 | static io_mtd_dev_spec_t spi_nand_dev_spec = { |
| 88 | .ops = { |
| 89 | .init = spi_nand_init, |
| 90 | .read = nand_read, |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 91 | .seek = nand_seek_bb |
Lionel Debieve | 186b046 | 2019-09-24 18:30:12 +0200 | [diff] [blame] | 92 | }, |
| 93 | }; |
Lionel Debieve | cb0dbc4 | 2019-09-25 09:11:31 +0200 | [diff] [blame] | 94 | #endif |
Lionel Debieve | 186b046 | 2019-09-24 18:30:12 +0200 | [diff] [blame] | 95 | |
Lionel Debieve | cb0dbc4 | 2019-09-25 09:11:31 +0200 | [diff] [blame] | 96 | #if STM32MP_SPI_NAND || STM32MP_SPI_NOR |
Lionel Debieve | 186b046 | 2019-09-24 18:30:12 +0200 | [diff] [blame] | 97 | static const io_dev_connector_t *spi_dev_con; |
| 98 | #endif |
| 99 | |
Yann Gautier | 658775c | 2021-07-06 10:00:44 +0200 | [diff] [blame^] | 100 | static const io_uuid_spec_t fw_config_uuid_spec = { |
| 101 | .uuid = UUID_FW_CONFIG, |
| 102 | }; |
| 103 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 104 | static const io_uuid_spec_t bl33_partition_spec = { |
| 105 | .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33 |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 106 | }; |
| 107 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 108 | static const io_uuid_spec_t tos_fw_config_uuid_spec = { |
| 109 | .uuid = UUID_TOS_FW_CONFIG, |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 110 | }; |
| 111 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 112 | static const io_uuid_spec_t hw_config_uuid_spec = { |
| 113 | .uuid = UUID_HW_CONFIG, |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 114 | }; |
| 115 | |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 116 | #ifdef AARCH32_SP_OPTEE |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 117 | static const io_uuid_spec_t optee_header_partition_spec = { |
| 118 | .uuid = UUID_SECURE_PAYLOAD_BL32 |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 119 | }; |
| 120 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 121 | static const io_uuid_spec_t optee_core_partition_spec = { |
| 122 | .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1 |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 123 | }; |
| 124 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 125 | static const io_uuid_spec_t optee_paged_partition_spec = { |
| 126 | .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA2 |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 127 | }; |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 128 | #else |
| 129 | static const io_uuid_spec_t bl32_partition_spec = { |
| 130 | .uuid = UUID_SECURE_PAYLOAD_BL32 |
| 131 | }; |
| 132 | #endif |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 133 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 134 | static io_block_spec_t image_block_spec = { |
| 135 | .offset = 0U, |
| 136 | .length = 0U, |
| 137 | }; |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 138 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 139 | static int open_fip(const uintptr_t spec); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 140 | static int open_storage(const uintptr_t spec); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 141 | |
| 142 | struct plat_io_policy { |
| 143 | uintptr_t *dev_handle; |
| 144 | uintptr_t image_spec; |
| 145 | int (*check)(const uintptr_t spec); |
| 146 | }; |
| 147 | |
| 148 | static const struct plat_io_policy policies[] = { |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 149 | [FIP_IMAGE_ID] = { |
| 150 | .dev_handle = &storage_dev_handle, |
| 151 | .image_spec = (uintptr_t)&image_block_spec, |
| 152 | .check = open_storage |
| 153 | }, |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 154 | #ifdef AARCH32_SP_OPTEE |
| 155 | [BL32_IMAGE_ID] = { |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 156 | .dev_handle = &fip_dev_handle, |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 157 | .image_spec = (uintptr_t)&optee_header_partition_spec, |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 158 | .check = open_fip |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 159 | }, |
| 160 | [BL32_EXTRA1_IMAGE_ID] = { |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 161 | .dev_handle = &fip_dev_handle, |
Yann Gautier | ebf15ba | 2021-05-19 16:10:25 +0200 | [diff] [blame] | 162 | .image_spec = (uintptr_t)&optee_core_partition_spec, |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 163 | .check = open_fip |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 164 | }, |
| 165 | [BL32_EXTRA2_IMAGE_ID] = { |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 166 | .dev_handle = &fip_dev_handle, |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 167 | .image_spec = (uintptr_t)&optee_paged_partition_spec, |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 168 | .check = open_fip |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 169 | }, |
| 170 | #else |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 171 | [BL32_IMAGE_ID] = { |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 172 | .dev_handle = &fip_dev_handle, |
| 173 | .image_spec = (uintptr_t)&bl32_partition_spec, |
| 174 | .check = open_fip |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 175 | }, |
Yann Gautier | b3386f7 | 2019-04-19 09:41:01 +0200 | [diff] [blame] | 176 | #endif |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 177 | [BL33_IMAGE_ID] = { |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 178 | .dev_handle = &fip_dev_handle, |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 179 | .image_spec = (uintptr_t)&bl33_partition_spec, |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 180 | .check = open_fip |
| 181 | }, |
Yann Gautier | 658775c | 2021-07-06 10:00:44 +0200 | [diff] [blame^] | 182 | [FW_CONFIG_ID] = { |
| 183 | .dev_handle = &fip_dev_handle, |
| 184 | .image_spec = (uintptr_t)&fw_config_uuid_spec, |
| 185 | .check = open_fip |
| 186 | }, |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 187 | [TOS_FW_CONFIG_ID] = { |
| 188 | .dev_handle = &fip_dev_handle, |
| 189 | .image_spec = (uintptr_t)&tos_fw_config_uuid_spec, |
| 190 | .check = open_fip |
| 191 | }, |
| 192 | [HW_CONFIG_ID] = { |
| 193 | .dev_handle = &fip_dev_handle, |
| 194 | .image_spec = (uintptr_t)&hw_config_uuid_spec, |
| 195 | .check = open_fip |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 196 | }, |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 197 | #if STM32MP_SDMMC || STM32MP_EMMC |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 198 | [GPT_IMAGE_ID] = { |
| 199 | .dev_handle = &storage_dev_handle, |
| 200 | .image_spec = (uintptr_t)&gpt_block_spec, |
| 201 | .check = open_storage |
| 202 | }, |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 203 | #endif |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 204 | }; |
| 205 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 206 | static int open_fip(const uintptr_t spec) |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 207 | { |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 208 | return io_dev_init(fip_dev_handle, (uintptr_t)FIP_IMAGE_ID); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 209 | } |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 210 | |
| 211 | static int open_storage(const uintptr_t spec) |
| 212 | { |
| 213 | return io_dev_init(storage_dev_handle, 0); |
| 214 | } |
Vyacheslav Yurkov | e43a080 | 2021-06-04 10:10:51 +0200 | [diff] [blame] | 215 | |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 216 | static void print_boot_device(boot_api_context_t *boot_context) |
| 217 | { |
| 218 | switch (boot_context->boot_interface_selected) { |
| 219 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD: |
| 220 | INFO("Using SDMMC\n"); |
| 221 | break; |
| 222 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC: |
| 223 | INFO("Using EMMC\n"); |
| 224 | break; |
Lionel Debieve | cb0dbc4 | 2019-09-25 09:11:31 +0200 | [diff] [blame] | 225 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI: |
| 226 | INFO("Using QSPI NOR\n"); |
| 227 | break; |
Lionel Debieve | 402a46b | 2019-11-04 12:28:15 +0100 | [diff] [blame] | 228 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC: |
| 229 | INFO("Using FMC NAND\n"); |
| 230 | break; |
Lionel Debieve | 186b046 | 2019-09-24 18:30:12 +0200 | [diff] [blame] | 231 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI: |
| 232 | INFO("Using SPI NAND\n"); |
| 233 | break; |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 234 | default: |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 235 | ERROR("Boot interface %u not found\n", |
| 236 | boot_context->boot_interface_selected); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 237 | panic(); |
| 238 | break; |
| 239 | } |
| 240 | |
| 241 | if (boot_context->boot_interface_instance != 0U) { |
| 242 | INFO(" Instance %d\n", boot_context->boot_interface_instance); |
| 243 | } |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 246 | #if STM32MP_SDMMC || STM32MP_EMMC |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 247 | static void boot_mmc(enum mmc_device_type mmc_dev_type, |
| 248 | uint16_t boot_interface_instance) |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 249 | { |
| 250 | int io_result __unused; |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 251 | struct stm32_sdmmc2_params params; |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 252 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 253 | zeromem(¶ms, sizeof(struct stm32_sdmmc2_params)); |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 254 | |
Yann Gautier | ac22dd5 | 2021-03-22 14:22:14 +0100 | [diff] [blame] | 255 | mmc_info.mmc_dev_type = mmc_dev_type; |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 256 | |
| 257 | switch (boot_interface_instance) { |
| 258 | case 1: |
| 259 | params.reg_base = STM32MP_SDMMC1_BASE; |
| 260 | break; |
| 261 | case 2: |
| 262 | params.reg_base = STM32MP_SDMMC2_BASE; |
| 263 | break; |
| 264 | case 3: |
| 265 | params.reg_base = STM32MP_SDMMC3_BASE; |
| 266 | break; |
| 267 | default: |
| 268 | WARN("SDMMC instance not found, using default\n"); |
| 269 | if (mmc_dev_type == MMC_IS_SD) { |
| 270 | params.reg_base = STM32MP_SDMMC1_BASE; |
| 271 | } else { |
| 272 | params.reg_base = STM32MP_SDMMC2_BASE; |
| 273 | } |
| 274 | break; |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 275 | } |
| 276 | |
Yann Gautier | ac22dd5 | 2021-03-22 14:22:14 +0100 | [diff] [blame] | 277 | params.device_info = &mmc_info; |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 278 | if (stm32_sdmmc2_mmc_init(¶ms) != 0) { |
| 279 | ERROR("SDMMC%u init failed\n", boot_interface_instance); |
| 280 | panic(); |
| 281 | } |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 282 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 283 | /* Open MMC as a block device to read GPT table */ |
| 284 | io_result = register_io_dev_block(&mmc_dev_con); |
| 285 | if (io_result != 0) { |
| 286 | panic(); |
| 287 | } |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 288 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 289 | io_result = io_dev_open(mmc_dev_con, (uintptr_t)&mmc_block_dev_spec, |
| 290 | &storage_dev_handle); |
| 291 | assert(io_result == 0); |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 292 | } |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 293 | #endif /* STM32MP_SDMMC || STM32MP_EMMC */ |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 294 | |
Lionel Debieve | cb0dbc4 | 2019-09-25 09:11:31 +0200 | [diff] [blame] | 295 | #if STM32MP_SPI_NOR |
| 296 | static void boot_spi_nor(boot_api_context_t *boot_context) |
| 297 | { |
| 298 | int io_result __unused; |
Lionel Debieve | cb0dbc4 | 2019-09-25 09:11:31 +0200 | [diff] [blame] | 299 | |
| 300 | io_result = stm32_qspi_init(); |
| 301 | assert(io_result == 0); |
| 302 | |
| 303 | io_result = register_io_dev_mtd(&spi_dev_con); |
| 304 | assert(io_result == 0); |
| 305 | |
| 306 | /* Open connections to device */ |
| 307 | io_result = io_dev_open(spi_dev_con, |
| 308 | (uintptr_t)&spi_nor_dev_spec, |
| 309 | &storage_dev_handle); |
| 310 | assert(io_result == 0); |
Lionel Debieve | cb0dbc4 | 2019-09-25 09:11:31 +0200 | [diff] [blame] | 311 | } |
| 312 | #endif /* STM32MP_SPI_NOR */ |
| 313 | |
Lionel Debieve | 402a46b | 2019-11-04 12:28:15 +0100 | [diff] [blame] | 314 | #if STM32MP_RAW_NAND |
| 315 | static void boot_fmc2_nand(boot_api_context_t *boot_context) |
| 316 | { |
| 317 | int io_result __unused; |
Lionel Debieve | 402a46b | 2019-11-04 12:28:15 +0100 | [diff] [blame] | 318 | |
| 319 | io_result = stm32_fmc2_init(); |
| 320 | assert(io_result == 0); |
| 321 | |
| 322 | /* Register the IO device on this platform */ |
| 323 | io_result = register_io_dev_mtd(&nand_dev_con); |
| 324 | assert(io_result == 0); |
| 325 | |
| 326 | /* Open connections to device */ |
| 327 | io_result = io_dev_open(nand_dev_con, (uintptr_t)&nand_dev_spec, |
| 328 | &storage_dev_handle); |
| 329 | assert(io_result == 0); |
Lionel Debieve | 402a46b | 2019-11-04 12:28:15 +0100 | [diff] [blame] | 330 | } |
| 331 | #endif /* STM32MP_RAW_NAND */ |
| 332 | |
Lionel Debieve | 186b046 | 2019-09-24 18:30:12 +0200 | [diff] [blame] | 333 | #if STM32MP_SPI_NAND |
| 334 | static void boot_spi_nand(boot_api_context_t *boot_context) |
| 335 | { |
| 336 | int io_result __unused; |
Lionel Debieve | 186b046 | 2019-09-24 18:30:12 +0200 | [diff] [blame] | 337 | |
| 338 | io_result = stm32_qspi_init(); |
| 339 | assert(io_result == 0); |
| 340 | |
| 341 | io_result = register_io_dev_mtd(&spi_dev_con); |
| 342 | assert(io_result == 0); |
| 343 | |
| 344 | /* Open connections to device */ |
| 345 | io_result = io_dev_open(spi_dev_con, |
| 346 | (uintptr_t)&spi_nand_dev_spec, |
| 347 | &storage_dev_handle); |
| 348 | assert(io_result == 0); |
Lionel Debieve | 186b046 | 2019-09-24 18:30:12 +0200 | [diff] [blame] | 349 | } |
| 350 | #endif /* STM32MP_SPI_NAND */ |
| 351 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 352 | void stm32mp_io_setup(void) |
| 353 | { |
| 354 | int io_result __unused; |
| 355 | boot_api_context_t *boot_context = |
| 356 | (boot_api_context_t *)stm32mp_get_boot_ctx_address(); |
Yann Gautier | f9d40d5 | 2019-01-17 14:41:46 +0100 | [diff] [blame] | 357 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 358 | print_boot_device(boot_context); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 359 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 360 | if ((boot_context->boot_partition_used_toboot == 1U) || |
| 361 | (boot_context->boot_partition_used_toboot == 2U)) { |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 362 | INFO("Boot used partition fsbl%u\n", |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 363 | boot_context->boot_partition_used_toboot); |
| 364 | } |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 365 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 366 | io_result = register_io_dev_fip(&fip_dev_con); |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 367 | assert(io_result == 0); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 368 | |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 369 | io_result = io_dev_open(fip_dev_con, (uintptr_t)NULL, |
| 370 | &fip_dev_handle); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 371 | |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 372 | switch (boot_context->boot_interface_selected) { |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 373 | #if STM32MP_SDMMC |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 374 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD: |
| 375 | dmbsy(); |
| 376 | boot_mmc(MMC_IS_SD, boot_context->boot_interface_instance); |
| 377 | break; |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 378 | #endif |
| 379 | #if STM32MP_EMMC |
Yann Gautier | eae3fbf | 2019-04-23 13:34:03 +0200 | [diff] [blame] | 380 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC: |
| 381 | dmbsy(); |
| 382 | boot_mmc(MMC_IS_EMMC, boot_context->boot_interface_instance); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 383 | break; |
Nicolas Le Bayon | 3f42cad | 2019-09-03 09:52:05 +0200 | [diff] [blame] | 384 | #endif |
Lionel Debieve | cb0dbc4 | 2019-09-25 09:11:31 +0200 | [diff] [blame] | 385 | #if STM32MP_SPI_NOR |
| 386 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI: |
| 387 | dmbsy(); |
| 388 | boot_spi_nor(boot_context); |
| 389 | break; |
| 390 | #endif |
Lionel Debieve | 402a46b | 2019-11-04 12:28:15 +0100 | [diff] [blame] | 391 | #if STM32MP_RAW_NAND |
| 392 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC: |
| 393 | dmbsy(); |
| 394 | boot_fmc2_nand(boot_context); |
| 395 | break; |
| 396 | #endif |
Lionel Debieve | 186b046 | 2019-09-24 18:30:12 +0200 | [diff] [blame] | 397 | #if STM32MP_SPI_NAND |
| 398 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI: |
| 399 | dmbsy(); |
| 400 | boot_spi_nand(boot_context); |
| 401 | break; |
| 402 | #endif |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 403 | |
| 404 | default: |
| 405 | ERROR("Boot interface %d not supported\n", |
| 406 | boot_context->boot_interface_selected); |
Yann Gautier | 4c2b73d | 2021-06-30 17:04:22 +0200 | [diff] [blame] | 407 | panic(); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 408 | break; |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
| 412 | int bl2_plat_handle_pre_image_load(unsigned int image_id) |
| 413 | { |
| 414 | static bool gpt_init_done __unused; |
| 415 | uint16_t boot_itf = stm32mp_get_boot_itf_selected(); |
| 416 | |
| 417 | switch (boot_itf) { |
| 418 | #if STM32MP_SDMMC || STM32MP_EMMC |
| 419 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_SD: |
| 420 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_EMMC: |
| 421 | if (!gpt_init_done) { |
| 422 | const partition_entry_t *entry; |
| 423 | |
| 424 | partition_init(GPT_IMAGE_ID); |
| 425 | entry = get_partition_entry(FIP_IMAGE_NAME); |
| 426 | if (entry == NULL) { |
| 427 | ERROR("Could NOT find the %s partition!\n", |
| 428 | FIP_IMAGE_NAME); |
| 429 | return -ENOENT; |
| 430 | } |
| 431 | |
| 432 | image_block_spec.offset = entry->start; |
| 433 | image_block_spec.length = entry->length; |
| 434 | |
| 435 | gpt_init_done = true; |
Yann Gautier | a3bd8d1 | 2021-06-18 11:33:26 +0200 | [diff] [blame] | 436 | } else { |
| 437 | bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id); |
| 438 | |
| 439 | mmc_block_dev_spec.buffer.offset = bl_mem_params->image_info.image_base; |
| 440 | mmc_block_dev_spec.buffer.length = bl_mem_params->image_info.image_max_size; |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | break; |
| 444 | #endif |
| 445 | |
| 446 | #if STM32MP_RAW_NAND || STM32MP_SPI_NAND |
| 447 | #if STM32MP_RAW_NAND |
| 448 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_FMC: |
| 449 | #endif |
| 450 | #if STM32MP_SPI_NAND |
| 451 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NAND_QSPI: |
| 452 | #endif |
| 453 | image_block_spec.offset = STM32MP_NAND_FIP_OFFSET; |
| 454 | break; |
| 455 | #endif |
| 456 | |
| 457 | #if STM32MP_SPI_NOR |
| 458 | case BOOT_API_CTX_BOOT_INTERFACE_SEL_FLASH_NOR_QSPI: |
| 459 | image_block_spec.offset = STM32MP_NOR_FIP_OFFSET; |
| 460 | break; |
| 461 | #endif |
| 462 | |
| 463 | default: |
| 464 | ERROR("FIP Not found\n"); |
| 465 | panic(); |
Yann Gautier | 8244e1d | 2018-10-15 09:36:58 +0200 | [diff] [blame] | 466 | } |
Yann Gautier | 0ed7b2a | 2021-05-19 18:48:16 +0200 | [diff] [blame] | 467 | |
| 468 | return 0; |
Yann Gautier | 4b0c72a | 2018-07-16 10:54:09 +0200 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | /* |
| 472 | * Return an IO device handle and specification which can be used to access |
| 473 | * an image. Use this to enforce platform load policy. |
| 474 | */ |
| 475 | int plat_get_image_source(unsigned int image_id, uintptr_t *dev_handle, |
| 476 | uintptr_t *image_spec) |
| 477 | { |
| 478 | int rc; |
| 479 | const struct plat_io_policy *policy; |
| 480 | |
| 481 | assert(image_id < ARRAY_SIZE(policies)); |
| 482 | |
| 483 | policy = &policies[image_id]; |
| 484 | rc = policy->check(policy->image_spec); |
| 485 | if (rc == 0) { |
| 486 | *image_spec = policy->image_spec; |
| 487 | *dev_handle = *(policy->dev_handle); |
| 488 | } |
| 489 | |
| 490 | return rc; |
| 491 | } |