Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 1 | /* |
Yann Gautier | 723133b | 2023-05-31 17:30:01 +0200 | [diff] [blame] | 2 | * Copyright (c) 2021-2024, STMicroelectronics - All Rights Reserved |
Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | |
| 9 | #include <common/debug.h> |
| 10 | #include <common/fdt_wrappers.h> |
| 11 | #include <drivers/io/io_storage.h> |
| 12 | #include <drivers/mmc.h> |
| 13 | #include <lib/fconf/fconf.h> |
| 14 | #include <lib/object_pool.h> |
| 15 | #include <libfdt.h> |
| 16 | #include <tools_share/firmware_image_package.h> |
| 17 | |
| 18 | #include <platform_def.h> |
Sughosh Ganu | 57c6f90 | 2021-11-10 15:24:56 +0530 | [diff] [blame] | 19 | #include <stm32mp_efi.h> |
Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 20 | #include <stm32mp_fconf_getter.h> |
| 21 | #include <stm32mp_io_storage.h> |
| 22 | |
| 23 | #if STM32MP_SDMMC || STM32MP_EMMC |
| 24 | static io_block_spec_t gpt_block_spec = { |
| 25 | .offset = 0U, |
| 26 | .length = 34U * MMC_BLOCK_SIZE, /* Size of GPT table */ |
| 27 | }; |
| 28 | #endif |
| 29 | |
Yann Gautier | 723133b | 2023-05-31 17:30:01 +0200 | [diff] [blame] | 30 | #if PSA_FWU_SUPPORT |
Yann Gautier | 6fbed5a | 2022-11-18 14:05:10 +0100 | [diff] [blame] | 31 | static io_block_spec_t metadata_block_spec = { |
Sughosh Ganu | d1f8713 | 2021-12-01 16:46:34 +0530 | [diff] [blame] | 32 | .offset = 0, /* To be filled at runtime */ |
| 33 | .length = 0, /* To be filled at runtime */ |
| 34 | }; |
Yann Gautier | 723133b | 2023-05-31 17:30:01 +0200 | [diff] [blame] | 35 | #endif /* PSA_FWU_SUPPORT */ |
Sughosh Ganu | d1f8713 | 2021-12-01 16:46:34 +0530 | [diff] [blame] | 36 | |
Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 37 | /* By default, STM32 platforms load images from the FIP */ |
| 38 | struct plat_io_policy policies[MAX_NUMBER_IDS] = { |
| 39 | [FIP_IMAGE_ID] = { |
Sughosh Ganu | 57c6f90 | 2021-11-10 15:24:56 +0530 | [diff] [blame] | 40 | .dev_handle = &storage_dev_handle, |
| 41 | .image_spec = (uintptr_t)&image_block_spec, |
| 42 | .img_type_guid = STM32MP_FIP_GUID, |
| 43 | .check = open_storage |
Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 44 | }, |
Lionel Debieve | 5adcd50 | 2022-10-05 16:51:12 +0200 | [diff] [blame] | 45 | #ifndef DECRYPTION_SUPPORT_none |
| 46 | [ENC_IMAGE_ID] = { |
| 47 | .dev_handle = &fip_dev_handle, |
| 48 | .image_spec = (uintptr_t)NULL, |
| 49 | .img_type_guid = NULL_GUID, |
| 50 | .check = open_fip |
| 51 | }, |
| 52 | #endif |
Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 53 | #if STM32MP_SDMMC || STM32MP_EMMC |
| 54 | [GPT_IMAGE_ID] = { |
Sughosh Ganu | 57c6f90 | 2021-11-10 15:24:56 +0530 | [diff] [blame] | 55 | .dev_handle = &storage_dev_handle, |
| 56 | .image_spec = (uintptr_t)&gpt_block_spec, |
| 57 | .img_type_guid = NULL_GUID, |
| 58 | .check = open_storage |
Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 59 | }, |
| 60 | #endif |
Yann Gautier | 723133b | 2023-05-31 17:30:01 +0200 | [diff] [blame] | 61 | #if PSA_FWU_SUPPORT |
Sughosh Ganu | d1f8713 | 2021-12-01 16:46:34 +0530 | [diff] [blame] | 62 | [FWU_METADATA_IMAGE_ID] = { |
| 63 | .dev_handle = &storage_dev_handle, |
| 64 | .image_spec = (uintptr_t)&metadata_block_spec, |
| 65 | .img_type_guid = NULL_GUID, |
| 66 | .check = open_storage |
| 67 | }, |
| 68 | [BKUP_FWU_METADATA_IMAGE_ID] = { |
| 69 | .dev_handle = &storage_dev_handle, |
| 70 | .image_spec = (uintptr_t)&metadata_block_spec, |
| 71 | .img_type_guid = NULL_GUID, |
| 72 | .check = open_storage |
| 73 | }, |
Yann Gautier | 723133b | 2023-05-31 17:30:01 +0200 | [diff] [blame] | 74 | #endif /* PSA_FWU_SUPPORT */ |
Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 75 | }; |
| 76 | |
Lionel Debieve | 13a668d | 2022-10-05 16:47:03 +0200 | [diff] [blame] | 77 | #define DEFAULT_UUID_NUMBER U(7) |
| 78 | |
Yann Gautier | 9189d16 | 2020-11-27 14:44:04 +0100 | [diff] [blame] | 79 | #ifdef __aarch64__ |
| 80 | #define BL31_UUID_NUMBER U(1) |
| 81 | #else |
| 82 | #define BL31_UUID_NUMBER U(0) |
| 83 | #endif |
| 84 | |
Lionel Debieve | 13a668d | 2022-10-05 16:47:03 +0200 | [diff] [blame] | 85 | #if TRUSTED_BOARD_BOOT |
| 86 | #define TBBR_UUID_NUMBER U(6) |
| 87 | #else |
| 88 | #define TBBR_UUID_NUMBER U(0) |
| 89 | #endif |
| 90 | |
Maxime Méré | b151f68 | 2024-09-13 17:57:58 +0200 | [diff] [blame] | 91 | #if STM32MP_DDR_FIP_IO_STORAGE |
| 92 | #define DDR_FW_UUID_NUMBER U(1) |
| 93 | #else |
| 94 | #define DDR_FW_UUID_NUMBER U(0) |
| 95 | #endif |
| 96 | |
Lionel Debieve | 13a668d | 2022-10-05 16:47:03 +0200 | [diff] [blame] | 97 | #define FCONF_ST_IO_UUID_NUMBER (DEFAULT_UUID_NUMBER + \ |
Yann Gautier | 9189d16 | 2020-11-27 14:44:04 +0100 | [diff] [blame] | 98 | BL31_UUID_NUMBER + \ |
Maxime Méré | b151f68 | 2024-09-13 17:57:58 +0200 | [diff] [blame] | 99 | TBBR_UUID_NUMBER + \ |
| 100 | DDR_FW_UUID_NUMBER) |
Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 101 | |
| 102 | static io_uuid_spec_t fconf_stm32mp_uuids[FCONF_ST_IO_UUID_NUMBER]; |
| 103 | static OBJECT_POOL_ARRAY(fconf_stm32mp_uuids_pool, fconf_stm32mp_uuids); |
| 104 | |
| 105 | struct policies_load_info { |
| 106 | unsigned int image_id; |
| 107 | const char *name; |
| 108 | }; |
| 109 | |
| 110 | /* image id to property name table */ |
| 111 | static const struct policies_load_info load_info[FCONF_ST_IO_UUID_NUMBER] = { |
Maxime Méré | b151f68 | 2024-09-13 17:57:58 +0200 | [diff] [blame] | 112 | #if STM32MP_DDR_FIP_IO_STORAGE |
| 113 | {DDR_FW_ID, "ddr_fw_uuid"}, |
| 114 | #endif |
Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 115 | {FW_CONFIG_ID, "fw_cfg_uuid"}, |
Yann Gautier | 9189d16 | 2020-11-27 14:44:04 +0100 | [diff] [blame] | 116 | #ifdef __aarch64__ |
| 117 | {BL31_IMAGE_ID, "bl31_uuid"}, |
| 118 | #endif |
Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 119 | {BL32_IMAGE_ID, "bl32_uuid"}, |
| 120 | {BL32_EXTRA1_IMAGE_ID, "bl32_extra1_uuid"}, |
| 121 | {BL32_EXTRA2_IMAGE_ID, "bl32_extra2_uuid"}, |
| 122 | {BL33_IMAGE_ID, "bl33_uuid"}, |
| 123 | {HW_CONFIG_ID, "hw_cfg_uuid"}, |
| 124 | {TOS_FW_CONFIG_ID, "tos_fw_cfg_uuid"}, |
Lionel Debieve | 13a668d | 2022-10-05 16:47:03 +0200 | [diff] [blame] | 125 | #if TRUSTED_BOARD_BOOT |
| 126 | {STM32MP_CONFIG_CERT_ID, "stm32mp_cfg_cert_uuid"}, |
| 127 | {TRUSTED_KEY_CERT_ID, "t_key_cert_uuid"}, |
| 128 | {TRUSTED_OS_FW_KEY_CERT_ID, "tos_fw_key_cert_uuid"}, |
| 129 | {NON_TRUSTED_FW_KEY_CERT_ID, "nt_fw_key_cert_uuid"}, |
| 130 | {TRUSTED_OS_FW_CONTENT_CERT_ID, "tos_fw_content_cert_uuid"}, |
| 131 | {NON_TRUSTED_FW_CONTENT_CERT_ID, "nt_fw_content_cert_uuid"}, |
| 132 | #endif /* TRUSTED_BOARD_BOOT */ |
Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | int fconf_populate_stm32mp_io_policies(uintptr_t config) |
| 136 | { |
| 137 | int node; |
| 138 | unsigned int i; |
| 139 | |
| 140 | /* As libfdt uses void *, we can't avoid this cast */ |
| 141 | const void *dtb = (void *)config; |
| 142 | |
| 143 | /* Assert the node offset point to "st,io-fip-handle" compatible property */ |
| 144 | const char *compatible_str = "st,io-fip-handle"; |
| 145 | |
| 146 | node = fdt_node_offset_by_compatible(dtb, -1, compatible_str); |
| 147 | if (node < 0) { |
| 148 | ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str); |
| 149 | return node; |
| 150 | } |
| 151 | |
| 152 | /* Locate the uuid cells and read the value for all the load info uuid */ |
| 153 | for (i = 0U; i < FCONF_ST_IO_UUID_NUMBER; i++) { |
| 154 | union uuid_helper_t uuid_helper; |
| 155 | io_uuid_spec_t *uuid_ptr; |
| 156 | int err; |
| 157 | |
| 158 | uuid_ptr = pool_alloc(&fconf_stm32mp_uuids_pool); |
| 159 | err = fdtw_read_uuid(dtb, node, load_info[i].name, 16, |
| 160 | (uint8_t *)&uuid_helper); |
| 161 | if (err < 0) { |
| 162 | WARN("FCONF: Read cell failed for %s\n", load_info[i].name); |
| 163 | return err; |
| 164 | } |
| 165 | |
| 166 | VERBOSE("FCONF: stm32mp-io_policies.%s cell found with value = " |
| 167 | "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n", |
| 168 | load_info[i].name, |
| 169 | uuid_helper.uuid_struct.time_low[0], uuid_helper.uuid_struct.time_low[1], |
| 170 | uuid_helper.uuid_struct.time_low[2], uuid_helper.uuid_struct.time_low[3], |
| 171 | uuid_helper.uuid_struct.time_mid[0], uuid_helper.uuid_struct.time_mid[1], |
| 172 | uuid_helper.uuid_struct.time_hi_and_version[0], |
| 173 | uuid_helper.uuid_struct.time_hi_and_version[1], |
| 174 | uuid_helper.uuid_struct.clock_seq_hi_and_reserved, |
| 175 | uuid_helper.uuid_struct.clock_seq_low, |
| 176 | uuid_helper.uuid_struct.node[0], uuid_helper.uuid_struct.node[1], |
| 177 | uuid_helper.uuid_struct.node[2], uuid_helper.uuid_struct.node[3], |
| 178 | uuid_helper.uuid_struct.node[4], uuid_helper.uuid_struct.node[5]); |
| 179 | |
| 180 | uuid_ptr->uuid = uuid_helper.uuid_struct; |
| 181 | policies[load_info[i].image_id].image_spec = (uintptr_t)uuid_ptr; |
Lionel Debieve | 5adcd50 | 2022-10-05 16:51:12 +0200 | [diff] [blame] | 182 | switch (load_info[i].image_id) { |
| 183 | #if ENCRYPT_BL32 && !defined(DECRYPTION_SUPPORT_none) |
| 184 | case BL32_IMAGE_ID: |
| 185 | case BL32_EXTRA1_IMAGE_ID: |
| 186 | case BL32_EXTRA2_IMAGE_ID: |
| 187 | policies[load_info[i].image_id].dev_handle = &enc_dev_handle; |
| 188 | policies[load_info[i].image_id].check = open_enc_fip; |
| 189 | break; |
| 190 | #endif |
| 191 | default: |
| 192 | policies[load_info[i].image_id].dev_handle = &fip_dev_handle; |
| 193 | policies[load_info[i].image_id].check = open_fip; |
| 194 | break; |
| 195 | } |
Yann Gautier | 29f1f94 | 2021-07-13 18:07:41 +0200 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | FCONF_REGISTER_POPULATOR(TB_FW, stm32mp_io, fconf_populate_stm32mp_io_policies); |