xref: /rk3399_ARM-atf/plat/arm/board/tc/tc_bl2_dpe.c (revision 4f5beb56de361577b3d517f8fa4f9ef569e65cba)
1e7f1181fSTamas Ban /*
2e7f1181fSTamas Ban  * Copyright (c) 2024, Arm Limited. All rights reserved.
3e7f1181fSTamas Ban  *
4e7f1181fSTamas Ban  * SPDX-License-Identifier: BSD-3-Clause
5e7f1181fSTamas Ban  */
6e7f1181fSTamas Ban 
7e7f1181fSTamas Ban #include <stdint.h>
8e7f1181fSTamas Ban 
903d388d8STamas Ban #include <common/debug.h>
107f8589cdSTamas Ban #include <drivers/arm/rse_comms.h>
11e7f1181fSTamas Ban #include <drivers/measured_boot/metadata.h>
127f8589cdSTamas Ban #include <drivers/measured_boot/rse/dice_prot_env.h>
13e7f1181fSTamas Ban #include <plat/arm/common/plat_arm.h>
14e7f1181fSTamas Ban #include <plat/common/platform.h>
15e7f1181fSTamas Ban #include <platform_def.h>
1603d388d8STamas Ban #include <tools_share/tbbr_oid.h>
17e7f1181fSTamas Ban 
18*4f5beb56STamas Ban #include "tc_dpe.h"
196df8d764STamas Ban 
20e7f1181fSTamas Ban /*
21e7f1181fSTamas Ban  * The content and the values of this array depends on:
22e7f1181fSTamas Ban  * - build config: Which components are loaded: SPMD, TOS, SPx, etc ?
23e7f1181fSTamas Ban  * - boot order: the last element in a layer should be treated differently.
24e7f1181fSTamas Ban  */
25e7f1181fSTamas Ban 
26e7f1181fSTamas Ban /*
27e7f1181fSTamas Ban  * TODO:
28e7f1181fSTamas Ban  *     - The content of the array must be tailored according to the build
29e7f1181fSTamas Ban  *       config (TOS, SPMD, etc). All loaded components (executables and
30e7f1181fSTamas Ban  *       config blobs) must be present in this array.
31e7f1181fSTamas Ban  *     - Current content is according to the Trusty build config.
32e7f1181fSTamas Ban  */
33e7f1181fSTamas Ban struct dpe_metadata tc_dpe_metadata[] = {
34e7f1181fSTamas Ban 	{
35e7f1181fSTamas Ban 		.id = BL31_IMAGE_ID,
366df8d764STamas Ban 		.cert_id = DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
37e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
38e7f1181fSTamas Ban 		.sw_type = MBOOT_BL31_IMAGE_STRING,
39e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
40e7f1181fSTamas Ban 		.retain_parent_context = true,
41e7f1181fSTamas Ban 		.create_certificate = false,
42e7f1181fSTamas Ban 		.pk_oid = BL31_IMAGE_KEY_OID },
43e7f1181fSTamas Ban 	{
44e7f1181fSTamas Ban 		.id = BL32_IMAGE_ID,
456df8d764STamas Ban 		.cert_id =  DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
46e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
47e7f1181fSTamas Ban 		.sw_type = MBOOT_BL32_IMAGE_STRING,
48e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
49e7f1181fSTamas Ban 		.retain_parent_context = true,
50e7f1181fSTamas Ban 		.create_certificate = false,
51e7f1181fSTamas Ban 		.pk_oid = BL32_IMAGE_KEY_OID },
52e7f1181fSTamas Ban 	{
53e7f1181fSTamas Ban 		.id = BL33_IMAGE_ID,
546df8d764STamas Ban 		.cert_id = DPE_HYPERVISOR_CERT_ID,
55e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
56e7f1181fSTamas Ban 		.sw_type = MBOOT_BL33_IMAGE_STRING,
57e7f1181fSTamas Ban 		.allow_new_context_to_derive = true,
58e7f1181fSTamas Ban 		.retain_parent_context = true,
59e7f1181fSTamas Ban 		.create_certificate = false,
60e7f1181fSTamas Ban 		.pk_oid = BL33_IMAGE_KEY_OID },
61e7f1181fSTamas Ban 
62e7f1181fSTamas Ban 	{
63e7f1181fSTamas Ban 		.id = HW_CONFIG_ID,
646df8d764STamas Ban 		.cert_id = DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
65e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
66e7f1181fSTamas Ban 		.sw_type = MBOOT_HW_CONFIG_STRING,
67e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
68e7f1181fSTamas Ban 		.retain_parent_context = true,
69e7f1181fSTamas Ban 		.create_certificate = false,
70e7f1181fSTamas Ban 		.pk_oid = HW_CONFIG_KEY_OID },
71e7f1181fSTamas Ban 	{
72e7f1181fSTamas Ban 		.id = NT_FW_CONFIG_ID,
736df8d764STamas Ban 		.cert_id = DPE_HYPERVISOR_CERT_ID,
74e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
75e7f1181fSTamas Ban 		.sw_type = MBOOT_NT_FW_CONFIG_STRING,
76e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
77e7f1181fSTamas Ban 		.retain_parent_context = true,
78e7f1181fSTamas Ban 		.create_certificate = false,
79e7f1181fSTamas Ban 		.pk_oid = NT_FW_CONFIG_KEY_OID },
80e7f1181fSTamas Ban 	{
81e7f1181fSTamas Ban 		.id = SCP_BL2_IMAGE_ID,
826df8d764STamas Ban 		.cert_id = DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
83e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
84e7f1181fSTamas Ban 		.sw_type = MBOOT_SCP_BL2_IMAGE_STRING,
85e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
86e7f1181fSTamas Ban 		.retain_parent_context = true,
87e7f1181fSTamas Ban 		.create_certificate = false,
88e7f1181fSTamas Ban 		.pk_oid = SCP_BL2_IMAGE_KEY_OID },
89e7f1181fSTamas Ban 	{
90e7f1181fSTamas Ban 		.id = SOC_FW_CONFIG_ID,
916df8d764STamas Ban 		.cert_id = DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
92e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
93e7f1181fSTamas Ban 		.sw_type = MBOOT_SOC_FW_CONFIG_STRING,
94e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
95e7f1181fSTamas Ban 		.retain_parent_context = true,
96e7f1181fSTamas Ban 		.create_certificate = false,
97e7f1181fSTamas Ban 		.pk_oid = SOC_FW_CONFIG_KEY_OID },
98e7f1181fSTamas Ban 	{
99e7f1181fSTamas Ban 		.id = TOS_FW_CONFIG_ID,
1006df8d764STamas Ban 		.cert_id = DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
101e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
102e7f1181fSTamas Ban 		.sw_type = MBOOT_TOS_FW_CONFIG_STRING,
103e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
104e7f1181fSTamas Ban 		.retain_parent_context = true,
105e7f1181fSTamas Ban 		.create_certificate = false,
106e7f1181fSTamas Ban 		.pk_oid = TOS_FW_CONFIG_KEY_OID },
107e7f1181fSTamas Ban #if defined(SPD_spmd)
108e7f1181fSTamas Ban 	{
109e7f1181fSTamas Ban 		.id = SP_PKG1_ID,
1106df8d764STamas Ban 		.cert_id = DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
111e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
112e7f1181fSTamas Ban 		.sw_type = MBOOT_SP1_STRING,
113e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
114e7f1181fSTamas Ban 		.retain_parent_context = true,
115e7f1181fSTamas Ban 		.create_certificate = true, /* With Trusty only one SP is loaded */
116e7f1181fSTamas Ban 		.pk_oid = NULL },
117e7f1181fSTamas Ban 	{
118e7f1181fSTamas Ban 		.id = SP_PKG2_ID,
1196df8d764STamas Ban 		.cert_id = DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
120e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
121e7f1181fSTamas Ban 		.sw_type = MBOOT_SP2_STRING,
122e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
123e7f1181fSTamas Ban 		.retain_parent_context = true,
124e7f1181fSTamas Ban 		.create_certificate = false,
125e7f1181fSTamas Ban 		.pk_oid = NULL },
126e7f1181fSTamas Ban 	{
127e7f1181fSTamas Ban 		.id = SP_PKG3_ID,
1286df8d764STamas Ban 		.cert_id = DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
129e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
130e7f1181fSTamas Ban 		.sw_type = MBOOT_SP3_STRING,
131e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
132e7f1181fSTamas Ban 		.retain_parent_context = true,
133e7f1181fSTamas Ban 		.create_certificate = false,
134e7f1181fSTamas Ban 		.pk_oid = NULL },
135e7f1181fSTamas Ban 	{
136e7f1181fSTamas Ban 		.id = SP_PKG4_ID,
1376df8d764STamas Ban 		.cert_id = DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
138e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
139e7f1181fSTamas Ban 		.sw_type = MBOOT_SP4_STRING,
140e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
141e7f1181fSTamas Ban 		.retain_parent_context = true,
142e7f1181fSTamas Ban 		.create_certificate = false,
143e7f1181fSTamas Ban 		.pk_oid = NULL },
144e7f1181fSTamas Ban 	{
145e7f1181fSTamas Ban 		.id = SP_PKG5_ID,
1466df8d764STamas Ban 		.cert_id = DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
147e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
148e7f1181fSTamas Ban 		.sw_type = MBOOT_SP5_STRING,
149e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
150e7f1181fSTamas Ban 		.retain_parent_context = true,
151e7f1181fSTamas Ban 		.create_certificate = false,
152e7f1181fSTamas Ban 		.pk_oid = NULL },
153e7f1181fSTamas Ban 	{
154e7f1181fSTamas Ban 		.id = SP_PKG6_ID,
1556df8d764STamas Ban 		.cert_id = DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
156e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
157e7f1181fSTamas Ban 		.sw_type = MBOOT_SP6_STRING,
158e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
159e7f1181fSTamas Ban 		.retain_parent_context = true,
160e7f1181fSTamas Ban 		.create_certificate = false,
161e7f1181fSTamas Ban 		.pk_oid = NULL },
162e7f1181fSTamas Ban 	{
163e7f1181fSTamas Ban 		.id = SP_PKG7_ID,
1646df8d764STamas Ban 		.cert_id = DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
165e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
166e7f1181fSTamas Ban 		.sw_type = MBOOT_SP7_STRING,
167e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
168e7f1181fSTamas Ban 		.retain_parent_context = true,
169e7f1181fSTamas Ban 		.create_certificate = false,
170e7f1181fSTamas Ban 		.pk_oid = NULL },
171e7f1181fSTamas Ban 	{
172e7f1181fSTamas Ban 		.id = SP_PKG8_ID,
1736df8d764STamas Ban 		.cert_id = DPE_CERT_ID_SAME_AS_PARENT, /* AP_BL2: DPE_AP_FW_CERT_ID */
174e7f1181fSTamas Ban 		.signer_id_size = SIGNER_ID_MIN_SIZE,
175e7f1181fSTamas Ban 		.sw_type = MBOOT_SP8_STRING,
176e7f1181fSTamas Ban 		.allow_new_context_to_derive = false,
177e7f1181fSTamas Ban 		.retain_parent_context = true,
178e7f1181fSTamas Ban 		.create_certificate = false,
179e7f1181fSTamas Ban 		.pk_oid = NULL },
180e7f1181fSTamas Ban 
181e7f1181fSTamas Ban #endif
182e7f1181fSTamas Ban 	{
183e7f1181fSTamas Ban 		.id = DPE_INVALID_ID }
184e7f1181fSTamas Ban };
185e7f1181fSTamas Ban 
18603d388d8STamas Ban /* Context handle is meant to be used by BL33. Sharing it via NT_FW_CONFIG */
18703d388d8STamas Ban static int new_ctx_handle;
18803d388d8STamas Ban 
1898e0fd0bfSTamas Ban void plat_dpe_share_context_handle(int *ctx_handle, int *parent_ctx_handle)
19003d388d8STamas Ban {
19103d388d8STamas Ban 	new_ctx_handle = *ctx_handle;
1928e0fd0bfSTamas Ban 
1938e0fd0bfSTamas Ban 	/* Irrelevant in BL2 because cold restart resumes CPU in BL1 */
1948e0fd0bfSTamas Ban 	(void)parent_ctx_handle;
19503d388d8STamas Ban }
19603d388d8STamas Ban 
197467bdf26STamas Ban void plat_dpe_get_context_handle(int *ctx_handle)
198467bdf26STamas Ban {
199467bdf26STamas Ban 	int rc;
200467bdf26STamas Ban 
201467bdf26STamas Ban 	rc = arm_get_tb_fw_info(ctx_handle);
202467bdf26STamas Ban 	if (rc != 0) {
203467bdf26STamas Ban 		ERROR("Unable to get DPE context handle from TB_FW_CONFIG\n");
204467bdf26STamas Ban 		/*
205467bdf26STamas Ban 		 * It is a fatal error because on FVP platform, BL2 software
206467bdf26STamas Ban 		 * assumes that a valid DPE context_handle is passed through
207467bdf26STamas Ban 		 * the DTB object by BL1.
208467bdf26STamas Ban 		 */
209467bdf26STamas Ban 		plat_panic_handler();
210467bdf26STamas Ban 	}
211467bdf26STamas Ban 
212467bdf26STamas Ban 	VERBOSE("Received DPE context handle: 0x%x\n", *ctx_handle);
213467bdf26STamas Ban }
214467bdf26STamas Ban 
215e7f1181fSTamas Ban void bl2_plat_mboot_init(void)
216e7f1181fSTamas Ban {
2177f8589cdSTamas Ban 	/* Initialize the communication channel between AP and RSE */
2187f8589cdSTamas Ban 	(void)rse_comms_init(PLAT_RSE_AP_SND_MHU_BASE,
2197f8589cdSTamas Ban 			     PLAT_RSE_AP_RCV_MHU_BASE);
220e7f1181fSTamas Ban 
221e7f1181fSTamas Ban 	dpe_init(tc_dpe_metadata);
222e7f1181fSTamas Ban }
223e7f1181fSTamas Ban 
224e7f1181fSTamas Ban void bl2_plat_mboot_finish(void)
225e7f1181fSTamas Ban {
22603d388d8STamas Ban 	int rc;
22703d388d8STamas Ban 
22803d388d8STamas Ban 	VERBOSE("Share DPE context handle with BL33: 0x%x\n", new_ctx_handle);
22903d388d8STamas Ban 	rc = arm_set_nt_fw_info(&new_ctx_handle);
23003d388d8STamas Ban 	if (rc != 0) {
23103d388d8STamas Ban 		ERROR("Unable to set DPE context handle in NT_FW_CONFIG\n");
23203d388d8STamas Ban 		/*
23303d388d8STamas Ban 		 * It is a fatal error because on TC platform, BL33 software
23403d388d8STamas Ban 		 * assumes that a valid DPE context_handle is passed through
23503d388d8STamas Ban 		 * the DTB object by BL2.
23603d388d8STamas Ban 		 */
23703d388d8STamas Ban 		plat_panic_handler();
23803d388d8STamas Ban 	}
239e7f1181fSTamas Ban }
240