blob: 5514c09c1433e411dfd65cfec977310822ce1c7f [file] [log] [blame]
Yann Gautier29f1f942021-07-13 18:07:41 +02001/*
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +01002 * Copyright (c) 2021-2023, STMicroelectronics - All Rights Reserved
Yann Gautier29f1f942021-07-13 18:07:41 +02003 *
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 Ganu57c6f902021-11-10 15:24:56 +053019#include <stm32mp_efi.h>
Yann Gautier29f1f942021-07-13 18:07:41 +020020#include <stm32mp_fconf_getter.h>
21#include <stm32mp_io_storage.h>
22
23#if STM32MP_SDMMC || STM32MP_EMMC
24static io_block_spec_t gpt_block_spec = {
25 .offset = 0U,
26 .length = 34U * MMC_BLOCK_SIZE, /* Size of GPT table */
27};
28#endif
29
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +010030#if (STM32MP_SDMMC || STM32MP_EMMC || STM32MP_SPI_NOR) && PSA_FWU_SUPPORT
Yann Gautier6fbed5a2022-11-18 14:05:10 +010031static io_block_spec_t metadata_block_spec = {
Sughosh Ganud1f87132021-12-01 16:46:34 +053032 .offset = 0, /* To be filled at runtime */
33 .length = 0, /* To be filled at runtime */
34};
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +010035#endif /* (STM32MP_SDMMC || STM32MP_EMMC || STM32MP_SPI_NOR) && PSA_FWU_SUPPORT */
Sughosh Ganud1f87132021-12-01 16:46:34 +053036
Yann Gautier29f1f942021-07-13 18:07:41 +020037/* By default, STM32 platforms load images from the FIP */
38struct plat_io_policy policies[MAX_NUMBER_IDS] = {
39 [FIP_IMAGE_ID] = {
Sughosh Ganu57c6f902021-11-10 15:24:56 +053040 .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 Gautier29f1f942021-07-13 18:07:41 +020044 },
Lionel Debieve5adcd502022-10-05 16:51:12 +020045#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 Gautier29f1f942021-07-13 18:07:41 +020053#if STM32MP_SDMMC || STM32MP_EMMC
54 [GPT_IMAGE_ID] = {
Sughosh Ganu57c6f902021-11-10 15:24:56 +053055 .dev_handle = &storage_dev_handle,
56 .image_spec = (uintptr_t)&gpt_block_spec,
57 .img_type_guid = NULL_GUID,
58 .check = open_storage
Yann Gautier29f1f942021-07-13 18:07:41 +020059 },
60#endif
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +010061#if (STM32MP_SDMMC || STM32MP_EMMC || STM32MP_SPI_NOR) && PSA_FWU_SUPPORT
Sughosh Ganud1f87132021-12-01 16:46:34 +053062 [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 },
Nicolas Toromanoff44adc4f2022-02-07 10:12:29 +010074#endif /* (STM32MP_SDMMC || STM32MP_EMMC || STM32MP_SPI_NOR) && PSA_FWU_SUPPORT */
Yann Gautier29f1f942021-07-13 18:07:41 +020075};
76
Lionel Debieve13a668d2022-10-05 16:47:03 +020077#define DEFAULT_UUID_NUMBER U(7)
78
79#if TRUSTED_BOARD_BOOT
80#define TBBR_UUID_NUMBER U(6)
81#else
82#define TBBR_UUID_NUMBER U(0)
83#endif
84
85#define FCONF_ST_IO_UUID_NUMBER (DEFAULT_UUID_NUMBER + \
86 TBBR_UUID_NUMBER)
Yann Gautier29f1f942021-07-13 18:07:41 +020087
88static io_uuid_spec_t fconf_stm32mp_uuids[FCONF_ST_IO_UUID_NUMBER];
89static OBJECT_POOL_ARRAY(fconf_stm32mp_uuids_pool, fconf_stm32mp_uuids);
90
91struct policies_load_info {
92 unsigned int image_id;
93 const char *name;
94};
95
96/* image id to property name table */
97static const struct policies_load_info load_info[FCONF_ST_IO_UUID_NUMBER] = {
98 {FW_CONFIG_ID, "fw_cfg_uuid"},
99 {BL32_IMAGE_ID, "bl32_uuid"},
100 {BL32_EXTRA1_IMAGE_ID, "bl32_extra1_uuid"},
101 {BL32_EXTRA2_IMAGE_ID, "bl32_extra2_uuid"},
102 {BL33_IMAGE_ID, "bl33_uuid"},
103 {HW_CONFIG_ID, "hw_cfg_uuid"},
104 {TOS_FW_CONFIG_ID, "tos_fw_cfg_uuid"},
Lionel Debieve13a668d2022-10-05 16:47:03 +0200105#if TRUSTED_BOARD_BOOT
106 {STM32MP_CONFIG_CERT_ID, "stm32mp_cfg_cert_uuid"},
107 {TRUSTED_KEY_CERT_ID, "t_key_cert_uuid"},
108 {TRUSTED_OS_FW_KEY_CERT_ID, "tos_fw_key_cert_uuid"},
109 {NON_TRUSTED_FW_KEY_CERT_ID, "nt_fw_key_cert_uuid"},
110 {TRUSTED_OS_FW_CONTENT_CERT_ID, "tos_fw_content_cert_uuid"},
111 {NON_TRUSTED_FW_CONTENT_CERT_ID, "nt_fw_content_cert_uuid"},
112#endif /* TRUSTED_BOARD_BOOT */
Yann Gautier29f1f942021-07-13 18:07:41 +0200113};
114
115int fconf_populate_stm32mp_io_policies(uintptr_t config)
116{
117 int node;
118 unsigned int i;
119
120 /* As libfdt uses void *, we can't avoid this cast */
121 const void *dtb = (void *)config;
122
123 /* Assert the node offset point to "st,io-fip-handle" compatible property */
124 const char *compatible_str = "st,io-fip-handle";
125
126 node = fdt_node_offset_by_compatible(dtb, -1, compatible_str);
127 if (node < 0) {
128 ERROR("FCONF: Can't find %s compatible in dtb\n", compatible_str);
129 return node;
130 }
131
132 /* Locate the uuid cells and read the value for all the load info uuid */
133 for (i = 0U; i < FCONF_ST_IO_UUID_NUMBER; i++) {
134 union uuid_helper_t uuid_helper;
135 io_uuid_spec_t *uuid_ptr;
136 int err;
137
138 uuid_ptr = pool_alloc(&fconf_stm32mp_uuids_pool);
139 err = fdtw_read_uuid(dtb, node, load_info[i].name, 16,
140 (uint8_t *)&uuid_helper);
141 if (err < 0) {
142 WARN("FCONF: Read cell failed for %s\n", load_info[i].name);
143 return err;
144 }
145
146 VERBOSE("FCONF: stm32mp-io_policies.%s cell found with value = "
147 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
148 load_info[i].name,
149 uuid_helper.uuid_struct.time_low[0], uuid_helper.uuid_struct.time_low[1],
150 uuid_helper.uuid_struct.time_low[2], uuid_helper.uuid_struct.time_low[3],
151 uuid_helper.uuid_struct.time_mid[0], uuid_helper.uuid_struct.time_mid[1],
152 uuid_helper.uuid_struct.time_hi_and_version[0],
153 uuid_helper.uuid_struct.time_hi_and_version[1],
154 uuid_helper.uuid_struct.clock_seq_hi_and_reserved,
155 uuid_helper.uuid_struct.clock_seq_low,
156 uuid_helper.uuid_struct.node[0], uuid_helper.uuid_struct.node[1],
157 uuid_helper.uuid_struct.node[2], uuid_helper.uuid_struct.node[3],
158 uuid_helper.uuid_struct.node[4], uuid_helper.uuid_struct.node[5]);
159
160 uuid_ptr->uuid = uuid_helper.uuid_struct;
161 policies[load_info[i].image_id].image_spec = (uintptr_t)uuid_ptr;
Lionel Debieve5adcd502022-10-05 16:51:12 +0200162 switch (load_info[i].image_id) {
163#if ENCRYPT_BL32 && !defined(DECRYPTION_SUPPORT_none)
164 case BL32_IMAGE_ID:
165 case BL32_EXTRA1_IMAGE_ID:
166 case BL32_EXTRA2_IMAGE_ID:
167 policies[load_info[i].image_id].dev_handle = &enc_dev_handle;
168 policies[load_info[i].image_id].check = open_enc_fip;
169 break;
170#endif
171 default:
172 policies[load_info[i].image_id].dev_handle = &fip_dev_handle;
173 policies[load_info[i].image_id].check = open_fip;
174 break;
175 }
Yann Gautier29f1f942021-07-13 18:07:41 +0200176 }
177
178 return 0;
179}
180
181FCONF_REGISTER_POPULATOR(TB_FW, stm32mp_io, fconf_populate_stm32mp_io_policies);